question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

refetch query throws error if query was prefetched via SSR and cache hydration

See original GitHub issue

Describe 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 screenshot

Additional context react-query 2.23.0 next: 9.5.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

1reaction
afilpcommented, Nov 6, 2020

@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

1reaction
chrisvaszcommented, Sep 30, 2020

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found