Skip to content

fix(react-query): retry fetch on remount when error boundary has not been reset#10962

Open
EduardF1 wants to merge 2 commits into
TanStack:mainfrom
EduardF1:fix-error-boundary-retry-on-mount
Open

fix(react-query): retry fetch on remount when error boundary has not been reset#10962
EduardF1 wants to merge 2 commits into
TanStack:mainfrom
EduardF1:fix-error-boundary-retry-on-mount

Conversation

@EduardF1

@EduardF1 EduardF1 commented Jun 16, 2026

Copy link
Copy Markdown

Summary

  • Fixes a bug where useQuery with throwOnError would refuse to retry on remount even after the error boundary had unmounted and remounted the failed observer — effectively leaving the component stuck in an error state with no recovery path unless the user explicitly reset the boundary.
  • The fix updates ensurePreventErrorBoundaryRetry in errorBoundaryUtils.ts: retry is only suppressed when the boundary has not been reset and the query is either using suspense or still has live observers. On a fresh mount (zero observers), the retry suppression is lifted so the remounted component can attempt a new fetch.
  • Adds two test cases covering the remount retry scenario, including an edge case with staleTime: Infinity.

Files changed

  • packages/react-query/src/errorBoundaryUtils.ts — guard loosened to allow remount retry
  • packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx — two new/updated test cases

Test plan

  • pnpm run test:lib -- --run QueryResetErrorBoundary in packages/react-query — all 14 tests pass
  • Full CI (pnpm test) — to be run by CI

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error boundary query recovery to intelligently retry queries on remount based on Suspense configuration and active query observers, providing more predictable error recovery behavior.

EduardF1 and others added 2 commits June 16, 2026 14:58
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a0151e48-390e-44d9-9522-7bc67a8d65fc

📥 Commits

Reviewing files that changed from the base of the PR and between 18d4504 and b9a9576.

📒 Files selected for processing (2)
  • packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx
  • packages/react-query/src/errorBoundaryUtils.ts

📝 Walkthrough

Walkthrough

ensurePreventErrorBoundaryRetry in errorBoundaryUtils.ts gains an additional guard: retryOnMount is set to false only when the error boundary is not reset and either Suspense is enabled or the query has active observers. Two related tests in QueryResetErrorBoundary.test.tsx are updated to reflect this looser suppression.

Changes

retryOnMount guard and test alignment

Layer / File(s) Summary
Retry-prevention condition
packages/react-query/src/errorBoundaryUtils.ts
ensurePreventErrorBoundaryRetry replaces the unconditional !errorResetBoundary.isReset() guard with !errorResetBoundary.isReset() && (options.suspense || query?.getObserversCount()), adding explanatory comments and leaving the retryOnMount = false assignment in place when the condition holds.
Test updates for new remount behavior
packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx
Renames the "not reset" test to assert that a remount does trigger a fetch; adds a fetchCount counter and a fetchCount === 2 assertion. Removes the intermediate retry step in the "after a previous reset" test and adjusts succeed/shouldReset sequencing to match the fewer-transition flow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop — the boundary gate,
once shut too tight, now checks your state:
suspense or observers? Then stay!
else remount fetches find their way.
A cleaner guard, a lighter load —
two tests now dance the new-found road. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: allowing retry on remount when error boundary has not been reset.
Description check ✅ Passed The description covers the bug fix, implementation details, and includes test results, but is missing completion of the provided template structure with proper sections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant