perf(next): send metadata with each compatible docs page
Problem
The persistent Next docs layout serializes metadata for the whole documentation tree into each page response. Compatible static pages need only their own metadata.
Change
Compile eligible MDX pages with a server boundary that uses the existing metadata builder and page renderer. Keep layout settings in the persistent provider, and send each page's metadata with that page. Preserve the legacy transport for custom layouts/providers/wrappers, compiler extensions, locales, roots, dynamic routes, authored exports, unsupported package versions, and explicit pageMetadata: "site".
Safety and compatibility
No theme CSS or public theme API changes. Both transports share the renderer. The boundary preserves whitespace, frontmatter, headings, structured data, single page wrappers, and client navigation/history. Eligibility is conservative; uncertain routes retain the existing behavior. The assistant-ui shared-theme fixture uses the optimized path; its customized docs application retains the compatibility path.
This changes the same client renderer touched by #621, but solves a different problem and does not implement or depend on that PR's title slots. Recheck their integration before merging both.
Verification
On this isolated branch, Node 24.21.0 / pnpm 10.9.0, macOS arm64:
pnpm install --frozen-lockfile: passed.pnpm --filter @farming-labs/docs build,pnpm --filter @farming-labs/theme build, andpnpm --filter @farming-labs/next build: passed.pnpm --workspace-concurrency=1 --filter @farming-labs/docs --filter @farming-labs/theme --filter @farming-labs/next test --maxWorkers=2: 2,355 passed (1,675 / 471 / 209).- The same filters with
typecheck: passed. node benchmark/adapters/pack-next.mjs /tmp/docs-performance-handoff/consumer-pass/pr-pass/packed-next: three actual tarballs, all explicit exports, and packed compiler-plugin import passed.- Changed supported files passed
oxfmt --check,oxlint(zero errors; nine existing test warnings), andgit diff --check.
The unchanged runtime implementation was also verified before splitting the PRs:
- Packed production assistant-ui shared theme: 22/22 pixel-identical screenshots, four desktop/phone light/dark interaction flows, and four no-JavaScript renders. Text, metadata, syntax-token colors, search, copy, tabs, navigation, history, and theme switching match baseline. The candidate build explicitly enables per-page metadata for both fixture routes. All 25 producer CSS files match baseline.
- Actual assistant-ui docs consumer, farming-labs baseline/candidate both 0.2.141: theme tests 58 passed, app tests 1,910 passed / 11 existing skips on both sides.
NEXT_PUBLIC_AUI_AI_PLAYGROUND_ENABLED=1 NEXT_PUBLIC_WEBMCP_ENABLED=1 pnpm --filter @assistant-ui/docs-site buildcompleted all 1,142 pages, TypeScript, and source-trace checks (123 bundles: six trace all 7,729 source files; 117 trace none). The build completed after Next's own prerender retries; no timeout was increased. - Four actual consumer browser flows passed against baseline, with no page errors. 13/18 screenshots are exactly equal; the other captures include animated terminal frames, loading state, and tiny search/header differences. A second capture of the same candidate also varies in these areas. This is not an 18/18 pixel-equality claim. Existing 404 and unavailable-auth console error categories match baseline. The full Markdown endpoint returns HTTP 200 with nonempty content.
- A packed Turbopack static-export fixture passed both
autoandsitemodes: eight direct renders, four metadata/text comparisons, and client navigation/back. Regression tests for compiler whitespace, custom generated layouts, and authored exports failed before their fixes.
On the earlier matched Next example (Apple M1 / Darwin 25.2.0 / Node 23.11.0, baseline c92045e8), HTML plus inline RSC fell 133,982 → 130,837 bytes, while initial decoded JavaScript increased 901,535 → 901,672 bytes. These are byte counts, not latency benchmarks. The measured source is unchanged in this split; no whole-framework speed advantage is claimed.
Not verified: Windows, hosted/serverless deployments, live LLM/account/billing flows, and a matched Fumadocs performance comparison. The Webpack static-export fixture fails with the same MDX/client-boundary error on pristine baseline and candidate; Webpack compatibility for that fixture remains unresolved. Browser/static-export evidence covers the combined implementation before splitting; package tests, types, builds, and packed checks were rerun on this independent branch.
Documentation and release
Updated the Next adapter reference and added benchmark/adapters/next.md with browser and packed-boundary reproduction commands. No version bump; release remains a separate action.
Summary by cubic
Sends each compatible production docs page only its own metadata instead of serializing the whole documentation tree into every page response.
Compatibility
- The optimized path applies only to ordinary Markdown/MDX file routes using the default generated layout and MDX provider in production.
- Custom layouts or MDX providers, compiler extensions,
components.wrapper, locales, multiple roots,basePath, dynamic/group routes, and authored exports keep the existing site-wide metadata transport. - Adds
pageMetadata: "auto" | "site"towithDocs;"site"forces the legacy transport. Unsupported or uncertain routes fall back automatically. - No theme CSS or public theme API changes;
@farming-labs/next,@farming-labs/theme, and@farming-labs/docsshare the same renderer.
Verification
- Package builds, typecheck, and 2,355 tests pass, including new route-discovery, boundary-compilation, and config-mode tests.
- A Playwright harness compares exact text, headings, structured data, navigation, and history between baseline and candidate production builds, plus a packed-tarball smoke.