Skip to content

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

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

Closed
JDMathew opened this issue May 14, 2025 · 2 comments
Labels
invalid This doesn't seem right

Comments

@JDMathew
Copy link

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

@TkDodo
Copy link
Collaborator

TkDodo commented May 14, 2025

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:

export function defaultShouldDehydrateQuery(query: Query) {
return query.state.status === 'success'
}

otherwise, you risk dehydrating non-serializable things.

@TkDodo TkDodo closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2025
@TkDodo TkDodo added the invalid This doesn't seem right label May 14, 2025
@JDMathew
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants