-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Pending manual refetch is cancelled on component unmount #9158
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
We don’t keep track of the reason that a The way query cancellation works is that is cancels a query as soon as the last observer unmounts, if you opt-in to it by using the In your example, the only observer is in Not sure what your scenario is but the best solution here would be to also have |
Thanks for chiming in @TkDodo, the info on how things are designed and work gives helpful context.
Do you think this should be considered, though? Semantically, wouldn't it make sense for an imperative
My scenario is firing refetches from a "cache buster", outside of any component. It sets up refetches for expensive queries via |
@TkDodo Here's another interesting example where the behaviour might be questionable. I've now updated https://qd3v7w.csb.app/component-b When you refetch the query in So it seems the way around it is not only for IMHO, it's worth considering treating imperative refetches differently. I think it makes more sense that when something is imperatively done, that it should only be imperatively cancelled, or by exception. But I realise I'm not the design authority on this repo - just sharing my 2C :) |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
refetchOnMount: false
for manual refetch control, as its data comes from an expensive fetchYour minimal, reproducible example
https://codesandbox.io/p/sandbox/weathered-hooks-qd3v7w
Steps to reproduce
Expected behavior
The manual refetch fired from Component B should not be cancelled or impacted by Component A's mount lifetime, however, it is cancelled when Component A is unmounted.
Why do I expect this behaviour:
Simply not using an abort signal to work around this is not a suitable option, because there are still valid scenarios when the pending requests should be cancelled otherwise, e.g. in the case of duplicate in-flight requests.
Platform
Tanstack Query adapter
react-query
TanStack Query version
5.76.1
TypeScript version
4.4.4
The text was updated successfully, but these errors were encountered: