fix: retry remounted queries after error reset#10921
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughError 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. ChangesError boundary remount retry fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🎯 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 withretryOnMount: falseand 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:
reset()on unmount✅ Checklist
pnpm run test:pr.pnpm run test:prwas attempted withNX_DAEMON=false, but Nx failed locally before running project targets withFailed to start plugin worker.Targeted verification completed locally:
npx pnpm@11.1.0 --filter @tanstack/react-query exec vitest run src/__tests__/QueryResetErrorBoundary.test.tsxnpx pnpm@11.1.0 --filter @tanstack/react-query run test:types:tscurrentnpx pnpm@11.1.0 --filter @tanstack/react-query run test:eslintnpx 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.tsxgit diff --checktest:eslintcompleted with existing warnings in unrelated test files.🚀 Release Impact
Summary by CodeRabbit
Release Notes
New Features
getResetCountfunction to the query error reset boundary for tracking reset counts.Bug Fixes