useQueries: stable combine returns a stale result when a query updates before setQueries runs
Maintainer antworten meist innerhalb von 1 Tag
@sakaintp arbeitet bereits daran.
Seit 19.11.2026.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 62/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- react, typescript
- Bereich
- frontend
Rechercherichtung
Start in packages/query-core/src/queriesObserver.ts: read #combineResult, #notify and getOptimisticResult in that order, and note that only the last passes queryHashes while #notify does not. Reproduce first by running the gist's repro.mjs against a local build (npm i, then node repro.mjs) and confirm the final line prints 3 instead of 5. Done means the combined result tracks the current query list and a regression test alongside the existing QueriesObserver tests covers the case where a query updates between render and setQueries.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
[!NOTE]
🤖 Claude Opus 5.5 responding on behalf of swheel33
Describe the bug
useQueries with a stable combine can return a combined result built from the previous query list, so its length no longer matches the queries passed in on that render. Code that indexes the combined result by the input list (results[index].data) then throws: we hit TypeError: Cannot read properties of undefined in our app.
This is a gap left by #9954 (the fix for #8781). #combineResult now detects a changed query list by comparing queryHashes with #lastQueryHashes, but only getOptimisticResult passes queryHashes. #notify calls #combineResult without them, so it recomputes from the observer's current results (the old list) while #lastQueryHashes still holds the new list from the last render. On the next render the hashes look unchanged, #result === #lastResult, and the stale combined result is returned.
Sequence:
- Render with queries A (3 queries). The effect calls
setQueries(A). - Render with queries B (5 queries).
getOptimisticResultcombines 5 results and sets#lastQueryHashes = B. - Before the effect calls
setQueries(B), a query in A updates.#onUpdate→#notify→#combineResultcombines the 3 results of A and caches them, leaving#lastQueryHashes = B. - The listener re-renders with B.
#combineResultsees no change and returns the 3-item result.
Your minimal, reproducible example
https://gist.github.com/swheel33/2f38c4065d592f58a8046917c405252e
Steps to reproduce
npm i @tanstack/[email protected]
node repro.mjs
Output:
render with 3 queries -> 3
render with 5 queries -> 5
re-render with 5 queries -> 3 (expected 5)
The script drives QueriesObserver the way useQueries does: getOptimisticResult per render, setQueries in an effect.
Expected behavior
The combined result reflects the queries passed on the current render, so the last line prints 5.
How often does this bug happen?
Sometimes
Platform
@tanstack/query-core5.108.0 (also seen on 5.103.0)@tanstack/react-query5.103.0, React 19- OS: macOS, Browser: Chrome
Tanstack Query adapter
react-query
TanStack Query version
5.108.0
TypeScript version
N/A (the repro is plain JS)
Additional context
In the browser this happens when the list of queries grows (in our case, one balance query per token, and the token list grows when a wallet connects) and an existing query resolves between the render and the useQueries effect.
We worked around it with a local patch that has #notify pass the hashes of the results it combines, so the next render sees the list changed:
this.#combineResult(
this.#trackResult(this.#result, this.#observerMatches),
this.#options?.combine,
this.#observerMatches.map((match) => match.defaultedQueryOptions.queryHash),
)
- Vorherrschende Sprache
- TypeScript
- Sterne
- 50.6k
- Forks
- 4.2k
- Ø Merge
- 9 Std. 50 Min.
- Gemergte PRs (30 T.)
- 310
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/query
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
TanStack/query#12466 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Evtl. wieder frei @LeonxLJX hat das vor 77 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
TanStack/query#11358 · 2 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
select that throws for placeholderData brings back the selection of data removed by resetQueriesEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 56/100
Maintainer antworten meist innerhalb von 1 Tag
-
Render loop since v5.105.2 when placeholderData, or its select result, is not referentially stableOffen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 54/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
inference/go type/feature
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 72/100
anomalyco/opencode#65148 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
truapi-release
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
paritytech/product-sdk#529 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add: Mansudae TVOffenapproved check:passed streams:add
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per nodeOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
devlikeapro/waha#2369 ·
Maintainer antworten meist innerhalb von 5 Tagen