Skip to content

fix(query-core): reset isPlaceholderData when select throws on placeholder data#11011

Open
chatman-media wants to merge 1 commit into
TanStack:mainfrom
chatman-media:fix/placeholder-data-select-error
Open

fix(query-core): reset isPlaceholderData when select throws on placeholder data#11011
chatman-media wants to merge 1 commit into
TanStack:mainfrom
chatman-media:fix/placeholder-data-select-error

Conversation

@chatman-media

@chatman-media chatman-media commented Jun 30, 2026

Copy link
Copy Markdown

When a query has placeholderData set and is still pending, createResult() applies the placeholder and sets isPlaceholderData = true. If select then throws on that placeholder value, the catch block recomputes error/data/status for the error state but never resets isPlaceholderData, so it stays true. You end up with { isError: true, isPlaceholderData: true }, a combination the QueryObserverResult discriminated union in types.ts says can't happen — every error variant hard-codes isPlaceholderData: false.

Fix is just setting isPlaceholderData = false alongside the other fields in that block. Added a regression test next to the existing "selector throws" tests, asserting via getCurrentResult() right after construction (that's where the bad state is actually observable, since it gets masked on subsequent renders by the placeholder memoization shortcut).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where results could incorrectly continue to appear as placeholder data after a selection step failed.
    • Error states now correctly show as errors with no placeholder-data flag, and data is cleared as expected.
    • Added test coverage to verify the corrected behavior when placeholder data and selection errors occur together.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ade716dc-c287-44b5-b222-7408f7cdbb32

📥 Commits

Reviewing files that changed from the base of the PR and between d6798b5 and 8567c49.

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

📝 Walkthrough

Walkthrough

This PR fixes QueryObserver's createResult method to reset isPlaceholderData to false when the select function throws and #selectError is set. A new test verifies the error state correctly excludes placeholder-data flags, and a changeset documents the patch.

Changes

Placeholder Data Error Fix

Layer / File(s) Summary
Reset isPlaceholderData on select error
packages/query-core/src/queryObserver.ts, packages/query-core/src/__tests__/queryObserver.test.tsx, .changeset/fix-placeholder-data-select-error.md
When #selectError is set, isPlaceholderData is forced to false; a new test verifies the error result has isError: true, isPlaceholderData: false, and data: undefined; a changeset documents the patch fix.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

A throw in select, a flag gone astray,
isPlaceholderData would not go away.
Now with one line, the bug hops out,
Error stays error, no placeholder doubt.
🐇✨ Carrots for clean code today!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug and fix, but it omits the required template sections for Changes, Checklist, and Release Impact. Add the template sections with a brief changes summary, checklist items, and release impact/changeset status.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main fix in query-core and is specific enough to understand the change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 PR with unit tests

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.

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.

1 participant