select that throws for placeholderData brings back the selection of data removed by resetQueries

オープン
#12,640 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@sakaintp がすでに取り組んでいます。

2026年11月20日 から。

  • #12641 @sakaintp による — オープン

評価

難易度
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
  1. Open the example and click "run" under "Issue 2".
  2. Before the reset, the result is { status: 'success', data: 'first', isPlaceholderData: false }.
  3. After the reset, the result is { status: 'error', data: 'first', isPlaceholderData: false }, and getQueryData(['label']) is undefined.
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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/query のほかの issue

TanStack/query の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。