Repository navigation
docs(server): add Next.js App Router section to response caching - #7853
Conversation
Co-authored-by: alexander <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
6 Skipped Deployments
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
@trpc/client
@trpc/next
@trpc/openapi
@trpc/react-query
@trpc/server
@trpc/tanstack-react-query
@trpc/upgrade
commit: |
trpc-bot
left a comment
There was a problem hiding this comment.
🤖 Checked against a production Next.js build: the App Router section matches what the route handler does, and CI is green.
|
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. |
Why
next buildandnext start(Next 15.5.25), inexamples/.experimental/next-app-dirandexamples/next-minimal-starter, using curl. Results:Cache-Controlset inresponseMetaonfetchRequestHandler, 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 = 0andrevalidate = 60don'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 exportsPOST.Cache-Controlinnext.configheaders()replaces theresponseMetaheader. 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.splitLinksendspublic.*queries as unbatchedGETs that carry the header. Other queries stay batched and get no header.What
www/v11/docs/server/caching.md:Cache-ControlinresponseMetaonfetchRequestHandlerin the route handler;next.configheaders();responseMetaruns once per batch. AsplitLinkexample sends public queries throughhttpLink.Links
splitLinkexampleAlternatives considered
next.configheaders(), as the issue suggests. I didn't, because it caches private batches and errors.Testing
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 [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit