fix(query-core): clear errors when select is removed - #11536
brennanbutler01 wants to merge 2 commits into
Conversation
Drop obsolete selection errors when select is removed and invalidate the remembered selector so re-adding it runs selection and error handling again. Cover cached data under the same and a different key, and React option updates with and without Strict Mode.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthrough
ChangesSelector error recovery
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The selector recovery behavior is covered across the core observer and React consumer paths, with no actionable merge-blocking risk identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
🟡 Changes recommended
Placeholder-data memoization can skip selector execution after select is removed and re-added.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes stale selector errors when a throwing select is removed, with core and React regression coverage.
Changes:
- Clears stale selection errors and selector identity.
- Adds cached-data, key-change, re-addition, and Strict Mode tests.
- Adds a query-core patch changeset.
Review finding: placeholder-data memoization may skip selector execution after remove/re-add and needs invalidation plus regression coverage.
File summaries
| File | Summary |
|---|---|
packages/react-query/src/__tests__/useQuery.test.tsx |
Adds React and Strict Mode regression tests. |
packages/query-core/src/queryObserver.ts |
Updates selector error and identity handling; placeholder memoization issue remains. |
packages/query-core/src/__tests__/queryObserver.test.tsx |
Adds core selector-removal recovery coverage. |
.changeset/removed-select-fix.md |
Documents the patch release. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Invalidate selected placeholder data when its selector changes. Cover a removed and re-added selector that throws, including React Strict Mode.
🎯 Changes
Removing a throwing
selectleaves the observer in an error state even when the cache contains successful data. Clear the obsolete selection error when the selector is absent, and clear its remembered identity so re-adding the same function runs selection and error handling again.Also invalidate selected-placeholder memoization when the selector changes. This shares the guard from #11535 so removal and re-addition work with placeholder data independently of merge order. Added core and React regressions for a re-added selector that throws.
This extends #11161's recovery for queries without data to the separate case where cached data exists but the selector has been removed. Covers same-key and cached-key changes, re-adding the failing selector, and React rerenders with and without Strict Mode.
Reproduced on 5.101.2, stable 5.103.1 source, and main (
bb9d313). All four added core/React regression cases failed before the fix. Afterward, 1,600 core assertions and 587 React tests pass.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.The full cross-framework
test:prrun was not performed. Both affected packages passedtest:lib,test:types,test:eslint, andtest:buildthrough Nx, including dependency builds. The compiler matrix covers TypeScript 5.6, 5.7, 5.8, 5.9, 6.0, and 7.0. Existing lint warnings are in unchanged code. Tested on Node 24.13.0.Implemented and locally verified with AI assistance. The contributor-understanding checkbox is left for the author's review.
🚀 Release Impact
Summary by CodeRabbit