-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
useSuspenseQuery
do not respect cached data in persister
#8400
Comments
Thanks for filing, I think I know why that is. The app continues to render in an In that state, we’re not supposed to fire any fetches, because we aren’t subscribed to the store yet. However, with suspense, we’re throwing promises from the render function directly, so this gets bypassed. We could stop that fetch from happening, too, however, then So I think suspense is just not really compatible with restoring data like that. The best workaround I can offer is writing a Here’s a fork that shows this, and it works like you’d expect: https://stackblitz.com/edit/vitejs-vite-zxnzxn3p?file=index.tsx As |
This feels like a major footgun to me. I just switched on the persister and spent a while figuring out why half of my hooks don't seem to use it before realizing that it's the But more importantly: we definitely want both suspenses and local storage persistence. In one case of interest, we're fetching app/user config from an API. Since this config has exist before we can call any other API, it's a perfect candidate for a suspense high up in the tree. But, for exactly the same reasons, and because it rarely changes, it's also a perfect candidate for persistence in local storage, to save that round-trip on every refresh. (Especially during development.) How to choose?!? 🤷 Looking at your example above, I wonder if the |
generally I’d say no, otherwise, this would’ve been the default behaviour. If you have a |
I agree it should definitely be updated in the docs. Would be great if you could file a PR 🙏 |
Describe the bug
I would like to pre-cache
useQuery
data, so when the user visits app a second time, the app will show stale data, and refetch in background.I used persisted with
useQuery
before it was working as expected, but when I switched touseSuspenseQuery
, the cached data is not used anymore.Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-ihky3z?file=index.tsx
Steps to reproduce
localStorage
Expected behavior
The loader should not be shown for second time.
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
Tanstack Query adapter
react-query
TanStack Query version
5.62.2
TypeScript version
5.7.2
Additional context
No response
The text was updated successfully, but these errors were encountered: