-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Disabled queries (enabled: false) get affected by invalidateQueries (refetchInactive: true) #3202
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
Comments
Thanks for filing the issue. It seems that a query is considered active` if it has at least one observer that is not disabled. From that definition, it follows that a a query is inactive if it has: In your case, b) would apply, which is why it is refetched. I've traced it back and it works the same as in v 3.2.0 (the first v3 release), so this is not a regression introduced recently. However, I think this is wrong and it contradicts the docs where it says:
From what I am seeing, the only check we should be doing is check a) it has no observers. Especially because To be on the safe side, I would still suggest to fix this with v4, where we have also changed the queryFilters. |
adding { exact : true } prevents refetching. |
no it doesn't, and it shouldn't. With your keys, there should be no difference between exact or fuzzy matching. |
@TkDodo why do i get a throttled response with { exact: true }, but get successful response without it? |
the api your sandbox queries against has rate limiting. Just use |
@TkDodo do you have workaround on your mind for now? |
+1 here. I've lost about 3 hours investigating why the query having {enabled: false} does fetch. The problem was invalidateQueries((q)=> ...). |
use invalidateQueries without refetchInactive. Not sure in what case you would need inactive queries (queries that are not mounted) to refetch? |
@TkDodo I found workaround for myself, but I hope this issue will be fixed in new version. |
🎉 This issue has been resolved in version 4.0.0-alpha.9 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 4.0.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Describe the bug
queryClient.invalidateQueries(queryKey, { refetchInactive: true, })
also refetches disabled queries (
enabled
: false)but - #947 (comment)
looks like this issue was introduce in this commit - f5ae636
Your minimal, reproducible example
https://codesandbox.io/s/quiet-dust-hegny?file=/src/App.js
Steps to reproduce
useQuery
and setenabled
option to false.invalidateQueries
and setrefetchInactive
to trueExpected behavior
I expected that disabled queries (
enabled: false
) would not refetch when I useinvalidateQueries
Platform
react-query version
v3.34.8
TypeScript version
v4.2.2
The text was updated successfully, but these errors were encountered: