Repository navigation
Description
Investigated as the follow-on to #791. The splitting itself works and is worth roughly 37% of per-page JavaScript. The resulting app does not start. Not shipped; this records the attempt so the next one starts from the diagnosis rather than repeating it.
app.config.ts carried // NOTE: asyncRoutes is disabled — see below. with no "below" — this is the missing explanation.
What enabling it achieves
plugins: [['expo-router', { asyncRoutes: { web: true, default: false } }]], then expo export --platform web:
before 1 entry bundle 13.60 MB
after 180 chunks
__common 7.44 MB
entry 1.06 MB
index-f84b76… (mapbox route) 1.85 MB
index-f341c3… (assessment route) 0.99 MB
per-route chunks 0.02 MB and under
Per page, measured by resolving the script tags the SSR HTML emits:
/ 8.52 MB /privacy 8.51 MB
/jobs 8.53 MB /terms 8.51 MB
13.60 MB → ~8.52 MB per page, -37%. And the two libraries #791 called out did move off the shared path:
mapbox-gl -> index-f84b76… (route chunk)
luscher-test -> index-f341c3… (route chunk)
lucide -> __common (correct — used by nearly every route)
SSR survives intact: every page still server-renders its title, /jobs still emits its ItemList JSON-LD with 3 entries, / still emits 3 structured-data blocks.
Why it does not boot
Every page renders blank, with:
Uncaught (in promise) Error: Requiring unknown module "1313". at entry-*.js
Uncaught Error: Requiring unknown module "930". at entry-*.js
The cause, end to end:
-
The SSR HTML emits all six script tags with
async="":<script src="/_expo/static/js/web/__common-….js" async=""> <script src="/_expo/static/js/web/entry-….js" async="">
-
asyncmeans execution order is whatever finishes downloading first — not document order. -
entryis 1.06 MB;__commonis 7.44 MB. Entry reliably wins. -
Modules
930and1313are both defined in__common— verified by searching every emitted chunk — so entry runs and requires modules that have not been registered yet.
This is size-dependent, which makes it nastier than a flat failure: with a small enough __common the race could resolve the other way and the build would appear to work, then break when the shared chunk grows.
What would fix it
The scripts need ordered execution — defer rather than async, or a loader that waits for the shared chunk. That emission is inside Expo's SSR HTML generation, not app code, so the options are roughly:
- an upstream fix / issue against
expo-router+@expo/clifor multi-chunk SSR output - a post-render rewrite of the script attributes in
apps/scaffald/server/index.js— I attempted this as a proof and the middleware did not intercept, because the SSR response streams rather than going throughres.send. Worth another look with the stream wrapped properly; if it renders, that both confirms the diagnosis and is a viable stopgap. - checking whether a newer expo-router emits
defer(this is[email protected],[email protected])
Acceptance
-
asyncRoutes: { web: true }produces a build that boots on every public route - Per-page JS around 8.5 MB rather than 13.6 MB, with mapbox-gl and luscher-test in route chunks
- SSR metadata and JSON-LD unchanged (they already survive splitting)
- Client navigation between routes works, including a cold jump into a split route
- Lighthouse re-run on
/jobsand/privacy, before/after recorded on First Lighthouse baseline: /jobs has a 94s LCP, and no public page meets its budget #774 - Replace the dangling
// NOTE: asyncRoutes is disabled — see below.with a link to this issue
Related: #791 (bundle audit — 31% of the bundle is feature code every page carries), #774, #795.
Activity
thinkclay commentedon Sep 17, 2026
Checked the upstream angle so the next attempt does not repeat it (2026-09-17):
deferfor this path. In both the installed@expo/[email protected]and the current@expo/[email protected], Expo's own static HTML emitters writedefer(build/src/start/server/metro/serializeHtml.js:90,build/src/export/html.js:30) — and the multi-chunk branch inserializeHtml.js:105-106has thedeferline commented out with a TODO, identical in both versions. Upgrading to SDK 57 (deps: Expo SDK 56 -> 57 must be one coordinated bump, not 7 individual Dependabot PRs #483) will not fix this on its own.async=""you observed does not come from those emitters (none of them writesasync), and nothing inexpo-router,@expo/cliorexpo-serverpassesbootstrapScripts. The remaining candidate is React 19's hoistable-resource rendering during the SSR stream (a<script async src>element rendered from the router's script-tag component becomesasync=""in the output). First step next time: grep the exported server bundle indist/server/forasyncnext to_expo/static/js, notnode_modules— the emission is compiled into the route render.apps/scaffald/server/index.js(it usesexpo-server/adapter/express'screateRequestHandlerat line 62, so intercept the response body write, notres.send) and rewriteasync=""→defer=""on<script src="/_expo/static/js/…">tags. Sincedeferpreserves document order andserializeHtmlalready orders__commonbeforeentry, that is sufficient. File the upstream issue in parallel, linking this one.Also a reminder that this is the only remaining lever that moves TBT/TTI: the nightly on
c67f930d2shows 2.9 MB on the wire per page but TBT 2.0–2.4 s and TTI ~17.5 s — the cost is parsing and executing 13.6 MB of JS, not downloading it.thinkclay commentedon Sep 17, 2026
Correction to my note above, and the diagnosis, with the PR up.
There is an upstream fix — I looked in the wrong packages. The streaming SSR renderer is not in
expo-routeror@expo/cli; it is@expo/router-server(build/server/renderStreamingContent.js), and it passes the chunk list to React asbootstrapScripts, which is whereasync=""comes from.@expo/[email protected]already replaces that with preload links in the head and<script defer>in the body, in asset order — their comment names this exact race. So the SDK 57 bump (#483) does fix it after all; what is true is that no 56.x release does.The stopgap is not the server rewrite.
apps/scaffald/server/index.jsis what the Lighthouse job and the Dockerfile run, but production is the EAS Hosting worker (scripts/deploy-web-eas.sh), which never executes that file. A rewrite there would have made CI green and left scaffald.com blank. The fix that reaches every runtime is to change the rendered HTML itself: a pnpm patch on the installed@expo/[email protected]back-porting the 57.0.10 change, compiled intodist/server/_expo/server/render.jsat export.Everything else in the issue held: the split is 13.6 MB → 8.5 MB per page (2.88 → 1.55 MB brotli), mapbox-gl and the assessment corpus are in their own route chunks, SSR metadata and JSON-LD survive, and the failure really is size-dependent. Two things the acceptance list did not anticipate: the hydration audit reports clean on a build whose JavaScript died before hydration (it only greps hydration messages), so there is now a
scripts/audit/boot-pages.mjsthat fails on "Requiring unknown module", a page error, or an empty root — and the Lighthouse job runs it before measuring anything.Lighthouse before/after follows from the
ci:fullrun on the PR.thinkclay commentedon Sep 17, 2026
Shipped in #803. Before/after from the same machine and harness (devtools throttling, mobile) is in the PR; the CI run on the final commit (35219924138, devtools throttling, median of 3):
//contact/jobs/privacy/support/termsAgainst last night's
main(simulated throttling, so directionally only): TBT ~2.0–2.4 s → ~0.93 s, TTI ~17.5 s → ~13 s, LCP run-to-run spread on/now 100 ms. The only assertion warning is the pre-existing/supportCLS 0.113 (#802 step 2).One finding the acceptance list did not anticipate, now written into the workflow: the first CI runs reported LCP of 13 s on
/and/contactin two runs out of three. That was Lighthouse's default simulated throttling — Lantern estimating from an unthrottled trace — folding hydration into LCP whenever Chrome's unthrottled first paint happened to land after the deferred chunks had already executed (they finish in ~450 ms on localhost). Observed LCP was 0.1–0.9 s in every one of those runs, and a Playwright probe under real throttling showed a single LCP candidate with the server-rendered node still in the DOM. The nightly now usesthrottlingMethod: devtools; pre-#803 nightly numbers are not comparable, and the budget ratchet waits for the first nightly onmain.Acceptance: boots on every public route ✓ (12/12 page×device, new
boot-pages.mjsin the job) · ~8.5 MB per page with mapbox-gl and luscher-test in route chunks ✓ · SSR metadata and JSON-LD unchanged ✓ · client navigation into a split route ✓ · Lighthouse before/after ✓ (above and in the PR) · dangling NOTE replaced ✓.fix(deps): align the Expo catalog with SDK 56's current patch set (#907…