-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Describe the bug
useQuery option refetchOnWindowFocus does not verify if the retry option value.
Queries are fetched unnecessary even when retry is set to false, retryCount resets every time on window focus.
Your minimal, reproducible example
https://codesandbox.io/s/react-query-continuous-fetching-on-error-40liyc
Steps to reproduce
- Create a useQuery hook which should always fail
- Set the
retryoption value to false - As the
refetchOnWindowFocusis true by default, the query will be refetched every time you switch tab and focus on window.
Expected behavior
As the retry option is set on per query basis, it should have higher precedence. refetchOnWindowFocus can't be disabled as it's a useful feature. If the dev is setting the retry option by checking the error message in the function to prevent retrying. It should not be overridden by the refetchOnWindowFocus feature.
Using enabled option to control this would add unnecessary state to the custom query hook for managing this behaviour. In my opinion, this looks like a very common use case and react-query should support this out of the box.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: MacOS
- Chrome v100.0
react-query version
v3.38.0
TypeScript version
No response
Additional context
No response