Skip to content

Settle defineWidget's contract: declare, failure beside authored content, TypeScript - #7448

Merged
max-sixty merged 2 commits into
mainfrom
effect-ui-core-adapter
Nov 27, 2026
Merged

max-sixty merged 2 commits into
mainfrom
effect-ui-core-adapter

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Requested by Maximilian · project thread

Part of the Effect UI core pass: defineWidget settles into one contract, stated in effect-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, or lf-layout for 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 says lf-commands after each of those, and lf-layout too 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 use declare and 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 own lfCommands.
  • Failure keeps the authored content visible. When a root fails or its inputs throw, the adapter places Leaf's failure box beside the authored children (placesFailure), and a failed shadow root draws a bare <slot>. Before this, failSoft replaced 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.
  • A member's get and set are both required, since every caller gives both.
  • properties and members both capture a value the page set before the tag was defined, as before. The capture now runs in one loop.
  • The header records the three Effect UI limits behind the design:
    • Each element mounts its own root, because defineElement shares its document host only through an internal argument, clears the element's children, and has no lf-connect, inputs or members.
    • A root has no hook on its flushes (Renderer.Root has model, send and setProps), which is why a widget declares on its own Model-driven draws.
    • patchAttrs removes dropped attributes before it sets new ones. lf-activity's tabindex workaround stays for this.

effect-widget is 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 for declare, including a row whose availability an in-widget message changes. Also the timeline, motion, options, command-reference and key-scope browser tests, and leaf-dev stills --base origin/main over 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_page and test_a_change_ends_where_a_disclosure_does[settled-options]. #7450 fixes both.

🤖 Generated with Claude Code

https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y

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


Generated by Claude Code

…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 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.

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 < last read it. drawn is 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 no lf-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 the motion.play row's title is read again only on lf-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.

Comment thread browser/runtime/effect-widget.ts Resolved
Comment thread packages/motion/widgets/lf-motion.js Resolved
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
@max-sixty
max-sixty merged commit b6460ff into main Nov 27, 2026
6 checks passed
@max-sixty
max-sixty deleted the effect-ui-core-adapter branch November 27, 2026 22: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.

3 participants