Skip to content

Drive a plain custom element as a widget: set its state and bound data, and hear lf-action - #6920

Merged
max-sixty merged 6 commits into
mainfrom
agent-ae467342026f70f1b
Nov 24, 2026
Merged

max-sixty merged 6 commits into
mainfrom
agent-ae467342026f70f1b

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

A widget that records had to extend LeafElement. Leaf now drives any other custom element whose tag declares verbs or inputs: it sets state and each bound input's property, hears lf-action and lf-undo, and reads comment targets from data-lf-part marks, so the module needs none of Leaf's helpers (module-plain-elements.md).

  • Step one of the package-interface redesign. LeafElement keeps its own wiring, which the host skips, until step two moves it onto this route; the two aren't meant to coexist.
  • One check is gone: page check --render no longer reports a declared visual that offers no part, a state marks make legitimate. An author who declares parts and offers none hears nothing; the picture takes comments whole.
  • data-lf-part has one meaning: lf-chart's Plot group names move to data-lf-plot, the primary reader's kind to data-lf-kind.
  • Scores: nine package cases pass 12 of 18 against the base's 14, and the case behind the gap 5 of 8 against 4 when repeated.

Max approved the redesign and hasn't read this diff; a fresh agent reviewed it. Tests: pnpm run check, pre-commit, 129 browser tests, the fixture in Chromium and Firefox.

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

A research arm of the package-interface design of 23 November, not for landing. It
builds the smallest runtime change under which a custom element that extends
HTMLElement and imports nothing from Leaf draws its recorded state, records an action
with Undo working, is a question on On Me, offers its parts as comment targets and reads
bound data.

- element-integration.js hosts every element of a tag declaring `verbs` or `inputs`
  that is no LeafElement, once its module defines it: inside a claim on the element's
  render region it sets `state` (widgetState, widget-controller.js) and each bound
  input's property (ElementData), in the stack that moved the reading.
- widget-controller.js hears `lf-action` and `lf-undo` at the document, finds the
  nearest recording widget on the event's path, sends through the existing dispatch,
  and sets `event.delivery` or cancels the event.
- visual-parts.js reads `data-lf-part` marks for a visual that registers nothing.
- leaf.js starts the host after the registry is adopted. widget-loader.js cannot: the
  import puts application.js inside the renderers' closure, which dependency-cruiser
  refuses.
- The shortlist fixture is a plain HTMLElement on the protocol, with no import.

LeafElement is unchanged and is skipped by the host.

Checked with .tmp/plain/journey.py and cases.py under `leaf-dev probe` in Chromium and
Firefox, 41 browser tests by node id (47 with parameters), the runtime's 1082 Node
tests, and check:browser.
…a, hear lf-action

Leaf now drives any custom element whose tag declares `verbs` or `inputs`, and whose
class is no `LeafElement`, from outside: it sets `state` and each bound input's
property, hears `lf-action` and `lf-undo`, and reads comment targets from
`data-lf-part` marks. `LeafElement` keeps its own wiring and the host skips it.

Built from the trial on agent-add6c632a27118846 (8fbd379), with these changes:

- A tag is watched once its class is defined, and a tag whose class extends
  `LeafElement` is never watched.
- Nothing is set until the reading holds every verb and bound data has been read,
  as a `LeafElement` gates its draws, and a written data body is set in that pass.
- A setter that throws is owed again in the next pass and no longer stops the other
  sets; the failure box stands after the element's content, in its shadow root
  where it has one, unless the element places its own.
- Drawing a setter announces with `pending-task` holds the render claim, so the
  data version and an element with no id wait for it. The trial's read of
  `updateComplete` is gone.
- `delivery` alone says an event was sent; an unsent event is no longer cancelled.
- `state` is immutable, carries no `unavailable`, and says `undoable` on each unit
  of a verb with per-part units; `lf-undo` on such a verb names the unit.
- A mark under a visual standing inside another is the inner visual's, and a marked
  visual's kept readings are made again when Leaf says `layoutChanged` after its sets.

@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 two items the description lists as open both sit in the path an agent follows from the new reference. So they should be fixed, or tracked in an issue the maintainer accepts, before this lands rather than after:

  • The render check refuses a correct marked visual. visualPartProblems reports unregistered whenever a source has no registration and no data-lf-part node at check time. A plain visual whose marks depend on state, such as one that draws nothing until it has data or a list that's empty, then fails with "neither marked a part with data-lf-part nor called registerVisualParts". The page is correct, so the agent's likely next attempt is to switch to registerVisualParts. That undoes what module-plain-elements.md and module-annotations.md now teach. (Inline below.)
  • data-lf-part already has another meaning. lf-chart writes Plot's group names into it (named.dataset.lfPart = label in lf-chart.js, values such as bar and x-axis tick label, which test_charts.py reads). Today the chart's registration hides those nodes from markedParts. But the same attribute now means a comment-target id in one place and a Plot group name in another. Any read that runs before the chart registers sees ids like bar, which its prefixes don't admit. Renaming the chart's attribute (it's a test hook, by its own comment) leaves one meaning per attribute.

PR #6894 also edits element-integration.js and module-authoring.md (quoted() off Leaf). Neither duplicates the other, but whichever lands second will need a rebase.

Comment thread browser/runtime/visual-parts.js Resolved
…ne meaning

`page check --render` no longer reports a declared visual that offers no part
(`visual-parts`, kind `unregistered`). With marks an empty inventory is a state a
correct visual can be in, as a list with no rows is, and the check could not tell it
from a mistake. An author whose module declares parts and offers none no longer
hears of it from the check: the picture takes comments whole, and no part does.
`unadmitted-parts` stays, and names a mark or a registered part the declaration's
prefixes don't admit.

`data-lf-part` now only marks a comment target. lf-chart keeps Plot's name for each
group as `data-lf-plot`, and the primary reader says each part's kind as
`data-lf-kind`.
@max-sixty
max-sixty merged commit ce94781 into main Nov 24, 2026
7 checks passed
@max-sixty
max-sixty deleted the agent-ae467342026f70f1b branch November 24, 2026 00:54
max-sixty added a commit that referenced this pull request Nov 24, 2026
Step one of the package-interface redesign landed as #6920 and reworked the host the
trial built. Where the two disagreed this takes main's host and re-applies what the
class needs on top of it: hosting on `lf-connect`, parents-first `state` sets, a
region for a `pending-task` no widget hears, `lf-hold`, and `attempt` on
`lf-action`. `state` is never null now: Leaf cancels `lf-connect` where it will set
`state`, and the class waits for it.
max-sixty added a commit that referenced this pull request Nov 24, 2026
#6936)

`LeafElement` reached Leaf through wiring of its own. It now takes
`state` and bound data as properties and speaks in events, as a plain
element does, so one route drives both. Step two of the
package-interface redesign, after #6920.

What the diff doesn't show:

- **Draw order is narrower.** A widget draws inside Leaf's set of its
`state`, parents first; a redraw it starts itself has no promised order.
- **Each class update is a `pending-task`**, holding rendering readiness
as a preparation does. Six pages announce none at rest; a playing
recording settles as often as on `main`.
- **New names**, each in `module-plain-elements.md`: `lf-connect`,
`lf-hold`, `attempt` on `lf-action`, `redraw()`. A class module now
declares a bound input reactive and a shadow root with `static shadow`.
- **One read went:** a class widget Leaf sets nothing on no longer asks
for a document read as it connects.

Max asked for the redesign and hasn't read this diff; a fresh agent
reviewed it twice. Tests: `pnpm run check`, 142 browser tests, a
four-widget journey matching `main` in Chromium and Firefox, and nine
package-author cases twice (13 of 18, base 12).

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent added a commit that referenced this pull request Nov 24, 2026
…mounts (#7024)

Since #6920, Leaf drives any custom element whose tag declares `verbs`
or `inputs` from early in boot (`hostDeclaredElements` in
`browser/leaf.js`), well before `mountApplication`. A widget whose class
a page's own script defines, as the published-capture journey's
`lf-options` is, can finish its first draw in that gap. Its
`widgetMounted` call then reached the application facade's
`invalidateDom`, which threw `Leaf application has not been mounted`,
and the render harness's error collector failed the page. Any page that
defines a declared widget in its own script would fail `page check
--render` the same way.

Before the mount no document-wide presenter is registered, and each
presents the document as it then stands once the mount registers it, so
a request to present the page again has nothing to reach. The facade's
`invalidateDom` now resolves without work until the application exists.
An `lf-defer` hold that ends before the mount reaches the same facade
and gets the same answer.

Both cases of
`tests/journeys/test_live_shell_artifact.py::test_a_browser_executes_the_published_capture_with_live_api_routes`
(`[False]` from source modules, `[True]` bundled) errored at teardown on
`main` and pass with the change. `pnpm run check:browser`, `pnpm run
test:runtime` (1115 pass) and the `state`/`record` cases in
`tests/browser/test_plain_elements.py` pass. `journeys/` doesn't run on
pull requests, so this PR's CI won't run the fixed test.

Closes #7019 — automated triage

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