refetch query throws error if query was prefetched via SSR and cache hydration
See original GitHub issueDescribe the bug I have a simple query with following config
{staleTime: Infinity,
cacheTime: Infinity,
enabled: true}
that is prefetched via NextJS app.getInitialProps(). When trying to refetch such a query, e.g. via queryCache.invalidateQueries(...)
then the refetch fails & throws an error (afaik because the queryFn is not found/set).
To Reproduce Here is a sandbox: https://codesandbox.io/s/refetch-failed-for-prefetch-queries-w340e?file=/pages/index.js
Expected behavior the query is properly refetched.
Screenshots
Additional context react-query 2.23.0 next: 9.5.3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11
Top Results From Across the Web
refetch query throws error if query was prefetched via ... - GitHub
Describe the bug I have a simple query with following config {staleTime: Infinity, cacheTime: Infinity, enabled: true} that is prefetched ...
Read more >SSR | TanStack Query Docs
React Query supports two ways of prefetching data on the server and ... Prefetch the query on the server, dehydrate the cache and...
Read more >Refetching queries in Apollo Client - Apollo GraphQL Docs
The client.refetchQueries method collects the TResult results returned by onQueryUpdated , defaulting to TResult = Promise<ApolloQueryResult<any>> if ...
Read more >React Query v4 + SSR in Next JS - DEV Community
P.S : We used fetchQuery instead of prefetchQuery , because prefetchQuery doesn't throw any error or return any data. We will talk more...
Read more >Prefetching - Redux Toolkit
Prefetching. The goal of prefetching is to make data fetch before the user navigates to a page or attempts to load some known...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@reabreu Yes, we use v3 in production and it seems to work as expected. The documentation for version 3 migration is here: https://react-query-beta.tanstack.com/guides/migrating-to-react-query-3
We’re having the same issue. The fix sounds like it will solve our problem. Is there any way the fix can be back-ported to v2?