Web: preload the phone push stack beside the entry (phone first paint) #1148

Closed
kayg wants to merge 0 commits from port/notes-float-phone-preload into port/notes-float
Owner

Phone first paint regressed by the trim (#1142: PhoneStack lazy, fetched only after the entry runs). Fix: the build writes <link rel="modulepreload" media="(max-width: 759px)"> (+ rel=preload as=style for CSS) for the PhoneStack chunk and its non-entry deps (PageToolbar, panes) into index.html, so a phone fetches them beside the entry; desktop ignores them (media does not match) and fetches nothing extra. The CSP forbids inline scripts, hence a media-gated link rather than a script. Same query as PHONE_QUERY. bundle-size.mjs and the service worker's core list skip media-gated links, so desktop first paint is unchanged (index 232.0 KB brotli, same hash as 9dd6b3930).

Evidence is in the comment below. Not merged.

Phone first paint regressed by the trim (#1142: PhoneStack lazy, fetched only after the entry runs). Fix: the build writes `<link rel="modulepreload" media="(max-width: 759px)">` (+ `rel=preload as=style` for CSS) for the PhoneStack chunk and its non-entry deps (PageToolbar, panes) into index.html, so a phone fetches them beside the entry; desktop ignores them (media does not match) and fetches nothing extra. The CSP forbids inline scripts, hence a media-gated link rather than a script. Same query as `PHONE_QUERY`. `bundle-size.mjs` and the service worker's core list skip media-gated links, so desktop first paint is unchanged (index 232.0 KB brotli, same hash as 9dd6b3930). Evidence is in the comment below. Not merged.
A media-gated modulepreload (+ style preload) written into index.html at build time, so a phone fetches the
PhoneStack chunk in parallel with the entry. Desktop first paint and the service worker's core list ignore them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Phone preload: read the chunks' CSS sets correctly
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled
f1ad093a09
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
Owner

Evidence (14 Nov night)

Phone first paint, iPhone 18 Pro sim (iOS 27.0, own sim, deleted), 10 cold loads each, interleaved (rotating order), warm-up load per variant discarded

Setup: dists built on dev-01 (pre-trim 6a3ef2e83, current 9dd6b3930, fix f1ad093a0) and served from std itself (a small Python server, no tunnel for assets); each load is its own cold origin (v-<variant>-<n>.localhost), Safari terminated before each. Network shaping is done by the server, not the OS Network Conditioner (not scriptable here): every response waits 100 ms RTT, then streams at 10 Mbit/s; precompressed br as the real server does. /api goes to a dev-user server (debug binary built from this base) through a tunnel (equal for all variants, unshaped extra latency). An identical inline probe records FCP and the first app frame (data-app=ready + rAF).

variant FCP median / mean (ms) first app frame median / mean (ms)
pre-trim 6a3ef2e83 3601 / 3533 3647 / 3576
current 9dd6b3930 3590 / 3644 3676 / 3786
fix f1ad093a0 3277 / 3330 3322 / 3374

Raw FCP ms: pre 3071 3081 3149 3171 3502 3700 3716 3851 3997 4088; cur 3253 3363 3376 3441 3552 3627 3647 3878 4083 4220; fix 3073 3079 3096 3125 3219 3334 3461 3484 3486 3941.
Fix is ~300 ms faster than current and ~320 ms faster than pre-trim (median). Spread is wide (shared sim, tunnel API); the fix's minimum equals pre's minimum and 8 of its 10 loads sit below the median of both others. Caveat: absolute values are inflated by the shaping and are not comparable to #1145's tunnel numbers; the account is not seeded, so the phone opens today's note directly, not the places list.

Safari support for media on modulepreload

Search found no statement that Safari ignores it; the spec allows media on rel=modulepreload and says an unmatching link is not fetched. Rather than rely on docs, the sim run shows it fetches on phone (fix gets faster); desktop gating is by the spec, and I did not measure Safari desktop request counts. A browser that ignored media would fetch ~PhoneStack chunk (few KB) early on desktop: harmless but it would not be counted by bundle-size.

Theme shots (iOS Safari sim, app's own ?theme=, not simctl appearance)

light: light
dark: dark

Gates

  • svelte-check: 0 errors, 19 warnings (pre-existing). vitest: 34 files, 319 passed. node --test scripts/test/*.test.mjs: 23 pass, 0 fail.
  • bundle-size.mjs dist: index 232.0 KB brotli, unchanged (same as 9dd6b3930).
  • Playwright e2e/notes-float-phone e2e/phone- e2e/lazy-ui e2e/app-switch --project=chromium-390 --workers=1 (dev-01, binary built from this head's base): 415 passed, 9 skipped. Same with --project=webkit-390 (dev-02): 415 passed, 9 skipped.
  • Decision: kept the lazy split (no undo); the preload closes the gap.
## Evidence (14 Nov night) ### Phone first paint, iPhone 18 Pro sim (iOS 27.0, own sim, deleted), 10 cold loads each, interleaved (rotating order), warm-up load per variant discarded Setup: dists built on dev-01 (pre-trim 6a3ef2e83, current 9dd6b3930, fix f1ad093a0) and served from std itself (a small Python server, no tunnel for assets); each load is its own cold origin (`v-<variant>-<n>.localhost`), Safari terminated before each. Network shaping is done by the server, not the OS Network Conditioner (not scriptable here): every response waits 100 ms RTT, then streams at 10 Mbit/s; precompressed br as the real server does. `/api` goes to a dev-user server (debug binary built from this base) through a tunnel (equal for all variants, unshaped extra latency). An identical inline probe records FCP and the first app frame (`data-app=ready` + rAF). | variant | FCP median / mean (ms) | first app frame median / mean (ms) | |---|---|---| | pre-trim 6a3ef2e83 | 3601 / 3533 | 3647 / 3576 | | current 9dd6b3930 | 3590 / 3644 | 3676 / 3786 | | fix f1ad093a0 | **3277 / 3330** | **3322 / 3374** | Raw FCP ms: pre 3071 3081 3149 3171 3502 3700 3716 3851 3997 4088; cur 3253 3363 3376 3441 3552 3627 3647 3878 4083 4220; fix 3073 3079 3096 3125 3219 3334 3461 3484 3486 3941. Fix is ~300 ms faster than current and ~320 ms faster than pre-trim (median). Spread is wide (shared sim, tunnel API); the fix's minimum equals pre's minimum and 8 of its 10 loads sit below the median of both others. Caveat: absolute values are inflated by the shaping and are not comparable to #1145's tunnel numbers; the account is not seeded, so the phone opens today's note directly, not the places list. ### Safari support for `media` on modulepreload Search found no statement that Safari ignores it; the spec allows `media` on rel=modulepreload and says an unmatching link is not fetched. Rather than rely on docs, the sim run shows it fetches on phone (fix gets faster); desktop gating is by the spec, and I did not measure Safari desktop request counts. A browser that ignored `media` would fetch ~PhoneStack chunk (few KB) early on desktop: harmless but it would not be counted by `bundle-size`. ### Theme shots (iOS Safari sim, app's own `?theme=`, not simctl appearance) light: ![light](https://git.kayg.org/attachments/444142a2-c4d5-4f52-96ae-2d770bb92453) dark: ![dark](https://git.kayg.org/attachments/8dba5317-574b-406a-9742-dc5e0bc68f1d) ### Gates - svelte-check: 0 errors, 19 warnings (pre-existing). vitest: 34 files, 319 passed. `node --test scripts/test/*.test.mjs`: 23 pass, 0 fail. - `bundle-size.mjs dist`: index 232.0 KB brotli, unchanged (same as 9dd6b3930). - Playwright `e2e/notes-float-phone e2e/phone- e2e/lazy-ui e2e/app-switch --project=chromium-390 --workers=1` (dev-01, binary built from this head's base): 415 passed, 9 skipped. Same with `--project=webkit-390` (dev-02): 415 passed, 9 skipped. - Decision: kept the lazy split (no undo); the preload closes the gap.
Author
Owner

Merged into port/notes-float with --no-ff by the orchestrator (phone FCP median 3277 ms vs 3601 pre-trim and 3590 current, same shaped setup; desktop first paint unchanged). Closing.

Merged into `port/notes-float` with `--no-ff` by the orchestrator (phone FCP median 3277 ms vs 3601 pre-trim and 3590 current, same shaped setup; desktop first paint unchanged). Closing.
kayg closed this pull request 2026-11-15 00:58:46 +00:00
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!1148
No description provided.