Skip to content

perf: precompressed immutable SPA assets + code splitting (wiki-v2#309) - #38

Merged
PMQ9 merged 3 commits into
wiki-v2from
perf/309-asset-delivery
Sep 18, 2026
Merged

PMQ9 merged 3 commits into
wiki-v2from
perf/309-asset-delivery

Conversation

@PMQ9

@PMQ9 PMQ9 commented Sep 18, 2026 •

Copy link
Copy Markdown

Summary

Serve the client build compressed and cacheable, and stop shipping one 3.5 MB entry chunk to every visitor. Paired with cccvu/wiki-v2 PR 410 (it re-pins the submodule here and carries the platform, nginx and docs halves). Design: wiki-v2 ADR 0020. Tracking issue: cccvu/wiki-v2 issue 309.

Server — fork-owned apps/server/src/authz/http-headers/client-static.ts (+ spec, 30 cases). static.module.ts (seam #86) now makes one call: @fastify/static with preCompressed (br → gzip → identity from build-time siblings), globIgnore for the siblings + index-template.html, cacheControl:false + setHeaders (hashed /assets/* → public, max-age=31536000, immutable; index.html, locales, manifest, icons → no-cache + ETag), and an onSend hook that append-merges Vary: Accept-Encoding on static-file routes only. The app.get('*') fallback and the window.CONFIG injection are untouched, and a stale /assets/<hash>.js URL keeps the fallback's no-store (load-bearing spec case).

Client — chunk-load recovery (review round 1) — every fork-owned React.lazy (features/layout/lazy-pages.ts, features/editor-ux/lazy/*) goes through features/layout/lazy-with-reload.ts: a tab left open across a deploy asks for a chunk hash the new image no longer has, the * fallback answers 200 text/html, and React.lazy caches that rejection for the life of the document, so the first chunk-load failure reloads the document once per 60 s per tab (guarded through sessionStorage); a second failure inside the window surfaces the error instead of looping. Pinned by lazy-with-reload.test.ts and a source-level check that no bare lazy() sits beside it.

Client — fork-owned apps/client/build/precompress.ts (+ 35 tests): deterministic .br/.gz siblings (never .html) and a build-time bundle budget computed from the chunk graph with a must-stay-lazy list (strict under BUNDLE_BUDGET_STRICT=1). vite.config.ts (seam #11): Rolldown codeSplitting.groups with $initial-tagged vendor chunks. Rarely-visited routes via fork-owned features/layout/lazy-pages.ts (seam #6); katex + the Bases grid via features/editor-ux/lazy/* (seam #59, new one-line seam in pages/page/page.tsx). Page/Home/login/Layout stay eager on purpose.

Standalone smoke — section 5 asserts the delivery contract with curl on every PR (fork-standalone-smoke).

Numbers (same toolchain as the image)

initial set raw brotli on the wire
before (= prod today) JS 3,984,824 918,146 identity, max-age=0
after JS (12 chunks) 3,254,272 789,788 brotli, immutable
before / after CSS 495,004 / 411,713 61,228 / 48,435

Cold /login transfer 4,501 KB → 893 KB; simulated slow-4G LCP 23.1 s → 4.9 s; warm loads 6 revalidations → 0. Full before/after tables in the super-repo PR.

Tests

pnpm exec jest src/authz src/service-bridge src/editor-compat 618 passed · pnpm --filter client test 263 passed · tsc --noEmit (client, server, build/) clean · BUNDLE_BUDGET_STRICT=1 vite build passes at 789,788 B (budget 860,000) · deploy/standalone/smoke.sh ALL CHECKS PASSED incl. section 5 · scripts/check-upstream-boundary.sh (super) exit 0.

Merge order: this PR first → the super PR re-pins the gitlink to its merge SHA.

🤖 Generated with Claude Code

PMQ9 and others added 3 commits September 18, 2026 13:28
Serve the client build compressed and cacheable, and stop shipping one
3.5 MB entry chunk to every visitor.

Server (fork-owned authz/http-headers/client-static.ts, seam #86 is one
call): @fastify/static with preCompressed (br > gzip > identity from
build-time siblings), globIgnore for the siblings + index-template.html,
cacheControl:false + setHeaders so hashed /assets/* get
`public, max-age=31536000, immutable` and stable names (index.html,
locales, manifest, icons) get `no-cache`; an onSend hook append-merges
`Vary: Accept-Encoding` on static-file routes only. index.html is never
precompressed (it is rewritten at boot to inject window.CONFIG).

Client: fork-owned Vite plugin apps/client/build/precompress.ts writes
deterministic .br/.gz siblings and enforces a build-time bundle budget
(initial set from the chunk graph; must-stay-lazy list; strict in CI).
vite.config.ts (seam #11) moves to Rolldown codeSplitting.groups with
$initial-tagged vendor chunks (react, mantine, editor, icons, hljs,
vendor). Rarely-visited routes load on demand via fork-owned
features/layout/lazy-pages.ts (seam #6); katex and the Bases grid via
features/editor-ux/lazy/* (seams #59 and page.tsx). Page/Home/login/
Layout stay eager on purpose.

Initial JS 3,984,824 raw / 918,146 brotli -> 3,254,272 / 789,788;
served brotli instead of identity. Standalone smoke section 5 asserts
the delivery contract per PR.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… tests (docmost#309 review round 1)

A tab left open across a deploy still holds the old chunk hashes; the `*` fallback answers a missing
`/assets/<hash>.js` with `200 text/html`, the browser refuses it as a module, and `React.lazy` caches
that rejection for the life of the document. With no error boundary above `<Routes>` the 32 newly-lazy
routes blanked the whole app until a manual reload (Correctness + DevOps blocking; Frontend + Security L3).

- features/layout/lazy-with-reload.ts (+ test): `lazyWithReload(factory)` — the first chunk-load
  rejection reloads the document once per 60 s per tab (sessionStorage stamp; no storage = no reload,
  so it can never loop) and never settles so the fallback stays up; a second failure inside the window
  propagates the original error. Every fork-owned lazy (lazy-pages.ts, editor-ux/lazy/*) goes through it.
- lazy-pages.test.ts: source pins — no bare `lazy()` beside the helper; App.tsx statically re-imports
  none of the lazied modules (the export-surface pin alone could not see that).
- build/precompress.test.ts: strict mode negative tests (`this.error` path, env-var selection, no siblings
  after a failed build) and the `compressSiblings` cache path (Testing L3 / L2).
- authz/http-headers/client-static.ts: the Vary hook comment now says it RUNS on the root instance and
  ACTS only for static-file routes.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@PMQ9
PMQ9 merged commit e9c0191 into wiki-v2 Sep 18, 2026
@PMQ9
PMQ9 deleted the perf/309-asset-delivery branch September 18, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant