fix(query-core): recompute placeholders when select changes #11535
main fromrefs/pull/11535/head·opened View on GitHub🎯 Changes#
Changing or removing select while a query uses placeholder data returns the previous selection. For example, placeholder 2 selected with value * 2 remains 4 after changing the selector to value * 3, instead of becoming 6.
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#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm run test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
The full cross-framework test:pr run was not performed. Both affected packages passed test:lib, test:types, test:eslint, and test:build through 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#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
Bug Fixes
- Placeholder data now updates correctly when its selector changes or is removed.
- Updated selected placeholder values are reflected consistently during query and React component rerenders.
Tests
- Added coverage for selector changes with and without React Strict Mode.
- 1
🟢 Approval recommended#
No unresolved blocking issues were identified.
Pull request overview
Fixes stale placeholder selections when the query’s
selectfunction 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.tsxTests rerenders with and without Strict Mode. packages/query-core/src/queryObserver.tsPrevents stale placeholder selections. packages/query-core/src/__tests__/queryObserver.test.tsxAdds core regression coverage. .changeset/placeholder-select-fix.mdDocuments the patch release. Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a
code-reviewagent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.sheraz4196(GitHub profile, opens in a new tab) approved these changes
Could someone help me replace this PR from the rewritten branch? I rewrote the commits on my personal fork so the author and committer use my personal GitHub identity. The patch is unchanged, but this PR still shows the old head (
5998b73). The rewritten branch isfix/placeholder-select-updates-rewritten(9d11c4e). My personal account can’t create a replacement PR because I’m not a member of the TanStack org. Could someone with org access open a replacement from that branch or tell me the right way to proceed? I’ve left this PR open so the discussion stays here.Superseded by #12564 — same patch, opened from the rewritten branch on my fork. This PR's head ref detached from its branch, so GitHub kept showing the frozen head
5998b73and a stale conflict even though the branch was rewritten on top of current main. Closing in favor of the replacement.
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
a6974f75-f473-458a-aabf-f928a2a64fa2📥 Commits
Reviewing files that changed from the base of the PR and between bb9d31306f4b71fc488c3d3038d6a1c0cde640a1 and 5998b73ee015566f1c9714c09f7bb5283c836e47.
📒 Files selected for processing (4)
.changeset/placeholder-select-fix.mdpackages/query-core/src/__tests__/queryObserver.test.tsxpackages/query-core/src/queryObserver.tspackages/react-query/src/__tests__/useQuery.test.tsxIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The query observer now recomputes placeholder data when the
selectoption changes or is removed. Query-core and React tests cover selector updates, unselected values, functional placeholders, and StrictMode rerenders. A patch changeset records the fix.Changes#
Placeholder selection
packages/query-core/src/queryObserver.ts,packages/query-core/src/__tests__/queryObserver.test.tsxplaceholderDataandselect. Tests verify values4,6,2, and8, whileisPlaceholderDataremainstrue.packages/react-query/src/__tests__/useQuery.test.tsx,.changeset/placeholder-select-fix.md@tanstack/query-core.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
sukvvonMerge Risk: ⚪ Minimal · up to
5998bThe 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)
selectfunction changes.test:prrun was not performed and that t…✨ 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.
❤️ Share