-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(queryClient): respect cancelRefetch flag #2798
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
Conversation
for refetchQueries, as well as for invalidateQueries
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tannerlinsley/react-query/6uJzVJgj49NYGHoLMfGzFjPeVvmX |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 65bcf42:
|
test for making sure that refetchQueries respects the cancelRefetch flag
because the options are forwarded to refetchQueries at runtime
|
🎉 This PR is included in version 3.27.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
@TkDodo Hey, until now we used whats written in this page for cancellation, the requests were cancelled without providing Will this behavior change in some way? (i.e similar to the test case you provided, basically works in our project without providing any |
|
Query cancellation, as described in the docs page, is just a mechanism to actually cancel the fetch on transport level. The This PR has been sparked by this twitter discussion, where I outline some cases where invalidation alone might not be enough: https://twitter.com/TkDodo/status/1448677532983832580 The bottom line is: If a fetch is already in progress and you instruct react-query to refetch (e.g. via invalidateQueries), it will not do that per default, because a fetch is already going on. With cancelRefetch, the ongoing fetch will be cancelled and a new fetch will be started. I think we might make this the default behaviour in the next major. If react-query is explicitly instructed to refetch, I think it should do so :) |
|
Thanks for this explanation @TkDodo. Just mentioning it seems to be a different behavior than what was before (as I don't see it in For example we pretty much rely on cancellation by default (well, not rely, but it helps us with high-bandwidth requests), and would want to avoid adding |
|
Just to be on the same page: This PR didn't change anything regarding the default behaviour. Now, you have the option of setting it to |
|
I'm commenting here before opening an issue. Should the docs at https://react-query.tanstack.com/guides/optimistic-updates be updated, so that onSettled: () => {
queryClient.invalidateQueries('todos')
},uses |
|
@VanTanev i don’t think so. We’re already canceling in onMutate, which should be enough for most cases. |
|
@TkDodo I wasn't sure, thanks for clarifying! |
for refetchQueries, as well as for invalidateQueries