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.
Describe the bug
When a query rejects with a falsy value such as
undefined, it does not retry on remount even thoughretryOnMountistrueandthrowOnErrorreturnsfalse.The condition that handles function-valued
throwOnErrorchecks the truthiness ofquery.state.error. As a result, the callback is not evaluated for falsy errors, andretryOnMountis incorrectly disabled.Your minimal, reproducible example
https://stackblitz.com/edit/react-b39iindy?file=src%2FModal.tsx
Steps to reproduce
Fetching...is logged once.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
retryOnMountistrueandthrowOnErrorreturnsfalse, the query should retry after remounting. The console should contain twoFetching...messages after opening, closing, and reopening the modal.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
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.erroris falsy, thethrowOnErrorcallback is not evaluated.The callback function itself is then treated as truthy, causing
retryOnMountto be set tofalse.Checking whether the query is in the
errorstate 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.