A hydrated query that rejects ignores the reader's `retry` and `retryDelay`
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 45/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- typescript
- Domínio
- backend-api-design
Direção de pesquisa
Start with the query-core retryer and hydration flow described in the issue: hydrate resumes the pending query before a QueryObserver exists, so later observer options may not reach the retryer. The issue says fix #12511 implements the desired precedence; inspect that change and the related query-core tests. Done means the repro succeeds with reader retry and retryDelay, while unset options still use hydrate options and client defaults.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
(🤖 Drafted with Opus 5.5, then read and edited word by word by me.)
Describe the bug
If the server dehydrates a query that's still pending, hydrate resumes it in the browser before any component reads it. If that promise rejects, the retries use the options the fetch started with - the hydrate options and the client's defaults. The retry and retryDelay the reader sets are ignored, even if the reader mounted before the promise settled.
So a reader can't recover from a failed server fetch:
- Client default
retry: false, reader setsretry: 1: the query never retries. It ends inerrorwith the messageredacted, sincedehydrateredacts the server's error. - Reader sets
retry: false: the query still retries, after the client's default delay of about a second. - Reader sets
retryDelay: 10: the retry still waits about a second.
Your minimal, reproducible example
- StackBlitz: https://stackblitz.com/github/KATT/tanstack-query-hydrated-retry-repro?file=repro.ts&terminalHeight=40&view=editor
- Repository: https://github.com/KATT/tanstack-query-hydrated-retry-repro
Steps to reproduce
- Open the StackBlitz link. It installs deps, runs
npm startby itself and prints the output in the terminal. Or clone the repo and runnpm install && npm start. npm startruns thisrepro.tswithtsx, against@tanstack/[email protected]:
import {
QueryClient,
QueryObserver,
defaultShouldDehydrateQuery,
dehydrate,
hydrate,
} from '@tanstack/query-core'
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))
const queryKey = ['post', 1]
// 🖥️ Server: the query is still pending at dehydrate, and rejects later
const serverClient = new QueryClient({
defaultOptions: {
dehydrate: {
// include pending queries in dehydration, as in the Advanced SSR guide
shouldDehydrateQuery: (query) =>
defaultShouldDehydrateQuery(query) || query.state.status === 'pending',
},
},
})
serverClient
.query({
queryKey,
queryFn: () => sleep(10).then(() => Promise.reject(new Error('server error'))),
retry: false,
})
.catch(() => {})
const dehydratedState = dehydrate(serverClient)
// 🌐 Browser: retries are off by default, so we can see whether the reader's option wins
const browserClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
})
hydrate(browserClient, dehydratedState)
// 👀 This reader asks for 1 retry
const observer = new QueryObserver(browserClient, {
queryKey,
queryFn: () => sleep(10).then(() => 'data from the browser'),
retry: 1,
retryDelay: 10,
})
observer.subscribe(() => {})
await sleep(500)
const { status, data, error } = browserClient.getQueryState(queryKey)!
console.log({ status, data, error: error?.message })
// ✅ Expected: { status: 'success', data: 'data from the browser', error: undefined }
// 🐛 Actual on 5.106.0: { status: 'error', data: undefined, error: 'redacted' }
process.exit(0)
- It prints
{ status: 'error', data: undefined, error: 'redacted' }. The reader'sretry: 1never ran.
Expected behavior
I'd expect a hydrated query that rejects to retry with its reader's retry and retryDelay, like any other fetch. The script should print { status: 'success', data: 'data from the browser', error: undefined }. Today it keeps the client's defaults and ends with the redacted server error.
Options the reader doesn't set should still come from the hydrate options first and the client's defaults second, like now.
How often does this bug happen?
Every time
Screenshots or Videos
None - the script's output above shows the result.
Platform
- OS: any. I reproduced it on Linux.
- Runtime: Node 22.23.4. It also runs in StackBlitz's WebContainer. The bug is in query-core, so the browser doesn't matter.
Tanstack Query adapter
vanilla
TanStack Query version
v5.106.0
TypeScript version
7.0.2
Additional context
- React hits the same bug:
useQueryanduseSuspenseQueryunderHydrationBoundaryread the query through aQueryObserver. hydrateresumes a pending query withquery.fetch(undefined, { initialPromise })before any observer exists. The retryer readsretryandretryDelayfrom the options that fetch started with, so options an observer sets later never reach it.- Fix in #12511: when a fetch resumes a hydrated promise, the retryer uses the
retryandretryDelayan observer set itself, then thehydrateoptions, then the client's defaults. With it, the script above prints{ status: 'success', data: 'data from the browser', error: undefined }.
- Linguagem predominante
- TypeScript
- Estrelas
- 50.6k
- Forks
- 4.2k
- Merge médio
- 9h 50min
- PRs com merge (30d)
- 310
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TanStack/query
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
TanStack/query#12466 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Talvez livre de novo @LeonxLJX assumiu há 77 dias e não há nenhum pull request aberto. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
TanStack/query#11358 · 2 comentários · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
select that throws for placeholderData brings back the selection of data removed by resetQueriesTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 56/100
Mantenedores costumam responder em até 1 dia
-
Render loop since v5.105.2 when placeholderData, or its select result, is not referentially stableAberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 54/100
Mantenedores costumam responder em até 1 dia
-
useQueries: stable combine returns a stale result when a query updates before setQueries runsTalvez já em andamento @sakaintp assumiu há 1 dia. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 62/100
TanStack/query#12626 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de TanStack/query
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
fb55/htmlparser2#2579 ·
Mantenedores costumam responder em até 1 dia
-
bug good first issue needs-review
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 83/100
Mantenedores costumam responder em até 1 dia
-
Add Module DB RulesAbertadocumentation public
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 68/100
midnightntwrk/umbradb#65 ·
Mantenedores costumam responder em até 2 dias
-
area/channels kind/bug priority/medium
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
nanocoai/nanoclaw#4501 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
needs verification
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
Mantenedores costumam responder em até 13 dias