Hydration error using loading state of useQuery when prefetching

未關閉
#9,399 20 則留言 7 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@DogPawHat 已經在處理了。

開始於 2026年9月15日。

  • #9572 來自 @joseph0926 —— 已關閉,未合併
  • #11278 來自 @adityachaudhary99 —— 已關閉,未合併
  • #11500 來自 @DogPawHat —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
45/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
react, typescript
領域
frontend

研究方向

從連結的 StackBlitz 重現開始,追蹤伺服器 prefetch、客戶端 hydration,以及 useQuery isLoading 的渲染路徑。閱讀相關的 tRPC issue 以了解背景;建置並啟動專案後,重現不再產生 hydration 錯誤即表示完成。

由索引模型根據 Issue 內容生成。

描述

Describe the bug

If you prefetch data on the server and then use useQuery with isLoading on the client, it can lead to a hydration error.

Your minimal, reproducible example

https://stackblitz.com/~/github.com/Icestonks/react-query-trpc-test

Steps to reproduce
  1. Prefetch something on the server
  2. Hydrate it to the client
  3. Use useQuery in the client, and have a loading fallback with isLoading.

Then there should come a hydration error.

Expected behavior

When first building and starting the project, we should see an hydration error. The error can also come at other times, but that's the most reliable way, to get the error to occur.

How often does this bug happen?

Sometimes

Screenshots or Videos
Image
Platform
  • OS: Windows
  • Browser: Google Chrome
  • Browser version: 138.0.7204.100
Tanstack Query adapter

react-query

TanStack Query version

5.82.0

TypeScript version

5.8.3

Additional context

Initially, the issue was thought to be related to tRPC, so there has been some discussion about the error over there: https://github.com/trpc/trpc/issues/6740

Would highly recommend reading some of the comments from that issue. Could maybe also give some more context.

主要語言
TypeScript
星號
50.5k
分支
4.2k
平均合併
10 小時 23 分鐘
30 天內合併 PR
581

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TanStack/query 的其他 Issue

查看 TanStack/query 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。