You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
docs: read unawaited RSC prefetches with useSuspenseQuery - #7838
It's a TanStack Query bug, still open upstream as TanStack/query#9399. It reproduces on the latest versions (Next 16.4.4, React 19.3.1, @tanstack/react-query 5.105.3), with plain TanStack Query and with tRPC handles plus unstable_createHydrateClient. useSuspenseQuery and awaited prefetches don't hit it.
The v11 docs pair a void prefetch with useQuery, and the handles page says the HTML just shows the loading state. The v12 docs (integrations/rsc.md) already say what to do.
What
Bring the v12 wording to v11: read an unawaited prefetch with useSuspenseQuery; for a component on useQuery, await the prefetch.
tanstack-react-query/server-components.md:
"Using your API" names useSuspenseQuery for unawaited prefetches and explains the mismatch.
Its useQuery example now awaits prefetchQuery.
The prefetch helper tip says to read its queries with useSuspenseQuery.
Using your API: same guidance; the useQuery example awaits prefetch.
Alternatives considered
Switch the useQuery examples to useSuspenseQuery: would repeat the "Leveraging Suspense" sections right below them.
Fix it in tRPC: the race is in TanStack Query's hydration (no server snapshot for useSyncExternalStore), not tRPC. The upstream fix, TanStack/query#11500, is still open.
Testing
node build/twoslash-check.ts on the four pages: 72 blocks compile.
pnpm build-www passes, including the legacy URL check.
@trpc/react-query: pnpm typecheck, pnpm lint and oxfmt --check pass.
A Next App Router repro (production build, Playwright) gives React error Bump @types/node from 15.3.1 to 15.6.0Β #418 for void prefetch + useQuery whenever the data reaches the browser before hydration, and no error for useSuspenseQuery or an awaited prefetch.
Β Β
Open in [code]smith Β· Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
Documentation
Clarified that useSuspenseQuery can consume data from a prefetch that hasnβt been awaited.
Warned that pairing an unawaited prefetch with useQuery can cause a hydration mismatch if the server renders a loading state while data is already available in the browser.
Updated examples and guidance to await prefetches when using useQuery; handle readers can use unstable_$ensure to wait for data.
Confirmed that the prefetch helper does not wait for a query to finish.
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
The guides clarify when to await server-side prefetching. They recommend useSuspenseQuery for unawaited prefetches and show awaited prefetch calls in examples.
Changes: Server Component prefetch guidance
Layer / File(s)
Summary
Prefetch guidance and examples www/v11/docs/client/nextjs/app-router-setup.md, www/v11/docs/client/tanstack-react-query/server-components.md, www/v11/docs/client/react/server-components.md, www/v11/docs/client/tanstack-react-query/handles.md, packages/react-query/src/rsc.tsx
The guides warn that an unawaited prefetch can cause a hydration mismatch when a server-rendered component uses useQuery. They recommend useSuspenseQuery for unawaited prefetches and awaiting prefetches for useQuery. Examples now await their prefetch calls. For handles, the guide recommends unstable_$ensure when a component uses useQuery.
The examples consistently distinguish awaited prefetches from suspense reads. The change is mergeable with minor wording follow-up; clarify when cached data avoids suspension and confirm the earlier useQuery wording concern is addressed.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbitβs high-level summary is enabled.
Title check
The title names the main change: the docs now tell readers to read unawaited RSC prefetches with useSuspenseQuery. The diffs in the three server-component guides and the rsc.tsx JSDoc example match β¦
Docstring Coverage
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentatβ¦
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: the docs now tell readers to read unawaited RSC prefetches with useSuspenseQuery. The diffs in the three server-component guides and the rsc.tsx JSDoc example match this. The title does not mention the hydration-mismatch fix or the await guidance for useQuery readers, but that is a detail, not the main point. The title is short, specific, and uses no vague terms.
Full details: Docstring Coverage
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (3 skipped: 3 unsupported.)
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix Β· Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Files skipped from review as they are similar to previous changes: 1
packages/react-query/src/rsc.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
423-423: Minor Β· Maintainability & Code Quality Β· Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Use βusing useQueryβ instead of βon useQueryβ.
The phrase βFor a component on useQueryβ is grammatically incorrect. Use βFor a component using useQueryβ. Apply the same correction in www/v11/docs/client/tanstack-react-query/server-components.md at Line 367. (github.com)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
cursorBot
changed the title
docs(v11): read unawaited RSC prefetches with useSuspenseQuery
docs: read unawaited RSC prefetches with useSuspenseQueryNov 2, 2026
The reason will be displayed to describe this comment to others. Learn more.
π€ Approving per Alex (option A). Docs plus one JSDoc example, no runtime change. Required checks are green on a357903. The guidance matches TanStack/query#9399, and a Next 16 + TanStack Query 5.105.3 repro confirms it.
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
π€ Docs and one JSDoc example; no runtime change. Related: #6740.
Why
await,useQuerycan hydrate wrong: the server renders the loading state while the browser already has the data, and React reports a mismatch (bug: Hydration error using loading state of useQuery when prefetchingΒ #6740).@tanstack/react-query5.105.3), with plain TanStack Query and with tRPC handles plusunstable_createHydrateClient.useSuspenseQueryand awaited prefetches don't hit it.voidprefetch withuseQuery, and the handles page says the HTML just shows the loading state. The v12 docs (integrations/rsc.md) already say what to do.What
useSuspenseQuery; for a component onuseQuery,awaitthe prefetch.tanstack-react-query/server-components.md:useSuspenseQueryfor unawaited prefetches and explains the mismatch.useQueryexample nowawaitsprefetchQuery.prefetchhelper tip says to read its queries withuseSuspenseQuery.tanstack-react-query/handles.md:useQuery": with server rendering, read anunstable_$prefetchhandle withuseSuspenseQuery, or wait withunstable_$ensure. Links Hydration error using loading state of useQuery when prefetchingΒ TanStack/query#9399.unstable_$prefetchbullet pointsuseQueryreaders there.nextjs/app-router-setup.md:useQuerybelow it, nowawaitsgetQueryClient().prefetchQuery(β¦)instead of callingprefetch.react/server-components.md(classic@trpc/react-query):useQueryexample nowawaitstrpc.hello.prefetch().packages/react-query/src/rsc.tsx: theHydrateClientJSDoc example, read withuseQuery, nowawaits the prefetch in anasynccomponent. Comment only.useSuspenseQuery; unchanged.Links
useSuspenseQueryfor unawaited prefetches; theuseQueryexampleawaits; the helper tip points to Suspense.useQuery: server-rendering bullet corrected.unstable_$prefetch: pointsuseQueryreaders to it.awaitsprefetchQuery.useQueryexampleawaitsprefetch.Alternatives considered
useQueryexamples touseSuspenseQuery: would repeat the "Leveraging Suspense" sections right below them.useSyncExternalStore), not tRPC. The upstream fix, TanStack/query#11500, is still open.Testing
node build/twoslash-check.tson the four pages: 72 blocks compile.pnpm build-wwwpasses, including the legacy URL check.@trpc/react-query:pnpm typecheck,pnpm lintandoxfmt --checkpass.voidprefetch +useQuerywhenever the data reaches the browser before hydration, and no error foruseSuspenseQueryor an awaited prefetch.Open in [code]smith Β· Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit
useSuspenseQuerycan consume data from a prefetch that hasnβt been awaited.useQuerycan cause a hydration mismatch if the server renders a loading state while data is already available in the browser.useQuery; handle readers can useunstable_$ensureto wait for data.prefetchhelper does not wait for a query to finish.