Skip to content

Move Leaf to Solid 2 with native rendering phases - #3462

Closed
max-sixty wants to merge 33 commits into
mainfrom
solid-2
Closed

max-sixty wants to merge 33 commits into
mainfrom
solid-2

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Leaf’s generated views now use one pinned Solid 2.0.0-rc.16 graph for application state, initial drawing and live updates. Explicit dependencies wait for committed DOM and post-render work; semantic presentation proof separately tracks asynchronous preparation, holds and replacement. Native editors, selection, focus and reading position remain retained.

The branch includes main through 0c4bb28, preserving its serving-runtime delivery and repository layout, unified panel search, visible-focus rules, hidden-in-place summary folds, shared lf-shot inspection, indexed diff preparation, shared composer draft payload, Resume writing selection, wrapped trace labels, and route-aware On me Show navigation. WebAwesome 3.14 remains for maintained copy and screenshot comparison behavior.

The integration fixes coalesced search focus, visual-review grid ownership, annotation phase ordering, and reentrant retirement of attributed render jobs. Retained views isolate binding failures and support recovery. Six checked upstream Solid adaptations remain documented in build/solid.mjs. Capture resource declarations make offline screenshot exports self-contained. Protocol 18 distinguishes the replacement public widget API: Lit layers vendored under protocol 17 are refused and re-vendored through the existing boundary. The unchanged composer draft keeps its own since 17.

Validation:

  • pnpm run check: 147 framework/build, 534 runtime and 85 Worker tests passed on dfd113f.
  • Final CI on dfd113f passed: 2,083 Python/browser tests, eight skipped and four subtests passed; full lint, website build, deployment dry-run and bundled-release browser loading passed. Automated review completed successfully. Seven focused admission, re-vendoring and website refusal checks also pass for the protocol bump.
  • Focused browser checks cover search and retained drafts, summary retention, screenshot replacement/refresh/reordering, offline capture inspection, diff inspection/selection, focus visibility and shift attribution. All 14 checks for the last main integration pass, including Firefox editor placement. WebKit verifies retained iframe documents and selected text across summary folds.
  • Independent desktop/light and phone/dark review passed tabs/history, options, editor undo/discard, search focus/caret, comparison controls and feedback retention. Further review verifies empty/drawing-only Resume writing, wrapped phone trace labels, and touch Show navigation with retained thread Close/Back and page-destination focus.
  • Matched screenshots against main d76ea44: eight of nine states are pixel-identical; the remaining difference is native filter styling. A corpus comparison at 4fcdd63 against main 0dec543 has no console errors, failed widgets or startup layout shifts on either arm. External code falls from 6,401,093 to 6,330,410 bytes (1.1%), with 118 versus 116 JavaScript requests. Single loads do not establish a timing improvement.

Review recommendation: retain Lit on main; keep this PR as an experiment. Main already uses native SignalWatcher, AsyncDirective, computed selections and keyed templates. Solid’s remaining advantages are more selective bindings and explicit committed-DOM dependencies. No measured user-visible speedup yet offsets the release-candidate, upstream-patch and custom-lifecycle costs.

Carry the capture-resource fix, DOM-completion contract and behavioral retention/error/attribution coverage back to Lit. Keep native framework ownership and choose UI libraries by their behavior and quality. Detailed assessment: notes/solid-2.md.

Move semantic publication, presentation subscriptions and private UI state from Preact signals to Solid 2. Bundle one Solid graph and renderer for native modules and build-free package components.

Port reaction strips, shared control faces, resolved-thread summaries and the file editor to mounted Solid views. Keep focused reaction controls across state updates; the new test protects their identity and current pressed state.
Reconcile view props through Solid projections so bindings follow only the fields they read. Route Solid DOM moves through Leaf's continuity owner and decouple that owner from focus initialization.

Port image inspection, the attachment shelf and draft toolbars to Solid. Give native command refs connection and disposal lifetimes. Regressions cover per-field updates and keyed reordering with focus, words and selection retained, with native moves and their fallback.
Use native custom-element scheduling with Leaf presentation claims, shallow immutable view props and component-owned list keys. Port visual review, diff headers, call trees, message bodies, transcript folds, search fields and copy controls. Preserve native state across updates and retire transient view resources.

Adapt the pinned Solid RC renderer for focus-safe moves, weak event containers, quiet native form writes and live custom-element template imports. Snapshot template traversal to support nested refs without retaining or visiting inserted trees. Validate 509 runtime and 132 framework tests plus focused Chromium editing, search, copy, refresh and GC cases.
Keep captured frames and their reserved geometry while a native range owns dragging and keyboard adjustment. Its transparent full-height thumb follows the divider without intercepting clicks across the rest of the image. Use a native slider in behavioral checks; remove the obsolete deferred Web Awesome bundle race test.

Remove unused Lit render-return sentinels from native LeafElement subclasses and describe synchronous Solid presentation. Focused Chromium checks cover caption targets, tall-image dragging at desktop and phone widths, reserved loading geometry and inspection modes.
Move panel, Page Map, trace/timeline, comparison and example widget views onto
native Solid HTML roots. Retain authored outlets, keyed controls, native editing
and lifecycle ownership; expose html, offered and commandsOn as the single author
APIs. Dispose generated roots at failure boundaries and remount on recovery.

Replace library controls with native search, copy, select, radio and range
controls. Give native controls their shared UI typography inside declared shadow
stages while leaving apparatus typography with its widget. Preserve desktop
search sizing and phone 44px targets. Split vendor range pseudo-elements into
separate rules so native pointer and touch dragging keeps receiving the track.

Remove Lit and Web Awesome dependencies, build adapters, vendor bundles and
library-specific tests. Update author contracts, examples and behavior fixtures;
remove write-watch exemptions for deleted controls and renderer artifacts.
Contain screenshot layers beneath sticky caption controls and restore a trace's
native image extent using CSS property names accepted by Solid's style binding.
Keep retained list rows attached during reconciliation instead of replacing them
with other retained rows and rebuilding equivalent intermediate lists.

Compare visual-response action anchors in the write watch: two identically
labelled controls can target different captured evidence. This retains strict
redundant-write checks without a blanket visual-action exception. Avoid redundant
copy hover/focus class writes now that the control is a native button.

Update contracts and consumers for native input/select/fieldset controls and
slider string values. Exercise native select changes through select_option or
keyboard arrows rather than a library popup's option nodes and open property.
Preserve the shared UI-face defaults in both document and declared shadow roots.
Drop unused exports and apply the repository's formatter to migrated sources.
Preserve main’s removal of custom dependency collectors with Solid reactions, observed outside readings, and explicit one-shot readiness. Detach imperative subscription and view lifetimes from their creating draw. Preserve the incoming panel motion and shared native control geometry.

Pin the Solid rc.16 completed-read wake adaptation with lazy-pull, self-publication, retention and disposal coverage. Replace Lit property tests with native signal and explicit update contracts; synchronous registration still refuses a reading that changes semantic state.

Validation: pnpm run check (134 framework, 516 runtime, 85 Worker); nine focused Chromium checks and two model checks pass.
Apply Prettier after the main merge. The change only indents the native Solid input-send template; pnpm run check remains green.
Wait for thread and projection presentation before a watched annotation paint, so admitting a pending comment cannot combine its new id with old placements and reset the open preview. Update the Page Map accessible-name check for its native search control. Existing trace-comment and submitted-comment journeys protect the regression.
Use WebAwesome's copy feedback, screenshot comparison, and case picker while retaining native buttons, search, and radio choices. Bundle Lit privately within the split WebAwesome graph; Leaf's application renderer and public author API remain Solid. Restore library-owned DOM-write accounting and existing interaction coverage.
Integrate main through 491a2c7. Port the visual-review approval queue to retained Solid views and share one Solid instance between parser-time TOC/activity producers and live modules. Preserve native subscription lifetimes and batched presentation, current-work replacement, native disclosure behavior, and main's server snapshot fix. Keep WebAwesome for copy feedback and screenshot comparison; the new queue no longer needs a select.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says Lit and Web Awesome are removed from the dependencies, but package.json still directly declares lit, lit-html, and @awesome.me/webawesome. The changed build/webawesome/chrome.mjs and entry.mjs still build copy and comparison controls, and skills/leaf/assets/leaf.js still loads the chrome bundle. The PR's updated build/AGENTS.md describes those retained controls as intentional. Please narrow the opening claim to Solid owning Leaf's views and native controls replacing the others, so the description accurately records what will ship.

@max-sixty max-sixty changed the title Move Leaf entirely to Solid 2 and native controls Move Leaf application rendering and reactivity to Solid 2 Oct 22, 2026
Route all LeafElement updates through the shared presentation queue, retaining request identity so an immediate draw cannot consume later queued work. Replace the deprecated tracked-effect adapter with native subscriptions and one-shot reactions.

Represent failed presenter readings as outcomes so they claim their revision and reach the existing failure path rather than acknowledging stale content. Cover failure, fallback, recovery, unrelated presenters, update ordering and input attribution.

Keep semantic presentation proof and ordered imperative commits: a native-effect experiment demonstrated stale immediate DOM reads. Document this boundary and the remaining adoption costs.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A binding that reacts to a signal outside createView.update() can throw in Solid's own flush. In that path Errored.fallback stores the error and returns null, but neither checkFailure() call runs. I reproduced it with a view rendering a createSignal accessor: after flush(() => setValue(true)) makes the binding throw, the host becomes empty and no error reaches Leaf's owner or presentation failure path. Route this asynchronous failure to the view's owner so it can show the failure and account for the affected presentation; the current test covers only initial mount and view.update() failures.

Solid effects now follow explicit parent/widget/projection/thread/obligation
DOM dependencies. Remove the sorted microtask pass and projection-watch queue;
keep semantic presentation proof separate from synchronous DOM completion.

Add renderCommit/afterRender on the public native onSettled boundary. Port
focus, measurement, editor setup and asynchronous presenter continuations
across every consumer. Retain native editing state, keyed nodes and held
semantic readings. Construct custom-element roots and controls before eager
connection registration can render them.

Own cancellation, reactive stretches, input attribution and async completion
per render generation. Independent native tasks start root commits; nested
commits compose their descendants before outer measurements. Retire cancelled
jobs, isolate binding/check errors by publication, and keep every joined
failure until the presentation pass consumes it.

Regression tests preserve editing, failure proof and disconnected lifetimes.
Replace assertions about independent queue FIFO with the owners' actual DOM
and lifetime guarantees; selective bindings cannot stand in for restoring a
native control that a held gesture changed imperatively.

Validation: 46 rendering/presentation tests; complete pnpm check; 24 focused
Chromium cases; independent visual-review and command-hub journeys; lint and
format gates. Solid remains an RC with six pinned upstream adaptations and
no established performance benefit; retain draft status.
The visual-run data contract did not declare before/after capture resources,
so the standard snapshot and exporter omitted their bytes. A live review
worked while its exported file failed to present. Declare both existing data
paths instead of adding an exporter-specific traversal.

A browser regression fails against the old declaration and passes with this
fix. With networking disabled, the file presents, decodes its captures,
switches cases and supports Home/End on the comparison slider without HTTP
requests. The delivered HTML also passes inspection focus-return checks.

Validation: four named export regressions, corpus regeneration, browser build,
lint/format hooks; all nine redesign stills are unchanged from a4959cb.
A component's local signal could fail between props publications, leaving an
empty host and no error report. Retain a native error surface and deliver
unconsumed failures through the platform error path after native settlement.

Give a view its publication's retirement before mounting: eager mounts may
flush before writeView returns, and cancellation may retire a check without
consuming its fault. Waiting on that actual retirement keeps owned failures
on their commit rejection path, while cancelled latest faults still report.
No pending flags, polling loop or new browser scheduler is needed.

Regression tests cover autonomous errors, cancelled safe and failed updates,
eager failed mounting, unrelated owners, recovery and owned-error deduplication.
An independent delivered-Chromium matrix also invalidates the current owner
from an earlier independent postcommit callback and checks real global error
events and readable failure surfaces.

Validation: pnpm check (145 framework/build, 538 runtime, 85 Worker), eight
final browser cases, lint/format hooks and zero-network exported HTML proof.
@max-sixty max-sixty changed the title Move Leaf application rendering and reactivity to Solid 2 Move Leaf to Solid 2 with native rendering phases Oct 22, 2026
The serving-runtime test now exercises Solid as the replaceable native vendor module. The face-order assertion retains the branch’s shadow-host coverage alongside main’s shared native control selector; neither product guarantee changes.
Integrate main through 0dec543. Keep the shared draft payload and content-aware Resume writing destinations, wrapped trace labels, canonical Python readings and publication admission, bounded upload reading and serving-runtime startup assertions. Rebuild the generated kernel from the integrated authored sources.
Preserve the retained Solid answer controls while adopting main’s route-aware Show navigation: keep On me open until arrival picks a page or thread destination. Retain main’s editor-seat placement and Escape scope assertions and regenerate the kernel.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The public widget API removes Lit exports such as nothing, but $events.protocol remains 17. A page vendored from current main can still contain the old lf-options import and pass the same-protocol check; its widget module then fails to load against this runtime. The page protocol contract explicitly requires a bump when a public package API export disappears. Please bump the protocol with this API replacement so those pages are refused and re-vendored before serving.

Main reached protocol 17 during the merge, so retaining that number admitted Lit-vendored modules that still import removed public exports. Use protocol 18 to refuse and re-vendor those layers through the existing boundary. The composer payload is unchanged and keeps draft since 17; no compatibility shim or migration is added.
max-sixty added a commit that referenced this pull request Oct 23, 2026
Leaf’s presentation pass ordered renderer starts without guaranteeing
that the DOM a later renderer reads had committed. This change retains
Lit and its native lifecycle, and separates explicit DOM dependencies
from the existing semantic presentation ledger. It also makes
visual-review captures available offline and preserves unfinished
replies when search is opened through the Page menu.

## Changes

- Replace numeric presentation ranks with declared DOM dependencies:
widget ancestors → projection → threads → obligations → annotations.
Widgets use native Lit `updateComplete`; imperative Lit renderers commit
synchronously. Dependencies follow replacement and stay transitive
through owners that do not repaint. Optimistic cyclic moves cannot block
rendering before server refusal.
- Keep asynchronous preparation, gesture holds and semantic proof
separate. An owner’s held proof does not block unrelated drawing. The
ledger still owns visible revisions, late failures, supersession and
disconnection. Async thread materialization still refreshes the targets
and annotations it changes; that coordination remains necessary because
those nodes arrive after the synchronous commit.
- Declare `cases[].before` and `cases[].after` in the visual-run
resource contract. The existing export mechanism embeds captures for
unopened cases too; no export-specific collector is added.
- Retire attributed jobs before invoking callbacks that can reenter.
Cancellation and completion cannot run the same job twice or consume its
successor.
- Let a menu command dismiss its invoking menu while preserving the
underlying thread. Page search exposes its own Close search action above
a retained thread, preserving the reply editor, text, caret and undo
history through both pointer and keyboard routes.

## Relation to the experiment

This uses [the Solid 2
experiment](#3462) and its
[assessment at
dfd113f](https://github.com/max-sixty/leaf/blob/dfd113f5ddc7ba0a34843cc942a3572dc9d6ae5d/notes/solid-2.md)
as behavioral references. Hidden-in-place summary folds, retained search
editors, shared `lf-shot` inspection, indexed/off-document diff
preparation, and logical versus visible focus already exist on main.
They remain intact and are not new work here. Solid’s lifecycle/error
adapters and upstream adaptations are unnecessary for Lit.

Public widget API exports and record/draft formats are unchanged. The
branch inherits main’s protocol 20; this work needs no protocol bump.
Lit, SignalWatcher, AsyncDirective, native computed selections, keyed
templates and WebAwesome remain.

## Validation

GitHub `relay`, `review` and `test` checks pass on
`cdc3b672aaba6f43069af0711434177f5b20b94a`; the automated reviewer
approved that exact head without findings.

Local validation includes `pnpm run check` (134 framework/build tests,
528 runtime tests and 85 Worker tests), every pre-commit gate, and
focused real-browser selections covering offline export, search
retention, stale image loads, parent ordering, widget lifetime, frozen
thread widgets and input attribution. A separate seven-case selection
exercises all three search routes, keyboard-reference retention, menu
dismissal, version navigation and copying a link.

Regression cases distinguish native DOM completion from held proof,
follow-up updates, idle intermediaries, supersession/disconnection and
late failures. Retention checks assert search focus before `fill()` and
wait for native stale-image load events before checking that current
captures survive. Offline checks decode all four images, switch cases,
use the keyboard comparison slider and observe no HTTP requests with
networking disabled. Existing Chromium/WebKit iframe document and
selection-retention cases pass.

Desktop-light and 390×844 dark-touch journeys exercise decision/undo, On
me, and comment/reply search round trips with identical editor nodes,
draft values and caret positions. Both have zero console errors and no
horizontal overflow. The menu/reply defect was reproduced on main before
the fix.

After integrating main at `783d3c150`, the complete local check and
applicable pre-commit gates pass again. A served startup comparison
against that main uses 46 code requests (44 JavaScript) on both sides
through widget upgrade and first server presentation. The candidate adds
1,820 code bytes, including 1,682 JavaScript bytes; all loaded bytes
increase by 1,919. Both have zero startup layout shifts and console
errors. Total requests vary from 51 to 53 because of polling; the single
heavily loaded run is not timing evidence. The added code coordinates
native completion on the path where another renderer needs that DOM.

The final visual sweep covers the shipped review example and focused
search fixture, with Chromium/WebKit retention checks. It does not
establish full-corpus, Firefox, print or physical mobile-keyboard
behavior.

The resulting Lit implementation is a net improvement in correctness and
ownership: it removes numeric ordering and the redundant annotation
proof wait, keeps one native completion producer, and fixes concrete
export, menu and reentrancy failures. No timing improvement is claimed;
native completion adds necessary waiting only where a consumer actually
needs that DOM.

> _This was written by Codex on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Oct 27, 2026
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

- #3904 (`grind/g-boot-tla`) moves `leaf.js`'s boot out of a top-level
await. On top of
it, at c7e3d23, this PR's chunk layout was the same 27 files as
main's; the lazily
imported `field-editor.js` alternative gave 30, two of them on the
opening. With
#3904's `architecture/top-level-await` rule this PR adds no top-level
await. Not
  re-checked on the new base.
- #3462 (Solid 2, draft) changes `composing/input.js`, the top of
`widget-api.js`'s
export list and the build scripts, and bumps the protocol too. It
touches neither
`text-field.js` nor `editor-view.js`. Expected conflicts: the protocol
number (take
one bump above whichever lands first) and `dist/kernel/`, which a
rebuild resolves.

## 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:

- #4116's row reveal and #3939's WebKit focus guard survive the move
into the
  factory, each with a bug-back check
(`test_sample_editor_focus_preserves_outer_scroll_and_the_caret` passes
in WebKit
  and fails `assert 1386 == 0` without the guard).
- Typing before CodeMirror loads, in Chromium, Firefox and WebKit.
- CI's website build and `leaf-dev verify-site website-worker`, green on
3a095de.

## 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_

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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

Copy link
Copy Markdown
Owner Author

Closing. This experiment's own assessment recommended keeping Lit, and main has built on Lit since. #3676 carried its main findings back to Lit: the DOM-completion contract and offline captures. The assessment stays at notes/solid-2.md on the solid-2 branch, which closing keeps.

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

@max-sixty max-sixty closed this Nov 18, 2026
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