useQueries: stable combine returns a stale result when a query updates before setQueries runs
Los mantenedores suelen responder en 1 día
@sakaintp ya está trabajando en esto.
Desde el 19/11/2026.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 62/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- react, typescript
- Área
- frontend
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
[!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),
)
- Lenguaje dominante
- TypeScript
- Estrellas
- 50.6k
- Forks
- 4.2k
- Merge medio
- 9 h 50 min
- PR fusionados (30 d)
- 310
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/query
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
TanStack/query#12466 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Quizá libre de nuevo @LeonxLJX la tomó hace 77 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
TanStack/query#11358 · 2 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
select that throws for placeholderData brings back the selection of data removed by resetQueriesPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 56/100
Los mantenedores suelen responder en 1 día
-
Render loop since v5.105.2 when placeholderData, or its select result, is not referentially stableAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 54/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/query
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
fb55/htmlparser2#2579 ·
Los mantenedores suelen responder en 1 día
-
bug good first issue needs-review
Dificultad 1/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 1 día
-
Add Module DB RulesAbiertodocumentation public
Dificultad 1/5 1-3 horas Aptitud para principiantes 68/100
midnightntwrk/umbradb#65 ·
Los mantenedores suelen responder en 2 días
-
area/channels kind/bug priority/medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
nanocoai/nanoclaw#4501 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Docker images: plain X.Y.Z tag (e.g. 7.2.3) is never updated after the initial release buildAbiertoneeds verification
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 13 días