perf(islands): render a streamed first navigation before React DOM loads
Implements RFC 0010 (#3054).
Problem
In islands mode a first navigation runs the router, and the router's chunk statically imports the client entry, which statically imports React DOM and islx. So a page that streams in waits for about 93 KB br of JavaScript before it renders, even when it has no React root to render into. On a slow connection that download decides the first tap: at 150 ms latency and 1.6 Mbit/s, a first tap on docs took 715 ms against RSC's 266.
Root cause
The entry imports react-dom/client and @farm.js/core/internal/islands-runtime at the top, so everything that imports the entry, including the lazily loaded router, waits for both. A streamed navigation only needs them to hydrate its islands, which can happen after the page is in the document.
Change
In an islands web build with React and no client route slots, the generated entry imports react-dom/client and islx when it first renders or hydrates (loadFarmRenderer()), not at the top.
- A navigation that streams its page swaps it in before they load. They load beside it and hydrate its islands. Until then the entry holds a click or submit on an unhydrated island (
holdFarmIslandInteractions, the existing prehydration click queue), and releases it once islx runs or fails to load. - A navigation that renders in a layout's React root (
createMatchedHydrationRoute), a lazily loaded route component, andhydrate()await the renderer first, as before. - Until islx loads, the islands runtime facade queues
hydrate,dispose, andendStreamin call order. - The loader names the islx exports it uses inside
.then(function({ ... }) { ... }). A module object that escapes keeps all of islx's exports, which cost 11 KB raw before this. - The preload manifest gains a
rendererlist besideentryandrouter, written asdata-farm-preload-renderer. The boot entry preloads it when the first navigation starts, except for a link that streams its page. A navigation's response leaves the list out, unless the route is shared-cacheable.
The mobile client and apps with client route slots keep the static import. They render into a React root on every navigation.
No new config or public API.
Safety and compatibility
- Only islands web builds with React and without client route slots change. RSC builds, the mobile client, other renderers, and the dev path are unchanged.
- A click on an island before islx loads is held and replayed, not lost. Without the hold, the contract test's click is dropped.
- A navigation into a layout root still waits for React DOM. Without that wait, the contract test's layout root breaks.
- If loading the renderer fails, the hold is released, the loader resets so the next call retries, and the error is rethrown.
- Bytes: first-load JavaScript stays 2.2 KB br (the boot grows by 32 B, 2066 to 2098 B). The router's static closure goes from 93.1 to 26.8 KB br. The runtime as a whole goes from 93.2 to 95.5 KB br: about 0.4 KB of code, the rest compression lost to three files instead of one. Data per navigation stays within 0.1 KB.
- Known limit: shop and guide render under a layout that hydrates as one root, so their first tap still waits for React DOM (776 and 826 ms at 1.6 Mbit/s, from 819 and 871).
Verification
first-navigation.mjs, interleaving rsc, a build of #3042 (islands-base), and this branch (islands). HTTP/2, 4x CPU. Apple M1, macOS 26.2, Node 24.21.0. Load average 8 to 55 from other work. Medians in ms, rsc / before / after:
| Section | 150 ms at 1.6 Mbit/s, 80 ms tap (5 rounds) | 50 ms, instant tap (5 rounds) | 150 ms, 100 ms hover (9 rounds) |
|---|---|---|---|
| docs | 266 / 715 / 316 | 124 / 163 / 137 | 197 / 157 / 160 |
| shop | 225 / 819 / 776 | 121 / 249 / 216 | 192 / 163 / 139 |
| blog | 290 / 801 / 389 | 169 / 213 / 162 | 252 / 204 / 210 |
| guide | 307 / 871 / 826 | 226 / 323 / 250 | 254 / 200 / 194 |
- A 150 ms, 80 ms tap stays within noise. A 15-round rerun of shop and guide put them at 246 to 240 ms and 269 to 255 ms.
- Before/after bytes come from the built clients' static import closures (
islands-baseandislandsoutputs).
Tests:
pnpm --filter @farm.js/core exec vitest runon the changed areas: island-runtime, islands-client-entry, client-module-preloads, islands-boot. All pass.pnpm exec vitest runinpackages/farm(full core suite): 687 files passed, 1 skipped, 51 failed. The 51 failures had two causes:- Workspace packages this checkout hadn't built (
@farm.js/integration-utils,stripe,jobs,mcp,otel, and others). - A gap in the
document-injection.test.tsharness, which runs the extracted document composer without the handler's newfarmNavigationRequestlocal. The harness now declares it.
After building those packages and fixing the harness, the 51 files pass on their own: 300 tests.
- Workspace packages this checkout hadn't built (
pnpm --filter @farm.js/core type-check,oxfmt --check,oxlinton changed files: clean.- Production e2e (
tests/e2e-server-components): islands 142 passed, 8 skipped. Cloudflare 140 and Vercel 141 passed, both 8 skipped. Client plugins 3 passed. CSP variants passed. The Cloudflare, Vercel, plugin, and CSP runs came before the last change, which leaves the renderer list out of navigation responses. - New contract tests:
- A client navigation's response leaves out the renderer's chunks.
- A streamed first navigation renders while the renderer is held, and its island keeps a click.
- A first navigation into a layout root waits for the renderer.
- Negative checks: removing the hold, the layout-root wait, or the navigation flag each fails its contract test.
Not verified:
- Windows.
- Real devices and real mobile networks (the network is emulated).
- The Netlify and Node presets beyond the islands prod config.
- The dev e2e config: one promise-streaming test failed under load and passed 3 of 3 alone. The dev path is unchanged.
Documentation and release
docs/src/app/docs/server-rendering/islands/page.md: the browser sentence, data per navigation, first-tap rows, and runtime size.benchmarks/server-components-payload/README.mdandresults/latest.json: the new measurements.- RFC 0010 is in #3054.
- No changeset: Farm releases with bumpp.
Summary by cubic
Streams a first navigation's page before React DOM and islx finish loading, fixing a first tap that waited on ~93 KB of renderer JavaScript.
- In islands web builds with React and no client route slots, the entry loads React DOM and islx on first render or hydration instead of statically.
- The boot script now sends a clicked link's navigation request with the click, and the router reuses that response; island clicks and submits are held and replayed once hydration runs.
- The preload manifest gains a
rendererchunk list; streamed navigation responses leave it out so the page and router get bandwidth first. - RSC builds, the mobile client, dev mode, and apps with client route slots keep the static import. No config or API changes.
Measured on a 150 ms, 1.6 Mbit/s network: first tap on docs drops from 715 ms to 316 ms; shop and guide still wait for a hydrating layout root (776 and 826 ms).