Repository navigation
Teach one way to write a widget: its declaration, plus a defineWidget component - #7544
Merged
Merged
Conversation
…Effect UI Not for landing as is: a measurement for the question whether defineWidget should hold the user's place itself. Three Codex reviews of the branch that rebuilt the adapter found new corner cases in each round, most of them in the adapter inferring from DOM mutations where the user was and what a draw did. The adapter no longer holds focus around a draw (holdFocus by data-lf-datum). Effect UI keeps focus, a field's words and its caret on every node a draw keeps, and moves a keyed node within its parent with moveBefore, so the hold did work only for a node a draw replaced: a row moved to another parent, or a row removed. Those now drop focus to the body, as a Lit widget's always did. lf-call-diff's FollowRow, which opened a folded root for the hold to land in, goes with it. What stays Leaf's, each without reading the DOM: - First props. The root mounts once the element has connected and the host has made its sets for this connection: after lf-connect where no host cancels it, else at the host's set of state, which element-integration now makes last in its pass, after the recorded properties. A host sets state again on each return (returned), keeping shown, so a returning widget mounts from fresh state and keeps unsent words in a recorded field. A state set before upgrade goes through the accessor. - declare sets every member Leaf reads off the element (DECLARED, the rule Max picked), climbing from the node's parent, so a Mount on a child widget's element declares for the parent; lf-draft and lf-options declare from a node their view drew. - A descendant's lf-connect moves the inputs' tracked signal, and a report reading told to wait follows the host's askedAgain signal, so a parent hears a new child's reports and a widget draws its reports once ready. Behaviour the tests now check differently: the shelf test asserts that a keyed item moved along its shelf keeps its node, focus and words (Effect UI's), and that a keep-alive item moved to another shelf keeps its node and words. Focus on an item moved to another shelf is no longer kept.
A reader who closed a root and pressed a key within the next frame found it open again (test_call_diff_projects_stable_commentable_rows, line 314). Chromium tells the page a details element folded with a toggle event about a frame after the press. A draw in that frame, here the one the location link's Command starts, writes the controlled open from a Model that hasn't heard the fold, which undoes it, and the toggle that follows reports open. An instrumented run showed the stale write at the next press, 17 ms after the click, with the toggle still unsent. The summary's press now sends ToggledGroup and prevents the browser's own fold, so the Model is the one writer of open and no frame stands between the press and the Model. A modified press keeps the browser's fold. The toggle handler stays for folds the browser makes itself, such as find in page. Making open an attribute instead kept the race out but had Effect UI rewrite an attribute that already stood, which write_watch refuses.
…own draws Main holds focus around each draw the adapter starts (holdFocus by data-lf-datum), and the prototype had dropped that, which left the user on the body when a new reading removed their row or moved it to another parent. The hold is back, without its guesses: - It lands on the datum itself, a stop lent where it is no control, rather than on the control in it with the same tag and classes, which picked the first of two alike buttons (Codex's R1#3). holdFocus takes `alike: false` for this. - It looks for the key among the widget's own datums (`owns`), so a nested widget's datum of the same key can't take the user, as it could on main. - It carries no words into a replacement node and reads no mutations. A draw the component's own message starts still has no hold, as on main: Effect UI gives no hook before its flush. Probed in Chromium and Firefox (the same in both): a row removed or moved by a set lands on its key or the nearest datum; a press whose own message removes or moves the row leaves the user on the body, as on main.
- The hold lands on the control at the user's control's place among those like it, in the item now carrying their key or the nearest one still drawn, and on the item where it has no control at that place. Main took the first alike control, which put a user on a second Remove on the first (R1#3). holdFocus does this for every caller, and `alike` goes. lf-call-diff's FollowRow comes back, so a call a new capture moves into a closed root opens it and keeps the user on its link (test_call_diff_keeps_the_user_on_a_row_a_new_capture_moves). - A fold that changes nothing leaves the Model as it stands, so the toggle that answers the Model's own write of open draws nothing (Codex #16: two passes over the capture per press, now one). - element-integration sets state first again, so a recorded property's setter reads the state it belongs to (Codex #17, lf-select), and gives each set its own attempt, so a setter that throws keeps no other set from the element. The first draw still has every set of the pass: an element whose lf-connect a host cancelled mounts at the end of the pass that sets its state, a microtask later, which the pass waits on through the mount's pending-task. - The readers of declared members follow a redeclare, as branch commit 32570de41e had them: thread placement asks the element for threadOutlets on each pass and registers or retires it on lf-layout; Copy places itself again on lf-layout; lf-draft declares lfCopy and lfBar. lfHold joins DECLARED, since Leaf reads it off an outlet, which may be the widget's element. Tests: the cancelled-lf-connect mount test now checks the mount waits for the pass and holds its later recorded property; the late-outlet browser test comes from 32570de41e.
…rol by its look Codex found three ways the hold's choice of a control by tag, classes and position put a keyboard user on the wrong action: a nested widget's Remove before their Edit, a disabled replacement that refused focus while the row went untried, and a same-class Remove inserted before Save. Each round had patched the same matching. The adapter's hold now lands on the user's own node where it survived the draw (Effect UI kept it, or it is a keep-alive child), else on the datum now carrying their key among the widget's own, else on the nearest one, on the datum itself (holdFocus, `alike: false`). A widget that keeps the user on their control across a move to another parent writes the row as a keep-alive child. holdFocus's other keyed callers (lf-diff's lines, the floating panel, the margin) keep main's pick, the first control like the user's, until each is checked: in lf-diff a user on a diff line whose new patch changes it would land on its gutter Comment, which comes first among the line's keyed nodes. - lf-call-diff: a call a new capture moves into another root lands the user on its row, as the test now says; writing the rows as keep-alive children would have kept them on the link at a cost of about 35 lines. - lfHold leaves DECLARED: Leaf reads it off the outlet a widget returns, which a defineWidget widget's view draws and sets with `.prop`. - Copy settles where it stands and the frame it wears together on each arrival and lf-layout: last in the widget's toolbar without data-lf-bar, or after its block with it.
… component Max picked, on the Effect UI review page (#7478), that every widget, other authors' included, is its declaration plus an Effect UI component that `defineWidget` defines if it draws anything, that a widget that draws nothing has no module, and no Lit in packages. The shipped references still offered three ways (a plain element, a `LeafElement`, a component). They now teach the component, against the thin adapter this branch builds on (effect-widget.ts's header), and describe the widget protocol as what the component receives and declares. - `module-plain-elements.md` becomes `module-widgets.md`, "A widget's module": a working `lf-verdict` component, its declaration and its first-box CSS, then each protocol entry in the component's terms: props (`state`, `properties`, `options.inputs`), Commands (`RecordAction`, `TakeBack`; widget-services.js's header owns what each does), `declare` for every member `DECLARED` lists, set from a Mount on a node the view drew, `statics` and `members`, and a Mount for what none of them carries, such as `drawn`, an output's `change` or `lf-hold`. It is renamed rather than merged into `module-authoring.md`, which sits near the 30,000-character cap and which page scripts read without the protocol. Every pointer moves with it. - Drawing, from the thin header: the first props hold `state` and each bound property; after a draw a set, an input or a member starts, the element says `lf-commands`, and `lf-layout` where it declares parts; a draw the component's own messages start is said by the widget's Mount. - Focus (module-input.md, "Focus and layers"): Effect UI keeps focus and typed words on the nodes a draw keeps; a row that moves to another parent is a keep-alive child (`h.keepAlive`); around a draw a set starts, the element lands the user on the row with the same `data-lf-datum`, or the nearest, on the row itself. A draw of the component's own messages has no such hold. - Marking drawn data: the widget reports `drawn` from a Mount whose args hold the value and the keys of the rows drawn, so rows the Model adds are reported too; an equal delivery gives no new props. - module-authoring, module-state, module-reading, module-input, module-annotations, module-previews, module-controls, module-scroll-and-motion, package-data, page-behavior: the component's form throughout, with no route to Lit for package authors (`axisMarks`, `offerActionElement` from a Mount, words or DOM nodes in a preview), and `threadOutlets` declared, which Leaf asks for on each placement pass. - The `package init --widget` starter is a `defineWidget` component whose buttons wear `pressAttributes("answer")`. - Evals: `widget-written-as-a-component` asks for a package with a widget that draws and one that doesn't, graded by `dev/leaf_dev/widget_form.py` (parsed calls, the package's declarations and modules, the page's markup) and by whether every widget drew. `widget-list-keeps-focus` asks for keep-alive rows, no focus code for a move or removal, and the popover's return to Add item with `focusDestination`. The rubrics that named `LeafElement` take the component form. The references were reviewed by Codex across four rounds against the earlier adapters; each finding that still holds is in this text. > _This was written by Claude Code on behalf of max-sixty_
…e browser The hold (Codex's third review of the thin adapter): - It puts the user on the datum it chose, never on the first control a boxless datum draws: focusDestination and holdOn take `itself`, and the adapter's hold passes it. A display: contents row with Remove before Edit sent the user to Remove; such a row takes no focus, so the hold goes on. - Where a datum takes no focus, it tries the next node its key marks, then the next key's: a disabled node before a focusable one of the same key sent the user to the next row. - lfHold returns to DECLARED, for a widget whose own element is the outlet, as the draft is; a child outlet's lfHold the view sets with `.prop`. - Copy treats a toolbar the renderer took out of the page as none, and stands after its block. The fold: root AGENTS.md has open disclosures belong to the browser until a gesture makes them part of the page's state, and the controlled `.open()` writes the Model's value on every draw, over a fold whose toggle hasn't arrived (a script's reveal, a summary press, find in page). lf-call-diff and lf-toc now write `open` as an attribute that doesn't change, so Effect UI writes it only as the disclosure arrives, and fold through the node: - lf-call-diff's Model hears each fold with toggle, for Expand all and Collapse all to read; their press folds every root from a Mount (`Folds`), which also opens the root a moved row lands in, as FollowRow did. The summary's press handler goes. - lf-toc's posture keeps the reader's choice in its Mount (FollowPosture), which opens the outline where the form hides its summary and restores the choice on return. Its Model loses open and exposed, and Toggled, Exposed and Returned go, with the story tests of that posture; the browser tests of the disclosure cover it. Probed in Chromium and Firefox: a script's open, or a summary's activation, followed in the same task by a draw, now stays open and the Model hears it. The header records each Effect UI gap with the idiom tried: no hook before a draw the component's own message starts (HtmlCommand.focus on a ref lands the user where the component says, and needs HtmlCommand, which the bundle doesn't export yet), the controlled open, and a kept child moved to another parent losing focus.
…s, as write_watch asks
Codex's review of ee45339 found `widget_form.py` still misgrading. It now grades only the packages the page's layer record selects, and a page's own module for a tag, which wins over its package's, fails the sample. A module's calls are read off its syntax tree with comments skipped, a namespace import of the adapter counts as its `defineWidget`, `customElements.define` counts on any object, and an `import()` of Lit counts as importing it. test_widget_form.py holds each case. > _This was written by Claude Code on behalf of max-sixty_
With the thin branch's head merged (83b0eb7, 6f3a7df: the hold lands on the datum itself, `lfHold` is back in `DECLARED`, disclosures fold through the browser), and Codex's review of ee45339: - Marking drawn data: the reporting Mount's args hold, beside the value, the key of each row drawn and the parent it stands in where rows move between parents, so a draw that adds or moves a marked row reports again. The example drops `data-lf-origin-path`, which names the datum's place in the value, not where the view shows it. Bound data says that each delivery is a new copy but a component's props change only where the contents differ. - Thread outlets: a component reads `threadSurface(element).open` in `options.inputs`, which follows its registration, and an outlet's `lfHold` is declared where the widget's own element is the outlet, or set with `.prop` on an outlet the view draws. - `declare`: each call says `lf-commands` for keys and `lf-layout` for the rest, and a preview already on screen reads again only on `lf-preview`. `closestAcross` finds the element unless the node is itself an element of the widget's tag. - Focus: a contenteditable's selection collapses on a keyed move; `h.keepAlive` takes a keyed child component; a widget whose rows draw no box leaves the user on the body when their row goes; after a move the component makes itself the user lands on the body. - A node's own key scope comes from a Mount on it, said as the Mount starts and on each change of what its rows read. The rendering guide's first draw is "as the root mounts". The authoring overview no longer says every fallback is a `widget-api.js` function. The cross-shadow invoker recipe gives the right cause: `commandfor` finds no target outside the button's tree. The widget reference's opening sentence names who does each thing. - Rubrics: `widget-list-keeps-focus` passes keep-alive rows or a Move button that carries the row's `data-lf-datum`; `widget-controller- lifetime` asks the reporting Mount to follow the drawn rows' keys; `thread-widget-actions` credits the element with ending what `options.inputs` follows; `widget-runs-off-leaf` admits no Lit among the vendored bundles; `widget-ratings-recorded-by-leaf` fails Lit or `LeafElement`. > _This was written by Claude Code on behalf of max-sixty_
Codex's fourth review of the thin prototype found that a Model following `toggle` keeps a stale copy of the fold: a bulk press before `toggle` arrived acted on the old reading, and each `toggle` redrew the widget. So the Model holds no fold. The view writes `open` once, as an attribute that doesn't change, and a Mount reads the live `<details>`, and folds there, where the widget folds, as for Expand all. The Model's example in module-widgets.md is now a drag under way. > _This was written by Claude Code on behalf of max-sixty_
Codex's fourth review of the thin adapter: - lf-call-diff kept the roots' folds in its Model as `toggle` reported them, a task late, and decided from that copy: a bulk press before the toggle closed the other root, and each toggle drew the whole capture again (28/180/648 root-label reads for a bulk fold of 4/12/24 roots, where the commit before made 12/36/72). The fold leaves the Model. One Mount, Folds, reads the roots' folds as Expand all or Collapse all is pressed, folds every root, and paints the control's face from the roots' folds on each toggle and each commit, with no draw; it also opens the root a moved row lands in. The update only announces the fold. - lf-toc read the host's authored open on every draw, so removing it closed a sidebar outline whose summary the form hides, to 0 px. The Model seeds it once, and FollowPosture reopens the outline after any fold from outside while the form holds it open, taking that fold as the reader's choice for flow. - The adapter's hold ends on the widget's own element, with a stop lent, where no datum takes focus, rather than on the body. - The hold looks for the user's own node before it searches the items, so a draw that keeps their control costs one scan of the datums, not two. - A datum whose shadow root delegates focus still hands the hold's focus to its first control, open root or closed; the header states it.
Codex's fifth review of the thin adapter: - Several holds can lose the same focus, as a nested widget's and the one around it do when one task redraws both. The inner hold put the user on its replacement Edit, and the outer hold, which counted no restore as a placement, then moved them to its host. A hold that puts the user back now counts as a placement to every other hold (holdOn), so the first restore ends the others, whatever stand-in they would try next. A runtime test covers the nested case. - lf-call-diff's bulk press already paints the control's face; the toggles it sets off read nothing now. A root's fold can only turn the face to Expand all, and its opening only back from it, so a toggle that can't do either is passed by (Codex: 6/14/26 root queries for one press on 4/12/24 roots). - lf-toc reads the outline's fold as the form shows its summary again, so a fold from outside whose toggle hasn't arrived is the reader's choice too (a script close and a narrowing in one frame reopened it, 402 px).
The rescore on the thin adapter failed head answers on rubric wording,
not on the behaviour each case pins:
- widget-owned-context-keys required setting `lfCommands` by hand and
dispatching `lf-commands`; it now also passes `declare(node,
{ lfCommands })` from a Mount, which does both, and a component whose
element says the event after a set of its props.
- widget-list-keeps-focus required a keep-alive row or a Move button
carrying the row's `data-lf-datum` to keep the user on Move; it now
also passes rows of both sections under one parent, where a keyed move
keeps the row's nodes, as module-input.md says.
> _This was written by Claude Code on behalf of max-sixty_
…t fallback The counting from the last commit made a hold's landing a placement to every other hold, and with the host fallback the outcome turned on which widget's hold ran first: an outer hold that refocused the old Edit, or took focus to its host, cancelled the inner hold that could reach the replacement Edit. A hold now puts the user back only while their focus is lost, on the body or on a node no longer drawn (holdOn, holdFocus). Focus that stands on a drawn node, where another hold or the user put it, stays. A hold's own landing is no placement again, and the yield to a newer placement stays. The adapter's host fallback goes, so where no datum takes focus, as where every row is boxless, the user lands on the body; the header states it. Probed in Chromium and Firefox: with the outer widget's move of a kept inner widget first, the inner hold reaches the replacement Edit; an outer redraw leaves the user on the inner replacement; a user who moves elsewhere in the task stays there. With the inner draw first and the outer move second, the user lands on the body, which main reaches the replacement for: the outer hold searches only its own datums, and the replacement is the inner's.
When a removal empties the list, the hold has no row to land the user on and names no control, so where the user goes is the author's choice, as on Add item. The rubric now passes focus code that runs only once no row remains, and still fails hand-written focus keeping for a move, or for a removal that leaves rows, which Leaf does. > _This was written by Claude Code on behalf of max-sixty_
The ordering cases came from each hold having its own idea of where the user belongs: an outer widget's hold searched only its own datums (`owns`), so when its move lost focus after the nested widget's hold had restored it, it couldn't find the nested replacement. holdFocus now takes `ownerOf`, the widget that drew an item, in place of `owns`. The place it looks up is the user's key under the widget that drew their datum, the same for every hold that lost that focus; where that widget has left the page, the datum around the user that the nearest widget still standing drew; failing both, the user's key among every item under the scope. A caller that names no owner looks among every item under the scope, as before. Probed in Chromium and Firefox: all four orderings of a kept nested widget moved while its own draw replaces the user's Edit land on the replacement; an outer row sharing a key with a nested datum keeps the user in the outer; a nested widget drawn anew elsewhere puts the user on its datum with their key, or on the outer row around it where there is one.
holdFocus promises the user is never left on the body because their row left the list, and a removal that emptied the list left them there. The shared destination now ends on the element of the widget that drew the user's datum, with a stop lent: their key there, then the nearest datum, then the widget. Every hold that lost the same focus computes the same widget, so this fallback can't take focus from a nested hold that would reach an exact replacement: the nested widget's commit and its restore run back to back. Probed in Chromium and Firefox: a removal that empties the list lands on the widget; with a kept nested widget that the outer moves while its own draw empties its rows, in either order, the user lands on the nested widget; the orderings where the nested draw replaces Edit still reach the replacement. A boxless row, which takes no focus, now leaves the user on the widget too.
…owner levels The owner levels (a504bad) carried a per-level lookup for one ordering: a nested widget's draw first, then the outer widget moving the kept nested widget in the same flush. A smaller rule covers it. holdOn tries the user's latest location before the place it held, where that stands again: where a nested hold put the user back and the outer move then took the node out and put it back, every hold that lost the same focus lands there, whatever the order, with no owner logic. holdFocus takes `owns` again, and the fallback for an emptied list is the holder's own element, with a stop lent. Probed in Chromium and Firefox: all six orderings of the kept nested widget land as with the owner levels; a key an outer row shares with a nested datum keeps the user in the outer; the probe table, an emptied list included, is unchanged. One rare case differs: a nested widget drawn anew elsewhere, with no outer row around it, leaves the user on the body, where the owner levels found the new widget's datum.
The adapter is the only caller of holdFocus with `alike: false`, so the fallback to the widget's element belongs to it: #redraws passes the element as the last stand-in, keyed hold or plain, and holdFocus loses the scope it added for an emptied list. The plain path, where the user's node stood in none of the widget's datums, as when the outer widget draws a nested one anew elsewhere, now lands on the outer widget rather than the body. Probed in Chromium and Firefox: a nested widget drawn anew elsewhere, with no outer row, lands on the outer widget; an emptied list lands on the widget; the six orderings of a kept nested widget land as before, with no outer restore taking focus ahead of the nested widget's.
The thin adapter's settled head (f9d5212, merged as 127bc1f) puts the user back only where a draw lost their focus, tries first where they last stood if that is drawn again, and tries the widget's own element last, as where a removal empties the list. module-input.md's "Focus and layers" says so, and drops the sentence that a widget of boxless rows leaves the user on the body, which the last stand-in ends. > _This was written by Claude Code on behalf of max-sixty_
The effect-widget.ts header's limits now say what a user gets where a widget's own draw hides their node and a nested widget's later draw in the same pass draws it anew: the outer hold runs first and leaves them on the outer widget or its row, one Tab from their control. Landing them on it would take holds that restore after every draw of the pass, innermost first, a queue a rare path doesn't pay for. The two comment lines the last rounds left long are reflowed, and oxfmt and eslint now pass on every file the branch changes: oxfmt's layout of earlier changes, and a test that reached a row's control through optional chaining eslint refuses.
… parent The thin adapter keys a held row within one parent, as Effect UI does, so only the widget knows that a row in its new parent is the old one. The root guidance's sentence on promises Leaf keeps for every widget gains that exception: the widget writes such a row as a keep-alive child. Max approved these words on the Effect UI direction review page (28 Nov 2026).
The widget-form grader imported resource_urls' private parser, and leaf-dev interface built its own copy of the same Tree-sitter grammar. javascript_language is now the one public grammar; javascript_imports builds its query from it, and the grader and the interface census build their parsers from it. > _This was written by Claude Code on behalf of max-sixty_
# Conflicts: # browser/runtime/dom/focus.js # browser/runtime/dom/focus.ts
leaf-agent
approved these changes
Nov 28, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 28, 2026
…7551) Max asked whether How it works was being updated for the new interfaces. The site's How it works and Extending pages now teach the form the references teach since #7544: a widget is its declaration plus, if it draws, an Effect UI component that `defineWidget` defines, which takes `state` as a prop and issues Commands such as `RecordAction`. How it works' Package interface tab gets a new widget definition, drawing, forms table and principles, and walks through `lf-verdict` as the component `module-widgets.md` shows. `docs/verdict`, which the page runs and quotes, changes with it. The prose describes a widget acting on Leaf through Commands and names none of the thread and obligation functions Max chose to remove. The example's two buttons sat with no gap between them. `docs/verdict`, the `module-widgets.md` example and the starter `leaf package init --widget` writes now space their row with a class of their own. `leaf-dev interface --base` reports no name added. The product-page, interface and starter tests pass, among them `test_widget_quality.py` and `test_plain_elements.py`'s starter test. A probe pressed Ship and Undo in the page's live sample. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The shipped references now teach one way to write a widget: its declaration, plus, if it draws, an Effect UI component that
defineWidgetdefines.module-plain-elements.mdbecomesmodule-widgets.md, which describes the element protocol as what the adapter does for the component, and the other module references drop their Lit and plain-element routes. The starterleaf package init --widgetwrites is now such a component.The eval suite grades the form a fresh agent writes: a new case,
widget-written-as-a-component, is graded bydev/leaf_dev/widget_form.py, which parses the module the page runs, and the rubrics whose expected form changed acceptdeclareand a keyed move. The grader andresource_urlsbuild their parsers from one grammar,javascript_language.Rescored against main, the references lead on 7 of 10 cases and tie on 3. Fresh agents wrote a
defineWidgetcomponent in 3 of 3 runs, against 0 of 3 on main. On keeping focus in a list, 1 of 2 graded runs passed, against 0 of 4.leaf-dev interfaceadds no name. Its protocol count drops from 78 to 77, since the index no longer listsredraw(), which a component never defines.--basecan't read this branch's base, which has nomodule-widgets.md, so compare runs on each tree.Max set the destination, every widget an Effect UI component, on the Effect UI review page and in #7478. This follows #7542, the adapter it describes, and Codex reviewed it.
pnpm run test:runtime(1240), the grader, interface and reference tests, and the starter's browser test pass.