Skip to content

useQuery does not perform a retry on mount when the function provided to throwOnError returns false, even if retryOnMount: true is set #9336

Open
@andromansky

Description

@andromansky

Describe the bug

If the query options include the following:

throwOnError: () => false,  
retryOnMount: true,  
staleTime: Infinity,

then on remount of the host component, queryFn is not called, even though the documentation suggests otherwise.

Your minimal, reproducible example

https://stackblitz.com/edit/react-93scwtvo

Steps to reproduce

  1. Wait for the app to load and open the console.
  2. Click the "Open Modal" button — you will see "Fetching..." messages in the console indicating data fetch attempts.
  3. Click the "Close Modal" button.
  4. Click "Open Modal" again — no more "Fetching..." messages appear.

Expected behavior

I expect that if a Query is in the error status and I set retryOnMount: true in the options, then when the function passed to throwOnError returns false, the Query should still call queryFn on remount of the host component.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Windows, macOS;
  • Browser: Chrome (137.0.7151.120);

Tanstack Query adapter

react-query

TanStack Query version

v5.81.4

TypeScript version

v5.8.3

Additional context

Here is the link to the source code where the condition is checked that forcibly sets retryOnMount to false:

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