Skip to content

Let a sample's first click or key end its height hold, and stop relaying a child's later arrivals - #4790

Merged
max-sixty merged 5 commits into
mainfrom
sample-host-simplify
Oct 31, 2026
Merged

max-sixty merged 5 commits into
mainfrom
sample-host-simplify

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Removes three mechanisms from how a page hosts a template lf-sample. Each one existed only for a rare case, and the code they guarded is the code most likely to misbehave in that case. The branch is net −100 lines. The runtime and widget lose 40 of them, about 25 of those logic.

A click or key inside the sample ends its height hold for that document. While a child is still arriving, a frame the reader can see keeps its loading height, so nothing below it moves (heldGrowth). Before, the child counted gestures until their rendering settled (afterSettling) and tagged each height notice with whether a gesture caused it. The host then went on holding untagged growth for as long as the child was still arriving. Now the reader's first click, key or typed text inside the child makes every later resize of that document theirs. The child stops counting and the gesture flag goes. Whatever grows while the child is still arriving after that press, moves what follows the frame. On every shipped template sample (docs/threads and the three developer galleries) a child goes from presented to arrived in 13–80 ms, so a press can't land between the two.

A wheel or a touch scroll over a loading frame no longer releases the hold. The child reports every input type, and the host used to release on any of them. So scrolling past a sample that was still loading applied its held resize mid-scroll, and the content below jumped (238 px in a probe). That happened on main too. Now only click, keydown and input release. The child still reports every type, because focus.js (inputInFrame) reads presses and keys from it. One gap is left, and main has it too: a reading key such as j, pressed with focus in the sample, passes out to scroll the containing page as a wheel would, but as a keydown it still releases the hold. Telling "acted in the child" apart from "passed through it" needs the child's word, not the event type, so that's a follow-up.

No re-arrival relay. The child reports arrived once. The arriving notice, the host's handler for it, and presentation.js's whenArriving are gone. Work a child starts after it has arrived, such as Reset on one of its own samples, is now counted only by the child's own readiness. No shipped page nests template samples.

showThread resolves false when the sample's document departs, as it already did when Reset replaced it, rather than retrying in the next document. Both shipped callers, the feature gallery and the thread-panel gallery, reapply their view on lf-sample-ready. skills/leaf/references/live-samples.md says so. module-authoring.md now lists the host's notices as they are: no arriving, height without gesture, and input carrying its {type}.

Tests:

  • test_a_sample_reached_while_loading_holds_growth_the_reader_did_not_cause now asserts that a wheel over the frame keeps its height. With release on every input it fails in Chromium and Firefox. It still asserts that a hidden tab lets held growth through, and it asserts that growth after a click applies at once.
  • test_a_sample_arriving_again_holds_growth_the_reader_did_not_cause and the inner-Reset half of test_a_sample_counts_each_document_its_frame_loads are deleted along with the relay.
  • test_a_reload_ends_a_sample_view_selection replaces the across-reload selection test.

test_sample_startup_exception_keeps_its_name_stack_and_document fails on main in the same way: an extra "page failed to start: Failed to fetch" console error. This branch doesn't cause it.

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

…d stop relaying a child's later arrivals

Three guarantees in the template sample host came from reasoning about edge cases rather than from anything a reader hit, and each kept its own machinery:

- The frame held growth the child made "of its own accord" even after the reader pressed inside it, so the child counted every gesture until its rendering settled (`afterSettling`) and tagged each height with whether a gesture caused it. Now the reader's first input inside a child makes every later resize of that document theirs. This also closes the gap #2817 left open: content a script deferred before the click and revealed by it stayed held.
- A Reset inside an arrived child's own sample sent the parent an `arriving` notice, so the containing page read as arriving again and held the frame's growth once more. The child now reports its first arrival only; work it starts after that is its own to count. `whenArriving` in presentation.js had no other user and goes.
- `showThread` retried a selection in the next document when the child reloaded. Every caller already reapplies its view on `lf-sample-ready`, which fires for that document, so the selection now answers false on departure, as it does when Reset replaces it.

Behavior that changed, by test:

- `test_a_sample_reached_while_loading_holds_growth_the_reader_did_not_cause`: growth the child makes after the reader's press applies at once.
- `test_a_sample_arriving_again_holds_growth_the_reader_did_not_cause` is deleted, and `test_a_sample_counts_each_document_its_frame_loads` no longer counts an inner Reset.
- `test_sample_view_selection_waits_across_a_reload` becomes `test_a_reload_ends_a_sample_view_selection`, and the native-departure test expects the pending selection to answer false at departure.
# Conflicts:
#	browser/runtime/rendering.js
#	dist/kernel/kernel.json
#	dist/kernel/runtime/bundle-content-layout.js
#	dist/kernel/runtime/bundle-restore-state.js
…ight

A wheel over a sample frame that is still loading reaches the child's document, which
reported it as input, and the containing page took any input as the reader claiming the
frame: the held resize applied mid-scroll and what follows the sample jumped (238 px in
a probe with a 600 px child, on main as well as on this branch). The containing page now
releases only on a click, a keydown or an input event, the events that activate
something; a wheel or a touch that scrolls past the frame claims nothing, as the
platform's user activation leaves both out. The child still reports every input type,
since focus.js reads presses and keys from it.

The hold test now wheels over the frame and asserts it keeps its height; with release on
every input it fails in Chromium and Firefox.
# Conflicts:
#	browser/runtime/rendering.ts
…ab release tested

module-authoring.md still listed the removed `arriving` notice and `height`'s
`gesture` field, and didn't say `input` carries its event type, which lf-sample's
release rule now reads. The hold test regains the hidden-tab step the gesture rewrite
dropped: it was the only browser test of held growth showing once the reading breaks.
It now waits for the reading to resume before going on. Comments stop justifying the
release list by user activation, which counts more events than the list does, and the
child's header points to the rule rather than restating it.
@max-sixty
max-sixty merged commit 14a1267 into main Oct 31, 2026
4 checks passed
@max-sixty
max-sixty deleted the sample-host-simplify branch October 31, 2026 01:27
max-sixty added a commit that referenced this pull request Oct 31, 2026
Main's #4790 and this branch each rebuilt dist/kernel, and the textual merge of the two left leaf.js and kernel.json stale for the merged sources.
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