You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking at the “if” statement in the link, it looks like the intended behavior.
Wouldn't it probably go something like this?
(I used a translator)
You have a React component state (n) initially at n = 1
You click a button, updating the state to n = 2
A re-render is immediately triggered by React (the current state is n = 2)
A new array of queries with length 2 is created and passed into useQueries
Internally, React Query’s QueriesObserver.setQueries() method is called, updating the internal observers and their options based on the new queries
However, React Query does not immediately recalculate the results. Instead, it initially returns an optimistic result based on the previously cached state (from when n was still 1). Thus, the UI temporarily reflects the old state (queries array length = 1)
Afterwards, React Query’s internal observers asynchronously detect the updated query states, perform the actual recalculations, and update the internal state with the correct results
Finally, in the next render cycle, React Query passes the updated results (queries array length = 2) back to the component, causing the UI to reflect the latest state—but delayed by one render cycle
Describe the bug
Clicking a few times the "Increase" button would give those logs:
Which is not the correct behavior.
When I'm not using a stable reference, i.e. directly passing
combine
:I get those logs:
Which is the correct behavior.
Your minimal, reproducible example
https://codesandbox.io/p/devbox/dank-smoke-7h8ssj?file=%2Fsrc%2Findex.tsx
Steps to reproduce
Open the repro. Click on "Increase". Look at the logs.
Expected behavior
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
Linux
Chrome
Tanstack Query adapter
react-query
TanStack Query version
5.59.20
TypeScript version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: