Repository navigation
refactor(www): swap static server fns for CDN cache headers - #235
Conversation
Replace the experimental @tanstack/start-static-server-functions middleware with plain GET server functions that set Cache-Control on their success path; Vercel's CDN caches responses until the next deploy purge. Also delete the unused lib/github.ts and the obsolete __tsr copy step in build:postprocess. Rationale and evidence in docs/research/2026-06-11-static-server-functions.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Performance: measured before/afterTTFB via curl on a pre-warmed connection (mimics a client-side nav reusing the page's HTTP/2 connection), 8 runs per URL across 9 docs pages + the page tree, single vantage point (FRA edge). Before = production dotui.org (static server functions). After = this PR's preview deployment (
Verified on the deployed preview:
Bottom line: steady-state nav latency is at parity; the cost is one ~0.3–0.5 s invocation per docs page per region per deploy (≈2 s if cold), paid by the first visitor only — in exchange for always-fresh data, a working not-found path, and dropping the experimental dependency plus its build hacks. Full methodology and caveats in 🤖 Generated with Claude Code |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Review follow-ups: the getPageTree comment now states that the header lands on 2xx HTML documents during SSR (revisit if per-request SSR lands under _app); the research doc records why the shipped header omits the sketch's stale-while-revalidate=60. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Why
@tanstack/start-static-server-functionsis officially experimental ("Static Server Functions are experimental!" in the TanStack docs), thinly maintained (~0.06% of Start's downloads, no README/tests, open core-mechanism bugs #7479, #6787 with no maintainer replies), and our integration had a live bug: the baked__tsrJSONs are served withcache-control: max-age=31557600, immutablewhile their filenames are input-addressed (slug-based, not content-based), so returning visitors kept year-old docs data on client-side navigations after content deploys. Its middleware also has no fallback on cache miss — a client-side nav to a removed/unbaked URL threw into the error boundary instead of rendering NotFound. This repo already needed two workarounds for its build plumbing (a pnpm patch, the__tsrcopy hack).Full assessment with sources:
docs/research/2026-06-11-static-server-functions.md.What
serverLoader(docs page data) andgetPageTreeare now plain GET server functions that setCache-Control: public, max-age=0, must-revalidate, s-maxage=31536000on their success path only — Vercel's CDN caches the response and purges on every deploy, so data is always fresh; not-found responses stay uncached. This is the same pattern tanstack.com uses for its own docs.www/src/lib/github.ts— dead code, nothing imports it (was the thirdstaticFunctionMiddlewareconsumer).@tanstack/start-static-server-functionsdependency.__tsrcopy step frombuild:postprocess(prerender writes directly into.vercel/output/staticsince fix: write static server function cache to correct output directory with Nitro TanStack/router#6940; verified on a current build).Prerendering is unaffected — direct visits keep serving build-time static HTML; only the data fetch behind client-side navigations changes (static JSON file → CDN-cached server fn response).
Verification
pnpm check,pnpm typecheck, fullpnpm buildpass; prerender emits all docs pages, no__tsroutput remains.vite preview): client-side navs Button → Select → Table → Tooltip render correctly with one/_serverFn/GET each; success responses carry the cache header, not-found responses carry none and serializeisNotFoundin-band (NotFound UI restored on bad client-side navs).🤖 Generated with Claude Code