Skip to content

docs(next): use TanStack React Query in Next.js docs, deprecate react-query-based helpers - #7830

Merged
KATT merged 7 commits into
mainfrom
cursor/next-docs-tanstack-react-query-8095
Nov 2, 2026
Merged

KATT merged 7 commits into
mainfrom
cursor/next-docs-tanstack-react-query-8095

Conversation

@KATT

@KATT KATT commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Follows #7829, which reverted #7805 and has merged.

Why

  • The Next.js docs still taught @trpc/react-query, which only gets bug fixes and goes away in the next major. @trpc/tanstack-react-query works with the Pages Router too, but no page showed how.
  • @trpc/next as a whole stays: its experimental App Router helpers have no TanStack replacement yet. Only the parts built on @trpc/react-query are deprecated.

What

  • Every Next.js page now uses @trpc/tanstack-react-query. Samples name their query results and use Suspense or switch on status.
    • Pages Router setup: a makeQueryClient factory, createTRPCContext, and QueryClientProvider, TRPCProvider and HydrationBoundary in _app. A "Using a data transformer" section runs the whole prefetched cache through superjson, because Next.js page props must be JSON, and query inputs are in the keys, not just the data. The createTRPCNext() options section is replaced by "Moving from createTRPCNext", a table of what replaces each part.
    • SSR: prefetch per page in getServerSideProps replaces ssr: true. It builds the context from context.req, verifying the session from the cookie, and sets the status and cache headers on context.res (with fetchQuery and notFound for a 404). Calling a separate API server is in a collapsible section.
    • SSG and Server-Side Helpers: createTRPCOptionsProxy, prefetchQuery and dehydrate instead of createServerSideHelpers.
    • Aborting: trpc: { abortOnUnmount: true } on each query, and a note that a batched request only stops once every query in it is cancelled.
    • App Router setup: two samples fixed for style. The rest already used TanStack.
    • Next.js overview: the Pages Router section and comparison table, plus a short deprecation note.
  • @deprecated JSDoc, linking to the replacement, on createTRPCNext, withTRPC, ssrPrepass, the ssr, ssrPrepass and responseMeta options, and their option types.
  • #7812, now on main, also marked the @trpc/next/app-dir/* exports @deprecated. This PR removes those tags, since nothing replaces those exports yet, and keeps docs(next): document the public API and deprecate it in favor of @trpc/tanstack-react-query #7812's descriptions. JSDoc links to setup anchors this PR removes now point to "Moving from createTRPCNext".
  • @trpc/next's README says the same.
  • Outside the Next.js pages: the Response Caching tip is scoped to the Pages Router (CodeRabbit's note on revert(www): un-deprecate @trpc/next for now #7829). The Client overview's Next.js sentence is updated. httpBatchLink drops its createTRPCNext sample. The classic useQuery page stops linking to the removed setup anchors.

Links

Alternatives considered

  • A helper that brings back ssr: true on top of TanStack. It would bring back a pattern the App Router has replaced, and per-page prefetchQuery plus dehydrate is only a few lines.
  • Deprecating all of @trpc/next. That's on hold until the App Router helpers have a replacement.
  • serializeData in the query client for the transformer, as the App Router setup does. It only transforms query data, so an undefined or Date in an input still fails Next.js's props check.

Testing

  • Twoslash compiles every changed sample. pnpm --filter www typecheck, lint and test (including the package docs-link check), pnpm format, pnpm validate-skills, the root test suite, and @trpc/next's typecheck and lint pass.
  • I ran the Pages Router pattern from the final docs in a throwaway Next.js 15 app (not committed), with next build, next start and a headless browser:
    • A plain page fetches in the browser.
    • A getServerSideProps page and a getStaticProps page, whose query input has an undefined field, render their data into the HTML. The superjson Date arrives as a Date, the browser sends no tRPC request, and there are no console errors.
    • The context reads the session from the cookie, notFound returns a 404, and the cache-control header is set.

The examples that still use createTRPCNext aren't moved here.

AI model

Claude Opus 5.5

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
    • Updated Next.js guidance to recommend the TanStack React Query integration for both App Router and Pages Router projects.
    • Clarified that createTRPCNext, withTRPC, and automatic SSR options are deprecated; the legacy integration receives bug fixes only and is planned for removal in the next major version.
    • Reworked Pages Router setup, query cancellation, SSR, SSG, and server-side helper examples around per-page prefetching and cache hydration.
    • Expanded guidance on cache headers, query cancellation, and prefetch-versus-fetch behavior, and improved examples with explicit loading, error, and success states.
    • Clarified that experimental App Router helpers are not deprecated.

@KATT
KATT requested review from a team as code owners November 2, 2026 18:08
@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
examples-next-minimal-starter Ready Ready Preview Nov 2, 2026 9:35pm UTC
examples-todomvc Ready Ready Preview Nov 2, 2026 9:35pm UTC
next-prisma-starter Ready Ready Preview Nov 2, 2026 9:35pm UTC
next-prisma-websockets-starter Ready Ready Preview Nov 2, 2026 9:35pm UTC
tanstack-start-sse-chat Ready Ready Preview Nov 2, 2026 9:35pm UTC
trpc-next-app-dir Ready Ready Preview Nov 2, 2026 9:35pm UTC
www Ready Ready Preview Nov 2, 2026 9:35pm 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

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 940bd37 and 42b9884.

Files selected for processing: 8
  • packages/next/src/app-dir/client.ts
  • packages/next/src/app-dir/create-action-hook.tsx
  • packages/next/src/app-dir/links/nextCache.ts
  • packages/next/src/app-dir/links/nextHttp.ts
  • packages/next/src/app-dir/server.ts
  • packages/next/src/createTRPCNext.tsx
  • packages/next/src/ssrPrepass.ts
  • packages/next/src/withTRPC.tsx
Files with no reviewable changes: 5
  • packages/next/src/app-dir/links/nextCache.ts
  • packages/next/src/app-dir/links/nextHttp.ts
  • packages/next/src/app-dir/client.ts
  • packages/next/src/app-dir/server.ts
  • packages/next/src/app-dir/create-action-hook.tsx
Files skipped from review as they are similar to previous changes: 3
  • packages/next/src/ssrPrepass.ts
  • packages/next/src/createTRPCNext.tsx
  • packages/next/src/withTRPC.tsx

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

Walkthrough

The PR updates @trpc/next deprecation guidance and rewrites Pages Router documentation around @trpc/tanstack-react-query. It documents client setup, per-page prefetching, hydration, query handling, and migration patterns. Experimental App Router helpers are not marked as deprecated.

Changes: Next.js TanStack React Query migration

Layer / File(s) Summary
Deprecation notices and migration guidance
packages/next/README.md, packages/next/src/*, www/v11/docs/client/nextjs.md, www/v11/docs/client/react/useQuery.md
Package comments and documentation mark classic Pages Router helpers as deprecated and direct readers to TanStack React Query migration guidance. The experimental App Router helpers are distinguished from the deprecated APIs.
Pages Router client setup and query use
www/v11/docs/client/nextjs/pages-router/setup.md, www/v11/docs/client/nextjs/pages-router/aborting-procedure-calls.md, www/v11/docs/client/nextjs/app-router-setup.md
Setup examples use TanStack React Query providers and query options. The aborting guide shows query-level cancellation. Query examples render pending, error, and success states.
Page prefetching, hydration, and rendering
www/v11/docs/client/nextjs/pages-router/server-side-helpers.md, www/v11/docs/client/nextjs/pages-router/ssg.md, www/v11/docs/client/nextjs/pages-router/ssr.md
The guides use query-option proxies and query clients for server-side and static-generation prefetching. They document dehydrated state, error handling, and query rendering.
Related Next.js integration guidance
www/v11/docs/client.md, www/v11/docs/client/links/httpBatchLink.md, www/v11/docs/server/caching.md
The client overview and HTTP batch link guidance point Next.js users to the TanStack React Query integration. The caching note links to the Pages Router SSR guide.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Possibly related issues

  • trpc/trpc#7596: The PR updates Next.js documentation to use @trpc/tanstack-react-query and changes App Router examples.
  • trpc/trpc#3708: The SSR guidance documents request-derived context for server-side tRPC calls.
  • trpc/trpc#4448: The aborting guide documents query-level abortOnUnmount behavior.

Possibly related PRs

  • trpc/trpc#7805: This PR also addresses the Pages Router migration to TanStack React Query.
  • trpc/trpc#7804: This PR marks classic React Query APIs deprecated in favor of TanStack React Query, which this PR applies to Next.js helpers and guides.
  • trpc/trpc#7829: This PR distinguishes experimental App Router helpers from deprecated Pages Router helpers.

Suggested reviewers: juliusmarminge, nick-lucas

Merge Risk: Minimal · up to 42b98

The documented Pages Router examples distinguish JSON-only data from the transformer path needed for non-JSON data. No identified issue remains to block merging.

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 clearly and concisely describes the main changes: updating Next.js documentation to use TanStack React Query and deprecating the React Query-based helpers.
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: 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 3 files.

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

@trpc-bot

trpc-bot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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 – next-prisma-starter November 2, 2026 18:19 Inactive
@vercel
vercel Bot temporarily deployed to Preview – trpc-next-app-dir November 2, 2026 18:19 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-next-minimal-starter November 2, 2026 18:19 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 2, 2026 18:19 Inactive
@trpc-bot

trpc-bot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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@7830

@trpc/next

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

@trpc/openapi

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

@trpc/react-query

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

@trpc/server

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

@trpc/tanstack-react-query

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

@trpc/upgrade

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

commit: 42b9884

Base automatically changed from cursor/revert-trpc-next-deprecation-8095 to main November 2, 2026 20:07
trpc-bot
trpc-bot previously approved these changes Nov 2, 2026

@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.

All required checks pass at 7fb7c7d, and every CodeRabbit thread is fixed or answered, then resolved.

Keep main's JSDoc descriptions for @trpc/next, with this branch's
deprecation notes on the react-query-based APIs. Leave the app-dir
exports undeprecated, and point links at setup anchors that still exist.

Co-authored-by: alexander <[email protected]>
@trpc-bot

trpc-bot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

Required checks pass at 42b9884, and no CodeRabbit threads are open.

@KATT
KATT added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit f11951c Nov 2, 2026
53 of 54 checks passed
@KATT
KATT deleted the cursor/next-docs-tanstack-react-query-8095 branch November 2, 2026 22:31
@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

5 active deployments
Preview – www — 42b98841 Deployed Nov 2, 2026 by vercel[bot]
Preview – next-prisma-starter — 42b98841 Deployed Nov 2, 2026 by vercel[bot]
Preview – examples-next-minimal-starter — 42b98841 Deployed Nov 2, 2026 by vercel[bot]
Preview – examples-todomvc — 42b98841 Deployed Nov 2, 2026 by vercel[bot]
Preview – trpc-next-app-dir — 42b98841 Deployed Nov 2, 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