Skip to content

fix(query-core): recompute placeholders when select changes - #11535

Open
brennanbutler01 wants to merge 1 commit into
TanStack:mainfrom
brennanbutler01:fix/placeholder-select-updates
Open

brennanbutler01 wants to merge 1 commit into
TanStack:mainfrom
brennanbutler01:fix/placeholder-select-updates

Conversation

@brennanbutler01

@brennanbutler01 brennanbutler01 commented Sep 18, 2026

Copy link
Copy Markdown

🎯 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.

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.
Copilot AI lite review requested due to automatic review settings September 18, 2026 07:43
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

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 bb9d313 and 5998b73.

📒 Files selected for processing (4)
  • .changeset/placeholder-select-fix.md
  • packages/query-core/src/__tests__/queryObserver.test.tsx
  • packages/query-core/src/queryObserver.ts
  • packages/react-query/src/__tests__/useQuery.test.tsx

Included 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 select option 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

Layer / File(s) Summary
Observer memoization and core coverage
packages/query-core/src/queryObserver.ts, packages/query-core/src/__tests__/queryObserver.test.tsx
The memoization guard now compares both placeholderData and select. Tests verify values 4, 6, 2, and 8, while isPlaceholderData remains true.
React integration and release metadata
packages/react-query/src/__tests__/useQuery.test.tsx, .changeset/placeholder-select-fix.md
React hook tests cover selector changes and removal during rerenders, including StrictMode. The changeset declares a patch release for @tanstack/query-core.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: sukvvon

Merge Risk: ⚪ Minimal · up to 5998b

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)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary fix: recomputing placeholder data when the select function changes.
Description check ✅ Passed The description explains the defect, implementation, regression coverage, validation results, release impact, and changeset. It also identifies that the full test:pr run was not performed and that t…
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

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.

3 participants