persistQueryClient does not synchronize cache invalidation across isolated JavaScript contexts
#10130
Unanswered
SEOKKAMONI
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
In our React Native application, each screen in the Stack Navigator renders a separate WebView loading a Next.js app. Since each WebView runs its own JavaScript runtime, each one instantiates its own
QueryClient.When a mutation in one screen invalidates a query, the invalidation does not propagate to the
QueryClientin another screen — even when usingpersistQueryClient.Steps to Reproduce
useQuery. Data is cached inQueryClient A.queryClient.invalidateQueries({ queryKey: ['reviews'] }).Why
persistQueryClientdid not helpWe attempted to solve this with
persistQueryClient, expecting that:This did not work because
persistQueryClientrestores the cache only duringQueryClientinitialization (whenhydrateis called at mount time). There is no mechanism for an already-mountedQueryClientto reactively subscribe to external changes in the persistence layer.In other words,
persistQueryClientis designed for cold-start restoration (e.g., app restart), not for real-time cross-instance synchronization.Questions
Is our understanding correct? Is
persistQueryClientintentionally scoped to initialization-time hydration only, with no support for runtime synchronization across multipleQueryClientinstances sharing the same persistence layer?Is there an existing or planned mechanism within TanStack Query to support cache synchronization across isolated JavaScript contexts (e.g., multiple WebViews, Web Workers, iframes)?
Thank you for your time and for the incredible work on TanStack Query.
Beta Was this translation helpful? Give feedback.
All reactions