Skip to content

Make layoutChanged only dispatch its event - #4509

Merged
max-sixty merged 6 commits into
mainfrom
widget-plain-html-status
Oct 27, 2026
Merged

max-sixty merged 6 commits into
mainfrom
widget-plain-html-status

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

layoutChanged(el) dispatched LAYOUT with a detail.present(promise) hook and returned the joined promise, so a caller could wait for listeners' asynchronous layout work. No listener in the tree calls present, so the returned promise was always already resolved, and the callers that passed it along (lf-tabs' view switch, lf-deck's #show, lf-trace-compare's #draw, the merge film's repaint) waited on nothing. The last real consumer of a similar promise, lf-reveal's present, went with #4500.

layoutChanged now only dispatches the event and returns nothing; those callers stop returning or collecting it, and lf-tabs' Back/Forward claim awaits its switch instead of chaining .then on it. module-authoring.md says to call layoutChanged rather than await it.

No protocol bump: a module vendored earlier that awaits the result or collects it in Promise.all keeps working, and no bundled module calls .then on it.

Part of #3833, which asks that a widget import from Leaf only what no standard form expresses.

Three browser tests used detail.present to hold a tab switch's layout completion. test_a_tab_layout_completion_preserves_native_navigation is deleted, since a tab switch now completes in its own task and the window it tested no longer exists; test_resume_writing_reveals_page_editor_from_a_covering_panel_and_keeps_back and test_an_obligation_walk_glides_within_a_view_and_opens_other_tabs_at_the_question keep their landing assertions without the hold.

Tests: pnpm run test:runtime (682), pnpm run check:browser, and 16 browser tests by node id over tab switching and history, the deck, trace comparison and travel into tabs and visual parts.

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

Before Leaf travels to a target (a comment's anchor, a search hit, an
obligation), it reveals what holds it. It used to dispatch its own
`lf-reveal` event on every ancestor, with `{target, mayReveal, present,
replacedView}`, so a widget that folds content had to import a Leaf contract
to open for Leaf's travel, and separately listen for `beforematch` to open
for the browser's find. This is the next slice of #3833: `reveal()` now does
what the browser's find-in-page and fragment navigation do (the HTML
standard's ancestor revealing algorithm), so a widget written as plain HTML
opens for both.

## The contract

- `reveal()` walks the target's ancestors outside-in. It opens a closed
  `<details>`, opens a closed popover (which the browser's find leaves shut),
  and at an element `hidden="until-found"` fires `beforematch` and removes the
  attribute, as the browser does. Checked in Chromium and Firefox:
  `beforematch` bubbles and the browser removes `hidden` after it.
- `replacedView`, which makes travel place the target at once instead of
  scrolling from the old view's offset, is derived: it is true when a sibling
  of the revealed element became hidden during the dispatch, as a tab set
  hides the panel it leaves. A disclosure that hides nothing scrolls as before.
- `present(promise)` is gone. `ready` joins the `updateComplete` of each Lit
  element holding what was revealed, so a widget whose switch finishes later
  extends its own `updateComplete`, the hook #3982 adopted for settling.
- `mayReveal` stays the caller's check between steps; no listener needed it,
  since listeners now run synchronously.

## Widgets

- `lf-tabs`, `lf-deck`, `lf-trace-compare`, `lf-options-settled` already hid
  with `hidden="until-found"` and listened for `beforematch`; their
  `lf-reveal` listeners are deleted. A settled options group used to open on
  any reveal passing through it; it now opens only for a target inside a
  folded option, so travel to the group's own row, already shown, leaves it
  shut.
- `lf-visual-review` hides an unchosen case with `hidden="until-found"` in
  place of `aria-hidden`, and opens it on `beforematch`. Its cases share one
  grid cell so choosing another moves no control, so its CSS keeps the box
  laid out (`content-visibility: visible`) and hides it with `visibility`, as
  before; the browser's find still skips it.
- `lf-gloss` lets reveal open its tip popover and pins it on `beforetoggle`
  when anything but the gloss opened it.
- `lf-diff` hides a file the filter leaves out with `hidden="until-found"`
  instead of a `display: none` class, and clears the filter on `beforematch`.
  Behavior change: the browser's find now reaches text in a filtered-out file
  and clears the filter, as `g v` already did.
- The thread transcript, which is runtime code, keeps folded messages
  `hidden`: thread reading takes a message an until-found box would leave as
  shown and would land on it rather than on its fold. It registers its fold's
  opener with the runtime-internal `revealedBy`, which `reveal()` calls.
- `lf-suggestion` no longer forces an immediate margin update on reveal;
  `test_the_obligation_walk_lands_on_a_suggestion_the_reveal_just_opened`
  passes without it.

`module-scroll-and-motion.md` ("Travel and history") states the new contract,
and the `view-reveal-arrival` eval's rubric follows it. I didn't score the
reference change: it replaces an API description rather than rewording a rule.

## Protocol 32 → 33

A page vendored at 32 has `lf-visual-review`, `lf-gloss` and `lf-diff` modules
that wait for an `lf-reveal` event this runtime no longer sends, so travel into
a hidden case, tip or filtered file would stop opening it.

## Tests

- `pnpm run test:runtime` (682 pass) and `pnpm run build:browser`.
- 42 focused browser tests by node id over tabs, deck, trace comparison,
  settled options, glosses, visual review, diff filtering and `g v`, thread
  folds and summaries, obligation walks, Go-to and thread travel, plus the
  visual-review journey and export tests (25).
- Tests that used `lf-reveal` as a hook to hold a reveal (`test_go_to`,
  `test_obligation_walk`, `test_on_panel`, `test_code_review`) now hide a
  holder with `hidden="until-found"` and hold its `updateComplete`.
- Selectors that read `.lf-vr-case[aria-hidden="false"]` or the
  `lf-diff-filtered` class read `:not([hidden])` instead.
- `test_a_widget_first_paints_the_box_it_presents[diff-closing-a-panel]` and
  `[diff-in-a-phone-column]` fail identically on main 37e9061.

Refs #3833
# Conflicts:
#	dist/kernel/kernel.json
#	dist/kernel/runtime/bundle-data.js
Nothing calls the LAYOUT event's detail.present, so the promise
layoutChanged returned was always resolved and the callers that passed it
along waited on nothing. It now dispatches and returns nothing.

Part of #3833.

@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 layout-completion regression still depends on the removed event hook; it needs to be revised with this API change.

Comment thread browser/runtime/widget-elements.js Resolved
test_a_tab_layout_completion_preserves_native_navigation tested a tab
switch whose layout completion a listener held; a tab switch now completes
in its own task, so that window no longer exists. The resume-writing and
obligation-walk tests keep their landing assertions without the hold.
@max-sixty
max-sixty merged commit a3197b4 into main Oct 27, 2026
5 checks passed
@max-sixty
max-sixty deleted the widget-plain-html-status branch October 27, 2026 21:24
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