Skip to content
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

Metro fast refresh seems to break persistQueryClient sometimes? #8204

Open
NicholasGWK opened this issue Oct 21, 2024 · 1 comment
Open

Metro fast refresh seems to break persistQueryClient sometimes? #8204

NicholasGWK opened this issue Oct 21, 2024 · 1 comment

Comments

@NicholasGWK
Copy link

Describe the bug

Hey there! Love the library. Just reporting a "bug" (not sure it's actually a bug, but threw me off for awhile until I realized what was happening). If this is already taken care of and my problem is something else, feel free to close!

Basically, in dev mode with React Native + persistQueryClient + fast refresh turned on it seems like:

  • The app is wrapped in <QueryClientProvider> and hydrates the cache as expected
  • If a hydrated query is mounted, and you're working on the query/related code, when you save it throws away the state of the query as it unmounts and remounts
  • Since the cache has already been hydrated but now the query data has been thrown out, it seems like it does not grab the data from the persisted data again and just initializes as if it's empty

I'm not sure how react-query could handle this as it's just how fast refresh works, but I don't know how to do a workaround either without checking hydration/cache status a whole bunch manually which could get kind of difficult.

Thanks for the help!

Your minimal, reproducible example

None

Steps to reproduce

Sorry, I don't have time to do a minimal example right now, but I'll try to soon. Should be simple-ish to test though based on above steps?

  • Have a query
  • Persist it
  • Load the app and hydrate it
  • Modify the query code so fast refresh mounts/unmounts it
  • Query data is now uninitialized, doesn't re-hydrate

Expected behavior

As mentioned, I'm not sure what I'd expect, as this is kind of outside of react-query, but I'd like to know if there's a workaround in dev that doesn't involve manually ensuring that hydration has happened

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

macOS + React Native + Expo 51

Tanstack Query adapter

react-query

TanStack Query version

5.51.23

TypeScript version

No response

Additional context

No response

@TkDodo
Copy link
Collaborator

TkDodo commented Nov 3, 2024

Hmm, so we only hydrate once per QueryClient:

if (!didRestore.current) {
didRestore.current = true
persistQueryClientRestore(options).then(async () => {

I guess you could always call persistQueryClientRestore manually when a refresh happens on your end ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants