Skip to content

useQuery refetchOnWindowFocus option does not respect retry value #3565

@himankpathak

Description

@himankpathak

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

  1. Create a useQuery hook which should always fail
  2. Set the retry option value to false
  3. As the refetchOnWindowFocus is 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions