TanStack / TanStack/query

Falsy query errors disable retryOnMount when throwOnError returns false

Open
#11,327 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
50.3k
Forks
4.2k
Avg merge
18h 25m
Merged PRs (30d)
200

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ensurePreventErrorBoundaryRetry and review the fix and regression test referenced in #11328. Run the relevant React Query tests and verify that a query rejecting with a falsy error is retried when the component remounts with retryOnMount enabled and throwOnError returning false.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.