Skip to content

docs(server): add Next.js App Router section to response caching - #7853

Merged
KATT merged 1 commit into
mainfrom
cursor/caching-docs-next-app-router-72a1
Nov 3, 2026
Merged

KATT merged 1 commit into
mainfrom
cursor/caching-docs-next-app-router-72a1

Conversation

@KATT

@KATT KATT commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Why

  • #5625: the caching docs don't say how to cache tRPC responses in the Next.js App Router. The issue suggests that Next overrides the headers you set.
  • I checked a production next build and next start (Next 15.5.25), in examples/.experimental/next-app-dir and examples/next-minimal-starter, using curl. Results:
    • With Cache-Control set in responseMeta on fetchRequestHandler, the header reaches the response for public queries, both batched and unbatched. A batch that also has a private query gets no header.
    • export const dynamic = 'force-dynamic', revalidate = 0 and revalidate = 60 don't change the header. Next doesn't cache the handler's output either.
    • dynamic = 'force-static' makes the handler fail with a 500, because it also exports POST.
    • Cache-Control in next.config headers() replaces the responseMeta header. It's also added to every response on the path, including mixed public and private batches, private queries and errors. That makes the workaround in the issue unsafe with batching.
    • A client using the doc's splitLink sends public.* queries as unbatched GETs that carry the header. Other queries stay batched and get no header.

What

  • New "Next.js App Router" section in www/v11/docs/server/caching.md:
    • set Cache-Control in responseMeta on fetchRequestHandler in the route handler;
    • a caution against setting it in next.config headers();
    • "Batching": responseMeta runs once per batch. A splitLink example sends public queries through httpLink.
  • The skill description in the page's frontmatter mentions the App Router too.

Links

Alternatives considered

  • Recommend next.config headers(), as the issue suggests. I didn't, because it caches private batches and errors.

Testing

  • The curl and client runs above, against next build + next start.
  • pnpm --filter www check-twoslash (all three samples on the page compile), pnpm --filter www test, pnpm validate-skills, pnpm format.

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
    • Expanded caching guidance to cover Next.js App Router setup and safe caching conditions.
    • Clarified that mutations, errors, authenticated responses, eager generation, and mixed public/private batches should not be cached.
    • Added guidance on response headers and separating public queries from other operations.

@KATT
KATT requested a review from a team as a code owner November 3, 2026 15:00
@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 3:02pm UTC
6 Skipped Deployments
Project Deployment Actions Updated
examples-next-minimal-starter Skipped Skipped Nov 3, 2026 3:02pm UTC
examples-todomvc Skipped Skipped Nov 3, 2026 3:02pm UTC
next-prisma-starter Skipped Skipped Nov 3, 2026 3:02pm UTC
next-prisma-websockets-starter Skipped Skipped Nov 3, 2026 3:02pm UTC
tanstack-start-sse-chat Skipped Skipped Nov 3, 2026 3:02pm UTC
trpc-next-app-dir Skipped Skipped Nov 3, 2026 3:02pm UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – next-prisma-starter November 3, 2026 15:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-todomvc November 3, 2026 15:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – examples-next-minimal-starter November 3, 2026 15:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – trpc-next-app-dir November 3, 2026 15:01 Inactive
@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 caching guide adds Next.js App Router instructions for setting response cache headers and for routing public queries separately from batched requests.

Changes: App Router caching

Layer / File(s) Summary
App Router cache headers
www/v11/docs/server/caching.md
The guide adds a fetchRequestHandler example that sets cache headers only for public, error-free queries when generation is not eager. It also explains that route segment configuration does not set this response header and that next.config.js headers can replace it.
Batching and public queries
www/v11/docs/server/caching.md
The guide explains that responseMeta applies to the whole batch and that mixed public/private batches are not cached. It shows splitLink routing public queries through httpLink and other operations through httpBatchLink.

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

Change: Other

Possibly related PRs

  • trpc/trpc#7830: Updates the Next.js caching note in the same guide.
  • trpc/trpc#7829: Changes the Next.js caching tip in the same guide.
  • trpc/trpc#7790: Updates the same guide with responseMeta behavior for batching, streaming, and authenticated requests.

Suggested reviewers: juliusmarminge

Merge Risk: Minimal · up to 33394

The guide adds App Router cache-header and public-query batching guidance. No concrete merge-blocking issue is established by the supplied evidence.

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 "docs(server): add Next.js App Router section to response caching" matches the main change. The PR adds a Next.js App Router section to the response caching page, which is the core of the ch…
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 "docs(server): add Next.js App Router section to response caching" matches the main change. The PR adds a Next.js App Router section to the response caching page, which is the core of the changeset. The title is specific and concise, and it follows a conventional commit style. It does not cover the batching section or the skill description update, which is expected for a title.

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 0 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 3cf9541 and 33394c5.

Files selected for processing: 1
  • www/v11/docs/server/caching.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.

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

@trpc/next

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

@trpc/openapi

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

@trpc/react-query

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

@trpc/server

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

@trpc/tanstack-react-query

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

@trpc/upgrade

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

commit: 33394c5

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

🤖 Checked against a production Next.js build: the App Router section matches what the route handler does, and CI is green.

@KATT
KATT added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit f4c2b5a Nov 3, 2026
53 of 54 checks passed
@KATT
KATT deleted the cursor/caching-docs-next-app-router-72a1 branch November 3, 2026 15:44
@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 — 33394c5a Deployed Nov 3, 2026 by vercel[bot]
Preview – trpc-next-app-dir — 33394c5a Deployed Nov 3, 2026 by vercel[bot]
Preview – next-prisma-starter — 33394c5a Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-todomvc — 33394c5a Deployed Nov 3, 2026 by vercel[bot]
Preview – examples-next-minimal-starter — 33394c5a 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