Skip to content

docs: read unawaited RSC prefetches with useSuspenseQuery - #7838

Merged
KATT merged 6 commits into
mainfrom
cursor/docs-unawaited-prefetch-suspense-56b3
Nov 3, 2026
Merged

KATT merged 6 commits into
mainfrom
cursor/docs-unawaited-prefetch-suspense-56b3

Conversation

@KATT

@KATT KATT commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

πŸ€– Docs and one JSDoc example; no runtime change. Related: #6740.

Why

  • With a prefetch you don't await, useQuery can 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).
  • 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.
  • tanstack-react-query/handles.md:
  • nextjs/app-router-setup.md:
    • "Prefetching in a Server Component" gets the same guidance.
    • Its example, read by useQuery below it, now awaits getQueryClient().prefetchQuery(…) instead of calling prefetch.
  • react/server-components.md (classic @trpc/react-query):
    • "Using your API" gets the same guidance.
    • Its useQuery example now awaits trpc.hello.prefetch().
  • packages/react-query/src/rsc.tsx: the HydrateClient JSDoc example, read with useQuery, now awaits the prefetch in an async component. Comment only.
  • The Suspense sections already pair an unawaited prefetch with useSuspenseQuery; unchanged.

Links

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 WebΒ Open in CursorΒ 

Autofix with [code]smith
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.

@KATT
KATT requested a review from a team as a code owner November 2, 2026 19:51
@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
www Ready Ready Preview Nov 3, 2026 11:56am UTC
6 Skipped Deployments
Project Deployment Actions Updated
examples-next-minimal-starter Skipped Skipped Nov 3, 2026 11:56am UTC
examples-todomvc Skipped Skipped Nov 3, 2026 11:56am UTC
next-prisma-starter Skipped Skipped Nov 3, 2026 11:56am UTC
next-prisma-websockets-starter Skipped Skipped Nov 3, 2026 11:56am UTC
tanstack-start-sse-chat Skipped Skipped Nov 3, 2026 11:56am UTC
trpc-next-app-dir Skipped Skipped Nov 3, 2026 11:56am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack β†’

Note

Reviews paused

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.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

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.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Suggested reviewers: nick-lucas, juliusmarminge

Merge Risk: Low Β· previous review d31fc

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: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 7a18440 and d31fc31.

Files selected for processing: 4
  • packages/react-query/src/rsc.tsx
  • www/v11/docs/client/nextjs/app-router-setup.md
  • www/v11/docs/client/tanstack-react-query/handles.md
  • www/v11/docs/client/tanstack-react-query/server-components.md
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.

@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 2, 2026 19:55 Inactive
@vercel
vercel Bot temporarily deployed to Preview – next-prisma-starter November 2, 2026 19:55 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-next-minimal-starter November 2, 2026 19:55 Inactive
@vercel
vercel Bot temporarily deployed to Preview – trpc-next-app-dir November 2, 2026 19:55 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1
www/v11/docs/client/nextjs/app-router-setup.md-423-423: 1

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)


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 33f6d49 and 012bbfb.

Files selected for processing: 2
  • www/v11/docs/client/nextjs/app-router-setup.md
  • www/v11/docs/client/tanstack-react-query/server-components.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/@trpc/client@7838

@trpc/next

npm i https://pkg.pr.new/@trpc/next@7838

@trpc/openapi

npm i https://pkg.pr.new/@trpc/openapi@7838

@trpc/react-query

npm i https://pkg.pr.new/@trpc/react-query@7838

@trpc/server

npm i https://pkg.pr.new/@trpc/server@7838

@trpc/tanstack-react-query

npm i https://pkg.pr.new/@trpc/tanstack-react-query@7838

@trpc/upgrade

npm i https://pkg.pr.new/@trpc/upgrade@7838

commit: a357903

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread packages/react-query/src/rsc.tsx Resolved

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

@vercel
vercel Bot temporarily deployed to Preview – trpc-next-app-dir November 3, 2026 11:54 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-next-minimal-starter November 3, 2026 11:54 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 3, 2026 11:54 Inactive
@vercel
vercel Bot temporarily deployed to Preview – next-prisma-starter November 3, 2026 11:54 Inactive

@trpc-bot trpc-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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.

@KATT
KATT added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit c6a7e7d Nov 3, 2026
52 checks passed
@KATT
KATT deleted the cursor/docs-unawaited-prefetch-suspense-56b3 branch November 3, 2026 12:36
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 4, 2026

This branch was successfully deployed

1 active and 4 inactive deployments
Preview – www β€” a3579033 Deployed Nov 3, 2026 by vercel[bot]
Preview – next-prisma-starter β€” a3579033 Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-todomvc β€” a3579033 Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-next-minimal-starter β€” a3579033 Deployed Nov 3, 2026 by vercel[bot]
Preview – trpc-next-app-dir β€” a3579033 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants