Skip to content

feat(tanstack-react-query): experimental nested queries in one request - #8041

Open
KATT wants to merge 293 commits into
claude/nested-clientfrom
claude/sweet-albattani-gdth4h
Open

KATT wants to merge 293 commits into
claude/nested-clientfrom
claude/sweet-albattani-gdth4h

Conversation

@KATT

@KATT KATT commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Why

What

  • loadHandles(trpc, entries) takes TanStack Query entries only: the verbs (prefetchEntry, ensureEntry, fetchEntry) say how each query starts. A bare experimental_query() is a type error. The package re-exports experimental_dataOf and experimental_perItem.
  • experimental_dataOf(entry, (data) => entry): an entry built from another entry's data, loaded in the same request when the link pipelines.
  • experimental_perItem: entries for every item of a list, which can read each other, with one run per item.
  • useLoadHandles (from feat(tanstack-react-query): useLoadHandles() loads handles on a page without a loader #8212) takes these entries too: experimental_dataOf and experimental_perItem in a client component, without a loader.
  • experimental_inferQueryHandleOfItem / experimental_inferInfiniteQueryHandleOfItem: type an unfinished handle by procedure, so a component can take and finish one without the page's handle type.
  • Opt-in and experimental. Without pipelining, the same code works with one round trip per step.
const post = ensureEntry(trpc.post.bySlug, { slug });
const [handles, data] = await loadHandles(trpc, {
  post,
  author: prefetchEntry(trpc.author.byId, {
    id: experimental_dataOf(post).authorId,
  }),
});

Links

Alternatives considered

  • Dropping the dataOf callback: entry types don't record what they read, so TanStack couldn't type unfinished handles.

Testing

  • Regression check: handles.shared.test.tsx (TanStack entries only, no bare experimental_query()) and handles.dataOf.test.tsx and handles.test.tsx, where each review fix names its test, also in its review reply. www/src/demos/demos.test.ts covers batching, cancellation and per-item queries.

AI model

Claude Opus 5.5, via Claude Code

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added experimental query handles for composing dependent and per-item queries, with skipped entries, selective waiting, settled results, and client-side rendering.
    • Added a nested-queries demo comparing waterfall and pipelined loading, with HTTP request timing.
    • Added a kitchen-sink blog showcase with pagination, author details, loading controls, and a request-and-results timeline.
    • Added HTTP request grouping and server-work timing to the network panel.
  • Documentation
    • Added nested-query guides and updated guidance for query handles, TanStack Start, and HTTP batching.

@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

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

7 Skipped Deployments
Project Deployment Actions Updated
examples-next-minimal-starter Skipped Skipped Nov 27, 2026 4:19pm UTC
examples-todomvc Skipped Skipped Nov 27, 2026 4:19pm UTC
next-prisma-starter Skipped Skipped Nov 27, 2026 4:19pm UTC
next-prisma-websockets-starter Skipped Skipped Nov 27, 2026 4:19pm UTC
tanstack-start-sse-chat Skipped Skipped Nov 27, 2026 4:19pm UTC
trpc-next-app-dir Skipped Skipped Nov 27, 2026 4:19pm UTC
www Skipped Skipped Nov 27, 2026 4:19pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Walkthrough

This pull request adds experimental TanStack React Query handles for dependent and per-item queries, including pipelined loading and client-side reuse. It also adds HTTP transport demos and a TanStack Start blog example that loads related posts and authors.

Changes: Nested-query handle APIs

Layer / File(s) Summary
Handle contracts and entry construction
packages/tanstack-react-query/src/unstable-handles/types.ts, entry.ts, list.ts, outcome.ts, packages/client/src/queries/path.ts, packages/client/src/unstable-internals.ts
Adds handle and entry types, query constructors, request-path and per-item planning helpers, outcome utilities, and package exports.
Entry linking and load execution
packages/tanstack-react-query/src/unstable-handles/plan.ts, shared.ts, load.ts
Adds entry-tree validation and linking, converts entries for TanStack Query, and coordinates dependent, per-item, pipelined, and settled loads.
Handle reads and client-side reuse
packages/tanstack-react-query/src/unstable-handles/handle.ts, handles.ts, pipelined.ts, index.ts, packages/tanstack-react-query/src/internals/createOptionsProxy.ts
Adds handle reading and per-item query support, consumes eligible pipelined results, exposes handle APIs, and reuses described loads in experimental_useHandles.
Handle validation and usage guidance
packages/tanstack-react-query/src/unstable-handles/*test.tsx, *test.ts, www/v11/docs/client/tanstack-react-query/*, www/v11/docs/client/vanilla/nested-queries.md, www/v11/docs/client/links/httpBatchLink.md, www/v11/docs/client/tanstack-react-query/tanstack-start.md, www/vercel.json
Adds coverage for loading, pipelining, hydration, skipped entries, and reuse. Adds documentation for nested queries, skipped handles, and error behavior.

HTTP demos and traces

Layer / File(s) Summary
HTTP transport and request tracing
www/src/demos/kit/session.tsx, frame.tsx, network.ts, network-panel.tsx, backend.ts, data.ts, www/src/demos/demos.test.ts
Adds selectable HTTP transport, batched demo requests, server-work timing, request tracing, cancellation handling, and related tests.
Nested-query demo routes and registration
www/src/demos/kit/author-blog.tsx, blog.tsx, blog-routes.tsx, www/src/demos/nested-queries.tsx, names.ts, page-demos.tsx
Adds pipelined and waterfall article and list routes, registers the demo, and exports shared blog UI and route helpers.

TanStack Start blog example

Layer / File(s) Summary
Blog data, API, and request tracking
www/src/routes/kitchen-sink/blog/-server/*, -settings.ts, -trpc.ts, api.$.ts, -request-meter.ts
Adds in-memory post and author procedures, request settings, tRPC clients, a streaming pipelined endpoint, and request event tracking.
Blog route loading and query entries
www/src/routes/kitchen-sink/blog/route.tsx, $slug.tsx
Loads post-list entries and post-page entries, derives author and team-post queries, and returns dehydrated query state and handles.
Blog pages and interactive components
www/src/routes/kitchen-sink/blog/index.tsx, -components/*, -date.ts, -links.ts, -next-page.ts, $slug.tsx
Adds the blog index, post and author views, paginated lists, loading states, settings controls, and request-meter UI.
Blog route registration and checks
www/src/routeTree.gen.ts, www/src/routes/kitchen-sink/-showcases.ts, www/src/routes/kitchen-sink/retries/index.tsx, www/build/kitchen-sink.test.ts, www/src/routes/kitchen-sink/blog/-showcase.ts
Adds blog routes to the generated route tree and kitchen-sink showcase checks.

Estimated code review effort: 5 (Critical) | ~120 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant loadHandles
  participant QueryClient
  participant tRPCLink
  participant Server
  loadHandles->>QueryClient: start source and dependent entries
  QueryClient->>tRPCLink: send pipelined query reads
  tRPCLink->>Server: send procedure calls and read references
  Server-->>tRPCLink: return query results
  tRPCLink-->>QueryClient: deliver results
  QueryClient-->>loadHandles: provide handles and loaded data
Loading
Merge Risk: Moderate · previous review e5539

This experimental API still has open concerns: nullable list items can be dropped from per-item loads, and some item-prefetch and routing paths can cache data under the wrong key. The standalone example also fails to build against the published canary packages. Resolve or explicitly accept these before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(tanstack-react-query): experimental nested queries in one request" matches the main change. The PR adds experimental nested query composition for TanStack React Query, pipelined into o…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "feat(tanstack-react-query): experimental nested queries in one request" matches the main change. The PR adds experimental nested query composition for TanStack React Query, pipelined into one request, with new handles APIs, docs, and a blog example. The title names the package, the feature type, and the core behavior. It is specific and concise.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5e928ff and e553978.

Files selected for processing: 7

  • packages/tanstack-react-query/src/unstable-handles/handles.shared.test.tsx
  • packages/tanstack-react-query/src/unstable-handles/handles.ts
  • packages/tanstack-react-query/src/unstable-handles/index.ts
  • packages/tanstack-react-query/src/unstable-handles/types.ts
  • www/src/demos/kit/author-blog.tsx
  • www/src/routes/kitchen-sink/blog/$slug.tsx
  • www/v11/docs/client/tanstack-react-query/nested-queries.md

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

KATT commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

"Check standalone tanstack-start-sse-chat package" fails, and can't pass before this is published.

  • The check copies the example out of the monorepo and installs @trpc/* from the canary tag on npm.
  • The blog pages import dataOf from @trpc/tanstack-react-query/unstable-handles, which this PR adds, so the published canary doesn't have it: "dataOf" is not exported by …/unstable-handles/index.mjs.
  • In the monorepo the example builds, typechecks and runs against the packages in this PR.

The only fix inside this PR is to drop the blog pages, which are the point of the prototype. If this goes further, the example can land in a follow-up once a canary has the new exports.


Generated by Claude Code

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

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

@trpc/next

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

@trpc/openapi

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

@trpc/react-query

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

@trpc/server

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

@trpc/tanstack-react-query

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

@trpc/upgrade

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

commit: aac66d4

@vercel
vercel Bot temporarily deployed to Preview – next-prisma-starter November 13, 2026 01:46 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 13, 2026 01:46 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 13, 2026 02:03 Inactive
KATT and others added 2 commits November 26, 2026 21:33
…e/sweet-albattani-gdth4h

# Conflicts:
#	www/v11/docs/client/vanilla/nested-queries.md
@KATT

KATT commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Head commit changed.

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.

@KATT

KATT commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 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.

…t's reader finishes the author's

A component that reads the author takes the author's finished handle,
typed from its procedure, and finishes the team's posts' handle with the
author. The component that reads the post finishes the author's handle,
so the post doesn't wait on the author. Applied to the nested-queries
example, the kitchen-sink blog's post page and the demo's article page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019Un67fr6whX1q318L8qKR1

KATT commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review


Generated by Claude Code

… `experimental_inferInfiniteQueryHandleOfItem`

Type an unfinished handle by its procedure and the data that finishes it,
so a component can take one and finish it without the page's handle type.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@KATT

KATT commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 26, 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 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

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.

KATT and others added 15 commits November 27, 2026 11:52
…th4h

`experimental_useHandles` is `useLoadHandles` now, from #8212.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#8212's `useLoadHandles`, ported to this branch's loads: a ref instead of a
map of loads, mount counts and a timer; a load per QueryClient; entries
compared without their order or first cursor; and a failed query that
rendering doesn't start again. The hook's tests compare one component
across renders, as components no longer share a load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nePath takes two arguments, tests use experimental_pipelineBudget()

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was previously deployed

5 inactive deployments
Preview – trpc-next-app-dir — da2fd1e6 Deployed Nov 27, 2026 by vercel[bot]
Preview – www — da2fd1e6 Deployed Nov 27, 2026 by vercel[bot]
Preview – examples-todomvc — da2fd1e6 Deployed Nov 27, 2026 by vercel[bot]
Preview – next-prisma-starter — da2fd1e6 Deployed Nov 27, 2026 by vercel[bot]
Preview – examples-next-minimal-starter — da2fd1e6 Deployed Nov 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants