fix(query-core): recompute placeholders when select changes - #11535
brennanbutler01 wants to merge 1 commit into
Conversation
Include selector identity when reusing selected placeholder data. Changing or removing select must recompute from the original placeholder rather than return the previous transformation. Cover constant and functional placeholders, removal and re-addition, and React rerenders 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 (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe query observer now recomputes placeholder data when the ChangesPlaceholder selection
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The placeholder result is recomputed when a selector changes or is removed, with regression coverage for core observers and React rerenders. No actionable merge risk remains. 🚥 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.
🟢 Approval recommended
No unresolved blocking issues were identified.
Pull request overview
Fixes stale placeholder selections when the query’s select function changes or is removed.
Changes:
- Include selector identity in placeholder memoization.
- Add core and React regression tests.
- Add a query-core patch changeset.
File summaries
| File | Description |
|---|---|
packages/react-query/src/__tests__/useQuery.test.tsx |
Tests rerenders with and without Strict Mode. |
packages/query-core/src/queryObserver.ts |
Prevents stale placeholder selections. |
packages/query-core/src/__tests__/queryObserver.test.tsx |
Adds core regression coverage. |
.changeset/placeholder-select-fix.md |
Documents the patch release. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🎯 Changes
Changing or removing
selectwhile a query uses placeholder data returns the previous selection. For example, placeholder2selected withvalue * 2remains4after changing the selector tovalue * 3, instead of becoming6.Include selector identity when reusing selected placeholder data. Unchanged selectors retain the existing memoization. Covers constant and functional placeholders, changing/removing/re-adding the selector, and React rerenders with and without Strict Mode.
Related to the optimization in #9007. 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,599 core assertions and 585 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
Bug Fixes
Tests