Skip to content
Source
Sign inSign up
TanStack/query

Metro fast refresh seems to break persistQueryClient sometimes? #8204

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

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

  1. Hmm, so we only hydrate once per QueryClient:

    https://github.com/TanStack/query/blob/39a35d88cc6ece8bd8b3bc3d45f408272fc19fd7/packages/react-query-persist-client/src/PersistQueryClientProvider.tsx#L37-L39

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

  2. closing this as its pretty stale and has no proper reproduction

  3. TkDodo closed this

  4. TkDodo added labelsneeds-info

Sign in to join this conversation.