Skip to content

Port lf-board to Effect UI, keeping lf-card a LeafElement - #7470

Closed
max-sixty wants to merge 9 commits into
mainfrom
effect-ui-lf-board
Closed

max-sixty wants to merge 9 commits into
mainfrom
effect-ui-lf-board

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Requested by Maximilian · project thread

Ports lf-board from Lit to an Effect UI component through defineWidget, written in TypeScript (lf-board.ts, compiled to the .js beside it). The board's Lit view is deleted.

lf-card is not ported. On this head it is a LeafElement that draws its grip and its Move to buttons with Lit, as its own children. On main it is a plain HTMLElement that draws nothing, and the board draws the grips. So this PR moves that Lit drawing from the board into the card rather than deleting it. browser/AGENTS.md ("Renderers") says a view that can't be ported is the point to stop and ask, so the PR is a draft until the question at the end is decided.

lf-board. Props are a Schema: the board element, its columns, its cards and state. The Model holds only the gesture under way:

  • the held placement;
  • the grab;
  • a pointer drag;
  • a reveal waiting for its move to land;
  • the placement a recorded move leaves, until its record settles.

Messages are a TaggedEnum. Every call to Leaf is a Command:

  • a move is RecordAction;
  • an announcement is Announce;
  • dropping a card that shows another widget's choice is AskOwner, which sends that widget --choose.

Sortable still does the pointer drag. The board draws in defineWidget's default light-DOM part, with no shadow root. Its root draws one hidden node, and a Mount on that node places the cards and gives each card its face.

lf-card. The board gives each card a face: its grip's name and keys, and its destinations. The card draws that face and records nothing. When Leaf sets the card's choice, the card fires change, so the board reads its cards again.

What this made easier. The board's gesture logic is now one update under Story tests (tests/runtime/lf-board-story.test.mjs), where only browser tests covered it before. The tests cover:

  • a keyboard grab, its steps and its drop;
  • a drop where the card started;
  • stacked steps;
  • Escape;
  • an unavailable move;
  • a pointer drag's end;
  • a phone button, and how long the landed placement holds;
  • a card that shows a choice.

Shared modules. None changed: the adapter, widget-services.js and margin-layout.js are as on main. leaf-dev interface --base reports no name added or removed.

Why lf-card isn't an Effect UI component

An Effect UI light widget stands in two display: contents wrappers inside its host. One is defineWidget's box, because Effect UI's mount needs a box of its own. The other is the view's root, because a view returns one root. Leaf's walkers (margin layout, passages, arrivals) pay for each element they meet, so a page of 256 Effect UI cards loaded 2496 → 3429 ms (+37%) in the previous bench. A profiling pass measured the per-mount host cost at about 0. A plain card that draws its controls as its own children measured within 2–5% of main.

Bench

uv run leaf-dev bench boards cards --input move --input key --input scroll --input revision --base origin/main --rounds 3 --sizes 64,256, run on this head (c715eb8) against main (f3c7186), with base and head interleaved and the lowest of 3 rounds kept. The host's load average was 4–5. Numbers are ms of main-thread CPU at 256, main then this branch.

boards ×256 (17k elements) cards ×256 (10k elements)
load 6274 → 6335 (+1%) 2652 → 2783 (+5%)
key 19.3 → 18.4 15.8 → 16.9
scroll 20.4 → 20.3 13.8 → 14.1
revision 612 → 626 328 → 309
move (keyboard drop) 505 → 533 (+6%) 333 → 360 (+8%)

What remains of the move gap is Effect UI's draw of the board. Margin layout, which is shared and on main as well, is most of either side's move time.

What looks or behaves differently

  • At rest, grabbed and after a move: nothing. leaf-dev stills --base origin/main gives 0 px for triage-grabbed, triage-moved and activity-feed.
  • Move to buttons. The card's own column and any column that doesn't take the card are left out of its Move to buttons, where main drew them hidden. A card with no destination left draws no Move to group. Tests count the buttons.
  • A grip's name during a pointer drag. The name follows the card's column once the placement lands, not while Sortable carries the card mid-drag. A MutationObserver used to rename it mid-drag; it is gone.
  • When a card binds its choice. The card binds its choice as it connects, which is before a customElements.whenDefined callback runs. A drop still asks the widget whose choice the card shows. The test that rewrites shows before the binding now does it as the card is parsed.
  • Leaving a held grip. The grab is cancelled through onCurrentLocation instead of a blur listener and timer. A new test checks that Tab away puts the card back with no move recorded.
  • Element APIs. lf-card.owner and the board's record and requestUpdate are gone. The test that called record now dispatches the lf-action event instead.

Failures not caused by this change

These fail locally and don't involve the board:

  • tests/browser/margin/test_pins.py::test_a_pin_keeps_clear_only_of_controls_the_user_can_see queries light-DOM lf-options buttons, which moved into a shadow root in Port lf-options to Effect UI as the first decorating widget #7417.
  • tests/browser/test_render_anchors.py::test_one_key_keeps_one_keyboard_face_across_the_page fails in getComputedStyle. Its page has no board.

Open question for the maintainer

Two ways forward:

  • A. Keep widgets that a page holds many of, such as lf-card, off Effect UI for now, and land the board port with the card as a LeafElement.
  • B. Fix the wrapper cost first, in defineWidget or upstream in Effect UI's mount, so a light widget draws without its two display: contents wrappers, then port the card too.

🤖 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

lf-board becomes an Effect UI component through defineWidget, written in
TypeScript (lf-board.ts, compiled to lf-board.js). Its props are a Schema
(the board element, columns, cards, state), its Model holds only the gesture
under way (the held placement, the grab, a pointer drag, a pending reveal),
its messages are a TaggedEnum, and every call to Leaf is a Command: a move
is RecordAction, an announcement Announce, and a drop of a card that shows
another widget's choice is AskOwner, which sends that widget `--choose`.
Story tests (tests/runtime/lf-board-story.test.mjs) cover the update with no
page behind it. Sortable stays the pointer drag.

lf-card becomes a decorating widget's member, as lf-options' options are:
shadow: true, the author's words through a <slot>, and the grip and the
phone's Move to buttons in its shadow root, which board.css dresses through
the parts grip, destinations, destinations-label and destination. The board
gives each card its face (grip name, keys, destinations); the card draws it
and records nothing. The card says `change` as Leaf sets its choice, so the
board reads its cards again.

What a user or a test sees differently:
- A destination a column doesn't take is left out of a card's Move to
  buttons rather than drawn hidden; tests count the buttons.
- A grip's name follows the card's column when the placement lands, not
  while Sortable carries the card mid-drag.
- The card binds its choice as it connects, before a
  customElements.whenDefined callback runs, so the test that rewrites
  `shows` before the binding now does so as the card is parsed.
- Leaving a held card's grip cancels the grab through onCurrentLocation
  rather than a blur listener; a new test holds that.

margin-layout.js walked a target that is a shadow host as one opaque box,
so a pin on a card that became a shadow host stood above the card, over
its column's count. The target's own shadow tree is now walked like its
children, as the walk's contract says (the target is not one to avoid),
and the triage stills are pixel-identical to main's.

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.

Two items from the port rule in browser/AGENTS.md, "Renderers", are still open.

Neither shadow root says why the light-DOM part fails. The rule reads: "A widget that decorates the author's children draws in a light-DOM part beside them first, as a LeafElement can and defineWidget does by default, and takes a shadow root only where that part fails." The PR gives "follows the lf-options pattern" as its reason. But lf-options' header sends the next decorating widget back to that rule ("browser/AGENTS.md, 'Renderers', says when another decorating widget takes one"), so pointing at lf-options doesn't settle it.

  • On lf-board the root holds nothing but its slot (the header says "the board's root holds only its slot").
  • On lf-card the Lit version drew the grip and Move to buttons as light children (:scope > .lf-grip). defineWidget's default display: contents box after the card's words looks like it would hold both: an absolutely positioned grip, and the destinations row after the prose.

Taking the shadow roots is what pulls in the margin-layout.js change to coverIn, which is shared runtime every pin passes through. It also moves the tests onto shadowRoot.querySelector. If the light part fails for a concrete reason, such as verbatim content, the carry key, or how Sortable's handle matches, the headers should say so. If it doesn't fail, the light box would drop the core change.

No bench. The rule also says: "A port benches a page full of its widget with leaf-dev bench, base beside head". COLLECTIONS already holds boards and cards, and this PR's bench job was skipped. The work that runs on each update (structure, arrange's placement check, and a JSON.stringify of every card's face) walks the whole board. The cards collection is the reading that would show whether that holds against the Lit version.

The port rule in browser/AGENTS.md, "Renderers", has a decorating widget
draw in a light-DOM part beside the author's children first, and take a
shadow root only where that part fails. Neither widget's part fails:

- lf-card's grip and Move to buttons draw in defineWidget's own
  `display: contents` box after the card's words, where the Lit version
  drew them as the card's children. board.css styles them by class again,
  as on main, and the Move to row clears the grip's float itself, since
  it is no longer a child of the card.
- lf-board's root draws one hidden node, whose Mount places the cards.

The cards are no longer shadow hosts, so the margin-layout.js change that
walked a shadow-host target's own tree goes, and pins on cards stand where
they do on main. Tests read the grip from the light DOM again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
…hange

`leaf-dev bench cards --input move` showed the port taking about twice
main's main-thread time for a keyboard drop on a board of 256 cards. Two
causes, both in lf-board:

- A draw commits before its Commands run, so the draw that ended a grab
  still had the old `state`. It put the card back in the column it came
  from, and the `state` that RecordAction then set put it in the new one
  again: two moves, each with a FLIP measure that forced a style pass over
  every card. The Model now keeps the placement a recorded move leaves,
  with the `state` it was recorded against (`landed`), and draws it while
  that `state` stands.
- `arrange` measured every card and re-read a column's cards once for each
  card it placed. It now measures and places only the cards of the
  columns whose order changes, reading each column's children once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
leaf-agent
leaf-agent previously approved these changes Nov 28, 2026
An Effect UI card stood its grip and Move to buttons in two display:
contents wrappers (defineWidget's box and the view's root) inside every
card, and Leaf's walkers pay for each element they meet: a page of 256
cards loaded about a third slower than main. lf-card is now a LeafElement
that draws the grip and the buttons as its own children, as on main, and
its header says why it isn't an Effect UI component. lf-board stays the
Effect UI port and tells each card its face.

The board's landed placement now holds while the recorded state still
places the cards as they stood, until the record settles, rather than
while the state is the same object: Leaf sets an equal state again when a
card connects, and the board drew the card back for one draw. A moved
card no longer reconnects where the browser has moveBefore.

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.

lf-card now stays on Lit, and the PR doesn't raise it with the maintainer. 8005e61 makes the card a LeafElement that draws its grip and Move to buttons with Lit. Its header gives the reason: the two display: contents wrappers, defineWidget's box and the view's root, made a page of 256 cards load about a third slower. On main, lf-card is a plain HTMLElement that draws nothing, and the board draws the grips. So this moves the Lit view from the board into a new LeafElement rather than deleting it.

browser/AGENTS.md, "Renderers", covers this case: "Lit and LeafElement leave the tree", "A port deletes the view it replaces", and "A view that can't meet this rule is the point to stop porting and raise it with the maintainer." Keeping the card on Lit to protect load time is a reasonable call, but it is the maintainer's call. The cause also sits a layer below this widget. Every decorating widget that draws inside its host pays for the two-wrapper box, so the fix belongs in defineWidget or Effect UI's mount. Until it lands there, no small decorating widget can be ported without the same load cost.

The description now contradicts the head, and it becomes main's commit message. It still says:

  • the PR ports both widgets to Effect UI (the title, and "The Lit views are deleted");
  • lf-card "is a small widget of its own" that draws in "defineWidget's default light-DOM part";
  • the cards load cost "comes from each card mounting its own Effect UI root".

The bench table measured the Effect UI card. The head's cards load, key and move numbers haven't been reported. A description that says which widget was ported, why the card stayed on Lit with the new bench numbers, and what is being asked of the maintainer would let them decide.

Comment thread packages/default/widgets/lf-board.ts Resolved
…no longer needs

samePlacement went in between withCard and its comment. With lf-card
drawing its grip and Move to buttons as its own children again, the
descendant grip selectors and the Move to row's clear: right are no
longer needed, so those files match main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
@max-sixty
max-sixty marked this pull request as draft November 28, 2026 04:35
@max-sixty max-sixty changed the title Port lf-board and lf-card to Effect UI components Port lf-board to Effect UI, keeping lf-card a LeafElement Nov 28, 2026
max-sixty added a commit that referenced this pull request Nov 29, 2026
…el (#7573)

Ports `lf-board` and `lf-card` to Effect UI components (`defineWidget`)
and removes SortableJS. It supersedes the draft #7470, which kept
Sortable moving the cards.

**How a move works.** The board's Model holds the card the user holds,
where it was picked up and the placement drawn meanwhile, with the card
where it would land; and, from a drop until Leaf's next reading, the
placement the drop left. The view draws that placement, else Leaf's
`state`, and one Mount places the author's `lf-card` nodes to match with
Leaf's `move`. A drop, a cancel, an undo, a refusal and a revision all
place cards the same way, and nothing moves a node behind the renderer.
A drop records the existing `move` verb with `RecordAction`, ranked
among the neighbours the user saw.

**The drag** uses Pointer Events through Leaf's `onPress`, as Leaf's own
drags do; the board finds the slot under the pointer and scrolls at an
edge itself. SortableJS moves the card nodes; dnd-kit's feedback lifts
the dragged node into the top layer beside a placeholder; Pragmatic drag
and drop needs a `draggable` card, in which Firefox lets nobody select
words to comment on.

**The card** draws on both sides of the author's words, its grip in the
top corner and a phone's Move to buttons under the prose, so it draws in
a shadow root (browser/AGENTS.md, "Renderers"), with its rules in
`styles/card-shadow.css`. Its grip draws its face with `actionPress` and
states the board's key rows with `Keys`.

**What the port made easier.** The gesture logic is one `update` under
Story tests (`tests/runtime/lf-board-story.test.mjs`); only browser
tests covered it before.

**What a user sees differently.** The label under the pointer is fully
opaque, as `board.css` asks; Sortable's inline `opacity: 0.8` overrode
it. A screen reader reads a card's grip before its title. `leaf-dev
stills` shows no other difference.

**Also.** Margin layout now crosses the shadow tree of a pin's own
target instead of reading it whole as cover, which stood a card's
comment pin above the card; and it no longer measures what a `display:
none` element holds inside a box-less wrapper. `lf-suggestion` keeps its
margin entries and emphasis when a move carries its card to another
column (`connectedMoveCallback`, `StaticRange`); on main a moved
suggestion lost its emphasis.

**Bench**, ms of main-thread CPU at 256, before the card took its shadow
root (`leaf-dev bench cards boards --input move --input key --input
scroll --input revision --sizes 64,256 --rounds 3 --read cpu --base`):

| ms at 256 | 256 boards of 3 cards, base | head | one board of 512
cards, base | head |
|---|---|---|---|---|
| load | 1678 | 1828 | 744 | 876 |
| key | 6.1 | 6.3 | 5.3 | 5.2 |
| scroll | 7.3 | 7.2 | 4.7 | 5.3 |
| revision | 192 | 215 | 97 | 101 |
| move | 154 | 154 | 97 | 119 |

The extra load is one Effect UI component per card and, on a page with
no other Effect UI widget, the bundle's evaluation. A page whose only
Effect UI widget is a board now loads Effect UI (192 KB gzipped) instead
of Sortable (28 KB).

> _This was written by Claude Code on behalf of max-sixty_
@max-sixty

Copy link
Copy Markdown
Owner Author

#7573 has landed the board's port, with lf-card ported too and the drag held in the board's Model, so this draft is superseded.

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

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