Repository navigation
Description
Provide environment information
bunx envinfo --system --binaries --browsers --npmPackages "typescript,next,react,@trpc/server,@trpc/client,@trpc/react,@trpc/react-query,@trpc/client,@trpc/next,@tanstack/react-query"
System:
OS: Windows 11 10.0.26100
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Memory: 11.88 GB / 31.92 GB
Binaries:
Node: 20.7.0 - C:\Program Files\nodejs\node.EXE
npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.14.3 - ~\AppData\Local\pnpm\pnpm.EXE
bun: 1.2.10 - ~\.bun\bin\bun.EXE
Browsers:
Edge: Chromium (134.0.3124.93)
Internet Explorer: 11.0.26100.1882
npmPackages:
@tanstack/react-query: ^5.74.7 => 5.74.7
@trpc/client: ^11.1.1 => 11.1.1
@trpc/server: ^11.1.1 => 11.1.1
next: 15.3.1 => 15.3.1
react: ^19.0.0 => 19.1.0
typescript: ^5 => 5.8.3
Describe the bug
By voiding your prefetch calls on the server (instead of awaiting), the prefetch sometimes isn't done when rendering on the server, so when using some kind of loading indicators, these will get rendered by the server. Now sometimes on the client, the data is instantly available by the prefetch, so by the time the client render starts, the data gets instantaneously rendered and the loading state gets skipped. This causes a hydration error.
This problem was also discussed on the discord: https://discord.com/channels/867764511159091230/1311314438443499621 / https://discord-questions.trpc.io/m/1311314438443499621
I'm not sure if this is a trpc or tanstack-react-query bug or if im doing something wrong.
Temporary fixes include:
awaiting your prefetch instead ofvoiding them like the docs currently say it they should asawaitdisables some of the streaming stuff- using
useSuspenseQuery(was said in the discord channel / haven't tested) - forcefully set
isPendingtotrueon the very first client-side render
Link to reproduction
https://github.com/Entropy-10/hydration-failed-trpc-clerk (note that this is not my link but from someone in the discord, haven't tested this)
To reproduce
do a prefetch call in a rsc component and not await it. in a child client-component use this query and have a loading-state and "data available"-state.
sometimes the loading state gets rendered on the server and the "data available"-state gets rendered on the client, resulting in a hydration error due to mismatch.
Additional information
No response
👨👧👦 Contributing
- 🙋♂️ Yes, I'd be down to file a PR fixing this bug!
Activity
ammarmbe commentedon May 27, 2025
i'm also getting this
saiichihashimoto commentedon Jun 3, 2025
I thought I was losing my mind, glad someone else can confirm this is happening
epicmau5time commentedon Jun 14, 2025
Also suppressHydrationWarning does not work on any components. Only thing I can do until a fix there is to comment out the voided prefetch call on the page.tsx and let the data be fetched after render in the client component. @leanderriefel, I feel it's repeatable enough for it to move from an unconfirmed tag.
Icestonks commentedon Jun 20, 2025
I think I'm encountering the same error.
I have tried to create a repo where the bug is being reproduced, as the one linked, is not available anymore: https://stackblitz.com/~/github.com/Icestonks/react-query-trpc-test
DogPawHat commentedon Jun 22, 2025
I was helping @Icestonks debug this. Its pretty infuriating, that much I can tell you.
Id like to know more about the api calls that people are doing with this. I could only get this to work under throttling in the browser - if the page hydrates before the api resolves you'll never see this issue, and I suspect most api endpoints are slower then nextjs page loads (especially in production).
Likewise, if anyone has managed to reproduce this issue outside of nextjs or trpc, just using react query - this feels very query specific to me.
leanderriefel commentedon Jun 22, 2025
Well there shouldn't be an error - especially when using the library the way the docs say it should be used - because a query responds too fast
saiichihashimoto commentedon Jun 22, 2025
I'm imagining a way to repro this would be to put a
setTimeoutdelay in a trpc route and the do thevoid prefetch. Then you'd get the page rendering while the prefetch is still occurring, which I believe is the source of the error.Icestonks commentedon Jun 22, 2025
@saiichihashimoto That's what I'm doing in the repo I sent a bit further up, where I'm encountering the error.
KATT commentedon Jul 9, 2025
Okay sooo
This is an annoying race condition indeed. And a
useSuspenseQuery()should circumvent ithttps://github.com/Icestonks/react-query-trpc-test
Let me have a play and see if it's something we can fix.
KATT commentedon Jul 9, 2025
Ah, note to self, I can only reproduce it reliably when first building and starting the project as then both the:
KATT commentedon Jul 9, 2025
Okay, I've debugged this now & appears that you can reproduce it without tRPC using only
@tanstack/react-query.@Icestonks, I've made a PR to your project to showcase it over @ Icestonks/react-query-trpc-test#4
Could you open an issue in https://github.com/TanStack/query instead?
KATT commentedon Jul 9, 2025
Possibly related: TanStack/query#9157 where
tryResolveSync(promise)was added which might be the root cause of this hydration issuemargs163 commentedon Jun 11, 2026
Is this issue solved? Because I followed all of the documentation steps for setting up trpc and react query with SSR, however I am still getting hydration issues
trpc-bot commentedon Nov 3, 2026
🤖 KATT traced this to TanStack Query's hydration (it reproduces without tRPC): with an unawaited prefetch, the server can render
useQuery's loading state while the browser already has the data. Read those prefetches withuseSuspenseQuery, orawaitthe prefetch for components that useuseQuery. #7838 updates the docs to say so. The fix belongs in TanStack Query, where it's tracked in TanStack/query#9399.docs: read unawaited RSC prefetches with `useSuspenseQuery` (trpc#7838)
github-actions commentedon Nov 4, 2026
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.