Repository navigation
Draw lf-tally as an Effect UI component, through a widget adapter on the plain-element protocol - #7374
Conversation
…the plain-element protocol
Adds Effect UI as the first component model a widget can draw with besides
Lit, and moves lf-tally onto it.
- `effect` 4.1.5 and `@effect/ui` (pkg.pr.new snapshot of Effect-TS/ui
7bff56b, which isn't on npm yet) become dev dependencies, and a new
`effect-ui` vendor row bundles them as `/vendor/effect-ui.js`: the Effect
modules a widget names plus Effect UI's public HTML surface. The maintainer
authorized installing the snapshot from its URL.
- `/runtime/lib/effect-widget.js` defines `defineWidget(tag, component,
{shadow, inputs})`, a plain custom element on module-plain-elements.md's
protocol. Leaf's `state` and whatever `inputs` reads inside a signal
effect arrive as props. `WidgetEvents.Recorded` and `TookBack` events
become `lf-action` and `lf-undo`. A set that gives new props dispatches a
`pending-task` settling after Effect UI's microtask flush, then
`lf-commands`. `lf-connect` is dispatched as it connects, and a root
failure reports through `failSoft`.
- `controls.js` keeps one home for a press's marks: `offerAttributes` and
`roleAttributes` compute them, `offerElement` and `roleElement` write
them, and `pressAttributes` hands them to a view that builds its own
button.
- `lf-tally` is an Effect UI component. Its count and Next On Me press come
from props, and the press steps through a Command. `tally-view.js` goes.
- The public module list gains `/vendor/effect-ui.js` and the adapter, and
module-authoring.md names the adapter beside `LeafElement`.
What a user sees doesn't change: `leaf-dev stills --base origin/main` finds
the tally states unchanged (alert-queue-tally, side-tab-focus,
alert-option-long). Tests: the eight test files that exercise lf-tally (330
passed), tests/journeys/test_widget_quality.py, a new runtime test of the
adapter, `pnpm run check`, and pre-commit.
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.
module-plain-elements.md, "LeafElement", still says "Only the class follows a page reading, so a widget that draws from one must extend it." Now module-authoring.md says an Effect UI component through defineWidget is the other route, so the two references contradict each other. An author reading the plain-element reference will think lf-tally's new form is off-contract. That sentence needs to name defineWidget too, or point to the adapter's header. The PR doesn't touch that file, so there's no line to attach a suggestion to.
Every page that shows a tally now loads /vendor/effect-ui.js, which is 594,156 bytes (195,924 gzipped). Lit is 32,215 bytes. Nothing the user sees changes, so this is the experiment's cost. AGENTS.md, "Working on the repository", asks a change that can alter browser startup to compare base and head (/developing-leaf, "Compare checkout versions") and to report the bytes. Please add both to the description so the maintainer can weigh them. The entry re-exports whole modules, such as Stream and Duration, that nothing in the tree imports yet, so the bundle may also be bigger than this step needs.
…dgets name An `inputs` function that throws when a signal moves reports through `failSoft` instead of leaving the signal effect, where it would abort the update that moved the signal. The Effect UI bundle exports only the modules the adapter and widgets import (500 KB, 167 KB gzipped, down from 594 KB). module-plain-elements.md names `defineWidget` beside `LeafElement` as a way to draw from a page reading. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
<!-- claude-projects-attribution: {"github_login":"max-sixty"} -->
_Requested by **Maximilian** · [project
thread](https://claude.ai/code/project/chan_01HAT2svakg1fTA5kitqhX9w?thread=cmsg_01HAT2svakg1fTA5kitqhX9wAWrHoDSUn5ogNyh9ijmSrr)_
This is the second step of moving Leaf's widgets to Effect UI, after
#7374. `lf-worktree` and `lf-worktree-diffs` now draw as Effect UI
components through `defineWidget`.
**What changes**
- Both widgets mount in a shadow root with `lfPatch: "members"`. Their
`inputs` read the element's attributes, and for the collection its
members' attributes. `worktree-view.js` and `worktree-diffs-view.js` are
deleted.
- `defineWidget` gains `lfPatch`. A descendant's `lf-connect` now reads
`inputs` again, as `LeafElement` draws again then, so a kept collection
redraws its totals in place after a revision changes its members.
- `inputs` is read through one guarded call, so a throw from that
re-read reports through `failSoft`, as a signal-driven one already does.
- `lf-worktree-diffs`'s view wraps its overview and slot in a `display:
contents` div, because an Effect UI view has one root.
- The capture test drives the defined elements instead of the deleted
view functions. It still checks that the disclosure, its open state,
focus and the slotted evidence are kept while totals change.
**What a user sees**
`leaf-dev stills --base origin/main` reports `worktree-startup`
unchanged. `worktree-summaries` and `worktree-cases-open` differ only in
how "+7" kerns: Lit wrote "+" and "7" as two text nodes, and Effect UI
writes one string. The styles diff lists only the wrapper div in place
of the overview and slot standing directly in the shadow root.
**Tests**
- `tests/browser/test_render_diff_controls.py` and
`tests/journeys/test_render_diff_controls.py`, worktree tests (5 passed,
WebKit skipped locally).
- `tests/runtime/authored-capture.test.mjs` and
`tests/runtime/effect-widget.test.mjs`.
- `pnpm run check` and pre-commit.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
> _This was written by Claude Code on behalf of max-sixty_
---
_Generated by [Claude Code](https://claude.ai/code)_
Co-authored-by: Claude <[email protected]>
…tructurally (#7388) `lf-tally` hands its region element to its Effect UI component as a prop. When a revision replaces that region, Effect UI's `propsEqual` sees the field differ by reference and falls back to `Equal.equals`, which in Effect 4 compares two objects structurally, through every property they reach. On a DOM node that walk covers the document; on command-hub it reaches an SVG length whose `value` getter throws `NotSupportedError: Could not resolve relative length`, so the page's reading fails (`leaf: read failed` from `layer-client.js`). Both cases of `test_command_hub_an_absorbed_input_stays_fulfilled` fail this way on main since #7374, first in [ci run 45985477026](https://github.com/max-sixty/leaf/actions/runs/45985477026). The adapter (`runtime/lib/effect-widget.js`) now marks each DOM node an `inputs` function returns with `Equal.byReferenceUnsafe`, so a replaced node counts as a changed prop and an unchanged one as equal, with no walk. The fix sits in the adapter rather than in `lf-tally`, because any widget whose `inputs` returns an element would hit the same walk. `/vendor/effect-ui.js` now exports `Equal` for this (rebuilt with `pnpm run build:browser`); `leaf-dev interface --base` reports no name added. **Verification:** `test_command_hub_an_absorbed_input_stays_fulfilled` (both cases) fails on `db508e5b8` with the SVGLength error and passes with this change. `test_a_tally_counts_its_regions_obligations_and_walks_them`, the runtime tests `effect-widget` and `authored-capture`, `pnpm run check:browser` and `pnpm run test:browser` pass. The run's other failures are not touched here: the floating-panel teardown shift is #7381, fixed by #7385, and the heading-link copy-button shift has its own cause issue. Refs #7387 — automated triage Co-authored-by: leaf-agent <[email protected]>
`leaf-dev interface --base` now reports the names the Effect UI ports made available to packages. Before this change it read functions from `widget-api.js` and `portable-api.js` alone, so it reported nothing for them. Run on each port's own commit against its parent, it now reports additions for every one of #7374, #7378, #7397, #7399, #7400 and #7395. For example, against the commit before #7374 it lists `/runtime/effect-widget.js`, `/runtime/widget-services.js` and `/vendor/effect-ui.js` as modules, `defineWidget`, `widgetProps` and the eight `widget-services.js` exports as functions, and Effect UI's 16 exports. The census now reads every module `$public-modules` lists outside the library, with each module's exports, including the vendored ones. It also reads every mark any reference gives, which adds 21 documented marks it missed, such as `data-lf-focus-visible`, and the chrome parts `package-themes.md` lists. Root `AGENTS.md`'s "Keep the package interface small" now names the public modules and their exports as part of the interface, and the references that gave Lit as the only way to follow a page reading, or `widget-api.js` as the only module to import, now name the Effect UI forms too. What the move to Effect UI keeps and retires is left to the guidance change that states Max's call on it. To weigh: a vendored module's exports count as names, so a Lit bump that adds an export shows as an addition. A widget's own `part` names are its package's, so the census doesn't count them. A function's options count as part of that function, so `--base` doesn't list them. Asked for by Max from the parts-column-scroll page and in the session. Codex reviewed five rounds. Tests: `dev/tests/model/test_interface.py`, `tests/runtime/widget-api.test.mjs`. Evals: `widget-controller-lifetime` and `widget-ratings-recorded-by-leaf`, 12/12 on both arms. > _This was written by Claude Code on behalf of max-sixty_
Requested by Maximilian · project thread
This is the first step of moving Leaf's widgets to Effect UI. It adds a widget adapter on the plain-element protocol and moves
lf-tallyonto it. Max asked for this ("experiment with moving a bunch of the code over; start with some of the widgets") and authorized installing@effect/uifrom its snapshot URL, which skips the three-day release age.What it adds
effect4.1.5 and@effect/uibecome dev dependencies.@effect/uiis pinned to the pkg.pr.new build of Effect-TS/ui7bff56b, since it isn't on npm. A neweffect-uivendor row bundles both as/vendor/effect-ui.js./runtime/lib/effect-widget.jsaddsdefineWidget(tag, component, {shadow, inputs}), a plain custom element onmodule-plain-elements.md's protocol:state, and whateverinputs(element)reads inside a signal effect, arrive as props.WidgetEvents.RecordedandTookBackevents becomelf-actionandlf-undo.pending-task, which settles after Effect UI's microtask flush, thenlf-commands.lf-connectas it connects, and a root failure reports throughfailSoft.controls.jskeeps one home for a press's marks.offerAttributesandroleAttributescompute them,offerElementandroleElementwrite them, andpressAttributeshands them to a view that builds its own button.lf-tallyis now an Effect UI component, and its Next On Me press runs through a Command.tally-view.jsis deleted./vendor/effect-ui.jsand the adapter, andmodule-authoring.mdandmodule-plain-elements.mdname the adapter besideLeafElement.What a user sees: nothing changes.
leaf-dev stills --base origin/mainreports the tally states as unchanged (alert-queue-tally,side-tab-focus,alert-option-long).Worth weighing
state, not before the setter returns asLeafElementdoes. The protocol allows this throughpending-task, and it still lands before the next frame./vendor/effect-ui.js, 500 KB (167 KB gzipped), beside Lit's 32 KB (11 KB gzipped).leaf-dev probe --base origin/mainmeasuresalert-review, which holds a tally, at +511 KB of JavaScript before it presents (6.29 MB to 6.80 MB), with presentation at 3.9 s on base and 3.7 s on head in one noisy run each.alert-thresholds, which holds none, moves by 2 KB. Max said bundle size is low priority for this assessment. The entry exports only the modules the adapter and widgets import.inputsfunction that throws reports throughfailSofton the widget, asLeafElementkeeps its failures, instead of aborting the update that moved the signal.mountEffectdoesn't take the shared host thatdefineElementuses internally. That's fine at this scale. A public shared-host mount upstream would remove it.Tests
lf-tally(330 passed).tests/journeys/test_widget_quality.py.inputsthat throws.pnpm run checkand pre-commit.🤖 Generated with Claude Code
https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
Generated by Claude Code