select that throws for placeholderData brings back the selection of data removed by resetQueries
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 56/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- backend
調査の方向性
Read the QueryObserver implementation at queryObserver.ts:705–:712, where createResult handles a thrown select and placeholder data. Start by tracing how reset state and the last successful selection interact; the issue includes a StackBlitz reproduction and a plain QueryObserver example. Done when resetting the query with a throwing select no longer exposes the selection of removed data, while the behavior without placeholderData remains consistent.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
A query has data and a stable select. After resetQueries, the cache is empty and the observer falls back to placeholderData. If select throws for the placeholder, the result is status: 'error' with data set to the selection of the data that was reset, and isPlaceholderData: false. Nothing in the result shows that this value is no longer in the cache.
This happens in v5.105.1. Since v5.105.2, a React component with this setup also loops (#12639), so the example uses a plain QueryObserver.
Without placeholderData, the same reset clears the stored select error, and the old selection does not come back.
Your minimal, reproducible example
https://stackblitz.com/github/jakubdrozdek/tanstack-query-placeholder-repro?file=src%2Fissue2.js
Steps to reproduce
- Open the example and click "run" under "Issue 2".
- Before the reset, the result is
{ status: 'success', data: 'first', isPlaceholderData: false }. - After the reset, the result is
{ status: 'error', data: 'first', isPlaceholderData: false }, andgetQueryData(['label'])isundefined.
const client = new QueryClient()
client.setQueryData(['label'], { label: 'first' })
const observer = new QueryObserver(client, {
queryKey: ['label'],
queryFn: () => new Promise(() => {}),
enabled: false,
placeholderData: { label: null },
select: (row) => {
if (row.label === null) throw new Error('label not ready')
return row.label
},
})
observer.subscribe(() => {})
await client.resetQueries({ queryKey: ['label'] })
observer.getCurrentResult() // { status: 'error', data: 'first', isPlaceholderData: false, ... }
Expected behavior
After the reset, the result does not include a selection of data the cache no longer holds. For example, status: 'error' with data: undefined, which is what you get without placeholderData.
How often does this bug happen?
Every time
Platform
Not platform specific. Reproduced with a plain QueryObserver under Bun and in the Vite example above.
Tanstack Query adapter
vanilla
TanStack Query version
v5.108.1 (also v5.105.1, v5.105.2 and v5.107.1)
Additional context
When select throws, createResult sets data to this.#selectResult, the last successful selection (queryObserver.ts:710–:712 in v5.108.1). That selection can come from data that is gone. The clean-up just before it (:705) runs only when there is no data at all, and placeholderData counts as data at that point. For example, after a sign-out that resets queries, this can show the previous user's value. Related: #12564.
- 主要言語
- TypeScript
- スター
- 50.6k
- フォーク
- 4.2k
- 平均マージ
- 9時間 50分
- マージ済み PR(30日)
- 310
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/query のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
TanStack/query#12466 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)再び着手できるかも @LeonxLJX が 77 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
TanStack/query#11358 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Render loop since v5.105.2 when placeholderData, or its select result, is not referentially stableオープン
難易度 4/5 3〜5日 初心者へのやさしさ 54/100
メンテナーはふだん 1 日以内に返信
-
useQueries: stable combine returns a stale result when a query updates before setQueries runs対応中かも @sakaintp が 1 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
TanStack/query#12626 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
inference/go type/feature
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
anomalyco/opencode#65148 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
truapi-release
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
paritytech/product-sdk#529 ·
メンテナーはふだん 1 日以内に返信
-
Add: Mansudae TVオープンapproved check:passed streams:add
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per nodeオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
devlikeapro/waha#2369 ·
メンテナーはふだん 5 日以内に返信