Skip to content

invaliateQueries race condition with refetchOnWindowFocus #5236

Answered by TkDodo
SevenOutman asked this question in Q&A
Discussion options

You must be logged in to vote

the then-invoked invalidateQueries would not send another refetch.

it does since v4. An explicit call to invalidateQueries() will cancel currently running requests and start a new one, to stop this exact issue.

If you don't want that, you can call invalidateQueries(['todos'], { cancelRefetch: false }). If you are on v3, you can explicitly pass cancelRefetch: true, because there, the defaults were reversed:

https://tanstack.com/query/v4/docs/react/guides/migrating-to-react-query-4#consistent-behavior-for-cancelrefetch

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@SevenOutman
Comment options

@TkDodo
Comment options

@SevenOutman
Comment options

Answer selected by SevenOutman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants