Skip to content

Hold keys pressed while a page loads until the page can run them - #5386

Merged
max-sixty merged 3 commits into
mainfrom
agent-af5d1b3f3f8dc8959
Nov 4, 2026
Merged

max-sixty merged 3 commits into
mainfrom
agent-af5d1b3f3f8dc8959

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Leaf holds printed keys pressed before its runtime loads and shows "Page still loading — t runs when it's ready". Since #1213 it also dropped them if the page hadn't upgraded ten seconds after it started, reading such a page as faulted. On a loaded Mac a healthy page takes longer than that, so keys the notice promised to run were dropped:

  • test_held_keys_after_one_that_opens_a_box_are_typed_into_it failed at load ~107. A page-side trace showed the keys held at 2.6 s, the notice gone at 15.4 s, and the page upgrading at 15.6 s with nothing left to take.
  • The phone variant of test_a_key_pressed_before_presentation_runs_once_the_page_presents[True-module] failed the same way at load ~90.
  • 8× CPU throttle reproduces both. Over the same hour dynamic-widgets took 18.8 s to upgrade under leaf-dev probe.

This reverses #1213's deadline. The hold now ends when the runtime takes it, when the page reports it cannot start, or when the user lets go, and never on a clock. On a page that truly hangs the hold costs little: only printed page keys are held, any other key or a pointer press already ends the run and acts natively, and "Page still loading" is then true.

Every mode that runs the hold now ends it:

  • Upgrade: the keyboard controller takes the run, as before.
  • A startup fault: a failed entry module or stylesheet, an uncaught error before upgrade, or boot() rejecting all reach recover, which ends the hold, as before.
  • A document the runtime gives up on: prepareDocument returns false when the registry names another layer, and boot returns without upgrading. Only the deadline ended the hold here. It now ends at that return, through letHeldKeysGo in keyboard/controller.js.
  • A sample opened as a window of its own: no containing page will connect it, so boot waits on lfSample.ready forever. It now holds nothing. This one is confirmed by reading the code rather than running it.
  • Quick shortcuts off: each key lets go at once, as before.
  • Exports: they don't run bootstrap.js.

The tests follow:

  • test_upgrade_relinquishes_the_bootstrap_timeout_for_held_keys becomes test_held_keys_outlast_any_wait_for_the_runtime, which advances the page's clock 30 s past a held t and checks the t still walks to the thread.
  • The journey test_a_page_that_never_presents_lets_its_held_keys_go waited ten real seconds for the deadline. It becomes test_a_page_that_cannot_start_lets_its_held_keys_go in browser/startup/test_keys.py, where a failed runtime module ends the hold and later presses reach the page.
  • test_a_document_the_runtime_gives_up_on_lets_its_held_keys_go covers the give-up path. With letHeldKeysGo taken out it fails with the notice still standing.
  • The tests that hold the runtime module now press their keys once the body is parsed, since holding the module's request doesn't prove bootstrap is listening. One local run lost its first key that way, with Playwright's fake clock installed; that hasn't reproduced without the clock, and the wait costs nothing either way.

Testing

After merging main: the six held-key tests above and test_a_key_that_is_not_printed_ends_the_held_run (10 items), serially under taskpolicy -b, pass; pnpm run test:runtime (813) and pnpm run check:browser pass. Before the merge, B and the phone's [True-module] also passed at --cpu-throttle 8, where both failed with the deadline. main has since fixed the phone variant's stale locator itself (#5350), so this branch keeps main's reading of it.

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

…ocus, and find reference rows as options

Three browser tests failed on main. Two were stale; the third caught a
product defect.

- Held keys under load. Bootstrap dropped the keys it held on a page not
  yet upgraded ten seconds after it started, a decision from #1213 that
  read such a page as faulted. On a loaded Mac a healthy page upgrades
  later than that. `test_held_keys_after_one_that_opens_a_box_are_typed_into_it`
  failed when a page-side trace showed the hold ending at 15.4 s and the
  page upgrading at 15.6 s with nothing left to take, and the phone's
  `test_a_key_pressed_before_presentation_runs_once_the_page_presents[True-module]`
  failed the same way. 8x CPU throttle reproduces both. The notice had
  told the user those keys "run when it's ready".

  This reverses #1213's deadline. The hold now ends when the runtime
  takes it, when the page reports it cannot start, or when the user lets
  go with another key or a pointer press, never on a clock. A page that
  hangs without a report keeps saying it is still loading, which is then
  true. Two modes never upgrade, so they end the hold at their own signal:
  a document the runtime gives up on as it starts (`prepareDocument`
  finds the registry on another layer) lets go through `letHeldKeysGo`,
  and a sample opened as a window of its own, which no containing page
  will connect, holds nothing. Behavior change: a key held while a page
  loads now runs however long the load takes.

  `test_upgrade_relinquishes_the_bootstrap_timeout_for_held_keys` becomes
  `test_held_keys_outlast_any_wait_for_the_runtime`, which advances the
  page's clock 30 s past a held key. The journey
  `test_a_page_that_never_presents_lets_its_held_keys_go` waited out the
  deadline. It becomes `test_a_page_that_cannot_start_lets_its_held_keys_go`
  in `startup/test_keys.py`, where a failed runtime module ends the hold,
  and `test_a_document_the_runtime_gives_up_on_lets_its_held_keys_go`
  covers the other path. The tests that hold the runtime module now press
  their keys once the body is parsed. Holding the module's request doesn't
  prove bootstrap is listening, and one run lost its first key that way.
- A held `t` on a phone. Since #5039 a phone opens the thread in the
  floating panel, whose head and thread view both carry
  `data-lf-thread`, with the head first in the document. Focus lands on
  the view, but the test took the first match. `startup/test_keys.py`
  now reads the held thread as the element carrying its id that holds
  focus (`ON_HELD_THREAD`): the card on a desktop, the panel's view on a
  phone.
- The command reference's rows. Since #5118 each row is a
  `button role="option"`, so `test_a_heading_copies_the_link_to_the_section_it_opens`
  found no button "Copy link to section". The row is still offered from
  a focused section and still copies the link. The same stale lookup
  failed `test_code_wrapping_keeps_source_copy_and_reader_choice` and
  `test_a_reference_command_finishes_its_gesture_before_a_newer_control`
  in CI, and both now ask for options too.

Closes #5137
Main's #5313 made the same fix for the command reference's rows, asking
for `option` rather than `button`, in test_render_heading_links,
test_render_code_reading and test_focus. Those files now match main, so
this branch's net change fixes two failures: held keys dropped while a
slow page loads, which removes bootstrap's ten-second deadline, and the
phone's held `t`, which reads the held thread by focus.
@max-sixty
max-sixty merged commit a428769 into main Nov 4, 2026
4 checks passed
@max-sixty
max-sixty deleted the agent-af5d1b3f3f8dc8959 branch November 4, 2026 19:02
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