-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"No QueryClient set" when upgrading from 3.12.0 to 3.12.1 #1936
Comments
Hm, I have seen something similar on stackoverflow: https://stackoverflow.com/questions/66553816/react-query-is-not-working-with-a-project-bootstrapped-with-vite what The QueryClient is now retrieved solely via react-context. If the |
@TkDodo Thanks for your response! I should have specified that I am indeed using Vite. That said, |
can you create a repo that I can check out that reproduces the issue? I have no idea what vite is or how it works 😅 . you can also try to turn on context sharing via the prop on the QueryClientProvider - that should "restore" the behaviour of 3.12.0. But again, we are just using react-context now :( |
@TkDodo I've added a reproduction to the original post! And I tried turning on context sharing but it does not appear to solve the issue. |
never mind that. cached service worker was showing the wrong app 😅 |
it seems that the react-query-devtools come with their own copy of react-query, and that they done use a different context or so. I have to admit that I don't quite understand how this bundling works, or how vite differs from create-react-app or webpack... |
@TkDodo do you think this is an issue that should be reported to Vite instead? I can't quite tell if |
it would be at least interesting to ask there, because it seems to work fine with other bundlers |
we have the same issue which prevent us from upgrading react-query to latest version |
@OliverwengFiltered Are you also using vite? |
I have the same issue in two projects: one using parcel and the other with a custom webpack config. |
@tannerlinsley can you maybe shed some light on how the devtools communicate with react-query? |
Oh, not sure if it matters, but I forgot to mention I am not using react-query-devtools. |
yes, that's fine. the |
@TkDodo I think you are onto something with there being two copies of |
Yes, I think so, too. Remaining questions:
FYI, here are the relevant changes I made in 3.12.1: v3.12.0...v3.12.1#diff-0cee58d9679ff6f79b5250cc0611ce6eaf8bc46a77416a09384ae4670adc9872R20-R67 |
@TkDodo Thanks for linking to the diff, I couldn't figure out how to get a diff between two versions earlier 😅 Here's my guess:
|
To answer the questions you posed more directly, to the best of my knowledge:
Webpack bundles things in a way that doesn't create two runtime copies of
Query client shared by default on
Query client is not shared by default on
That question remains! |
that sounds spot on! Yes, I had to use another context to know if the context shared on the window should be used when getting the real context. A bit complex, but a legit solution I think. Of course, the I do think that we should not have two copies of react-query -I hope that we can somehow find a fix for packaging up the devtools to not come with their own copy :) |
@TkDodo Oh I didn't realise you were the one who implemented those context sharing changes! Yeah, I think those changes were perfectly legitimate and the underlying issue here is the two copies of |
I'm not sure if it helps anyone, but I've got same problem when using WMR (which prepares dev server more or less similar way as Vite does). |
Any update on this one? |
I'm also encountering this issue when upgrading above 3.12 |
So I just tried this out on a |
This same issue is present in the Next.js example provided in this repo https://github.com/tannerlinsley/react-query/tree/master/examples/nextjs. Explicitly installing [email protected] resolves this. Does the example project need updating, or is this something that is incorrect in the 3.12.1 and up package? |
We are experiencing this issue with If we remove the |
The analysis by @hmaurer is spot on. Hydration is also affected by an identical problem which I've opened a separate issue for. This devtools-issue is a bit more involved than the hydration one, but it stems from this line: import { useQueryClient } from '../react'
// Should probably be:
// import { useQueryClient } from 'react-query' Because the reference here is relative, the whole I'm also guessing that if you build your |
Hydration and the NextJS-example should now be fixed as well by #2121 which was released as |
@TkDodo @Ephem I am still getting
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
},
mutations: {},
},
}) and I'm using Parcel v |
hmm, I'm on parcel |
I wasn't able reproduce it in a simple repo, probably because my actual case is a bit more complicated. Let me try to describe it. I'm creating a library using TSDX (rollup). This library has So in the parcel app that's using the library I have Does this setup explain why there is a problem with |
and why is that please? Either the library brings react-query with it, or not. if you need it for development, use |
Of course, you're right. I changed just it to But this still doesn't change anything with the problem at hand. On versions higher than 3.12.0 (including 3.13.9) I'm getting the error. On 3.12.0 it works fine. |
@michalHT Unless we missed some place in the code when fixing this bug, this error can happen for two reasons:
In your case it definitely seems like nr 2 is the culprit. Your library is pulling in and bundling one version of React Query, while the application code is using another (or just two instances of the same version). There are two ways to fix this:
Hope that makes sense? |
For different reasons I cannot go with the first approach, so I tried the second one with <QueryClientProvider client={queryClient} contextSharing={true}> but it doesn't help - I'm still getting an error although the app doesn't do SSR. |
Aha, if
While there are several things intermingled here and some of them has been fixed, I think it makes sense to reopen this issue to continue tracking that specific bug. |
@fev4 you are calling useQuery in App outside of the QueryClientProvider. The Provider must wrap all useQuery calls! |
@TkDodo ouch! you are totally right! 😅 thanks for pointing it out |
Quite happy this issue has been resolved in version |
Confirmed issue is fixed for us with Vite with v3.13.10 |
@Ephem As far as I can see, the original issue with the devtools has been fixed. With two versions of react-query, where both have
I'd need to see a reproduction please that shows the issue. To avoid confusion, I would still close this issue. @michalHT feel free to open a new issue with a codesandbox reproduction. |
was on react-query |
Me facing this too... |
Hey, I have the same problem with:
If I remove the |
same thing happened here after upgrading vite to 2.9.2. But 2.9.3 was just released and seems to fix it 👍🏻 |
doesn't work for me right now, getting the error with vite 2.9.3 and 2.9.4. Will keep investigating |
yeah, while it worked for some time, it suddenly stopped again. I'm back to 2.9.1 for now :/ |
I am having this error too, link to reproduce error: https://github.com/coolcorexix/saleshood-playground/tree/vite-react-query-err My investigation is that it currently break with Vite 3.0 |
Same with
After adding ReactQueryDevtools |
You probably use the wrong devtools |
I did :/ thanks |
I am having this same error even without the dev tools, and I've triple checked that my "useQuery" calls are way down the tree, and the provider is the very top of the stack:
I can use react-query v3.x with vite, but v4.x (@tanstack/react-query) has this problem. Back to react-query 3.x 😢 |
Describe the bug
When upgrading from
[email protected]
to[email protected]
, getting the following error in the browser console:To Reproduce
Open the dev server in the browser. You should see a blank page and observe the following error in the browser console:
Now change the version of
react-query
inpackage.json
to3.12.0
, runnpm install
and re-start the dev server (interruptnpm run dev
and run it again). You should now seeApp
on the page and no error in the console.The text was updated successfully, but these errors were encountered: