Repository navigation
Conversation
…r owned by a Mount lf-code's numbered lines, elided rows, notes and toolbar are now an Effect UI component (`defineWidget`, `shadow: true`, `slotAssignment: "manual"`), styled by shadow parts from code.css. Each `lf-note` stays where the author wrote it and shows under its line through a slot of its own, so the widget no longer moves the author's notes or writes styles on them. Shiki runs in the `Color` mount. What the port made easier: the rows a block draws (excerpt numbering, elided rows, their captions, notes at the foot) are one pure function, `rowsOf`, and the wrap and notes keys are messages whose `KeepInTab` Commands a Story test asserts (tests/runtime/lf-code-story.test.mjs); before, each was reachable only through a browser test. The reader's wrap and notes choices are the Model, so the hand-written repaint of the notes toggle and its attribute are gone. Why a shadow root rather than a light-DOM part: a note reads between two drawn lines, and the light part stands after the authored children, so the note would come before every line in document order, the order selection, copy and a passage's quote read. Moving the note into the part takes it from where `inputs` and revisions find it. Shared modules: - effect-widget.ts: `slotAssignment` option, and `lfElementsFor` among the declarations. - syntax-tokens.ts: `synAttributes`, a token's colour as attributes. - stage-integration.ts: the layer's shadow rules are one adopted sheet every stage shares, in place of a `<style>` per stage, which cost about half a second of a 256-block page's profiled load. - bench.py: a `code` collection, a page of n lf-code blocks. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
…enderers hold 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.
Two points to settle alongside the performance question the description already raises.
Package interface. effect-widget.js is a public module ($public-modules). This PR adds two things to it: a slotAssignment option on defineWidget, and lfElementsFor among the keys declare accepts. Root AGENTS.md ("The maintainer decides", "Growing the package interface") makes each of these the maintainer's call. leaf-dev interface --base doesn't list either one, because it lists names, not options. So the description should name both as additions for the maintainer to approve, next to the perf trade-off, not under "Shared modules" as implementation detail.
Dead stage-integration contract. The stage integration now returns [] in every case. shadowStage in dom/shadow-stage.ts still threads that return value through setChildren(root, [...styles, ...nodes]). Its header still says "The host returns its retained style nodes so imperative staging keeps them alongside the rendering". No integration retains a node anymore, so the Node[] return type, the styles spread and that header sentence can go, and installStageIntegration can take (root: ShadowRoot) => void.
…urns now The shadow rules are an adopted sheet, so the integration retains no node in a stage and shadowStage has none to keep beside the rendering. Also hold that a block without notes stands Copy alone on its toolbar. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
# Conflicts: # dev/leaf_dev/commands/bench.py
…7542) `defineWidget` stops guessing. It no longer infers from DOM mutations when a component has drawn, or which node in a new parent is the row the user was on. Effect UI already keeps focus, typed words and the caret on every node a draw keeps. Where a draw Leaf starts replaces the user's row, the adapter's hold (`holdFocus`, keyed by `data-lf-datum` as on main) puts the user on the row now carrying that key, or its nearest neighbour, on the row itself rather than on a control picked by its look. Where nothing it knows stands, as when a removal empties the list, the user lands on the widget's element. The adapter's hold restores only while focus is lost and tries where the user last stood first, so a nested widget and its parent put the user in the same place; other holds are as on main. Also in this change: - `declare` sets every member Leaf reads off a widget's element (`DECLARED` in `effect-widget.ts`). - `lf-call-diff` and `lf-toc` leave a fold's `open` to the browser, so it stays where the user or a reveal left it. - Root `AGENTS.md` names the one case a widget keeps itself: a row it moves to another parent, written as a keep-alive child. `effect-widget.ts`'s header lists the limits, among them a parent's draw hiding a node that a nested widget's draw then restores, which lands the user on the parent, one Tab away. Max picked this rebuild on the Effect UI review page, with the `AGENTS.md` words; Codex reviewed it over seven rounds. `pnpm run test:runtime` (1240) and 13 focused browser tests pass. #7484 (`lf-code`'s port) adapts to `lfElementsFor` in `DECLARED` if it lands second. > _This was written by Claude Code on behalf of max-sixty_
Requested by Maximilian · project thread
This ports
lf-codefrom aLeafElementto an Effect UI component (defineWidget,shadow: true,slotAssignment: "manual"), followingbrowser/AGENTS.md, "Renderers". It is slower than the Lit block on a large page: about 17% on load and 38% on resolving a comment at 256 blocks (numbers below). By the rule, that means it shouldn't land as it stands. It is open so the maintainer can decide.It also grows the package interface.
effect-widget.jsis a public module, and this PR adds to it, which is the maintainer's call (rootAGENTS.md, "Growing the package interface"):slotAssignmentoption ondefineWidget("manual"lets a Mount assign each authored child to a slot of its own);lfElementsForamong the keysdeclareaccepts.What changed
frame,source,row/line/elided(withhi,at,folded,wrap/scroll),note,captionandbar.lf-notestays where the author wrote it and shows under its line through a slot of its own, which theAssignmount fills withslot.assign. The widget no longer moves notes or writes styles on them.Colormount. It holds Leaf's presentation (pending-task) until the coloured lines are drawn.wandnkeys send messages, and each message'sKeepInTabCommand records the choice.rowsOf. That function and the key Commands are covered by a Story test (tests/runtime/lf-code-story.test.mjs); before, only browser tests reached them.ordermoves only the paint. Moving the note into the part would take it from whereinputsand revisions look for it. The header says this.verbatim. The registry doesn't need it forlf-note.lf-notehas no module and isn't upgraded, andlf-codewas already opaque.lf-optionneeded it only because it became an upgraded element.Shared modules
effect-widget.ts: the two additions above, and a failed root with manual slots assigns all of its children to the fallback slot.syntax-tokens.ts:synAttributes, which gives a token's colour as attributes.stage-integration.ts: every stage now shares one adopted sheet of the layer's shadow rules, first among its adopted sheets. This replaces a<style>per stage, which cost about 0.5 s of profiled load on a page of 256 blocks. It applies to every shadow widget,lf-optionsincluded. The integration therefore retains no node, soinstallStageIntegrationtakes a function that returns nothing, andshadowStage(dom/shadow-stage.ts) no longer keeps style nodes beside the rendering.bench.py: acodecollection, a page of nlf-codeblocks, each with a highlighted line and two notes.Bench
Command:
leaf-dev bench code --rounds 3 --base origin/main(Chromium). Each cell is the lowest of 3 rounds, in ms of main-thread CPU unless the row says otherwise. Each cell reads base → head. Other suites were running on the host at the same time.Load grows at about the same exponent in both arms (1.04 base, 1.06 head), so the cost per block is higher rather than the growth worse. Before the shared sheet, load at 256 was 3817 → 4537 in a noisier run. The remaining cost, read from CPU profiles at 256:
nearWindow(Copy'sanchorControl) andlayoutWindow(the margin'swindowHoldsRail) are the largest items.effect-ui.jsitself adds about 0.3 s.frame-pass.js passforces layout for about 260 ms, against 60 ms on base.I didn't find the cause of the higher forced-layout cost. Batching each stage's first arrivals into one microtask cut the 256 calls to Copy's
prepareDeclaredBlocksto one, but load didn't move, so I reverted it.Visible and behavioural differences
::part, for example#id::part(line). There is nolf-renderedclass;:definedtakes its place.wpress reads whether lines wrap from the drawn line's computed style. A page's later CSS therefore counts as the default the first press turns the other way.lfBar), even with no notes. Copy beside the block hangs from an anchor named in the document, which a control inside the shadow tree doesn't find.getSelection().toString()leaves out the slotted notes. A real copy (Ctrl+C) includes them, and the excerpt test now reads the clipboard.::part(source)rather than the reading face.::afterscroll clearance is gone, so a block with a note at its foot ends about 13 px sooner. This shows inwalkthrough-code,walkthrough-copy-*andcode-reader-feedbackfromleaf-dev stills --base.native-code,annotated-codeandnative-code-copy-hovershow 0 px of change, only computed-style differences on the host.Tests
tests/browser/widgets/test_code_and_documents.pyandtests/journeys/test_render_code_reading.py, and in the stills states indev/leaf_dev/states.py.MOVINGprobe now walks open shadow trees and skips authored children that a shadow tree shows nowhere. Those have no computed style to read.a894fd6), run locally by node id.tests/journeys/widgets/test_code_and_documents.py::test_a_long_text_document_draws_the_lines_in_view_and_keeps_the_rest_wholetests/browser/widgets/test_diffs.py::test_print_wraps_diff_lines_and_keeps_file_headers_in_place🤖 Generated with Claude Code
https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
Generated by Claude Code