Skip to content

fix: retry remounted queries after error reset#10921

Open
pupuking723 wants to merge 1 commit into
TanStack:mainfrom
pupuking723:fix/error-boundary-remount-retry
Open

fix: retry remounted queries after error reset#10921
pupuking723 wants to merge 1 commit into
TanStack:mainfrom
pupuking723:fix/error-boundary-remount-retry

Conversation

@pupuking723

@pupuking723 pupuking723 commented Jun 11, 2026

Copy link
Copy Markdown

🎯 Changes

Fixes #2712.

React Query currently stores error boundary reset state as a single boolean. When an errored query is unmounted, the fallback can call reset(), but another query mounted before the original query remounts can clear that reset state. The original query then remounts with retryOnMount: false and stays in the error boundary instead of retrying.

This PR tracks reset generations per query instance so a remounted errored query can still observe that a reset happened after it last mounted, even if another query has already cleared the global reset flag.

It also adds a regression test for the route/page switch case where:

  • the first query errors into an error boundary
  • the fallback calls reset() on unmount
  • another query mounts and clears the reset state
  • the original query remounts and retries successfully

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

pnpm run test:pr was attempted with NX_DAEMON=false, but Nx failed locally before running project targets with Failed to start plugin worker.

Targeted verification completed locally:

  • npx pnpm@11.1.0 --filter @tanstack/react-query exec vitest run src/__tests__/QueryResetErrorBoundary.test.tsx
  • npx pnpm@11.1.0 --filter @tanstack/react-query run test:types:tscurrent
  • npx pnpm@11.1.0 --filter @tanstack/react-query run test:eslint
  • npx pnpm@11.1.0 exec prettier --experimental-cli --check .changeset/error-boundary-remount-retry.md packages/react-query/src/QueryErrorResetBoundary.tsx packages/react-query/src/errorBoundaryUtils.ts packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx
  • git diff --check

test:eslint completed with existing warnings in unrelated test files.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

Release Notes

  • New Features

    • Added getResetCount function to the query error reset boundary for tracking reset counts.
  • Bug Fixes

    • Fixed error boundary reset behavior to preserve retry logic for remounted queries, even when other queries clear the reset state first.

@coderabbitai

coderabbitai Bot commented Jun 11, 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: e77be7af-0f82-4f08-ab65-bc09713a503e

📥 Commits

Reviewing files that changed from the base of the PR and between feb1efd and 9b5b780.

📒 Files selected for processing (4)
  • .changeset/error-boundary-remount-retry.md
  • packages/react-query/src/QueryErrorResetBoundary.tsx
  • packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx
  • packages/react-query/src/errorBoundaryUtils.ts

📝 Walkthrough

Walkthrough

Error boundary retry behavior is refined by tracking reset counts per query. A boundary reset now applies only to queries caught during that specific reset, not globally. Remounted queries retry independently even when other queries have mounted post-reset.

Changes

Error boundary remount retry fix

Layer / File(s) Summary
Reset count tracking contract
packages/react-query/src/QueryErrorResetBoundary.tsx
QueryErrorResetCountFunction type and getResetCount accessor are added to QueryErrorResetBoundaryValue. Internal createValue() tracks and increments a resetCount on each reset() call.
Query-specific reset detection
packages/react-query/src/errorBoundaryUtils.ts
Nested WeakMaps store reset counts per boundary per query. New isResetForQuery() replaces the global isReset() check, so retry prevention applies only to queries covered by a boundary reset.
Remount retry test validation
packages/react-query/src/__tests__/QueryResetErrorBoundary.test.tsx
New test confirms errored queries retry on remount even when another query mounts and unmounts between error and remount, invoking the boundary reset() in cleanup.
Changeset documentation
.changeset/error-boundary-remount-retry.md
Patch-level change describes preserved error boundary reset retry behavior for remounted queries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A boundary reset, once wild and free,
Now tracks its queries with identity,
When others unmount, your quest stays bright,
Retry on mount—the fix feels right!

🚥 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 'fix: retry remounted queries after error reset' clearly and concisely summarizes the main change: fixing retry behavior for remounted queries after error boundary resets.
Description check ✅ Passed The PR description follows the template with detailed explanation of the issue, solution, and verification steps; checklist items are properly marked.
Linked Issues check ✅ Passed All coding requirements from issue #2712 are met: per-query reset tracking is implemented to ensure remounted errored queries can detect resets and retry on mount as expected.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing issue #2712: the changeset, new type/interface exports, error boundary tracking logic, and regression test are all scoped to the error boundary reset behavior fix.

✏️ 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.

Errored queries caught by ErrorBoundary are not retried on mount

1 participant