Skip to content

Bundle the published Leaf runtime - #442

Merged
max-sixty merged 3 commits into
mainfrom
codex/bundle-published-runtime
Sep 8, 2026
Merged

max-sixty merged 3 commits into
mainfrom
codex/bundle-published-runtime

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 8, 2026 •

Copy link
Copy Markdown
Owner

A fresh leaf.page visit waited on about 100 JavaScript modules before DOMContentLoaded, so each release and cold edge/browser cache made startup latency recur. This builds the already-scoped public runtime and widget entries into shared ESM chunks while leaving installed and local Leaf's source modules unchanged and large optional renderers lazy. The product page's JavaScript requests fell from 100 to 9 in the production-shaped local Worker; the full feature gallery and both embedded interaction frames start without browser errors. The publish workflow now verifies that bundled release locally through Worker, Chrome, and container activation before its first public operation.

This was written by Codex on behalf of max-sixty

The public site loaded roughly 100 JavaScript modules before it could present a page. Build code-split website entries and widgets from the already-scoped live shell so cold releases need nine JavaScript requests on the product page while the installed Leaf runtime remains source modules.

@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.

bundle_published_runtime runs only from main(), so build() — the entry every test in tests/test_site.py uses — produces the unbundled tree while publish-site.yaml deploys the bundled one. test_the_edge_shell_is_the_document_and_runtime_the_leaf_server_serves still passes by comparing examples/design-decision/runtime/state-feed.js in the asset tree against what the canonical server serves, and test_the_asset_site_is_the_live_immutable_half_of_each_page still asserts runtime/margin-layout.js is present and hard-linked — both files the runtime/**/*.js sweep deletes. That test's stated invariant, "Materialization reuses Leaf's delivery transforms rather than approximating them", is now certified against a tree that is never published.

What that leaves as the real gate: ci's test job runs scripts/site.py, so a bundle that errors is caught before merge, but nothing loads the bundled module graph in a browser until scripts/verify-site.py — and that runs after wrangler deploy, so a runtime defect in the bundle (a URL the plugin rewrote wrong, a module the sweep deleted that something still fetches) is live on leaf.page before anything reports it. Either move the bundle into build() so the published-site tests describe the deployed shape, or check the bundled tree in a browser ahead of the deploy step.

Separately, the .css branch of preserve-module-urls computes relative(layerRoot, resolve(dirname(importer), path)), and for a root-absolute specifier resolve returns the URL path unchanged, so the result is a filesystem-relative path measured against a URL. import sheet from "/runtime/marks.css" with { type: "css" } in a widget emits <assetRoot>/../../…/runtime/marks.css, which normalizes back to the right URL only because layerRoot happens to sit at least as deep as assetRoot is long; at /tmp/x it resolves to /_leaf-release/_leaf-release/… and 404s. Root-absolute imports are the documented package contract — scope_page_routes in skills/leaf/scripts/leaf/http.py: "Package modules intentionally speak the same root-relative browser contract as the kernel" — and every package widget already uses that form for JS, which the ^/ branch just below handles. No package imports CSS that way today, so this is a trap for the next one rather than a live break.

@max-sixty
max-sixty merged commit f38be9e into main Sep 8, 2026
7 checks passed
@max-sixty
max-sixty deleted the codex/bundle-published-runtime branch September 8, 2026 08:23
max-sixty pushed a commit that referenced this pull request Sep 8, 2026
`test_an_inline_thread_uses_surface_focus_until_its_reply_takes_over`
has been red on every complete run since a15715c, and it is the third
failure in the nightly [`ci` run on
`7e403108`](https://github.com/max-sixty/leaf/actions/runs/34217624366)
— the one #444 measured at its merge base and correctly set aside as not
its branch's. `git bisect` over `0b50e4c5…7e403108` puts it on a15715c
(`Simplify thread and reply chrome`): the case passes at that commit's
parent b094e80 and fails at a15715c, alone under `-n0`.

Two things were wrong, and the second was hidden behind the first.

**The case read the thread before the preview built one.** a15715c
added a resting-tint reading as its first act on the page, from
`.lf-margin-preview .lf-conversation-thread`. The margin preview builds
its thread when it opens one, so at rest that locator resolves nothing
and the case spent its 30s timeout there. The resting tint now comes
from the same element once the region gives the focus back, so
`pointer["background"] != resting` still contrasts a current thread
against a quiet one rather than against a value read before the thread
existed.

**Every reading after that point had never run, and one of them was
measuring a cascade collision.** a15715c's message says *Reply fields
use one focus ring instead of an accented border plus outline*, and it
set the chrome text-box rule to `outline-offset: 0` with the border
cleared under the ring. `theme.css`'s conversation rule still said
`outline-offset: 1px`, and it wins the declaration at (0,3,0) against
the text-box rule's (0,2,1) — the extra class coming from `.lf-btn`
sitting in that `:is()` list beside `textarea`. So the offset that
commit set reached every text box in the document except the reply field
it was written for, and one control shape wore the band at two offsets.

The fix is in the layer rather than the expectation. The reply is a text
box, so it takes the text box's band: the conversation rule keeps its
1px gap for the thread's buttons and summary, and the reply gets the
chrome rule's terms — ring on the border, border cleared under it —
repeated inside the shadow-carried slice.

That repeat is the fix rather than a restatement of a rule that already
reached the field. A thread an `x-thread-surface` widget seats inside
its own shadow tree reads only the theme's `lf-shadow` slice;
`runtime/chrome.css` is never adopted there, so the reply in a diff's
inline outlet never met the text-box rule at all. Measured on the diff
fixture before this change, that field wore its resting `--border-2`
border (`rgb(69, 63, 54)` on the dark scheme) *and* the 2px accent ring
1px outside it — exactly the accented border plus outline a15715c
removed from the document copy. It now wears the same single band as the
panel's copy, at `offset: 0px` with the border transparent.

`test_a_diff_surface_keeps_the_complete_thread_lifecycle_inline` gained
the reading that pins the shadow half: it focuses the reply in both
seats and asserts the two bands are identical. Reverting `theme.css`
alone fails it on all three fields — offset, border, and the ring's own
name.

Verified: `tests/test_render_navigation.py`,
`tests/test_render_anchors.py`, and `tests/test_render_conversations.py`
green in full (253 passed); every `-k ring` case across the nightly
suite green (91 passed), including the corpus ring floor; the everyday
suite green (904 passed, 6 skipped); pre-commit clean on the three
changed files. The margin and startup failures in the same nightly run
are #444's.

<details><summary>Bisect and the state the preview is in at
rest</summary>

```
0b50e4c  Simplify Leaf state, serving, and browser initialization (#429)   pass
c20aaa5  Use standard UI and keyboard terminology (#431)                   pass
b094e80  Keep go-to hints stable across filters                            pass
a15715c  Simplify thread and reply chrome                                  fail
f38be9e  Bundle the published Leaf runtime (#442)                          fail
7e40310  Polish thread controls and reaction picker (#441)                 fail
```

Probing `INLINE_PAGE` with one anchored mark, on `7e403108`:

```
AT REST      .lf-conversation-thread count: 0   .lf-margin-preview count: 1
AFTER CLICK  background: color(srgb 0.967373 0.969412 0.96502)   (thread focused)
AFTER BLUR   background: rgba(0, 0, 0, 0)       (thread still built, preview still open)
AFTER ESC    preview hidden, thread retained
```

</details>

<details><summary>The reply field's band before and after, in both
seats</summary>

Read with `getComputedStyle` on the focused reply textarea. The
light-DOM reading is the inline thread the margin preview builds; the
shadow reading is the same shared Thread view seated in `lf-diff`'s
outlet, which adopts only the theme's `lf-shadow` slice.

| seat | before | after |
| --- | --- | --- |
| light DOM | `offset: 1px`, `border: transparent`, `--lf-here-ring:
conversation` | `offset: 0px`, `border: transparent`, `--lf-here-ring:
text-box` |
| widget shadow tree | `offset: 1px`, `border: rgb(213, 207, 194)` light
/ `rgb(69, 63, 54)` dark — the resting `--border-2` — `--lf-here-ring:
conversation` | `offset: 0px`, `border: transparent`, `--lf-here-ring:
text-box` |

The panel's own reply field was already the second column and did not
move; it is the control the new assertion compares the inline copy
against.

</details>

---------

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