Repository navigation
Drive LeafElement through the property and events a plain element gets - #6936
Conversation
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.
…ent-a7732fdfff9661052
A research arm of the package-interface design of 23 November, not for landing. It builds on the plain-element trial (8fbd379), merged in the commit before this one, and asks whether the base class of the bundled widgets can reach Leaf only through names a plain custom element could also use. It can. leaf-element.js now imports Lit, the Preact signal watcher and widget-upgrade.js, and nothing else; `installElementIntegration`, the class's own presentation region, `queueWidgetUpdate`, `drawsItself`, the controller's `defer` and the class's `reading`, `controller` and `whenReady` are gone. Leaf hosts a LeafElement from outside, as it hosts any element (element-integration.js). What the class needed that the designed names did not carry, each built here: - `lf-connect`, an event the element dispatches as it connects. Leaf hosts the element before the event returns, so `setup()` and the first draw read `state` and the bound inputs. Without it Lit's first update runs before Leaf has set anything: with the synchronous answer taken out, 8 of the 74 browser tests below failed and 20 errored. - `state` is `null` while Leaf has more to set (a source nobody has read, a revision's replacement not yet adopted), and Leaf sets an empty `state` on an element that only reads data, so the class can draw nothing until its inputs are in. - `pending-task` from an element with no widget on its path holds a region of that element's, so an element with no id, and Leaf's own floating panel, still hold the page's presentation. - `attempt` in an `lf-action`'s detail, the id a draft minted for the words it sends. - `lf-hold`, an event with a promise, for a gesture that rewrites the element's nodes; Leaf reads the document again as it ends. `drawn` with no property was tried first and reached a page's own `drawn` listener as an event naming no value. - `commandsChanged(element, {within: true})`: the keys declared on the element and under it read again, since `state` is a plain property the key reflection no longer follows. - Leaf dresses the open shadow root of an element that says `lf-connect`; a module on the class asks for one with `static shadow = true`. Draw order is the part the names do not carry. Leaf's document-wide renderers no longer wait for a widget's DOM (`queueWidgetUpdate` and `PRESENTATION_DOM.widgets` are deleted). The class draws before the caller returns at its first connection and at each `state` Leaf sets, and Leaf sets the `state`s one publication moves in the page's rendered order, parents first. An update the element schedules itself, for a signal, a bound input or a reactive property, runs on Lit's schedule and is ordered against no pass. Behaviour that changed: - A LeafElement draws inside `connectedCallback` the first time, where it drew a microtask later. One browser test's script named its element in a paint closure before the binding existed, and now names it by `this`. - A bound input reaches the element when Leaf sets it, not when the element next updates, so a module declares the property reactive. Every bundled module did; one test fixture and four Node probes now do. - `reportsReady` asks from reports.js and takes one more update per narrated change. - lf-playground tells a tune it has not drawn by its values, since `state` names no event. Tests: four Node tests of the deleted queue and of `whenReady` are removed, and three are rewritten to hold a presenter's DOM dependency to a plain promise. Not adapted, and failing as they stand: 19 places in 7 browser and journey test files that read `element.controller`, `controller.defer()`, `whenReady` or `this.reading`. The references under skills/leaf/references still describe the old class. Checked with `pnpm run check:browser`, `pnpm run test:runtime` (1080 pass), 74 browser tests by node id (.tmp/trial/tests.txt), and .tmp/trial/journey.py under `leaf-dev probe --base` in Chromium and Firefox, where every step matched the merge base.
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.
…ts and references A `pending-task` an element Leaf drives dispatches on itself is that element's drawing: inside a pass of sets it joins the pass, and at any other time it holds the same render region, so it no longer reaches the widget's preparation region, where a new reading's batch released an older preparation still under way. The tests that reached a `LeafElement` through `controller`, `reading` or `whenReady` now use `record()`, `takeBack()`, `defer()`, `state` and `widgetController()`, and the references describe the class on the plain-element protocol: `lf-connect`, `lf-hold`, `attempt`, `redraw()` and the order of sets are in `module-plain-elements.md`. `reportsReady` asks once more: its own update no longer holds the region it reads. Scored on the nine package-author cases against the merge base: 7 of 9 against 6.
… only later claims, and the first draw back on Lit's schedule
…, and a drawing lets go of rendering readiness while its element is away A drawing the element announced between a pass being taken and that pass's deferred state set claimed the region for itself, and the state's drawing rode the superseded claim: the claim now stands until the pass settles it. A drawing's hold on rendering readiness follows its element's standing, as a preparation's does. A visual's marks follow any drawing under way, not only one the pass's own sets announced, and the mounting read skips an element that has left.
…its sets were made
leaf-agent
left a comment
There was a problem hiding this comment.
Whether a LeafElement draws into a shadow root is now declared twice: once as the tag's shadow in the registry and once as static shadow on the class. Before this change, the registry entry alone decided it. The two can disagree without any warning. If a class says static shadow = true and its tag doesn't declare shadow, the root gets Leaf's styles, because the lf-connect listener dresses any open root. But declaredRoot (shadow.js) still reads registry[host.localName]?.shadow, so the widget's words can't be quoted or commented on, and page check says nothing. module-authoring.md now asks authors to keep the two in step by hand ("A LeafElement whose tag declares shadow says static shadow = true on its class"). That is a second copy of one fact, and nothing in the agent's path reports when the copies disagree.
There are three ways out, and the choice is yours:
- Keep the registry as the only source and let the
lf-connectanswer decide the render root. - Accept the class as a second source and have
package checkreport a mismatch. - Name the cost and keep both as they are.
This PR also overlaps #6894, which edits element-integration.js and leaf-element.js against the integration this PR removes (installElementIntegration, the LeafElement path through elementIntegration). Whichever lands second will need its change redone, not just rebased.
The reference read as one fact kept in step by hand. The class's static says where the widget draws, as attachShadow does for a plain element; the tag's shadow says the user may quote what the root shows, as it does for a root shadowStage makes.
|
On Making the registry the only source needs a route by which an element reads its tag's declaration. The redesign leaves how a widget learns facts beyond The overlap is real. That pull request adds
|
#6941) One step of the package-interface redesign: names that only name an event Leaf already sends, or that only rebuild what Leaf already does with a plain object, leave the package API. Six go, 183 names to 177. Packages write `lf-page-interface`, `lf-presentation`, `lf-layout` and `lf-preview-ended` in place of `PAGE_INTERFACE`, `PRESENTATION`, `LAYOUT` and `PREVIEW_ENDED`. `registerContribution` and `presentContributionEntry` already normalize a plain entry, so `contributionEntry` goes and callers pass the object. `contributionItemKey` only joined an item's `owner` and `id`, which `module-annotations.md` now tells a `consumeAnnotations` caller to key rows by. To weigh: nothing a user sees should change, and no lint rule or test watch changed. Left in: `clockValue`, `partOver` and `matchesWhen`, which nothing outside the runtime calls but which each give a package a rule of Leaf's own, so removing them is a feature's removal for Max to decide; and `PendingTaskEvent`, since #6936 made it how a widget announces preparation and five packages build it, so it belongs in the library. The shared-contribution-actions eval now passes plain entries. Max approved the redesign and asked for small steps. He hasn't read this diff. A fresh agent reviewed it. Ran: pre-commit, `pnpm run check`, 20 browser tests by node id. > _This was written by Claude Code on behalf of max-sixty_
…gets (#6963) #6936 changed `LeafElement` so that a class redraws on a bound input only when it declares that input as a Lit reactive property (`static properties = { value: { attribute: false } }`, `module-authoring.md`, "Drawing what a widget reads"). It updated the shipped widgets, but not the two inline test modules in `test_projected_data.py`. Both read `this.value` in `render()` without the declaration, so a `leaf data set` after the first draw reached the element but never redrew it. As a result, `test_a_comment_on_an_identified_datum_follows_the_subject_across_replacements` never saw row `a-2`, and `test_data_consumers_clear_and_recover_across_contract_only_rebindings` kept `["same bytes"]` after the rebind. The second test's teardown also reported the stale draw's contract error. Both modules now declare the property. The product code isn't changed: the tests drift from a contract #6936 changed on purpose. Both tests fail on `main` at `77da815d6` and pass on this branch, rebased on `7da7a6a71`. Bisecting `8bbb4ee1c..4660b58` put the break at `9aa6fdcd2` (#6936): they pass at its parent `e9c4cc6bb`. The same `ci` run had two more errors that bisect to #6936. Both are unchanged-write findings: `selected` on `lf-option` in `test_one_shared_added_option_has_one_action_payload_across_tabs`, and `tabindex` on the file editor's CodeMirror content in `test_a_reload_that_loses_a_saves_answer_keeps_the_typing_after_it`. They are product-side redundant writes, so this PR leaves them to their own issue. Refs #6960 — automated triage Co-authored-by: leaf-agent <[email protected]>
…op forging a selection through a pick (#6973) Two browser tests have ended with an `unchanged write` finding since #6936. That PR made a `LeafElement` draw inside Leaf's set of its `state`, so two draws that used to land in separate tasks now land in one script. The write watch then sees the attribute end where it started. The two findings have separate causes. - **`lf-file-editor`, `tabindex` on CodeMirror's content.** The editor was created read-only, and a draft kept across a reload was recovered only after that. On reload the first paint in the same setup task found the file writable, so `tabindex="0"` was set and removed in one script. Drafts are now recovered before the editor is created, and the editor starts with the read-only state the paint would give it. Creation and the paint share one `readOnly(of)` rule. - **`lf-options`, `selected` on `#job-mounts`.** This one was made by the test. `test_one_shared_added_option_has_one_action_payload_across_tabs` forges `selected` in the DOM so that the draft generation records it, but the tab's state never held it. The click's `add` draw put the DOM back to the state, and the pick in the same click restored it. The test now removes the forged attribute once the generation has recorded it. Both tabs then send with their state's selection, and the test's `picks == {("job-mounts", <added>)}` assertion still requires the pick to come from the generation's recorded choice. The widget is unchanged. On a real page the DOM follows the state, so this double write can't happen there. Both tests failed on `7da7a6a71` (current `main` when this run started) and pass with the change. Other checks that pass on this branch: the file editor's reload, retry, export, first-read-wait, phone and navigation tests in `tests/browser/test_render_files.py`, the other `option` test in `test_shared_drafts.py`, `pnpm run check` and pre-commit. Closes #6964 — automated triage Co-authored-by: leaf-agent <[email protected]>
LeafElementreached Leaf through wiring of its own. It now takesstateand 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:
state, parents first; a redraw it starts itself has no promised order.pending-task, holding rendering readiness as a preparation does. Six pages announce none at rest; a playing recording settles as often as onmain.module-plain-elements.md:lf-connect,lf-hold,attemptonlf-action,redraw(). A class module now declares a bound input reactive and a shadow root withstatic shadow.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 matchingmainin Chromium and Firefox, and nine package-author cases twice (13 of 18, base 12).