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

Additional context
react-query 2.23.0
next: 9.5.3
Hmmm. I was under the impression that we already had this error, but then @boschni fixed it. I'll double check with him. This needs to be a test case for sure.
No query function has been set because the hook never fetched. Think this can be solved by having the first observer to subscribe to a query also set its config
Fixed in V3
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?
Currently, the fix cannot be backported to v2 without inflicting breaking changes.
Not sure if it is the same bug, I see that the onSuccess handler is not triggered when I use refetch() on a query that is set with enabled: false.
My goal is to fetch data only on user-click, so the above combination should work. Everything works (click, data fetching, etc.) except of the automatic invocation of the onSuccess handler at the end.
Hello all, I'm also having this problem, is there a planned fix on the way ? Thanks!
@reabreu It appears that this is fixed in v3, I tested it and worked there.
@afilp Thanks for the information! Can I ask if v3 is recommended for production use already and if there is a migration guide? Looks to me the official documentation refers to v2 still?
Have a nice weekend!
@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
@afilp thanks for your help! Have a nice weekend!