Skip to content

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

Open
chatman-media wants to merge 2 commits 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 2 commits 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
    • Resolved an issue where errored results could be incorrectly labeled as placeholder data after the selection step failed.
    • Error states now consistently clear placeholder-data indicators and ensure returned data is unset when selection throws.
  • Tests
    • Added coverage to verify the correct observer behavior when placeholderData is used and select throws.

@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 Plus

Run ID: 2d1cf07d-ed50-4281-a2aa-7d635129fd42

📥 Commits

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

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/queryObserver.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/query-core/src/tests/queryObserver.test.tsx

📝 Walkthrough

Walkthrough

This PR resets isPlaceholderData when QueryObserver selection throws, adds a regression test for the resulting error state, and records the fix in a changeset.

Changes

Placeholder Data Error Fix

Layer / File(s) Summary
Reset placeholder state on select error
packages/query-core/src/queryObserver.ts, packages/query-core/src/__tests__/queryObserver.test.tsx, .changeset/fix-placeholder-data-select-error.md
isPlaceholderData is cleared when select throws; the test verifies isError: true, isPlaceholderData: false, and data: undefined; a patch changeset documents the fix.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix, but it does not follow the required template sections or checklist items. Add the required Changes, Checklist, and Release Impact sections, including testing and whether a changeset was generated.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the query-core bug fix and matches the code 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