Skip to content

feat(docsite): migrate to Next.js 16.3 Cache Components - #3433

Merged
cixzhang merged 10 commits into
meta:mainfrom
aurorascharff:docsite-cache-components
Jul 4, 2026
Merged

cixzhang merged 10 commits into
meta:mainfrom
aurorascharff:docsite-cache-components

Conversation

@aurorascharff

@aurorascharff aurorascharff commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Route Prod (before) Preview (after)
/ 135 ms 98 ms
/components 208 ms 66 ms
/docs/getting-started 160 ms 75 ms
/templates 261 ms 58 ms
/themes 133 ms 69 ms
/blog 101 ms 69 ms
/playground 139 ms 74 ms

It 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-adoption skill 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: MISS on everything). After migrating to Cache Components, every route prerenders (○ or ◐, daily revalidation) except /mcp, which is request-time by nature.

What (by commit)

  1. Upgrade to Next.js 16.3.0-preview.5 (16.3 has the instant route config and adoption codemod; will bump to stable when it ships). Adds --webpack to dev/build since the StyleX Babel setup doesn't run under Turbopack.
  2. Enable cacheComponents: true and opt every route out with export const instant = false via codemod (behavior-preserving checkpoint).
  3. Remove the opt-outs and fix what surfaces: drop the headers() UA sniffing (client-side matchMedia takes over), cache the footer year and sitemap lastModified with 'use cache', add the missing Suspense boundary around the /templates useSearchParams() read, move the /themes searchParams read into a Suspense child.
  4. Cleanups the migration exposed: remove the obsolete conditionNames webpack 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 AppShell decides 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 in AppShell would 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)

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. Dropping them stops both registries from being serialized into the RSC flight payload of every (docs) page.

Route RSC flight (before) RSC flight (after) Δ
/components 1337 KB 252 KB −81%
/components/[name] 1341 KB 261 KB −80%
/docs/getting-started 1338 KB 253 KB −81%
/docs/tokens 1338 KB 253 KB −81%

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

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

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 2, 2026
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.
@aurorascharff aurorascharff changed the title feat(docsite): adopt Cache Components (Next.js 16.3) — flag + per-route opt-outs feat(docsite): migrate to Next.js 16.3 Cache Components Jul 2, 2026
@aurorascharff
aurorascharff marked this pull request as ready for review July 2, 2026 16:35
@aurorascharff
aurorascharff requested a review from cixzhang as a code owner July 2, 2026 16:35
Copilot AI review requested due to automatic review settings July 2, 2026 16:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to next dev/build --webpack, and enables cacheComponents: 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() / async searchParams are read, and caches sitemap lastModified via '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.

@aurorascharff
aurorascharff marked this pull request as draft July 2, 2026 16:53
@aurorascharff
aurorascharff marked this pull request as ready for review July 2, 2026 22:03
@vercel

vercel Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Error Error Jul 4, 2026 2:27pm

Request Review

@cixzhang

cixzhang commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This is amazing! Thank you!

Comment thread apps/docsite/src/app/(site)/layout.tsx Resolved
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 cixzhang 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.

Thank you for making our docsite more snappy!

@cixzhang

cixzhang commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Some merge conflicts but I can help resolve those

@aurorascharff

Copy link
Copy Markdown
Contributor Author

Some merge conflicts but I can help resolve those

Yes i just saw, dw I can resolve them!

aurorascharff and others added 2 commits July 3, 2026 23:15
…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]>
@aurorascharff

Copy link
Copy Markdown
Contributor Author

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:

  • Server costs. Every route is static now except /mcp (they were all rendering on each request before), so your Function Invocations and compute should drop noticeably.
  • Any tracking you have for interactions, or anything else worth looking at.

Feel free to re-run the tests and take a look at the preview on your end too!

@cixzhang
cixzhang enabled auto-merge (squash) July 4, 2026 14:22
@cixzhang

cixzhang commented Jul 4, 2026 •

Copy link
Copy Markdown
Contributor
  • Any tracking you have for interactions, or anything else worth looking at.

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.

@cixzhang
cixzhang merged commit 5a012db into meta:main Jul 4, 2026
15 of 16 checks passed
@aurorascharff
aurorascharff deleted the docsite-cache-components branch July 4, 2026 14:34
cixzhang added a commit that referenced this pull request Jul 6, 2026
… 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.
cixzhang added a commit that referenced this pull request Jul 10, 2026
… 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.
cixzhang added a commit that referenced this pull request Jul 11, 2026
… 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.

This branch had an error being deployed

1 failed deployment
Preview — 15e541a1 Deployed Jul 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants