Skip to content

Show keys pressed while the page loads in the floating panel's field - #5800

Merged
max-sixty merged 5 commits into
mainfrom
early-key-panel-shell
Nov 18, 2026
Merged

max-sixty merged 5 commits into
mainfrom
early-key-panel-shell

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Keys pressed before the runtime can run them used to show in a notice of their own at the window's right edge, which stood beside the panel once the panel loaded. They now show in the panel's text field, in place of its status: "m runs when the page is ready".

The panel exists only once the runtime's modules have loaded, 240-640 ms after first paint here depending on CPU load. Until then a stand-in for the panel's row says the words: runtime/panel-stand-in.js, which the bootstrap imports by its rooted path (the document's import map sends it to the revision) on the first words it shows, once the document is parsed (stylesheets.js throws without the sheets the document carries, and that failure would take leaf.js down with it). It imports only control-faces.js, icon-paths.js and stylesheets.js, which import nothing, so it evaluates without waiting for the boot module's graph; a closure rule in .dependency-cruiser.mjs holds it to those three. In the compiled kernel it shares the portable helpers' chunk, which imports Lit, so there it waits for that chunk too. It draws the leaf and the On Me mark by role and action as the panel does, on the panel's own classes, and adopts the runtime's own chrome sheet instance, taking its adoption away at the handover. When the panel mounts it offers its field with lf-held-keys-seat, and the bootstrap shows the words through the panel's heldWords signal from then on. The handover moves nothing: the stand-in's last frame and the panel's first differ only on the ring at the card's corners (79 pixels in a 1010x110 capture).

Behaviour that changed:

  • An error keeps the field's words, since it says why the page may not get ready; held keys then stand in the mode chip, as they do where a draft hides the field's words. The chip is bounded to half the field. The folded leaf's peek says them as it says a notice.
  • The field offers no key at its end while keys are held, since c would only queue behind them. enters in composing/input.js may now return null for that.
  • Words already shown are not shown again. Each panel repaint makes the keyboard owner retake the keys and pause on the same one, which otherwise flipped the field between the words and the status every frame.
  • Words stay shown while the keyboard owner presses a taken run, until it releases or pauses, rather than coming down at the take.
  • The words lead with the keys ("m j run when the page is ready", was "Page still loading — m j run when it's ready"), so a phone's field shows them whole.

Startup cost: a source-served page loads nothing new until a key is held before the panel mounts, and then one module (panel-stand-in.js). The compiled kernel gains the stand-in as an entry, which splits stylesheets.js into its own 863-byte chunk that leaf.js also loads, so a prepared installation (the website) makes one more request before presentation.

When the stand-in shows: on review-a-plan at 4x CPU throttling, cold, every module has arrived about 100 ms after first paint, and evaluating the graph is then one ~120 ms long task that mounts the panel and in which nothing paints. So locally the stand-in shows only for a key whose 150 ms beat ends while modules are still arriving; a slow network lengthens that phase.

Tests: the presentation test in test_keys.py covers the stand-in, the panel taking the words over in place, and the chrome sheet staying adopted once; the failed-first-read test covers the keys in the chip under the error; a new test covers a saved draft; held-key assertions read the .lf-held-key badges.

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

Keys pressed before the runtime can run them used to show in a notice of their own at the window's right edge, which stood beside the panel once the panel loaded. They now show in the panel's text field, in place of its status: "m runs when the page is ready".

The panel exists only once the runtime's modules have loaded, 240-640 ms after first paint here depending on CPU load. Until then the bootstrap draws a stand-in for the panel's row: it adopts a sheet built from the chrome stylesheet text the document already carries for stylesheets.js, on the panel's own classes, so its box, leaf and words stand where the panel's will. When the panel mounts it offers its field with `lf-held-keys-seat`; the bootstrap drops the stand-in and its sheet and shows the words through the panel's `heldWords` signal from then on.

Behaviour that changed:
- The field offers no key at its end while it says held keys, since `c` would only queue behind them. `enters` in composing/input.js may now return null for that.
- Where a draft hides the field's words, the mode chip says the keys, bounded to half the field; the folded leaf's peek says them as it says a notice.
- Words already shown are not shown again. Each panel repaint makes the keyboard owner retake the keys and pause on the same one, which otherwise flipped the field between the words and the status every frame.
- Words stay shown while the keyboard owner presses a taken run, until it releases or pauses, rather than coming down at the take.
- The words lead with the keys ("m j run when the page is ready", was "Page still loading — m j run when it's ready"), so a phone's field shows them whole.

Tests: the presentation test in test_keys.py now covers the stand-in and the panel taking the words over in place; a new test covers a saved draft; held-key assertions read the `.lf-held-key` badges.
leaf-agent
leaf-agent previously approved these changes Nov 10, 2026
…or keep the field

CI found two faults in the first commit.

The stand-in for the panel's row spelled the symbol face's class (`lf-icon-action`) inside bootstrap.js, which `test_controls_are_built_by_role_and_never_by_face` refuses: a copy of the face that would drift silently if the face changed. The stand-in is now a module of its own, runtime/panel-stand-in.js, which the bootstrap imports by its rooted path (the document's import map sends it to the revision) on the first words it shows. It imports only control-faces.js, icon-paths.js and stylesheets.js, which import nothing, so it evaluates without waiting for the boot module's graph; a closure rule in .dependency-cruiser.mjs holds it to those three. It draws the leaf and the On Me mark by role and action as the panel does, so the handover now differs only on the ring at the card's corners (79 pixels in a 1010x110 capture), and it adopts the runtime's own chrome sheet instance rather than a copy, taking its own adoption away at the handover. The kernel builds it as an entry, so a prepared installation serves it at its URL.

The bootstrap imports the stand-in only once the document is parsed. stylesheets.js reads the sheets the document carries as it evaluates and throws without them, and a module that fails to evaluate fails every importer, leaf.js included, so a key held while the network paused the document between the bootstrap and the sheets data left the page unable to start ("The document has no runtime stylesheets"). Reproduced by holding a parser-blocking script inserted right after the bootstrap, pressing a key past the beat, then releasing it: the page fails to start without the wait and presents with it. In the compiled kernel the stand-in shares the portable helpers' chunk (which imports Lit), so it waits for that chunk, though not for the rest of the graph.

Held keys outranked an error in the field, so a failed first read never said so, and `test_a_failed_first_read_stays_unpresented_across_the_retry_clock` waited until the read expired. An error now keeps the field's words, and the held keys stand in the mode chip beside it, as they do beside a draft. The field's end offers no key while any keys are held, whatever it says.

Measured on review-a-plan at 4x CPU throttling, cold: every module has arrived about 100 ms after first paint, and evaluating the graph is then one ~120 ms long task that mounts the panel, so the stand-in paints only for a key whose 150 ms beat ends while modules are still arriving. It matters most on a slow network.

Tests: the retry-clock test asserts the keys in the chip under the error; the presentation test asserts the chrome sheet stays adopted once after the handover.

@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 test job fails because of this change. runtime/panel-stand-in.js is now a kernel entry in runtimeEntries, but the layer that worker/test/bundle-runtime.test.ts builds ("bundles every captured layer without absorbing shared page modules") writes no such file. So bundleRuntime stops with [UNRESOLVED_ENTRY] Cannot resolve entry module runtime/panel-stand-in.js, and the job ends before running its later checks. This PR already updated the matching fixture in runtime-preloads.test.ts, but not this one. That file isn't in the diff, so I can't attach a suggestion. Add "panel-stand-in", after "media", in the fixture's for (const entry of [...]) list of runtime stubs. With that line, npx vitest run test/bundle-runtime.test.ts passes locally (2/2). I can push that commit if you'd like.

Apart from that, the incremental commit looks right to me: the stand-in as its own module, the import waiting until the document is parsed, and an error now outranking held keys.

The kernel builds runtime/panel-stand-in.js as an entry, so the layer worker/test/bundle-runtime.test.ts builds needs a stub for it, as runtime-preloads.test.ts already has. pnpm run check passes.
leaf-agent
leaf-agent previously approved these changes Nov 10, 2026
Conflicts resolved:
- base.css: the held-keys notice's rule stays removed; main had only renamed its tokens.
- floating-panel.js: keeps main's draft count in the On Me mark's name and its
  `lead` in the field's parts beside the held keys; `offeredPress` is gone on main.
- floating-panel.css: the panel's placeholder ink moved into the theme as
  `--lf-quiet` (#5842), so the stand-in's held words read that token; the
  stand-in's lift reads `--lf-raise-2`.
- test_render_startup.py: main's `selected` attribute with the branch's
  `.lf-held-key` badge.

The decision prose drops its dates, which main's headers no longer carry.
@max-sixty
max-sixty merged commit 5e7a70a into main Nov 18, 2026
7 of 8 checks passed
@max-sixty
max-sixty deleted the early-key-panel-shell branch November 18, 2026 07:04
max-sixty added a commit that referenced this pull request Nov 18, 2026
)

The floating panel's row now stands on every served page from the first
paint, instead of appearing when the runtime mounts the panel 240–640 ms
later. Keys pressed before then show in its field, and a reader who
clicks the field and types before then writes words that carry into the
panel's field. This removes the stand-in #5800 added for held keys
(`runtime/panel-stand-in.js`, its dependency-cruiser closure rule and
its kernel entry). The runtime's panel takes the row over as it mounts,
and the leaf, field and On Me mark don't move.

<table>
<tr><td>First paint, main</td><td><img
src="https://gist.githubusercontent.com/max-sixty/cbfb1b052d92b8d93b879f9a40e7f48f/raw/2d846a81f31d574b4c2bce86683c6d318fdcdd6b/first-paint-main.png"
width="580"></td></tr>
<tr><td>First paint, this PR</td><td><img
src="https://gist.githubusercontent.com/max-sixty/cbfb1b052d92b8d93b879f9a40e7f48f/raw/2d846a81f31d574b4c2bce86683c6d318fdcdd6b/first-paint-head.png"
width="580"></td></tr>
<tr><td>Once mounted, this PR</td><td><img
src="https://gist.githubusercontent.com/max-sixty/cbfb1b052d92b8d93b879f9a40e7f48f/raw/2d846a81f31d574b4c2bce86683c6d318fdcdd6b/mounted-head.png"
width="580"></td></tr>
</table>

**How the row reaches the first paint.** There's still one drawing of
the row. `build/panel-row.mjs` renders the panel's own detached first
drawing (`panelTemplate(true)`) in happy-dom and writes
`runtime/panel-row.html`. `pnpm run build:browser` regenerates it, and
`check:browser` fails while it is stale. The served document carries it
in an inert `<template>`, and the bootstrap stands it after `body` at
the size the reader left the panel. The prepaint now builds the
constructed sheets once (`window.lfSheets`), so the row and the runtime
adopt the same chrome sheet. Delivery writes the chrome sheet's URLs
inline as data URLs (today only the layer's `icon.svg`, the leaf's
mask), so the leaf is in the row's first frame without a fetch. A
preload missed whenever another script world, such as a test driver or
an extension, styled the row first. Lit hydration was rejected, since
`@lit-labs/ssr` emits nothing for element-part directives.

**Calls to weigh:**
- The served row's field is a textarea, so the browser keeps what a
reader types there before the runtime mounts: caret, selection, paste,
input methods, a phone's keyboard. As the panel mounts, its field takes
the words and caret, after any composition ends, since words taken
mid-composition the input method writes again. Before mount, Return
makes a line, since nothing can send yet, and Escape does nothing (a key
listener beside the register would break its test for a rare path);
while the reader is in the field, On Me steps aside as in the panel's
writing posture. Undo after the handover takes back all pre-load typing
in one step. A click on the leaf or On Me does nothing until mount.
Dropping those keys, and drawing them as a run of words in the field,
were both built and reverted: the first loses every word typed before
load, the second lost words on Enter, Escape or a second click. Only the
row's buttons are inert, and its words are a status, so screen readers
hear held keys. Typed before load, then just after, in Firefox:
<img
src="https://gist.githubusercontent.com/max-sixty/cbfb1b052d92b8d93b879f9a40e7f48f/raw/2e6c3913e61f28d91d94d363617982764063d154/typed-before-load.png"
width="580"> <img
src="https://gist.githubusercontent.com/max-sixty/cbfb1b052d92b8d93b879f9a40e7f48f/raw/2e6c3913e61f28d91d94d363617982764063d154/typed-after-load.png"
width="580">
- **Every text field's box before CodeMirror is now a textarea**
(`composing/text-field.js`, `#rest`). Firefox deletes nothing from a
`contenteditable` standing after `body`, where the chrome stands
(notes/browser-support.md has the reproduction), so in Firefox Backspace
did nothing in any panel field or reply box until its editor loaded, and
the handover above moved typed words into that window. The textarea
reads its words and selection directly, which drops the old box's Range
walk.
- A reader who folded the panel sees the folded leaf from the first
paint, with held keys beside it. The stand-in drew a full row there,
which jumped to the corner at mount.
<img
src="https://gist.githubusercontent.com/max-sixty/cbfb1b052d92b8d93b879f9a40e7f48f/raw/2d846a81f31d574b4c2bce86683c6d318fdcdd6b/folded-main.png"
width="320"> <img
src="https://gist.githubusercontent.com/max-sixty/cbfb1b052d92b8d93b879f9a40e7f48f/raw/2d846a81f31d574b4c2bce86683c6d318fdcdd6b/folded-head.png"
width="320">
- A page with an unsent draft in the panel's field shows the one-line
row ("Connecting…") until mount, and then the card grows to hold the
draft. This is a rare path that redraws once (SOUL.md).
<img
src="https://gist.githubusercontent.com/max-sixty/cbfb1b052d92b8d93b879f9a40e7f48f/raw/2d846a81f31d574b4c2bce86683c6d318fdcdd6b/draft-strip.png"
width="420">

**Cost.** First paint is later, and the time until the page shows the
server's state doesn't change beyond the spread. Each figure is the
paired difference over 8 alternating Chromium runs at 1440×900, median
and range:
- alert-review: +8 ms (+4 to +16), and +16 ms (+8 to +28) at 4× CPU.
- review-a-plan: +6 ms (+4 to +16), and +8 ms (−8 to +24) at 4× CPU.

These figures were measured before the icon was inlined and the field
became a textarea. Inlining removes the mask's icon request, so one
fewer request comes before presentation. The chrome sheet carries the
icon as about 4 KB of base64, once for `mask` and once for
`-webkit-mask`. The textarea adds about 3 KB to the inline bootstrap,
mostly its header comment, and does no work until a click.

**Tests.** `pnpm run check` passes. The changed startup tests are
`tests/browser/startup/test_keys.py` and `test_presentation.py`: they
cover the row in the first frame and still across the handover at four
widths, held keys in the field and the folded peek, held keys as a
status, words typed in the served field carrying into the panel's field
(in Chromium and Firefox, including Backspace in the panel's field while
CodeMirror loads, which fails in Firefox with the old box, and an input
method composing across the mount), words kept when no panel comes, and
the row going away when it holds none. Independent Codex reviews and
cold UI reviews in Chromium and Firefox found the screen-reader gap, the
leaf's late first frame, overstated startup figures, the typing problem
above, and then, on the textarea, Firefox's dead Backspace after the
handover, a duplicated composition, words lost on a failed start (they
now stay until recovery reloads the page), and a swallowed Return. All
are fixed here.

Max asked for this on a Leaf page, after #5800 merged.

> _This was written by Claude Code on behalf of max-sixty_
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