Skip to content

docs(tanstack-react-query): start queries ahead of time with handles in the setup guides - #7847

Closed
KATT wants to merge 4 commits into
mainfrom
v11-docs-ensure-queries
Closed

KATT wants to merge 4 commits into
mainfrom
v11-docs-ensure-queries

Conversation

@KATT

@KATT KATT commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Why

  • The setup guides showed useQuery(trpc.x.queryOptions(input)) called ad hoc in components. A server or loader prefetch then had to repeat the same procedure and input, and nothing checked that they matched.
  • 11.23.0's handles fix that: a loader or server component starts the query with unstable_$ensure (or unstable_$prefetch), and the component reads the handle with trpc.unstable_$fromHandle(handle). The data is in the cache before render, and the read can't drift from what was started.
  • This makes that the default pattern in the guides. Pages about query options themselves keep queryOptions.

What

  • Next.js App Router setup and Server Components:
    • trpc/client.tsx exports type TRPC = TRPCOptionsProxy<AppRouter>.
    • trpc/server.tsx uses unstable_createHydrateClient(getQueryClient) instead of a hand-written HydrateClient and prefetch helper.
    • Pages await trpc.hello.unstable_$ensure(input) and pass the handle. Client components read it with useQuery(trpc.unstable_$fromHandle(props.greeting)).
    • The Suspense section streams with unstable_$prefetch and useSuspenseQuery.
    • "Data on the server" uses unstable_$ensure plus ensureQueryData, not fetchQuery.
    • The examples compile against a real router and proxy, not declare module stubs.
  • Pages Router (setup step 7, SSR, SSG, server-side helpers): getServerSideProps/getStaticProps return the handle from unstable_$ensure next to trpcState, and the page reads it. The 404 example catches the rejection from unstable_$ensure. The setup page's mistakes list says to pass handles instead of repeating the query.
  • TanStack React Query setup step 4: a UserCard reads a handle. It's fed by a React Router loader with unstable_$ensure, or in render with unstable_$prefetch when there's no loader.
  • Usage: the quick example shows a loader with unstable_$ensure and a component reading the handle. The rest of the page, which documents the options and keys, is unchanged.
  • Migrating: a tip after the hook mapping points to handles. The mapping tables are unchanged.
  • Handles guide: the Next.js section now says the setup already has TRPC and unstable_createHydrateClient.
  • Not changed: abortOnUnmount pages, the waterfalls demo, v9/v10 docs and blog posts.
  • www/build/collapse.ts: the Shiki transformer is named trpc-docs:collapse, like the others (trpc-docs:code-meta, trpc-docs:type-queries).

Before (pages-router/ssr.md):

await queryClient.prefetchQuery(trpc.post.byId.queryOptions({ id }));
return { props: { trpcState: dehydrate(queryClient), id } };
// page
const postQuery = useQuery(trpc.post.byId.queryOptions({ id: props.id }));

After:

const post = await trpc.post.byId.unstable_$ensure({ id });
return { props: { trpcState: dehydrate(queryClient), post } };
// page
const postQuery = useQuery(trpc.unstable_$fromHandle(props.post));

Checks run locally:

  • pnpm --filter www check-twoslash: 461 blocks in 102 files compile.
  • pnpm typecheck-www, pnpm --filter www test and pnpm --filter www lint pass.
  • pnpm validate-skills passes. The generated nextjs-pages-router skill is 494 lines, under the 500-line limit.
  • pnpm --filter www build passes: all 698 URLs work.
  • A handle returned from getServerSideProps passes Next.js's isSerializableProps check and reads back after hydrating. A handle for a procedure without an input carries input: undefined, which Next.js rejects. The SSR page notes this.

Links

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 App Router and Pages Router guides with examples for starting server-side queries and reading them through query handles.
    • Added guidance on waiting for query results, streaming pending queries with Suspense, handling errors, and reusing cached data.
    • Expanded TanStack Query setup and migration examples to cover query handles in loaders and server components, including loading-state considerations and handle input requirements.
    • Clarified setup guidance for hydrating server-started queries and passing query handles to client components.

cursoragent and others added 3 commits November 3, 2026 11:30
…_$ensure and pass handles in the setup guides

Co-authored-by: alexander <[email protected]>
…the handles guide at the setup's HydrateClient

Co-authored-by: alexander <[email protected]>
@KATT
KATT requested a review from a team as a code owner November 3, 2026 11:50
@vercel

vercel Bot commented Nov 3, 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 12:02pm UTC
6 Skipped Deployments
Project Deployment Actions Updated
examples-next-minimal-starter Skipped Skipped Nov 3, 2026 12:02pm UTC
examples-todomvc Skipped Skipped Nov 3, 2026 12:02pm UTC
next-prisma-starter Skipped Skipped Nov 3, 2026 12:02pm UTC
next-prisma-websockets-starter Skipped Skipped Nov 3, 2026 12:02pm UTC
tanstack-start-sse-chat Skipped Skipped Nov 3, 2026 12:02pm UTC
trpc-next-app-dir Skipped Skipped Nov 3, 2026 12:02pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The documentation updates show query handles in TanStack React Query and Next.js server-rendering examples. The examples cover starting queries, passing handles to client components, reading cached data, and handling query failures. The Shiki transformer’s registered name also changes.

Changes: Query Handle Guides

Layer / File(s) Summary
TanStack setup and usage
www/v11/docs/client/tanstack-react-query/setup.md, www/v11/docs/client/tanstack-react-query/usage.md, www/v11/docs/client/tanstack-react-query/migrating.md
The setup and quick-start examples use typed handles, loader-based unstable_$ensure, unstable_$prefetch, and client-side unstable_$fromHandle. The migration guide adds a handle-based query example.
App Router and server-component handle flow
www/v11/docs/client/nextjs/app-router-setup.md, www/v11/docs/client/tanstack-react-query/server-components.md, www/v11/docs/client/tanstack-react-query/handles.md
The guides show HydrateClient created with unstable_createHydrateClient, server-side query handles, and client-side handle readers. They include ensured and pending query examples, Suspense usage, cached-data reads, and related setup guidance.
Pages Router server-rendered query flow
www/v11/docs/client/nextjs/pages-router/*
The SSR, SSG, setup, and helper examples return handles alongside dehydrated cache state. Pages read queries from those handles. The SSR guide also shows handling NOT_FOUND errors from unstable_$ensure.

Transformer Name

Layer / File(s) Summary
Transformer registration
www/build/collapse.ts
The Shiki transformer’s registered name changes from raf-query-docs:collapse to trpc-docs:collapse. Its folding behavior is unchanged.

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

Change: Other

Possibly related issues

  • trpc/trpc#7596 — The App Router setup guide replaces the deprecated prefetch calls described in the issue with unstable_$ensure, unstable_$prefetch, and query handles.

Possibly related PRs

  • trpc/trpc#7830 — This PR continues the Next.js guide updates by showing handle-based query flows in the Pages Router and App Router.
  • trpc/trpc#7759 — This PR documents the query-handle APIs and hydration helper introduced in that PR.
  • trpc/trpc#7817 — This PR applies the handle-based loader-to-component flow to the Next.js and server-component guides.

Suggested reviewers: nick-lucas

Merge Risk: Minimal · up to 70b68

The handle-reader example now distinguishes loading from failure. No actionable merge-blocking issue remains in the supplied changes.

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 uses the conventional docs(scope) prefix and names the main change: the TanStack React Query setup guides now start queries ahead of time with handles. The raw summary confirms the bulk of t…
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 uses the conventional docs(scope) prefix and names the main change: the TanStack React Query setup guides now start queries ahead of time with handles. The raw summary confirms the bulk of the changeset is documentation for unstable_$ensure, unstable_$prefetch, and unstable_$fromHandle in those guides. The changeset also includes Next.js, Pages Router, and Shiki-transformer edits, which the title does not mention, but that is expected for a concise title. The title is specific and accurate.

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. (1 skipped: 1 unsupported.)

Finishing Touches
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 a3207bc and 70b68f9.

Files selected for processing: 1
  • 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; 7 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

@vercel
vercel Bot temporarily deployed to Preview – next-prisma-starter November 3, 2026 12:00 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-next-minimal-starter November 3, 2026 12:00 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 3, 2026 12:00 Inactive
@vercel
vercel Bot temporarily deployed to Preview – trpc-next-app-dir November 3, 2026 12:00 Inactive
@pkg-pr-new

pkg-pr-new Bot commented Nov 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

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

@trpc/next

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

@trpc/openapi

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

@trpc/react-query

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

@trpc/server

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

@trpc/tanstack-react-query

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

@trpc/upgrade

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

commit: 70b68f9

KATT added a commit that referenced this pull request Nov 3, 2026
…ined (#7848)

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Why

- A handle for a procedure without input carried `input: undefined`.
- Next.js rejects `undefined` anywhere in `getServerSideProps` /
`getStaticProps` props, so this threw:

  ```ts
  export async function getServerSideProps() {
    const viewer = await trpc.viewer.unstable_$ensure();
    return { props: { trpcState: dehydrate(queryClient), viewer } };
// Error serializing `.viewer.input` returned from `getServerSideProps`
in "/".
  }
  ```

## What

- `startHandle` leaves out the `input` key when the input is
`undefined`. All of `unstable_$prefetch`, `unstable_$ensure` and
`unstable_$fetch`, and the in-render prefetch, go through it.
- Before: `{ queryKey: [['viewer'], { type: 'query' }], input: undefined
}`
  - After: `{ queryKey: [['viewer'], { type: 'query' }] }`
- Reading `handle.input` still gives `undefined`, so types don't change.
The doc comment on `input` now says the key can be absent.
- Query keys don't change: the key already left out `undefined` input.
- No changeset, because the repo doesn't use changesets.
- Follow-up for [#7847](#7847): its
Pages Router SSR page has a note about this error. The note can go once
both PRs merge. If this PR merges first, #7847 removes the note.

## Links

None. No docs or examples change.

## Alternatives considered

- Keep the key and tell Pages Router users to work around it (the #7847
note). This loses because the handle is meant to be passed as a prop as
is.
- Use `null` for "no input". This loses because `null` is valid input
for some procedures and would change what `unstable_$fromHandle` passes
on.

## Testing

- New test in `packages/tanstack-react-query/test/handles.test.tsx`:
handles for a no-input procedure, from each verb and from an explicit
`undefined`, have only a `queryKey` key. They survive a JSON round trip
under `toStrictEqual`. After that round trip, `unstable_$fromHandle`
keys still match `queryOptions()` keys, both with and without input.
- It failed before the fix (`expected [ 'queryKey', 'input' ] to deeply
equal [ 'queryKey' ]`) and passes after. See the two commits.
- Checked against Next.js's own `isSerializableProps`: `main` throws
`Error serializing .viewer.input`, and this branch returns `true`.
- `pnpm test -- --watch false packages/tanstack-react-query`: 1479 tests
passed. `tsc --noEmit`, `oxlint` and `oxfmt --check` are clean.

## AI model

Claude Opus 5.5
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-1e6b0138-e595-5202-932f-a58bcf357f2b?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-1e6b0138-e595-5202-932f-a58bcf357f2b&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

<!-- codesmith:footer -->
---
<a
href="https://backend.blacksmith.sh/track/enable-autofix?expires=1796299078&installation_model_id=443568&pr_number=7848&ref=codesmith_pr_footer&repository=trpc%2Ftrpc&return_to=https%3A%2F%2Fgithub.com%2Ftrpc%2Ftrpc%2Fpull%2F7848&signature=f9042dc3fe5f7b5731189dc96179ac767028b62d4e4a1ab4a4027bb0d2693136"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img
alt="Autofix with [code]smith"
src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png"
width="190" height="28"></picture></a>
<sup><a
href="https://app.blacksmith.sh/trpc/codesmith/trpc/pr/7848?autoLogin=true&ref=codesmith_pr_footer">Open
in [code]smith</a> · Need help on this PR? Tag
<code>@codesmith-bot</code> with what you need.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Query handles for procedures without input now contain only the query
key, including when called with `undefined`. Handles for procedures with
defined input still include their input.
* This behavior is preserved when handles are serialized and
deserialized.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Cursor Agent <[email protected]>
@KATT KATT closed this Nov 3, 2026
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-trpc__trpc that referenced this pull request Nov 3, 2026
…ter setup samples (trpc#7849)

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Why

- Readers of the setup and prefetching guides don't learn that handles
exist until they reach the handles guide.
[trpc#7847](trpc#7847) rewrites those guides
around handles. This PR is the smaller option: the guides keep
`queryOptions`, and a few tips point to handles where a page can start
its queries early.
- The App Router setup's samples typed `~/trpc/server` and
`~/trpc/client` with hand-written `declare module` stubs. The setup's
router makes `hello` take `{ text }`, but four samples called it with no
input, which fails input validation at runtime. The stubs hid that.

## What

- Four `:::tip` callouts, each linking to [Prefetching with
handles](/docs/client/tanstack-react-query/handles):
- TanStack React Query setup, after step 4: start the query in a loader
or server component with `unstable_$ensure` and pass the handle, or use
`unstable_$prefetch` on `useTRPC()` at the top of the page.
- Migrating, after "Migrating Queries": once a component is on
`queryOptions`, it can read a handle instead.
- Pages Router SSR, after the `getServerSideProps` sample: return a
handle instead of the `id`, so the two inputs can't drift apart.
- Pages Router server-side helpers, after "Prefetch, fetch and
dehydrate": the proxy can return a handle to pass in `props`.
- The App Router setup and Server Components pages already had a handles
tip, so they get none.
- Fixes carried over from
[trpc#7847](trpc#7847), without its handles
rewrite:
- App Router setup: the samples in steps 7 and later share one `twoslash
include` built from the setup's real router, query client and server
file (`prefetch` and `HydrateClient` as on the page).
`trpc.hello.queryOptions()` and `caller.hello()` now pass `{ text:
'world' }`.
- Server Components: the `useQuery` sample switches on
`greetingQuery.status` instead of checking `!greeting.data`, and the
`useSuspenseQuery` sample names its result `greetingQuery` instead of
destructuring `data`.
- Usage: the quick example's component is `Greeting`, not `Users`, and
renders `greetingQuery.data`.
- `www/build/collapse.ts`: the Shiki transformer is named
`trpc-docs:collapse`, like the others, not `raf-query-docs:collapse`.
- Not carried over: anything that turns a sample into a handles sample.

## Links

- [TanStack React Query
setup](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/tanstack-react-query/setup)
- [4. Fetch
data](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/tanstack-react-query/setup#4-fetch-data):
new tip.
-
[Migrating](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/tanstack-react-query/migrating)
- [Migrating
Queries](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/tanstack-react-query/migrating#migrating-queries):
new tip.
- [Pages Router
SSR](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/nextjs/pages-router/ssr)
- [Prefetch in
`getServerSideProps`](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/nextjs/pages-router/ssr#prefetch-in-getserversideprops):
new tip.
- [Pages Router server-side
helpers](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/nextjs/pages-router/server-side-helpers)
- [Prefetch, fetch and
dehydrate](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/nextjs/pages-router/server-side-helpers#prefetch-fetch-and-dehydrate):
new tip.
- [Next.js App Router
setup](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/nextjs/app-router-setup)
- [7. Make API
requests](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/nextjs/app-router-setup#7-make-api-requests),
[Leveraging
Suspense](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/nextjs/app-router-setup#leveraging-suspense)
and [Getting data in a Server
Component](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/nextjs/app-router-setup#getting-data-in-a-server-component):
samples checked against the real router, with `{ text: 'world' }` where
it was missing.
- [Server
Components](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/tanstack-react-query/server-components)
- [Using your
API](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/tanstack-react-query/server-components#using-your-api):
the client component switches on `status`.
- [Leveraging
Suspense](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/tanstack-react-query/server-components#leveraging-suspense):
the query result is named `greetingQuery`.
-
[Usage](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/tanstack-react-query/usage)
- [Quick example
query](https://www-git-cursor-docs-handles-tips-trpc.vercel.app/docs/client/tanstack-react-query/usage#quick-example-query):
`Greeting` renders the data.

## Alternatives considered

- [trpc#7847](trpc#7847): every setup guide
reads handles. It teaches the new pattern first, but it changes many
samples at once while the APIs are still `unstable_`.
- A tip on every page that prefetches, such as SSG and the Next.js
overview: more tips than readers need. SSR and server-side helpers cover
the Pages Router.

## Testing

- `pnpm --filter www check-twoslash`: 462 blocks compile, including the
App Router samples against the real router.
- `pnpm validate-skills`: all 24 skills pass, including the size limit
on the generated Pages Router skill.
- `pnpm --filter www test` (314 tests), `pnpm --filter www lint`, `pnpm
typecheck-www` and `pnpm --filter www build` pass. All 698 trpc.io URLs
work.
- In the built HTML, each new tip renders as a `callout-tip` aside.
- Handles fit in Pages Router `props`: a handle is a plain `{ queryKey,
input }` object, and since
[trpc#7848](trpc#7848) it leaves out `input`
when it's `undefined`.

## AI model

Claude Opus 5.5
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-d9d00df6-3344-5394-89b4-74130061fc31?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-d9d00df6-3344-5394-89b4-74130061fc31&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

<!-- codesmith:footer -->
---
<a
href="https://backend.blacksmith.sh/track/enable-autofix?expires=1796302697&installation_model_id=443568&pr_number=7849&ref=codesmith_pr_footer&repository=trpc%2Ftrpc&return_to=https%3A%2F%2Fgithub.com%2Ftrpc%2Ftrpc%2Fpull%2F7849&signature=088413ffc68c65697ecaf0a6ba9688e786a595e34d1aa13739eda2e5eb2dae9e"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img
alt="Autofix with [code]smith"
src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png"
width="190" height="28"></picture></a>
<sup><a
href="https://app.blacksmith.sh/trpc/codesmith/trpc/pr/7849?autoLogin=true&ref=codesmith_pr_footer">Open
in [code]smith</a> · Need help on this PR? Tag
<code>@codesmith-bot</code> with what you need.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Documentation**
* Expanded guidance for using prefetched query handles with Next.js
pages and TanStack React Query, including passing handles to components
and reading the associated queries.
* Clarified how query handles compare with existing prefetching and
fetching methods, and when cached data must be available.
* Updated App Router and React Query examples with consistent inputs and
clearer loading, error, and success states.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Cursor Agent <[email protected]>
@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 — 70b68f9e Deployed Nov 3, 2026 by vercel[bot]
Preview – trpc-next-app-dir — 70b68f9e Deployed Nov 3, 2026 by vercel[bot]
Preview – next-prisma-starter — 70b68f9e Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-next-minimal-starter — 70b68f9e Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-todomvc — 70b68f9e 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.

2 participants