Skip to content

Falsy query errors disable retryOnMount when throwOnError returns false #11327

Description

@jeonghoon11

Describe the bug

When a query rejects with a falsy value such as undefined, it does not retry on remount even though retryOnMount is true and throwOnError returns false.

The condition that handles function-valued throwOnError checks the truthiness of query.state.error. As a result, the callback is not evaluated for falsy errors, and retryOnMount is incorrectly disabled.

Your minimal, reproducible example

https://stackblitz.com/edit/react-b39iindy?file=src%2FModal.tsx

Steps to reproduce

  1. Open the reproduction and open the browser console.
  2. Click the "Open Modal" button.
  3. Wait for the query to fail and confirm that Fetching... is logged once.
  4. Click the "Close Modal" button to unmount the component.
  5. Click the "Open Modal" button again.
  6. Observe that the console still contains only one Fetching... message because the query function is not called after remounting.

Expected behavior

The query function should be called again when the component remounts.

Because retryOnMount is true and throwOnError returns false, the query should retry after remounting. The console should contain two Fetching... messages after opening, closing, and reopening the modal.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: macOS 26.6.2
  • Browser: Chrome
  • Version: 151.0.7922.174

Tanstack Query adapter

react-query

TanStack Query version

v5.102.8

TypeScript version

v5.8.3

Additional context

The issue appears to be in ensurePreventErrorBoundaryRetry.

When query.state.error is falsy, the throwOnError callback is not evaluated.
The callback function itself is then treated as truthy, causing retryOnMount to be set to false.

Checking whether the query is in the error state instead of checking the truthiness of the error value allows the callback to be evaluated for all query errors, including falsy ones.

A fix and regression test are available in #11328.

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