Skip to content

Load CodeMirror after the page presents, not before - #3897

Merged
max-sixty merged 10 commits into
mainfrom
grind/g-boot-codemirror
Oct 27, 2026
Merged

max-sixty merged 10 commits into
mainfrom
grind/g-boot-codemirror

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Every opening fetched and evaluated CodeMirror (vendor/codemirror.esm.js, 345 KB)
before the page first showed the server's state. bundle-answer imported it statically
through the text field (composing/text-field.js), and widget-api.js re-exported
LeafEditorView, which extends CodeMirror's EditorView. Only writing needs it, and
an empty field already built its editor only when the user arrived in it.

CodeMirror now loads with a dynamic import once the page has presented
(afterPresentation, the route floating-ui takes), as an arrival the page answers
for. The code that needs CodeMirror is built over the loaded module: the field's
state, decorations, preview and row reveal in composing/field-editor.js
(loadFieldEditor), and the view class in editor-view.js
(leafEditorView(codemirror), one class per module). caretAt, which main's #4116
exported for the field's row reveal, needs CodeMirror's Direction, so it is now the
view's method (view.caretAt(pos)). These modules stay in the page's static graph, so
the kernel's chunks keep their shape. Importing field-editor.js lazily instead made
the compiler regroup the shared chunks around it: four more requests on every opening
with the compiler's chunk optimization off, as on main, and two more
(bundle-editor-view, bundle-widget-upgrade) on top of #3904, which turns it on.

Before its editor exists, a field holds a plain draft: its words, its selection, the
words its history starts from, and the history steps its owner recorded. A field that
must build before CodeMirror has arrived, because it holds words or the user arrived in
it, keeps a rendering hold until the module lands. Meanwhile it shows its words plain
in the empty line's place, with the draft's caret there while the user is in it.
Typing lands natively in that place, as does a selection the page sets, and the field reads the words and caret back
after each input, so the editor builds holding both. Words an input method is still
composing join the draft when it commits, and the editor builds then. The editor's
history starts from the draft's base words, with the early typing as one step undo
takes back. Return still asks the owner first (lf-edit-return), and Shift+Return
breaks the line.

widget-api.js exports leafEditorView(codemirror) in place of LeafEditorView, and
the file editor passes the CodeMirror module it already imports, so it gets the class
synchronously, with no top-level await. Removing a public export breaks pages vendored
before this change, so the page protocol (browser/runtime/kernel-registry.json)
moves from 28 to 29.

A one-line field (aria-multiline="false", #4323) holds one line in both forms: its
editor turns a pasted or platform line break into a space and takes no Shift+Return,
as on main, and the plain draft before CodeMirror arrives does the same.

Measured with uv run leaf-dev probe <page> --base against merge base f90ff10 (first
measured at 4789149; an independent run reproduced the release-notes figures), on
the compiled kernel. JS requests and JS bytes (decoded) are those loaded when the page
first showed the server's state (presented). Release-notes read the same in both
runs. On triage-board, markdown-it.esm.js (102 KB) sometimes finishes just before
presented on either arm, on a host at load 30-48; the table gives the reading without
it, which base gave in 4 of 5 runs and this branch in 3 of 5. In every run on this branch codemirror.esm.js finished after
presented.

page arm JS requests JS bytes
release-notes base 45 2,494 KB
release-notes this 44 2,156 KB
triage-board base 38 2,360 KB
triage-board this 37 2,022 KB

Time to presented wasn't measured on the new base, since the host was too loaded for
timings to mean anything. On earlier bases it didn't move beyond run-to-run noise:
medians of three runs were 510 → 411 ms and 323 → 314 ms at 1x against c7e3d23, and
1,135 → 1,112 ms and 851 → 773 ms at 4x CPU against 936b607.

From a press of c to a focused editor in the page comment box (Event Timing on the
keydown, measured against 936b607), focus was in CodeMirror's content node by the
first animation frame after the press in every run of both arms. The keydown's
input-to-paint duration was 16 ms at 1x on both arms; at 4x it was 64-72 ms on both,
with handler time 27-30 ms on base and 33-35 ms here on release-notes. With CodeMirror
held, focus lands in the field in the first frame, and in Chromium and Firefox the
words typed meanwhile, a caret moved with the arrow keys and a Shift+Return included,
are in the editor once it builds.

Tests:

  • test_words_typed_while_the_editor_loads_are_its_first_words, in Chromium and
    Firefox, holding CodeMirror's module: the page presents and reads arrived; c,
    typing, a caret moved back, more typing and a Shift+Return reach the editor with the
    caret where it was; undo takes back the editor's typing, then the early words.
  • test_a_kept_draft_and_an_input_method_reach_the_editor_as_it_loads, in Chromium
    (the input method goes through CDP), holding CodeMirror's module: words typed after
    a kept draft on reload follow it; a selection the page sets (setSelectionRange)
    is where the next words land; an input method composing as CodeMirror lands
    commits its words once.
  • test_an_unavailable_editor_module_leaves_fields_writing_plain_words, with
    CodeMirror's module aborted: Leaf reports the failure each time a field asks for
    its editor, and the field keeps writing plain words, Shift+Return breaking the line
    and Return sending.

On the merge base the first test times out, since the held module keeps the page from
loading; on this PR's first version both fail (caret at 16 not 14; " wordsKept").

How it merges with other bundle work

Calls Max may reverse

  • The public API shape leafEditorView(codemirror), which takes the CodeMirror module
    the caller imports.
  • caretAt as a method of the view class rather than a module export.
  • CodeMirror loads as an arrival after presentation rather than on idle or on a first
    pointer or key intent. In every measured run it had arrived before the probe pressed
    c.
  • The rendering hold covers the load only: an input method still composing when
    CodeMirror lands defers the build to its commit without holding the page's readiness
    on the user.

Checks run

On the merge with main at b1fdabcb4: pnpm run check; the three tests above;
test_render_options_addition.py's one-line phone case and add-field preview.

On an earlier merge with main:

  • pnpm run check: the build check, framework (134 passed), runtime (562 passed) and
    Worker (85 passed) tests.
  • The three tests above (4 runs), and main's
    test_a_scrolling_draft_shows_the_caret_s_row_with_the_padding_beside_it in Chromium
    and Firefox (4 passed).
  • -k selections of test_render_files.py (file editor), test_render_shift_watch.py,
    threads/test_layout.py, margin/test_card_reply.py, threads/test_rewrites.py and
    test_chrome_contracts.py on editor carets, reveals and scrolling drafts (17 passed).

Earlier, on c7e3d23: tests/browser/startup/test_modules.py,
tests/browser/drafts/test_composer.py, test_draft_editing.py, test_keys.py,
tests/browser/threads/test_composing.py, tests/browser/test_render_files.py,
tests/browser/test_chrome_contracts.py, tests/browser/test_render_export.py,
tests/browser/test_render_words_watch.py (230 passed).

An independent review on 3a095de also checked:

Not verified

  • An input method in Firefox or WebKit; the composition test drives Chromium's CDP.
  • Time to presented on the new base.

This was written by Claude Code on behalf of max-sixty

Comment thread tests/browser/startup/test_modules.py Resolved
Every opening fetched and evaluated CodeMirror (`vendor/codemirror.esm.js`, 345 KB)
before the page first showed the server's state. `bundle-answer` imported it statically
through the text field (`composing/text-field.js`), and `widget-api.js` re-exported
`LeafEditorView`, which extends CodeMirror's `EditorView`. Only writing needs it, and
an empty field already built its editor only when the user arrived in it.

CodeMirror now loads with a dynamic import once the page has presented
(`afterPresentation`, the route `floating-ui` takes), as an arrival the page answers
for. The code that needs CodeMirror is built over the loaded module: the field's
state, decorations and preview in `composing/field-editor.js` (`loadFieldEditor`), and
the view class in `editor-view.js` (`leafEditorView(codemirror)`, one class per
module). These modules stay in the page's static graph, so the kernel's chunks keep
their shape. Importing `field-editor.js` lazily instead made the compiler regroup the
shared chunks around it: four more requests on every opening with the compiler's
chunk optimization off, as on main, and two more (`bundle-editor-view`,
`bundle-widget-upgrade`) on top of #3904, which turns it on.

Before its editor exists, a field holds a plain draft: its words, its selection, the
words its history starts from, and the history steps its owner recorded. A field that
must build before CodeMirror has arrived, because it holds words or the user arrived in
it, keeps a rendering hold until the module lands. Meanwhile it shows its words plain
in the empty line's place, with the draft's caret there while the user is in it.
Typing lands natively in that place, and the field reads the words and caret back
after each input, so the editor builds holding both. Words an input method is still
composing join the draft when it commits, and the editor builds then. The editor's
history starts from the draft's base words, with the early typing as one step undo
takes back. Return still asks the owner first (`lf-edit-return`), and Shift+Return
breaks the line.

`widget-api.js` exports `leafEditorView(codemirror)` in place of `LeafEditorView`, and
the file editor passes the CodeMirror module it already imports, so it gets the class
synchronously, with no top-level await. Removing a public export breaks pages vendored
before this change, so the page protocol moves to 25.

Measured with `uv run leaf-dev probe <page> --base` against merge base c7e3d23, on the
compiled kernel. Requests and JS bytes are those loaded when the page first showed the
server's state (`presented`), the same in every run.

| page | arm | requests | JS bytes |
| --- | --- | --: | --: |
| release-notes | base | 51 | 2,413 KB |
| release-notes | this | 50 | 2,083 KB |
| triage-board | base | 43 | 2,309 KB |
| triage-board | this | 42 | 1,978 KB |

Time to `presented` didn't move beyond run-to-run noise: medians of three runs were
510 → 411 ms and 323 → 314 ms at 1x, and in an earlier run against 936b607,
1,135 → 1,112 ms and 851 → 773 ms at 4x CPU.

From a press of `c` to a focused editor in the page comment box (Event Timing on the
keydown, measured against 936b607), focus was in CodeMirror's content node by the
first animation frame after the press in every run of both arms. The keydown's
input-to-paint duration was 16 ms at 1x on both arms; at 4x it was 64-72 ms on both,
with handler time 27-30 ms on base and 33-35 ms here on release-notes. With CodeMirror
held, focus lands in the field in the first frame, and in Chromium and Firefox the
words typed meanwhile, a caret moved with the arrow keys and a Shift+Return included,
are in the editor once it builds.

Tests, both holding CodeMirror's module:

- `test_words_typed_while_the_editor_loads_are_its_first_words`: the page presents and
  reads `arrived`; `c`, typing, a caret moved back and more typing reach the editor
  with the caret where it was; undo takes back the editor's typing, then the early
  words.
- `test_a_kept_draft_and_an_input_method_reach_the_editor_as_it_loads`: words typed
  after a kept draft on reload follow it; an input method composing as CodeMirror
  lands commits its words once.

On the merge base the first test times out, since the held module keeps the page from
loading; on this PR's first version both fail (caret at 16 not 14; " wordsKept").

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty and others added 3 commits October 25, 2026 14:19
Main's #4116 rests a scrolling draft at its end: the field reveals the
caret's whole row through a scroll handler on its state and `caretAt`,
which main exported from editor-view.js. Here the state is built in
field-editor.js over the loaded CodeMirror, so the handler joins
`fieldState` and calls the field's `revealed` hook, and `caretAt`, which
needs CodeMirror's `Direction`, is the view's method. Main's
`#focusing` guard in `focus()` moves into the class `leafEditorView`
builds. Main is at protocol 26, so this change takes 27; the kernel and
baseline are rebuilt.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The early-typing test now runs in Chromium and Firefox and breaks a line
with Shift+Return before the editor builds. A new test aborts CodeMirror's
module: Leaf reports the failure each time a field asks for its editor,
and the field keeps writing plain words, Shift+Return breaking the line
and Return sending. widget-api.js no longer claims the runtime never
loads CodeMirror for a page that doesn't edit; it loads once the page has
presented.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread browser/runtime/composing/text-field.js Resolved
max-sixty and others added 2 commits October 26, 2026 22:19
Main moved the page protocol to browser/runtime/kernel-registry.json at 28, so
this change bumps it there to 29 and rebuilds the baseline from main's.

Main's one-line field (aria-multiline="false", #4323) lived in text-field.js's
editor state; it moves with that state into field-editor.js, read through the
field's hooks (oneLine), and the plain draft before CodeMirror loads holds one
line the same way: Shift+Return inserts nothing and a pasted line break becomes
a space. Kernel rebuilt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review October 27, 2026 05:23
max-sixty added a commit that referenced this pull request Oct 27, 2026
Main moved the page protocol to browser/runtime/kernel-registry.json at 28; this
change bumps it there to 30, after #3897's 29, and rebuilds the baseline from
main's. The x-refers description's mention of indicate is dropped where main now
keeps it. Kernel rebuilt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
max-sixty and others added 3 commits October 26, 2026 22:34
setSelectionRange (and select, and a caret restore through it) moved only the
draft's range while CodeMirror loaded, so typing landed at the native caret and
the editor then built from that one. The draft's place now shows the range.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Kernel rebuilt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 27, 2026
Kernel rebuilt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty merged commit 3dffc17 into main Oct 27, 2026
4 checks passed
@max-sixty
max-sixty deleted the grind/g-boot-codemirror branch October 27, 2026 07:08
max-sixty added a commit that referenced this pull request Oct 27, 2026
#3897 took protocol 29, so this change bumps browser/runtime/kernel-registry.json
to 30 and rebuilds the baseline from main's. Kernel rebuilt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
max-sixty added a commit that referenced this pull request Oct 27, 2026
`indicate()` (`browser/runtime/indication.js`, experimental since #1129)
let one widget mark elements in another that it names through
`x-refers`. Its only caller was `examples/rust-sort`'s film, which lit
the Rust line each step executes in the `lf-code` excerpts beside it,
and an inline script on the page scrolled that line into view. This PR
removes the API, as Max decided.

**What users lose:** rust-sort no longer lights or scrolls to the source
line the current step executes. The film, its narration, inputs and
commentable parts are unchanged.

## What goes

- `indication.js`, its export from `widget-api.js`, the
`data-lf-indicated` paint attribute in `page-paint.js`, the default
contour in `marks.css`, `lf-code`'s indicated-line face (`code.css` and
the generated `theme.css`), the dependency-cruiser entry, the
"Indicating (experimental)" section of `module-reading.md`, and the
tests of indication itself: its union and per-driver keys, re-resolution
on layout, lf-code's indicated face, and rust-sort following the line.
- Mentions of `indicate` in the `x-refers` description in
`browser/registry.json`, and in comments in `references.js`,
`stylesheets.js`, `floating-panel.css`, `annotation-marks.css` and
`lf-code.js`.
- In rust-sort: the follow-the-line script, the film's `sort-code`,
`head-code` and `merge-code` attributes and their `x-refers`, the
`sort-step` event that nothing listens to any more, `sort.js`'s `LINES`
table and the per-step `line` names it mapped. The collapse() clauses
now match by `key` instead of a `c-` line name.

`lf-code` keeps `lfElementsFor`, which `navigateToDatum` reads through
`addressedElements`.

## Tests kept

Some tests that went with `indicate()` also held code that stays. They
are kept:

- `indication.test.mjs`'s tests of `referencedProjection` (message
before page, never another message; a keyed reference in its own scope)
move unchanged to `tests/runtime/references.test.mjs`. Its
undeclared-attribute test now calls `requireReference` directly.
`navigateToDatum` (`anchor-travel.js`) and widget data inputs
(`data.js`) both use these functions.
- The lf-code excerpt test asserted `lfElementsFor`'s rows through the
removed `point()` driver. It now reads `#walk.lfElementsFor(key)`
directly: `1507-1550` gives rows `1507`, `1508-1549`, `1550`; `1520`
gives the elided row `1508-1549`; `3` gives none.

Bug-back, each change reverted after: making `referencedProjection`'s
keyed branch ignore scope, making its id lookup skip the referrer's own
message, or making `requireReference` a no-op each fails one test in
`references.test.mjs`. Making `lfElementsFor` return `[]` fails the
excerpt test.

## Protocol bump: 29 → 30

`layer-registry.md`, "Page protocol", says whoever removes a
`widget-api.js` export bumps the number, because a vendored module that
imports it breaks. That happens here, so `$events.protocol` in
`browser/runtime/kernel-registry.json` moves to 30, one past the 29 that
#3897 landed with. Main's rust-sort, served by this branch's runtime,
fails to start:

```
uv run leaf-dev probe .tmp/base/examples/rust-sort.html --base \
  --do 'focus:#sort-film .sort-scrub' --do press:ArrowRight ... --js '<collect [data-lf-indicated] through shadow roots>'
base (main runtime):  indicated ["while start > 0 && compa…"]
worktree:             "leaf: page failed to start: The requested module '…/runtime/widget-api.js'
                       does not provide an export named 'indicate'"
```

(`.tmp/base/examples/` holds main's `rust-sort.html` and
`rust-sort.page/`, from `git archive`.) With the bump, an older page is
re-vendored by the session holding it instead of failing to start. The
new rust-sort on this branch starts with no console errors, and stepping
the film works.

## Tests run

- On the merge with main: `pnpm run check` (runtime 673 pass);
`test_render_pages.py -k sort` and `test_code_and_documents.py -k 'sort
or excerpt or code_line'` (4 pass)
- Earlier: `pnpm run test:runtime` (560 pass), `pnpm run check:browser`
(committed bundles match a fresh build)
- `tests/browser/test_render_pages.py` and
`tests/journeys/test_render_pages.py -k sort` (4 pass)
- `tests/browser/widgets/test_code_and_documents.py -k 'excerpt or
code_line'` (2 pass; `-k excerpt` re-run after the review fixes)
- `tests/model/test_interact_product.py`, `test_product_page.py`,
`test_interact_layer.py`, `test_claims.py`,
`interact_contract/test_layer_contract.py`, `test_registry_door.py`,
`test_data_contracts.py` (447 pass)
- `tests/model/test_interact_document.py -k declared_attribute` (1 pass)

Not run: the full suite. Rust-sort's first screen changes (on main, the
film's first step lights `while end > 0 {` in the source pane), so the
landing pass ran `wt refresh-previews`, which recaptured every catalog
still from this tree after its last merge of main and moved the
`leaf-assets.json` pin and the README's image URLs to
`max-sixty/leaf-assets@6ad7cc888`.

Started from the survey's commit `a4fff17e0` on
`grind/s-maintenance-survey`, rebased onto current main with the kernel
rebuilt. On top of it, this PR removes the rust-sort leftovers the
survey kept (attributes, `x-refers`, `sort-step`, `LINES`), fixes the
page's description and lede that still said the source "follows along",
and bumps the protocol.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty added a commit that referenced this pull request Oct 27, 2026
Main's #3897 moved caretAt onto the editor view; the free-corner check
now calls view.caretAt as the rest of text-field.js does.
max-sixty added a commit that referenced this pull request Oct 27, 2026
#3904)

Every page loaded eleven more kernel chunks than it needed before it
first showed the
server's state. `browser/leaf.js` booted with two top-level awaits (the
live sample's
`lfSample.ready`, and the annotation renderer's dynamic import). A
top-level await in
any module rolldown compiles turns off its chunk optimization
(`mergeCommonChunks`,
`avoidRedundantChunkLoads`) for the whole build, which is how rolldown
keeps a waiting
module's execution order (`chunkOptimization` in rolldown's options
types). The
website's rebundle compiles each layer's widgets in the same build, so
`lf-trace.js`'s own top-level awaits kept it unoptimized for any layer
with the
playwright package even without leaf.js's.

## What changed

- `leaf.js` runs its boot sequence, unchanged and in the same order,
inside
`async function boot()`, called with `boot().catch(reportError)`. The
first
statement is still the sample wait, so nothing in the boot runs before a
sample
child's connection, as before. `reportError` hands a failure to the
window as the
same uncaught `error` event a rejected module evaluation fired, which
the prepaint
reads as a startup fault. Checked in Chromium and Firefox with a two-arm
page: a
throw after `await 0` at module top level and a throw in `boot()`
reported by
`reportError` fire identical `error` events (target `window`, same
`error`,
message and line). The diff is mostly reindentation; `git diff -w` shows
the
  wrapper alone.
- `lf-trace.js` imports `webawesome.esm.js` and `images.esm.js`
statically, as
`lf-diff.js` already imports WebAwesome. They evaluate in the same order
as before,
  after the widget's other imports.
- The build refuses a top-level await. Rolldown doesn't warn about one;
the build
  succeeds, and every page just loads more chunks. `moduleBoundaries` in
`build/runtime-bundle.mjs`, the plugin every compiled module passes
through, now
parses each module that mentions `await` in its `transform` hook and
fails the
build at a top-level `await`, `for await` or `await using`, naming the
module.
That covers everything either build compiles: the runtime, and in the
website's
rebundle every widget in the layer, from bundled packages or not. A
kernel built from the merge base's `leaf.js`
fails with `leaf.js awaits at its top level`, and the website's rebundle
of a layer
  holding the merge base's `lf-trace.js` fails with
`widgets/lf-trace.js awaits at its top level`. The committed bundles are
unchanged by the check (`pnpm run check:browser`). A comparison arm's
kernel, which `leaf-dev probe --base` and
  `stills` build from an older tree with this checkout's compiler
(`distribution.py`, through the script's command-line entry), compiles
with the
  refusal off, since that tree's modules may await at their top level.
- The kernel in `dist/kernel/` is rebuilt: against current `main`, 44
runtime files
  become 31.

## Evidence

Requests and JavaScript at presentation, from
`uv run leaf-dev probe <page> --base` against merge base c7e3d23 on
the
compiled kernel, three runs per page. Request counts were identical
across runs;
the time is the median and diagnostic only.

| page | arm | requests | JS requests | JS KB | presented (1x) |
| --- | --- | --: | --: | --: | --: |
| triage-board | base | 43 | 38 | 2,309 | 343 ms |
| triage-board | this | 32 | 27 | 2,305 | 325 ms |
| release-notes | base | 51 | 44 | 2,413 | 412 ms |
| release-notes | this | 40 | 33 | 2,410 | 423 ms |
| review-a-plan | base | 44 | 39 | 2,321 | 419 ms |
| review-a-plan | this | 33 | 28 | 2,318 | 392 ms |
| motion-playground | base | 48 | 38 | 2,214 | 373 ms |
| motion-playground | this | 37 | 27 | 2,211 | 368 ms |
| command-hub | base | 58 | 52 | 2,538 | 668 ms |
| command-hub | this | 47 | 41 | 2,535 | 673 ms |

At 4x CPU throttling (`--cpu-throttle 4`, three runs each), the gap
holds: release-notes
52 to 41 requests, triage-board 44-45 to 33-34 (one lazy module
sometimes lands
before presentation under throttling, on both arms). Median presentation
was 1,030
against 1,021 ms on release-notes and 760 against 774 ms on
triage-board. On a local
server neither speed shows a time difference beyond run-to-run spread;
the saving is
round trips, which cost more on a slower link.

The website's minified rebundle (`worker/bundle-runtime.mjs`,
`bundleLayer`), run in
scratch over a layer with every bundled package beside the kernel the
install
serves, as the site publishes a revision. The count is the compiled
files a page
statically loads (leaf.js plus the widgets named), vendor modules aside:

| entries | base | this |
| --- | --: | --: |
| leaf.js | 22 | 12 |
| + lf-suggestion, lf-options | 27 | 17 |
| + lf-board, lf-tabs, lf-chart, lf-code | 28 | 17 |
| + lf-trace | 27 | 16 |
| + lf-diff, lf-file-editor | 28 | 18 |

Removing only leaf.js's awaits left this table unchanged for a layer
with the
playwright package (22 files for leaf.js in both arms), which is why
`lf-trace.js`
changes too.

With optimization on, the compiled `widget-api.js` entry holds modules
rolldown
merged into it, and a widget may import it for them.
`bundle-runtime.test.ts`
asserted that `lf-suggestion.js` never names `/runtime/widget-api.js` at
all; it now
asserts what that assertion protected, that the widget's runtime imports
are compiled
chunks and never the public module URL.

## Tests

`test_a_boot_that_fails_after_it_waits_names_the_startup_fault` refuses
the
annotation renderer the boot waits for and checks that the page names
its startup
fault. It passes on the merge base and on this branch, and fails when
the boot is
started with `void boot()` instead, where the failure becomes an
unhandled rejection
the prepaint doesn't read. `build/runtime-bundle.test.mjs` checks that
the kernel
build refuses a runtime module's top-level `for await`, the website
build refuses a
widget's top-level `await`, and an await inside a function builds.

Ran: `pnpm run test:runtime` (550 passed), `pnpm run check:browser`,
`node --test build/*.test.mjs build/browser/*.test.mjs` (29 passed),
`pnpm run check:worker` (85 passed), and `uv run pytest -n 2` on
`tests/browser/startup`, `tests/browser/controls/test_live_samples.py`,
`tests/browser/test_render_playwright_trace.py`,
`tests/browser/test_render_initial_delivery.py`,
`tests/model/test_distribution.py`
(179 passed, 1 failed). The failure,

`test_package_reading_keys_work_while_history_waits_and_after_offline_fallback`,
is
flaky on the merge base at the same rate: 5 of 10 runs passed on base, 4
of 10 here.

After merging current `main`, `browser/leaf.js` is main's boot wrapped
in `boot()`
again (a whitespace-blind diff against main shows only the wrapper and
two lines
Prettier rewrapped). `node --test build/*.test.mjs
build/browser/*.test.mjs`,
`pnpm run test:runtime`, `pnpm run check`, the boot-failure test, the
live sample
tests and two trace tests pass. The evidence tables above were measured
against
the earlier merge base. Against current `main`,
`uv run leaf-dev probe triage-board --base=origin/main` loads 44
requests (39 JS)
before presentation on main and 34 (29 JS) on this branch.

## Not verified

- `leaf-dev verify-site website-worker` and the site build; the pull
request's
  checks run those.
- WebKit.
- Request timing over a real network to leaf.page; the saving is in
round trips, which the local probes barely price.

## How it merges with #3897 and #3462

- #3897 (`grind/g-boot-codemirror`) adds `await loadEditorView()` at the
top level
of `packages/file-editor/widgets/editor.js`. The website's rebundle now
refuses
it, since it would turn chunk optimization off again for any layer with
the
file-editor package (the kernel leaves package widgets native, so it
builds). That
widget would have to define its element once the class arrives, for
example in
`loadEditorView().then(...)`. Otherwise the two touch different files
except
`dist/kernel/`, which a rebuild resolves. #3897 found that importing a
lazy runtime
module regrouped the kernel's shared chunks and added four requests;
with
optimization on that may no longer hold, so that version could be
measured again.
- #3462 (Solid 2, draft) doesn't touch `leaf.js` and adds no top-level
await
  (scanned its `browser/` tree). It replaces rolldown with esbuild in
`build/runtime-bundle.mjs`, so `moduleBoundaries` becomes an esbuild
plugin and
  this PR's `transform` hook conflicts there. The premise is rolldown's
(`chunkOptimization`); whichever lands second should check whether
esbuild's
splitting changes with a top-level await, and move the check to the
plugin's
`onLoad` if it does or drop it if it doesn't. `dist/kernel/` resolves by
  rebuilding.

## Calls Max may reverse

- The build refuses rather than warns, for every widget the website
compiles,
including a package from outside the tree. The website build only runs
over pages
in this repository (`leaf-dev site`), so the refusal reaches a
maintainer, and a
  user's own install never compiles widgets.
- `lf-trace.js` changes in this PR rather than in its own, because
without it the
website keeps the unoptimized chunks for every layer that has the
playwright
  package.

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
max-sixty pushed a commit that referenced this pull request Nov 2, 2026
…ace test (#5105)

The Markdown state race test held the module before navigation, then
waited for full readiness before reaching the code that releases it. The
editor's after-presentation preload participates in readiness, so the
fixture deadlocked at startup instead of testing whether an older state
can overwrite a newer comment.

Open only through presentation while Markdown is held, using the
existing readiness stage, and let the editor's preload start the import
instead of explicitly starting it again. The held older poll, newer
comment response and final assertions remain in place. The shared parser
preparation added in #4738 makes Markdown part of the editor preload;
this preserves that behavior and the deferred editor loading introduced
by #3897. No product behavior changes.

Validation: the focused test reproduces the startup timeout before the
change and passes after it (4.81 seconds); Ruff and `git diff --check`
pass.

Closes #5088 — automated triage

Co-authored-by: leaf-agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants