Repository navigation
feat(docsite): migrate to Next.js 16.3 Cache Components - #3433
Conversation
Turns on cacheComponents and runs the cache-components-instant-false codemod so every page/layout keeps its current blocking behavior. The TODO comments are the work queue for route-by-route adoption.
|
@aurorascharff is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
Removes the instant opt-outs from the root, (site), (docs), and blog layouts and makes their shells prerenderable: - Drop the await headers() user-agent sniffing; AppShell's client-side matchMedia takes over after hydration (SSR HTML assumes desktop). - Move the footer copyright year and the sitemap lastModified into 'use cache' functions (cacheLife 'days') so they no longer block prerendering. - Wrap the templates gallery in Suspense: its useSearchParams() read had no boundary above it, which failed the route's prerender once the (site) layout became static. - Remove the obsolete conditionNames webpack override; the CJS 'use client' ordering bug it patched is gone (core ships ESM-only) and the global override broke React module resolution during prerendering. - Switch to @vercel/analytics/next, the documented Next.js entry. Result: /, blog, changelog, community, components, docs and templates routes (~260 pages) now prerender as static or partially-prerendered instead of fully dynamic.
Deletes the codemod's export const instant = false from the remaining 14 pages and layouts and fixes the two routes with real request-time reads: - /themes: move the await searchParams read into a Suspense-wrapped child so the shell prerenders; the seeded theme explorer streams in. The ?theme= deep link still preselects the picker. - /playground: drop the await headers() UA sniffing, same treatment as the shared layouts (client-side matchMedia takes over). Every route now prerenders as Static or Partial Prerender; only /mcp stays dynamic (request-time by nature). No instant opt-outs remain.
There was a problem hiding this comment.
Pull request overview
Migrates the docsite to Next.js 16.3 Cache Components to restore static/partial prerendering across routes by removing request-time dependencies (notably headers() UA sniffing) from shared layouts and caching time-based reads.
Changes:
- Upgrades docsite to
[email protected], switches tonext dev/build --webpack, and enablescacheComponents: true. - Removes
headers()-based UA sniffing from layouts/pages and shifts mobile detection to client-side behavior; updates footer to accept a cached year value. - Fixes prerender blockers by adding Suspense boundaries where
useSearchParams()/ asyncsearchParamsare read, and caches sitemaplastModifiedvia'use cache'+cacheLife('days').
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Locks upgraded Next.js 16.3 preview dependency graph (incl. SWC binaries). |
| apps/docsite/package.json | Pins Next.js 16.3 preview; uses --webpack for dev/build compatibility with existing config. |
| apps/docsite/next.config.mjs | Enables cacheComponents and removes the prior conditionNames override while retaining theme CSS aliasing. |
| apps/docsite/tsconfig.json | Adjusts JSX transform and includes additional Next-generated type output path. |
| apps/docsite/src/lib/copyrightYear.ts | Introduces cached (daily) server-side year computation for footer rendering. |
| apps/docsite/src/components/SiteFooter.tsx | Requires a year prop (computed server-side) instead of reading time directly in the client component. |
| apps/docsite/src/app/sitemap.ts | Caches lastModified computation and makes sitemap async. |
| apps/docsite/src/tests/sitemap.test.ts | Updates sitemap test for async sitemap and stubs next/cache for Vitest execution. |
| apps/docsite/src/app/layout.tsx | Switches Vercel Analytics integration to @vercel/analytics/next. |
| apps/docsite/src/app/not-found.tsx | Removes UA sniffing and passes cached footer year. |
| apps/docsite/src/app/(site)/layout.tsx | Removes UA sniffing and passes cached footer year. |
| apps/docsite/src/app/(docs)/layout.tsx | Removes UA sniffing and passes cached footer year. |
| apps/docsite/src/app/blog/layout.tsx | Removes UA sniffing and passes cached footer year. |
| apps/docsite/src/app/playground/page.tsx | Removes UA sniffing and wraps the client playground in Suspense for safe query-param reads. |
| apps/docsite/src/app/(site)/themes/page.tsx | Moves async searchParams reading into a Suspense-wrapped child to preserve prerenderability. |
| apps/docsite/src/app/(site)/templates/page.tsx | Adds a Suspense boundary so useSearchParams() doesn’t block prerendering. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This is amazing! Thank you! |
DocsShell received the full component and template registries as props but never read them — the sidebar builds from getComponentSidebarData() directly. The props were orphaned by an earlier sidebar refactor and frozen in place by an unused-vars lint pass that prefixed them with `_` instead of removing them. Serializing those two registries into the RSC flight payload cost ~1MB on every docs page. Measured on /components/Button: total HTML 1748KB -> 468KB, flight payload 1325KB -> 261KB (-80%). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
cixzhang
left a comment
There was a problem hiding this comment.
Thank you for making our docsite more snappy!
|
Some merge conflicts but I can help resolve those |
Yes i just saw, dw I can resolve them! |
…nents # Conflicts: # apps/docsite/next.config.mjs
- next.config: remove the conditionNames webpack override the upstream sync reintroduced. It was deliberately dropped in 941beaa because it breaks React resolution during Cache Components prerendering. - Restore 8 packages/core/src files that the merge's pre-commit prettier pass reformatted (whitespace only, no logic change, out of scope for this PR). - Remove the now-unused defaultIsMobile prop from DocsShell and PlaygroundClient, orphaned when the shared layouts stopped UA-sniffing via headers(). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks for the approval! I can't merge this myself now, so whenever you do, would you mind letting me know how it goes? Couple of things I'm curious about:
Feel free to re-run the tests and take a look at the preview on your end too! |
We did set up some logging in Vercel analytics with the basics plus some user interaction events. I don't think I have the permissions to view the full cost data since I'm not admin on the Vercel account but can ask around. |
… mobile-hint Rebased onto main's Next.js 16.3 Cache Components migration (#3433). Two follow-ups so the dual-version build still works: - `'use cache'` + cacheLife (in copyrightYear.ts and sitemap.ts's getLastModified) is a Cache Components / dynamicIO feature enabled by `cacheComponents: true`. The canary build is a static export (output:'export') which cannot enable cacheComponents, so `'use cache'` is invalid there — and copyrightYear is imported by every layout, so it would break the whole export. Select a plain (uncached) implementation when DOCSITE_TARGET=canary; the latest (server) build keeps the cached variant. Same values, only the caching directive differs. sitemap also gets a canary-gated `dynamic='force-static'` so it still emits as a file under export while latest keeps 'use cache'. - serverMobileHint.ts is now dead code: main's migration removed the server-side UA mobile hint from the layouts (DocsShell/PlaygroundClient no longer take defaultIsMobile), so our export-safe wrapper has no consumers. Removed. Verified: latest generate → 191 pinned components; canary config carries no cacheComponents/rewrites; tsc has only the 2 pre-existing `cacheLife` import errors that main itself has against [email protected] (main imports the same bare `cacheLife`; its `next build --webpack` resolves it) — zero new errors from this branch.
… mobile-hint Rebased onto main's Next.js 16.3 Cache Components migration (#3433). Two follow-ups so the dual-version build still works: - `'use cache'` + cacheLife (in copyrightYear.ts and sitemap.ts's getLastModified) is a Cache Components / dynamicIO feature enabled by `cacheComponents: true`. The canary build is a static export (output:'export') which cannot enable cacheComponents, so `'use cache'` is invalid there — and copyrightYear is imported by every layout, so it would break the whole export. Select a plain (uncached) implementation when DOCSITE_TARGET=canary; the latest (server) build keeps the cached variant. Same values, only the caching directive differs. sitemap also gets a canary-gated `dynamic='force-static'` so it still emits as a file under export while latest keeps 'use cache'. - serverMobileHint.ts is now dead code: main's migration removed the server-side UA mobile hint from the layouts (DocsShell/PlaygroundClient no longer take defaultIsMobile), so our export-safe wrapper has no consumers. Removed. Verified: latest generate → 191 pinned components; canary config carries no cacheComponents/rewrites; tsc has only the 2 pre-existing `cacheLife` import errors that main itself has against [email protected] (main imports the same bare `cacheLife`; its `next build --webpack` resolves it) — zero new errors from this branch.
… mobile-hint Rebased onto main's Next.js 16.3 Cache Components migration (#3433). Two follow-ups so the dual-version build still works: - `'use cache'` + cacheLife (in copyrightYear.ts and sitemap.ts's getLastModified) is a Cache Components / dynamicIO feature enabled by `cacheComponents: true`. The canary build is a static export (output:'export') which cannot enable cacheComponents, so `'use cache'` is invalid there — and copyrightYear is imported by every layout, so it would break the whole export. Select a plain (uncached) implementation when DOCSITE_TARGET=canary; the latest (server) build keeps the cached variant. Same values, only the caching directive differs. sitemap also gets a canary-gated `dynamic='force-static'` so it still emits as a file under export while latest keeps 'use cache'. - serverMobileHint.ts is now dead code: main's migration removed the server-side UA mobile hint from the layouts (DocsShell/PlaygroundClient no longer take defaultIsMobile), so our export-safe wrapper has no consumers. Removed. Verified: latest generate → 191 pinned components; canary config carries no cacheComponents/rewrites; tsc has only the 2 pre-existing `cacheLife` import errors that main itself has against [email protected] (main imports the same bare `cacheLife`; its `next build --webpack` resolves it) — zero new errors from this branch.
Hi! I work on Next.js at Vercel. The top nav on astryx.atmeta.com felt slow, so I wanted to see if upgrading the docsite to Cache Components with Instant Navigations would fix it. It did: every page is now static instead of rendering on each request, so navigation is instant.
Before
https://astryx.atmeta.com/
CleanShot.2026-07-02.at.16.10.20.mp4
After
https://astryx-docsite-preview-qwdpqbbqx.labs.vercel.dev/
CleanShot.2026-07-02.at.16.29.48.mp4
Numbers
//components/docs/getting-started/templates/themes/blog/playgroundIt would be nice if you also tested this yourselves by clicking through the two URLs above. And if you would like, enable a preview deployment for this branch so you can verify it on your real project.
Migration followed the
next-cache-components-adoptionskill from the Next.js repo.Details (AI-generated summary)
Why
The shared layouts read
headers()for user-agent sniffing, which forces every route to render on each request (x-vercel-cache: MISSon everything). After migrating to Cache Components, every route prerenders (○or◐, daily revalidation) except/mcp, which is request-time by nature.What (by commit)
instantroute config and adoption codemod; will bump to stable when it ships). Adds--webpacktodev/buildsince the StyleX Babel setup doesn't run under Turbopack.cacheComponents: trueand opt every route out withexport const instant = falsevia codemod (behavior-preserving checkpoint).headers()UA sniffing (client-sidematchMediatakes over), cache the footer year and sitemaplastModifiedwith'use cache', add the missing Suspense boundary around the/templatesuseSearchParams()read, move the/themessearchParamsread into a Suspense child.conditionNameswebpack override (its CJS bug is gone and it broke React resolution during prerendering), switch to@vercel/analytics/next.Something I noticed but are not fixing here: on a cold mobile load, the first paint shows desktop nav chrome until React hydrates, because
AppShelldecides the mobile breakpoint in JS and the prerendered HTML assumes desktop. The user agent sniffing this PR removes had the same failure mode whenever its guess was wrong (Android tablets, narrow windows), so this is not a regression, just now consistent. A CSS-driven breakpoint inAppShellwould remove it entirely.One more thing while I was in here: I noticed every docs page was shipping ~1.3 MB of React flight data for a prop nothing actually used, so I removed it. The RSC payload on docs pages is now ~80% smaller.
Details (AI-generated summary)
DocsShellreceived the full component and template registries as props but never read them — the sidebar builds fromgetComponentSidebarData()directly. The props were orphaned by an earlier sidebar refactor and frozen in place by an unused-vars lint pass that prefixed them with_instead of removing them. Dropping them stops both registries from being serialized into the RSC flight payload of every(docs)page./components/components/[name]/docs/getting-started/docs/tokens"Before" measured on the preview deployment, "after" locally with the removal — flight size is data-determined, so dev ≈ prod (local "before" matched the preview within ~1%). Routes outside the
(docs)layout (e.g./templates, ~21 KB) never carried the registries and are unchanged.