perf(core): load the islands router on the hover that loads the client
Problem
In islands mode, the first client navigation from a page is slower than RSC's in every section of benchmarks/server-components-payload. Navigations after it are as fast or faster. The benchmark reports the median of ten navigations, so the first one didn't show.
On a page with no client component that hydrates at load (docs, blog, guide), a hover over a link loaded only the client entry and React. The router, the route table and the hovered page's prefetch all waited for the click, and then ran one after another:
hover: farm-client.js, react.js
click: farm-client-routes.js, farm-client-router.js, then fetch /blog/b1
Root cause
Two listeners respond to the same hover:
- The boot script listens for link intent (
mouseover,focusin,pointerdown) and loads the client entry. - The client entry's lazy router stand-in listens for the same events to load the router (
farmRouterIntent).
The stand-in's listeners only exist once the entry has run, which is after the hover that loaded it. So the router waited for the next intent event, usually the click's pointerdown.
The browser test "Links in server components prefetch once the router loads" documented this as expected: "a first hover loads the client entry, and the next one the production router".
Change
When the stand-in runs, it checks for a link that is still hovered or focused (a[href]:hover, a[href]:focus) and treats it as the intent that loaded the entry. Now one hover loads the router and the route table and prefetches the page:
hover: farm-client.js, react.js, farm-client-routes.js, farm-client-router.js, fetch /blog/b1
click: (nothing for blog and docs)
A page whose islands hydrate on load, with no link under the pointer, still never loads the router. The stand-in's existing farmRouterIntent filters still apply: hash links and absolute URLs don't count.
Safety and compatibility
- This only affects the production islands client entry, the one that splits the router. RSC mode and dev already load the router with the page.
- There's no new option or public API.
- A link the visitor hovers but never clicks now loads the router while it's under the pointer. Before, the router loaded on the next
mouseover,focusinorpointerdownover a link.
Verification
- New unit tests in
lazy-router-stand-in.test.ts:- "loads the router at once when the link that loaded the entry is still focused". It fails without the change.
- "leaves the router unloaded when no link is focused or under the pointer".
islands-client-entry.test.tsandlazy-router-stand-in.test.ts: 20 passed.- The browser test "Links in server components prefetch once the router loads" now hovers once instead of twice. It fails without the change (the prefetch never happens) and passes with it.
- Islands production Playwright suite (
FARM_SERVER_COMPONENTS_MODE=islands,playwright.server-components.config.ts): 136 passed, 8 skipped. - Dev islands, tests matching "router": 2 passed, 3 skipped.
oxfmtandoxlinton the changed files: clean.
First navigation after a cold visit, benchmarks/server-components-payload production builds:
- Chrome with 4x CPU throttling. The pointer rests on "Next" for 150 ms before the click.
- 12 rounds, with the three builds interleaved in alternating order.
- Medians in ms. "Before" is
main.
| Section | RSC | Islands, before | Islands, after |
|---|---|---|---|
| guide | 182 | 295 | 256 |
| blog | 186 | 284 | 216 |
| docs | 124 | 158 | 152 |
This machine had other work running (load average 50–70), so individual samples are noisy; the full lists are below. The second navigation is unchanged (guide 120 → 128, blog 114 → 109, docs 75 → 76).
Samples (ms)
guide islands-base 295,298,329,248,232,180,238,360,309,298,203,212
guide islands-fix 406,256,478,308,220,250,214,294,412,211,206,240
guide rsc 180,572,263,333,182,150,170,373,214,155,163,179
blog islands-base 301,182,343,214,517,330,284,326,169,209,249,168
blog islands-fix 299,150,170,140,172,247,297,391,248,183,216,171
blog rsc 257,431,183,155,150,143,194,278,137,308,186,153
docs islands-base 158,384,216,147,113,180,241,128,159,112,125,128
docs islands-fix 140,603,131,108,220,293,177,301,127,100,152,94
docs rsc 124,77,124,92,158,140,132,108,108,109,123,143
Islands still trails RSC on the first navigation. The hover has to download and run the whole client entry (271 KB raw, 81.5 KB brotli), including react-dom, even for a navigation that only swaps HTML. RSC loaded that upfront. That's a separate change.
Not verified: Windows, Cloudflare and Vercel targets (this changes only browser code), and touch devices (there's no hover; pointerdown already loads the router there).
Documentation and release
None.
Summary by cubic
Speeds up the first client-side navigation in islands mode by loading the router on the hover that loads the client entry, so the route table and page prefetch no longer wait for the click.
Previously, a hover loaded only the client entry and React. The router, route table, and prefetch ran in series after the click, slowing the first navigation versus RSC.
- The lazy router stand-in now checks for a link still hovered or focused when it runs and treats that as the loading intent.
- A link that's hovered without a click now loads the router; before, it loaded on the next intent event.
- Only affects the production islands client entry; RSC mode and dev already load the router with the page, and there's no new option or public API.