Falsy query errors disable retryOnMount when throwOnError returns false
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
- Open the reproduction and open the browser console.
- Click the "Open Modal" button.
- Wait for the query to fail and confirm that
Fetching...is logged once. - Click the "Close Modal" button to unmount the component.
- Click the "Open Modal" button again.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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