A hydrated query that rejects ignores the reader's `retry` and `retryDelay`
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
(🤖 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 }.
- Ngôn ngữ chính
- TypeScript
- Star
- 50.6k
- Fork
- 4.2k
- Merge trung bình
- 9 giờ 50 phút
- Pull request đã merge (30 ngày)
- 310
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/query
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
TanStack/query#12466 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Có thể làm lại được @LeonxLJX đã nhận 77 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
TanStack/query#11358 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
select that throws for placeholderData brings back the selection of data removed by resetQueriesCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 56/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Render loop since v5.105.2 when placeholderData, or its select result, is not referentially stableĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 54/100
Maintainer thường phản hồi trong vòng 1 ngày
-
useQueries: stable combine returns a stale result when a query updates before setQueries runsCó thể đã có người làm @sakaintp đã nhận 1 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
TanStack/query#12626 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/query
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fb55/htmlparser2#2579 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue needs-review
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add Module DB RulesĐang mởdocumentation public
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
midnightntwrk/umbradb#65 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area/channels kind/bug priority/medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nanocoai/nanoclaw#4501 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docker images: plain X.Y.Z tag (e.g. 7.2.3) is never updated after the initial release buildĐang mởneeds verification
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 13 ngày