fix(query-core): replace scheduleMicrotask with queueMicrotask #6592
main fromrefs/pull/6592/head·opened View on GitHubscheduleMicrotask was implemented incorrectly with setTimeout, causing the passed callback to run in the next task instead of a microtask. This sometimes resulted in a layout shift in my solid project. Fix this by replacing scheduleMicrotask with queueMicrotask, which is supported by all browsers query supports.12
Footnotes#
- 1
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit e78f591e2bda3e3b5b122f58088260a11491f229:
Sandbox Source @tanstack/query-example-angular-basic Configuration @tanstack/query-example-react-basic-typescript Configuration @tanstack/query-example-solid-basic-typescript Configuration @tanstack/query-example-svelte-basic Configuration @tanstack/query-example-vue-basic Configuration ☁️ Nx Cloud Report#
CI is running/has finished running commands for commit e78f591e2bda3e3b5b122f58088260a11491f229. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this CI Pipeline Execution
🟥 Failed Commands nx affected --targets=test:eslint,test:lib,test:types,test:build,test:bundle
Sent with 💌 from NxCloud.
There are different tradeoffs here. In react, this will likely result in more re-renders because fewer things can be batched together. This is likely shown in the failing tests. I think to not make this breaking, we could offer a batching strategy as an option somewhere, like timeout (default, current version), queueMicroTask and maybe even requestAnimationFrame that the user can choose from. I think redux toolkit has such an option: https://redux-toolkit.js.org/api/autoBatchEnhancer#autobatchenhancer-1
Hmm, I did not consider that, requestAnimationFrame could also be interesting. Maybe a setter on the notify manager like this:
function setBatchType(config: { type: 'raf' | 'tick' } | { type: 'timer', timeout?: number}) { /* ... */ }But then I'm not really sure how to expose this to the api surface in solid-query, react-query, etc.
Edit: I guess since they're re-exporting query-core that's not necessary
I implemented a PoC here: https://github.com/NathanHuisman/query/commit/38b41a31f42ddf6c79136074c95571644e9ce0be
Will add some tests later
That looks really good. I think we'd need some docs and tests, too please
I'm closing this pull request in favor of opening a new one with the new changes I made
Sign in to join this conversation.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment