-
-
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
invalidateQueries not invalidating outgoing first request #8530
Comments
seems like this is on purpose - query/packages/query-core/src/query.ts Lines 357 to 359 in 5edd617
I guess that’s why it’s called I wrote the docs where it says:
because I thought that’s what’s happening, and I always wondered why it’s not named Maybe the best we can do now is change the documentation to reflect what is actually happening ? |
I also felt the name |
I wonder why that condition (
? If that was the original intention, maybe a better strategy would be to accept the new data (instead of canceling the request) but still fire the new request in the background, as soon as "invalidateQueries" is called. 🤔 |
It was like that since v3, then I added those sentences to the docs somewhen last year only. I think it would also be unintuitive if the setting called
I can also only guess the intent, but yes, I think getting data earlier is better and frequent calls to an imperative refetch would delay that. Your suggestion would mean we would have to queue up the refetch, which is something that we don’t currently do. It also sounds unrelated to |
Yes, I totally agree there. Maybe a good middle ground would be to add a
Scrap that suggestion then, it seems it'd increase complexity a lot 😅 |
What’s your use-case for needing to cancel the initial fetch ? Yes, we could add that option and then later consolidate it to a |
Sure! My use case (for invalidation in general) is the same: the BE sends ws messages to the web client, which mark that some data is stale. To use an example from the docs, let's say github exposes an endpoint Let me invert the question: when would it be a good idea to cancel a refetch but not a fetch? 🤔 |
Describe the bug
Per the docs, the default behavior of
invalidateQueries
should be that if a query gets invalidated while it's being fetched, then the queryFn should be called again (i.e., the query should be restarted). However, currently that's only the case if the request has already been executed in the past (so, if the current query execution is a refech). If we're talking about a query that has never been run before, then invalidating it mid-flight does nothing.Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-query-igjd7d57?file=src%2Findex.tsx
Steps to reproduce
>>>> query start
in the console.>>>> query start
each time you click it.>>>> query start
each time you click it.Expected behavior
The query should be invalidated even if it's fetching for the first time.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
react-query
TanStack Query version
5.64.1
TypeScript version
5.7.2
Additional context
No response
The text was updated successfully, but these errors were encountered: