Render loop since v5.105.2 when placeholderData, or its select result, is not referentially stable
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 54/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- react, typescript
研究方向
Start with QueryObserver.createResult in queryObserver.ts, especially the placeholder data and select handling; the report points to the result notification path and compares behavior between v5.105.1 and v5.105.2. Reproduce with the linked example or add a regression test covering the listed useQuery and useQueries cases. Done when the results settle without repeated notifications while preserving the expected placeholder result.
由索引模型根據 Issue 內容生成。
描述
Describe the bug
Since v5.105.2, a query that shows placeholderData can re-render in a loop until React throws "Maximum update depth exceeded". This happens when the placeholder result is a new reference each time the observer computes it, and the component renders again after mount (for example, because its parent re-renders). In v5.105.1, every case below settles.
| Case (the query never resolves) | useQuery |
useQueries |
|---|---|---|
placeholderData is a class instance created on every render |
settles | loops |
placeholderData is plain data whose content changes on every render |
settles | loops |
placeholderData is equal plain data created on every render, with a stable select that returns a Set |
loops | loops |
placeholderData is a stable object, with a stable select that throws for it |
loops | loops |
This looks like the same missing fixed point in QueryObserver.createResult as #12574, reached through placeholderData instead of keepPreviousData. The last row is not #12532: the select function is stable, and useQuery loops too.
Your minimal, reproducible example
https://stackblitz.com/github/jakubdrozdek/tanstack-query-placeholder-repro?file=src%2Fissue1.jsx
Steps to reproduce
- Open the example. Under "Issue 1", pick a case marked "loops".
- Click "re-render" once. The case shows "Maximum update depth exceeded".
- Set
@tanstack/react-queryto5.105.1inpackage.json. Every case settles.
The first case, for example:
class Row {
constructor(name) {
this.name = name
}
}
function Example() {
const [result] = useQueries({
queries: [{ queryKey: ['row'], queryFn: () => new Promise(() => {}), placeholderData: new Row('row') }],
})
return <p>{String(result.isPlaceholderData)}</p>
}
Expected behavior
The result settles, as in v5.105.1. A placeholder result that has not changed in meaning should not notify again only because its reference changed.
How often does this bug happen?
Every time
Platform
Not platform specific. Reproduced with React 19.2.8 in tests (Bun with happy-dom) and in the Vite example above.
Tanstack Query adapter
react-query
TanStack Query version
v5.108.1 (also v5.105.2 and v5.107.1; v5.105.1 is fine)
Additional context
On every render, useQuery and useQueries compute an optimistic result and then set the options again (#12230). replaceData cannot keep the previous reference for a class instance, a Set, or changed content, so each computation returns a new result and the observer notifies again. A select that throws creates a new error each time, with the same effect (queryObserver.ts:710 in v5.108.1).
- 主要語言
- TypeScript
- 星號
- 50.6k
- 分支
- 4.2k
- 平均合併
- 9 小時 50 分鐘
- 30 天內合併 PR
- 310
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 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 天前認領,目前沒有進行中的 PR。 未關閉
難度 2/5 1-3 小時 新手友好度 84/100
TanStack/query#11358 · 2 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆
-
select that throws for placeholderData brings back the selection of data removed by resetQueries可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 3/5 1-2 天 新手友好度 56/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
-
難度 2/5 1-3 小時 新手友好度 78/100
fb55/htmlparser2#2579 ·
維護者通常 1 天內回覆
-
bug good first issue needs-review
難度 1/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆
-
documentation public
難度 1/5 1-3 小時 新手友好度 68/100
midnightntwrk/umbradb#65 ·
維護者通常 2 天內回覆
-
area/channels kind/bug priority/medium
難度 2/5 1-3 小時 新手友好度 78/100
nanocoai/nanoclaw#4501 · 1 則留言 ·
維護者通常 1 天內回覆
-
needs verification
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 13 天內回覆