Skip to content
Source
Sign inSign up
TanStack/query

Async storage persister is saving pending Promise's and not the resulted data or undefined when app is closed #9148

Send to my agent
ClosedJDMathew(GitHub profile, opens in a new tab) opened this issue 2 comments

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

  • OS: [Android, iOS]

Tanstack Query adapter

None

TanStack Query version

5.76.1

TypeScript version

No response

Additional context

No response

  1. 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.

  2. TkDodo closed this

  3. TkDodo added labelsinvalid

  4. @TkDodo, that was the issue, thanks for the assist!

Sign in to join this conversation.