perf(theme): load page feedback, the locale control, and sidebar AI on demand
Merged
KI
11h ago+62+62+01234567890123456789-4-4-0123456789
Problem
The TanStack layout and the page client import four features statically, so every site downloads them on its first visit, even with the feature turned off:
- page feedback;
- the locale control;
- the sidebar AI search;
- the AI features.
BrowserDocsLayout is the Farm.js adapter's layout, and it renders through the TanStack layout. The Next.js layout already loads the AI features lazily through docs-ai-features-lazy.
Change
tanstack-layout.tsximportsDocsAIFeaturesfrom the existingdocs-ai-features-lazywrapper.- A new
optional-components-lazy.tsxwrapsDocsFeedback,LocaleThemeControlandSidebarSearchWithAI. Each one loads on its first render and sits inside its ownSuspenseboundary. tanstack-layout.tsxanddocs-page-client.tsximport those wrappers.
Safety and compatibility
- Server render: an enabled feature still renders in the server HTML, in place. The Farm.js adapter awaits
allReady, and the new test asserts the feedback section renders once, with no<template id="B:and no$RC. - Hydration: in the browser, each boundary keeps the server's HTML until its chunk arrives.
- Markdown components stay eager.
universal-content.tsxrenders page Markdown with the synchronousrenderToStaticMarkup, which would render a lazy component's empty fallback. I tried makingPromptandHoverLinklazy, and themdx.test.tstests that renderPromptfailed for that reason, so I left them out. - Public exports are unchanged:
@farming-labs/themestill exports the eager components.
Verification
pnpm exec vitest runin packages/fumadocs: 480 passed.pnpm exec vitest runin packages/farmjs: 244 passed, including the new feedback SSR test.tsc --noEmitpasses, and oxlint is clean.- farmjs.dev, built locally with this theme (node-server preset):
- The shared theme chunk shrank from 400,640 to 384,337 bytes raw. With brotli at quality 11 that's 103,999 ā 101,803 bytes; with gzip, 126,758 ā 123,571.
- Feedback, the locale control and the sidebar AI search now build as their own chunks of 1.7, 1.6 and 0.7 KB (brotli). farmjs.dev never requests them.
- The same build with
feedback.enabled: true, checked in Chrome:- The server HTML has the feedback section, and
docs-feedbackloads. - The button hydrates and works.
- The section survives client navigation, with no console errors.
- The server HTML has the feedback section, and
Documentation and release
None. This is a small saving, so it can ride along with the next release rather than getting its own.
š¤ Generated with Claude Code
Summary by cubic
Loads page feedback, the locale control, sidebar AI search, and AI features only when a site actually enables them, instead of bundling them into every first visit.
- The TanStack layout and page client now import these via lazy
Suspensewrappers; enabled features still render in the server HTML in place because the Farm.js adapter awaitsallReady. - Markdown components (
Prompt,HoverLink) stay eager since page Markdown is rendered synchronously withrenderToStaticMarkup, which wouldn't wait for lazy chunks. - Adds an SSR test asserting an enabled feedback section renders once with no suspended-template markers.
- For farmjs.dev, the shared theme chunk drops from 400,640 to 384,337 bytes raw (104.0 ā 101.8 KB brotli).
- Public exports from
@farming-labs/themeare unchanged.