Repository navigation
perf: precompressed immutable SPA assets + code splitting (wiki-v2#309) - #38
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/staticwithpreCompressed(br → gzip → identity from build-time siblings),globIgnorefor the siblings +index-template.html,cacheControl:false+setHeaders(hashed/assets/*→public, max-age=31536000, immutable;index.html, locales, manifest, icons →no-cache+ ETag), and anonSendhook that append-mergesVary: Accept-Encodingon static-file routes only. Theapp.get('*')fallback and thewindow.CONFIGinjection are untouched, and a stale/assets/<hash>.jsURL keeps the fallback'sno-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 throughfeatures/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 answers200 text/html, andReact.lazycaches that rejection for the life of the document, so the first chunk-load failure reloads the document once per 60 s per tab (guarded throughsessionStorage); a second failure inside the window surfaces the error instead of looping. Pinned bylazy-with-reload.test.tsand a source-level check that no barelazy()sits beside it.Client — fork-owned
apps/client/build/precompress.ts(+ 35 tests): deterministic.br/.gzsiblings (never.html) and a build-time bundle budget computed from the chunk graph with a must-stay-lazy list (strict underBUNDLE_BUDGET_STRICT=1).vite.config.ts(seam #11): RolldowncodeSplitting.groupswith$initial-tagged vendor chunks. Rarely-visited routes via fork-ownedfeatures/layout/lazy-pages.ts(seam #6); katex + the Bases grid viafeatures/editor-ux/lazy/*(seam #59, new one-line seam inpages/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)
max-age=0Cold
/logintransfer 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-compat618 passed ·pnpm --filter client test263 passed ·tsc --noEmit(client, server,build/) clean ·BUNDLE_BUDGET_STRICT=1 vite buildpasses at 789,788 B (budget 860,000) ·deploy/standalone/smoke.shALL 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