useQueries: stable combine returns a stale result when a query updates before setQueries runs
Les mainteneurs répondent en général sous 1 jour
@sakaintp y travaille déjà.
Depuis le 19/11/2026.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 62/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- react, typescript
- Domaine
- frontend
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
[!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),
)
- Langage dominant
- TypeScript
- Étoiles
- 50.6k
- Forks
- 4.2k
- Merge moyen
- 9 h 50 min
- PR mergées (30 j)
- 310
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de TanStack/query
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
TanStack/query#12466 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Peut-être à nouveau libre @LeonxLJX l’a pris il y a 77 jours, et aucune pull request n’est ouverte. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
TanStack/query#11358 · 2 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
select that throws for placeholderData brings back the selection of data removed by resetQueriesPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 56/100
Les mainteneurs répondent en général sous 1 jour
-
Render loop since v5.105.2 when placeholderData, or its select result, is not referentially stableOuverte
Difficulté 4/5 3-5 jours Accessibilité débutants 54/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de TanStack/query
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
fb55/htmlparser2#2579 ·
Les mainteneurs répondent en général sous 1 jour
-
bug good first issue needs-review
Difficulté 1/5 1-3 heures Accessibilité débutants 83/100
Les mainteneurs répondent en général sous 1 jour
-
Add Module DB RulesOuvertedocumentation public
Difficulté 1/5 1-3 heures Accessibilité débutants 68/100
midnightntwrk/umbradb#65 ·
Les mainteneurs répondent en général sous 2 jours
-
area/channels kind/bug priority/medium
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
nanocoai/nanoclaw#4501 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Docker images: plain X.Y.Z tag (e.g. 7.2.3) is never updated after the initial release buildOuverteneeds verification
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 13 jours