Repository navigation
perf(web): route-level code splitting — 13.6 MB → 8.5 MB of JS per page - #803
Merged
Merged
Conversation
…ge (#797) `asyncRoutes: { web: true }` splits the single entry bundle into 180 chunks: mapbox-gl (1.9 MB) and the assessment corpus (1.0 MB) now ship only on the routes that use them, and every public page drops from 13.6 MB to 8.5 MB of JavaScript (2.88 MB → 1.55 MB brotli on the wire). The reason it was never enabled: the SSR HTML emitted every chunk `async`, so the 1 MB entry chunk could execute before the 7 MB shared chunk it requires and every page died with "Requiring unknown module". The `async` comes from React's `bootstrapScripts`, which `@expo/router-server`'s streaming renderer passed the chunk list to. Upstream fixed exactly this in `@expo/[email protected]` (preload in the head, `<script defer>` in the body, in asset order); this back-ports that change as a pnpm patch on the installed 56.0.18, so it lands in `dist/server/_expo/server/render.js` at export and covers every runtime — the Express server CI measures with, the EAS Hosting worker, and `expo serve`. Drop the patch with the SDK 57 bump. Verified on a served export with the CI env: 12/12 page×device pairs render with no page errors, the hydration audit is 18/18 clean, desktop client navigation into the lazily loaded /jobs chunk keeps the document, and the JSON-LD on / and /jobs is unchanged. `scripts/audit/boot-pages.mjs` is the regression check the hydration audit cannot be: it loads each public page in a real browser and fails on "Requiring unknown module", a page error, or an empty root. The Lighthouse job now runs it before measuring, because Lighthouse happily reports paint metrics for a page whose JavaScript died. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…xports only The first Lighthouse run on the split build showed /support painting at 10–12 s in two of three runs where every other page moved ~150 ms: the back-ported preload links load every chunk at default (High) priority, so the 1.5 MB shared chunk contended with the fonts, which did not start until it finished. React's bootstrapScripts preload — what production shipped before — carried fetchPriority="low"; the patch now emits the same. The scripts are deferred regardless, so nothing waits on the lower priority. asyncRoutes is 'production' rather than true: the dev server keeps eager bundling, so `pnpm web` and the Playwright e2e job (which failed on this branch with waitForLoadState timeouts against the dev server) are unchanged. `expo export` is a production build, so the split is unaffected. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…n a deferred-script build Lighthouse's default `simulate` mode records an unthrottled trace and has Lantern estimate the metrics from it. On the split build the deferred chunks download and execute within ~450 ms on localhost, so whether Chrome's first paint lands before or after them is a coin flip — and when it lands after, Lantern folds all of hydration into LCP: the same commit and page reported 2.2 s and 13 s in alternating runs, with observed LCP at 0.1–0.9 s in every one. The unsplit build never hit this because its 2.6 MB async entry could not arrive before the first paint. `throttlingMethod: devtools` measures the paint under real throttling instead: LCP 1.28–1.34 s across three local runs on /, TBT ~500 ms, TTI ~12.6 s. Runs take ~35 s each instead of ~13 s, so the job timeout rises to 35 minutes. Numbers from before this change are not comparable. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Closed
6 tasks
This was referenced Sep 17, 2026
thinkclay
added a commit
that referenced
this pull request
Sep 25, 2026
…) (#908) `expo install --check` resolves expected versions from Expo's live registry, so when Expo cut the SDK 56 patch set below, the Monorepo integrity job started failing on every branch at once. That job is gated on `deps == 'true'`, so only dependency PRs run it — which made it look as though each of the five open Dependabot PRs was individually broken. #853 bumps `adm-zip` alone and failed identically. Catalog pins moved to what the registry expects: expo ~56.0.21 -> ~56.0.22 expo-constants ~56.0.25 -> ~56.0.26 expo-dev-client ~56.0.26 -> ~56.0.27 expo-image ~56.0.12 -> ~56.0.13 expo-linking ~56.0.17 -> ~56.0.18 expo-location ~56.0.25 -> ~56.0.26 expo-router ~56.2.20 -> ~56.2.21 expo-updates ~56.0.26 -> ~56.0.27 Patch-level within SDK 56. This is not #483, the coordinated 56 -> 57 bump. ## The @expo/router-server patch had to move with it `[email protected]` pulls `@expo/cli@^56.1.26`, which wants `@expo/router-server@^56.0.19` — so the #797/#803 patch pinned at 56.0.18 stopped applying and pnpm refused the install with ERR_PNPM_UNUSED_PATCH. Half of that patch is now upstream. 56.0.19 ships the module-ordering fix itself: it drops `bootstrapScripts` from `renderToReadableStream` and injects `createInjectedScriptAsNodes` into head and body, carrying its own note that React's bootstrapScripts emits async scripts while Metro chunks must be ordered. That is the half that stopped the route-split build dying with "Requiring unknown module". The `fetchPriority="low"` half is not upstream. Without it the 1.5 MB shared chunk preloads at default priority, contends with fonts, and first paint slips from 2 s to 10 s on a throttled connection (#797). So the patch is re-targeted to 56.0.19 and reduced to that one hunk. Verified in the exported server bundle, not just in node_modules: a web export puts `fetchPriority:"low"` on the preload links and `defer` on the body script nodes in `dist/server/_expo/server/render.js`. The remaining `bootstrapScripts` strings in that file are react-dom's own server internals, not an expo call site. Also checked: `expo install --check` reports up to date, `pnpm dedupe --check` is clean, and `pnpm prepush` passes (build for 9 projects, Deno suites load, autolinking exports match, overrides/catalog aligned). Co-authored-by: Claude Opus 5 <[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.
Closes #797. Part of #802.
What
Enables
asyncRoutes: { web: 'production' }and makes the result boot.main)__common7.4 MB + entry 1.1 MB + route chunk)luscher-test)Measured, same machine, same harness (devtools throttling, mobile, median of 2)
//jobs/privacy/terms/contact/supportPaint metrics unchanged (they were already fine), TBT −25–40 %, TTI −27 % on every page — the parse/execute cost the split removes. The CI run on the same commit is linked from #797.
Why it never booted, and the fix
The SSR HTML emitted every chunk with
async="", so the 1 MB entry chunk regularly executed before the 7.4 MB__commonchunk it requires —Requiring unknown module "1313"on every page. Theasyncis React'sbootstrapScripts:@expo/router-server's streaming renderer (build/server/renderStreamingContent.js) handed it the chunk list. Expo's own static emitters already writedefer; SSR does not use them.Upstream fixed exactly this in
@expo/[email protected]— preload links in the head,<script defer>in the body, in asset order (their comment: "React's bootstrapScripts emits async scripts, but Metro chunks must execute in asset order"). This PR back-ports that change as a pnpm patch on the installed 56.0.18, with one addition: the preload links keepfetchPriority="low", as React's did — at default priority the shared chunk contended with the fonts and/support's first paint slipped from 2 s to 10 s in the first CI run. Because the patch is compiled intodist/server/_expo/server/render.jsat export time it covers every runtime: the Express server CI measures with, the EAS Hosting worker production runs on, andexpo serve. A rewrite inapps/scaffald/server/index.js(the stopgap #797 proposed) would have fixed CI and left production broken, since production never runs that file.Drop the patch with the SDK 57 bump (#483). Recorded in
.radium/ci-deployment.mdbeside the other pins, and in theapp.config.tscomment that used to say "see below" with no below.'production'rather thantrue: the dev server keeps eager bundling, sopnpm weband the Playwright e2e job (which timed out onwaitForLoadStateagainst a split dev server in the first run) are unchanged.expo exportis always a production build.The harness change
.lighthouserc.jsonnow setsthrottlingMethod: devtools. Lighthouse's defaultsimulaterecords an unthrottled trace and has Lantern estimate the metrics; on this build the deferred chunks download and execute within ~450 ms on localhost, so whether Chrome's first paint lands before or after them is a coin flip — and when it lands after, Lantern folds all of hydration into LCP. Same commit, same page: 2.2 s and 13 s in alternating runs, with observed LCP at 0.1–0.9 s in every one (a Playwright probe under real throttling confirmed no remount: one LCP candidate, the server-rendered node still in the DOM). The unsplit build never hit this because its 2.6 MB async entry could not arrive before the first paint. Devtools throttling measures the paint that actually happens: three local runs within 60 ms of each other. Runs take ~35 s instead of ~13 s, timeout raised to 35 min. Nightly numbers from before this change are not comparable.Verification
scripts/audit/boot-pages.mjs(new, also runs in the Lighthouse job before it measures): 12/12 page × device pairs render with no page error; desktop client navigation/→/jobskeeps the document and loads the route chunk lazily. It exists becausehydration-pages.mjsreported clean on the build whose JavaScript died before hydration — it only greps hydration messages.scripts/audit/hydration-pages.mjs: 18/18 clean across phone / tablet / desktop__expo-metro-runtime,__common,entry, layouts, route — alldefer, in that order, on every page; JSON-LD unchanged (3 blocks on/, ItemList on/jobs)pnpm prepushgreen;pnpm radium:check's three violations are pre-existing and not in touched filesTwo traps, written down in
.radium/ci-deployment.md: an export withoutEXPO_PUBLIC_SUPABASE_URL/ANON_KEYthrows on the client before rendering, and Metro's cache serves that env-less transform on the next export until$TMPDIR/metro-cacheis wiped.Not in this PR
.lighthouserc.json— after a nightly onmainwith the new throttling, not from a guess.__common(step 3 of Epic: public site performance, iteration 2 — route splitting, immutable assets, and the post-Sentry loose ends #802): tree-shaking experiment, then the icon barrel.🤖 Generated with Claude Code