Describe the bug
Critical UI updates derived from queries can be batched into later cycles, creating a detrimental experience. We have a fairly large component that shows loading spinners derived from isLoading. We are using a mix of useQuery and useQueries, and unfortunately the internal batching strategy can lead to more critical visual updates being delayed. In this case, fewer re-renders is not good, as they occur near the tail end.
To Reproduce
There may be several variables, but here is our scenario:
- A large table with many rows
- Rows can display a loading spinner derived from
isLoading status
- Loading spinner display is heavily delayed, due to batching
- UX suffers
Expected behavior
I expect to be able to control data/renders in my own hooks with refs or state, and not always use the built-in batching behaviour.
Desktop (please complete the following information):
- OS: macOS Mojave
- Browser: Chrome
- Version: 87.0.4280.141
Additional context
As a quick, very naive hack, I replaced the scheduleMicrotask function here:
https://github.com/tannerlinsley/react-query/blob/80cecef22c3e088d6cd9f8fbc5cd9e2c0aab962f/src/core/utils.ts#L362
with the following:
export function scheduleMicrotask(callback) {
callback()
}
This substantially improved UI responsiveness in our case, dramatically improving timings by removing the batch update triggered from here:
https://github.com/tannerlinsley/react-query/blob/ac342e237ae9fab6759f2d7be616662da6c16225/src/core/notifyManager.ts#L68
I would like to request that batching either be opt-in or opt-out, either globally or maybe per query. I'd be perfectly happy with a global workaround if it provides a quicker resolution.
Edit: Forgot to mention I may be able to help with this depending on what the best course of action is!
Describe the bug
Critical UI updates derived from queries can be batched into later cycles, creating a detrimental experience. We have a fairly large component that shows loading spinners derived from
isLoading. We are using a mix ofuseQueryanduseQueries, and unfortunately the internal batching strategy can lead to more critical visual updates being delayed. In this case, fewer re-renders is not good, as they occur near the tail end.To Reproduce
There may be several variables, but here is our scenario:
isLoadingstatusExpected behavior
I expect to be able to control data/renders in my own hooks with refs or state, and not always use the built-in batching behaviour.
Desktop (please complete the following information):
Additional context
As a quick, very naive hack, I replaced the
scheduleMicrotaskfunction here:https://github.com/tannerlinsley/react-query/blob/80cecef22c3e088d6cd9f8fbc5cd9e2c0aab962f/src/core/utils.ts#L362
with the following:
This substantially improved UI responsiveness in our case, dramatically improving timings by removing the batch update triggered from here:
https://github.com/tannerlinsley/react-query/blob/ac342e237ae9fab6759f2d7be616662da6c16225/src/core/notifyManager.ts#L68
I would like to request that batching either be opt-in or opt-out, either globally or maybe per query. I'd be perfectly happy with a global workaround if it provides a quicker resolution.
Edit: Forgot to mention I may be able to help with this depending on what the best course of action is!