Repository navigation
Settle defineWidget's contract: declare, failure beside authored content, TypeScript - #7448
Conversation
…ent, TypeScript
The adapter grew one port at a time. This settles it into the contract its
header states, before the next widgets build against it:
- `declare(node, {lfCommands, lfParts})` states what Leaf reads off a widget's
element from a Mount, says a declaration that changed, and withdraws it when
the root closes; the element already says each draw, and now says
`lf-layout` too where it declares parts. lf-timeline, lf-motion and
lf-options use it and dispatch nothing themselves.
- A failed root or inputs that throw keep the authored children in view: the
adapter places Leaf's failure box beside them, and a failed shadow root draws
a bare slot. failSoft used to replace the element's children with the box.
- A member's `get` and `set` are both required, as every caller gives both.
- The header records the Effect UI limits behind the design: one host per
mount, since `defineElement` shares one only internally, and attributes
removed before the new ones are set (lf-activity's tabindex keeps a row's
target focusable).
effect-widget is now written in TypeScript.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
leaf-agent
left a comment
There was a problem hiding this comment.
A draw that comes from the component's own Model now announces nothing, and lf-timeline and lf-motion depended on what this PR removes from them. The adapter calls #drawn() only at mount and through #redraws(), which #update() and a member's set reach. A message the view sends itself, such as PressedStepControl, MeasuredRuler, or play/pause flipping model.playing, redraws without lf-commands or lf-layout. I checked this with a throwaway runtime test: a shadow widget whose button sends a message that bumps its Model redraws the count (0 → 1), and it dispatches lf-commands once at mount and never again.
On main, those Model-driven draws were announced by the widgets' own changes streams, which this PR deletes:
- lf-timeline. Stepping changes
drawn, and the First/Last rows'when: () => drawn > 0/drawn < lastread it.drawnis a plain variable, not a signal, so Leaf's availability readers (scopes.js) stay on the availability last announced. A ruler measurement relays out the labels inside an unchanged box with nolf-layout, so readers that measure the event parts, such as thread outlets on a timeline event, keep the old positions. - lf-motion. Pressing play swaps the button's
aria-label, but themotion.playrow's title is read again only onlf-commands, so Leaf keeps saying the old word.
The header's "after each draw the element dispatches lf-commands" (and lf-layout where it declares parts) is the right contract, but it only holds if the adapter hears every flush of the root, not just the ones it started. If Effect UI gives the mount no such hook, the widgets need to keep announcing on their changes streams until it does.
The browser tests this PR ran pass because none of them reads a row's availability or title after an in-widget step.
Effect UI gives a root's owner no hook on a flush, so the adapter hears only the draws it starts: a timeline step, a ruler measurement or motion's play/pause redrew without lf-commands or lf-layout. `declare` now says its declarations on every call, and lf-timeline and lf-motion declare from their Mount's `changes`, whose args hold what their rows and parts read. The header records the gap. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
Requested by Maximilian · project thread
Part of the Effect UI core pass:
defineWidgetsettles into one contract, stated ineffect-widget.ts's header, before the next widgets (lf-tabs, lf-board, lf-code, lf-toc, lf-draft, lf-call-diff) build against it.What changed in the contract
declare(node, {lfCommands, lfParts})is now the one way an Effect widget states what Leaf reads off its element. A widget calls it from a Mount, passing its element or any node its view drew. Each call says the declarations (lf-commands, orlf-layoutfor parts), and the adapter withdraws both when the root closes. Effect UI gives a root's owner no hook on a flush, so the adapter hears only the draws it starts. It sayslf-commandsafter each of those, andlf-layouttoo when the widget declares parts. A draw that the component's own messages start, such as a timeline step or motion's play/pause, is said by the widget: it passes what its rows and parts read as the Mount's args and declares on each change. lf-timeline, lf-motion and lf-options usedeclareand dispatch nothing themselves. A key scope that belongs to one control node, such as lf-option's mark or lf-file-tree's rows, stays that node's ownlfCommands.placesFailure), and a failed shadow root draws a bare<slot>. Before this,failSoftreplaced the element's children with the box, so a failed lf-timeline lost its lanes. A failure from the inputs clears once they read cleanly again. A failed root stays failed until the element connects again.getandsetare both required, since every caller gives both.propertiesandmembersboth capture a value the page set before the tag was defined, as before. The capture now runs in one loop.defineElementshares its document host only through an internal argument, clears the element's children, and has nolf-connect,inputsormembers.Renderer.Roothasmodel,sendandsetProps), which is why a widget declares on its own Model-driven draws.patchAttrsremoves dropped attributes before it sets new ones. lf-activity'stabindexworkaround stays for this.effect-widgetis now written in TypeScript. No option was removed: every one has a caller.Checks:
pnpm run test:runtime, with new tests for failure in a light and a shadow root, for failing inputs, and fordeclare, including a row whose availability an in-widget message changes. Also the timeline, motion, options, command-reference and key-scope browser tests, andleaf-dev stills --base origin/mainover the timeline, motion, options, activity, tally, file-tree and failed-widget states: no visible difference. Two lf-options tests already fail on main and fail the same way here:test_a_group_of_bare_labels_reads_as_a_question_about_the_pageandtest_a_change_ends_where_a_disclosure_does[settled-options]. #7450 fixes both.🤖 Generated with Claude Code
https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
Generated by Claude Code