Skip to content

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

Merged
TkDodo merged 3 commits into
TanStack:mainfrom
chatman-media:fix/placeholder-data-select-error
Aug 18, 2026
Merged

fix(query-core): reset isPlaceholderData when select throws on placeholder data#11011
TkDodo merged 3 commits into
TanStack:mainfrom
chatman-media:fix/placeholder-data-select-error

Conversation

@chatman-media

@chatman-mediachatman-media commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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 be incorrectly labeled as placeholder data when selection failed.
    • Error states now consistently clear placeholder-data indicators and return no data when selection throws.
  • Tests

    • Added coverage for selection errors involving placeholder data.

@coderabbitai

coderabbitaiBot 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: 45f44522-7527-4a55-8203-a7e0d13c477b

📥 Commits

Reviewing files that changed from the base of the PR and between 18c1c1e and 026dcd1.

📒 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
🚧 Files skipped from review as they are similar to previous changes (3)
  • .changeset/fix-placeholder-data-select-error.md
  • packages/query-core/src/queryObserver.ts
  • packages/query-core/src/tests/queryObserver.test.tsx

Included review availability: Your plan includes up to 10 reviews per rolling hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

This PR resets isPlaceholderData when QueryObserver selection throws, adds regression coverage for the error result, 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 the error result has isPlaceholderData: false and data: undefined. A patch changeset records the fix.

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

Merge Risk:⚪ Minimal · up to 026dc

This narrowly resets placeholder-state metadata when selector processing produces an error, with a regression test covering the affected result. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Description check⚠️ WarningThe description clearly explains the bug, fix, and regression test, but it omits the required Changes, Checklist, and Release Impact headings and checklist entries.Use the repository template headings and complete the checklist, including the testing status and confirmation that the changeset was generated.
✅ Passed checks (4 passed)
Check nameStatusExplanation
Title check✅ PassedThe title clearly and concisely identifies the query-core bug fix for resetting isPlaceholderData when select throws.
Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck 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.

@coderabbitai

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nx-cloud

nx-cloudBot commented Aug 18, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 026dcd1

CommandStatusDurationResult
nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded7m 51sView ↗
nx run-many --target=build --exclude=examples/*...✅ Succeeded1m 50sView ↗

☁️ Nx Cloud last updated this comment at 2026-08-18 08:42:42 UTC

@pkg-pr-new

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@11011

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@11011

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@11011

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@11011

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@11011

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11011

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@11011

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@11011

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@11011

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@11011

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@11011

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@11011

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@11011

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@11011

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@11011

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@11011

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@11011

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@11011

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@11011

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@11011

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@11011

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@11011

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@11011

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@11011

commit: 026dcd1

@TkDodo
TkDodo merged commit ba4650c into TanStack:mainAug 18, 2026
9 checks passed
@github-actionsgithub-actionsBot mentioned this pull request Aug 18, 2026
Sign up for freeto 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.

2 participants

@chatman-media@TkDodo