-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#initialState set incorrectly to persisted state #6682
Comments
Did you manage to find any workaround? I tried messing with the state after queries are loaded from the persistent store, but I only ended up with inconsistent states. |
I ended up using a slightly different approach that works around this limitation. |
We are also running into this issue with v4. No solution yet, I tried changing the |
Describe the bug
When using
PersistQueryClientProvider
the query#initialState
will be set to the state loaded from storage on page/app load. RunningresetQueries
will now give unexpected behaviour across app reloads.Looks like hydrate is using QueryCache.build() to create queries
https://github.com/TanStack/query/blob/main/packages/query-core/src/hydration.ts#L145-L159
This will create a new Query:
https://github.com/TanStack/query/blob/main/packages/query-core/src/queryCache.ts#L111-L118
Since state is set, #initialState will be set to config.state
https://github.com/TanStack/query/blob/main/packages/query-core/src/query.ts#L177
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/query-async-test-rqf58n
Steps to reproduce
If this is the first time you open the page you should see in the console:
Data was now loaded from storage and you will see
Expected behavior
I expect
initialState
to be consistent across reloads. So when not settinginitialData
, runningresetQueries
will givestatus: 'pending', data: undefined
even after the query was loaded from storage. I think we should persist#initialState
to storage as well.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Any
Tanstack Query adapter
react-query
TanStack Query version
v5.17.9
TypeScript version
No response
Additional context
Discussion with @TkDodo
https://discord.com/channels/719702312431386674/1194615111529287820
The text was updated successfully, but these errors were encountered: