HydrationBoundary double fetching on subsequent visits
Maintainer thường phản hồi trong vòng 1 ngày
@sukvvon đang làm issue này rồi.
Từ ngày 14/12/2025.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu với bản tái hiện trên StackBlitz và theo dõi loader, HydrationBoundary, React.useMemo/useEffect cũng như hành vi của refetchOnMount khi điều hướng đi nơi khác rồi quay lại. Xác nhận rằng server tính toán dữ liệu dehydrated mới hai lần, sau đó kiểm tra rằng một query mới từ loader không refetch trên client trước khi quá trình hydration hoàn tất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
I used HydrationBoundary in React Router. In loader(), I get the data, dehydrate it, then hydrate the client side query client.
- For the first visit, since it's a new query, it got hydrated in
React.useMemo - For subsequent visits, it will be deferred to
React.useEffect, however, if the cache is stale, query client will refetch beforeuseEffect, which makes the server compute the data twice: one in loader, the other in the component
I looked into the source code and found that it's due to refetchOnMount, which is true by default. I think it would be plausible to prevent a refetch if the query in the dehydrated state is fresh.
There are some experiments in the provided code, e.g. initialData from React Query meets React Router, initialData + initialDataUpdatedAt, HydrationBoundary, and my custom hook use-hydrated-query which sets refetchOnMount to false for that query if not explicitly provided during hydration. You may navigate away and back for each experiment and see the log in console to reproduce the issue.
Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-yiggax3s
Steps to reproduce
mentioned in 'Describe the bug'
Expected behavior
If query is fresh from loader(), client side query client should not refetch
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Any browser
Tanstack Query adapter
react-query
TanStack Query version
v5.85.3
TypeScript version
5.8.3
Additional context
No response
- Ngôn ngữ chính
- TypeScript
- Star
- 50.4k
- Fork
- 4.2k
- Merge trung bình
- 11 giờ 33 phút
- Pull request đã merge (30 ngày)
- 421
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
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đ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
-
solid-query: switching the queryClient accessor strands the new client's cache (subscription stays on the old observer)Có thể đã có người làm @MaNaN1803 đã nhận 74 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
TanStack/query#11106 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
setQueryData: NoInfer loses discriminated-union members when spreading a narrowed updater valueCó thể đã có người làm @iosayin đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
-
setQueryData updater loses discriminated-union fields when spreading inferred NoInfer dataCó thể đã có người làm @boriskozak đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
TanStack/query#11794 · 1 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ự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
solana-foundation/solana-com#2245 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`document.cookie` with `max-age=0` does not delete the cookieCó thể đã có người làm @BartInTheField đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
capricorn86/happy-dom#2460 ·
Maintainer thường phản hồi trong vòng 2 ngày