Describe the bug#
I'm not sure if this is an issue with @tanstack/query-async-storage-persister package or the @tanstack/react-query-persist-client package. I have implemented the base setup for async storage persister in a react native app with PersistQueryClientProvider as the provider instead of the imperative approach.
If the app is loading data from an API endpoint and the user force closes the app, the persisted data is left in a broken state. This will most likely cause the app to crash on next cold start. My understanding is that this is because the data saved may be a pending promise in some cases. In my case I expected some data to be a string but got: {"_h": 0, "_i": 0, "_j": null, "_k": null}
Another issue may be that some data may be partially defined and partially undefined.
Your minimal, reproducible example#
https://snack.expo.dev/@justinmathew/tanstack-async-persistence
Steps to reproduce#
Force close the app while data is fetching
Expected behavior#
The app shouldn't crash on cold start after failed data fetch
How often does this bug happen?#
None
Screenshots or Videos#
No response
Platform#
Tanstack Query adapter#
None
TanStack Query version#
5.76.1
TypeScript version#
No response
Additional context#
No response
if you implement
shouldDehydrateQuery, make sure to only include queries that are in’success’state. We do that per default and also export the util for this:https://github.com/TanStack/query/blob/e73d5b419ea4f1b1970affddbe28807899095422/packages/query-core/src/hydration.ts#L108-L110
otherwise, you risk dehydrating non-serializable things.