Open
Description
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
- Open the devtools, so that you can see the console.log output
- Go to the MWE
- You'll see
>>>> query start
in the console. - Before the query finishes (5 seconds), click the "Invalidate Query" button as many times as you want. You'll see nothing in the console: this is the bug, you should see
>>>> query start
each time you click it. - After the query finishes, the behavior is correct: if you click the button, and click it again, you'll see
>>>> 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
- OS: Macos
- Browser: Chrome
Tanstack Query adapter
react-query
TanStack Query version
5.64.1
TypeScript version
5.7.2
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels