Repository navigation
Port lf-toc to an Effect UI component, in TypeScript - #7457
Conversation
lf-toc is now an Effect UI component (lf-toc.ts, compiled to lf-toc.js) and toc-view.js, its Lit view, is gone. `inputs` reads the outline, each row's marks and the `open` attribute; the Model holds the reader's disclosure choice, whether the form stands the outline open, the row the reader is in and the rows the map leaves off. Three Mounts do the post-commit work: - FollowReading hears the headings cross the window's top half with an IntersectionObserver, and the scroller reach its end, in place of measuring every destination against the landing band on each scroll. - FitMap measures the reading map as the document, its destinations or the track change size, writes each row's place and the lens's scroll-driven keyframes, and reports the rows it leaves off the map. - FollowPosture hears the summary's box come and go, which says whether the form stands the outline open, in place of reading it at each measure. Behaviour that changed: - The window's half the current section is read against is the scroller's, not the landing band clear of the top chrome and the panel's row, and a section crosses it at its heading rather than its destination's top. - While every destination is hidden the start row stays current, where none was; the outline is hidden then, so the reader sees no difference. test_contents_with_every_destination_hidden_returns_when_the_disclosure_opens no longer asserts no aria-current while hidden. - A row keeps its nodes, and focus on its link, by its heading's authored id or else its destination's, which the heading keeps while it stands. A heading replaced in a place with neither authored id takes a new row. - A change that spans a section the map leaves off and the row above it counts twice in that row's preview. - The map's labels off the map wear `data-lf-toc-off`, which the Mount writes, in place of `data-lf-toc-shown`, which the view drew and the widget took off. The Lit drawing's node test in authored-capture.test.mjs goes, the browser suite covering what it held; toc-marks.test.mjs reads the outline with `readOutline`, and lf-toc-story.test.mjs covers the disclosure's update. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
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.
In a framed page, FollowReading measures the top half against the wrong window. With root: null, the IntersectionObserver's implicit root is the top-level browsing context's viewport, not the document the outline covers. So a Leaf page inside an lf-sample frame, such as a window sample, which scrolls inside itself, reads "the window's top half" as the parent's. If the frame sits in the parent's lower half, no heading ever intersects, and the current row falls back to the "above" rule whatever the reader is looking at. On top of that, entry.rootBounds is in the parent's coordinates while boundingClientRect is in the frame's, so above and top compare two different coordinate spaces. The code this replaces measured against the frame's own scroller band, so this is a regression for framed pages. margin-projection.js (watchNear) already passes root: document for the same reason ("rather than the top window a framed page stands in"). The inline suggestion makes that change. The served lf-toc.js needs the same one-line edit, or a rebuild.
The rest holds up. No package-interface name is added (leaf-dev interface --base shows none), and holdFocus, frameFor, the Lit view and the per-scroll measurement go away. check:browser reports the compiled module in sync, and pnpm run test:runtime passes (1225 tests).
…oice as the form opens the outline
FollowReading's IntersectionObserver took the top window's viewport as its implicit
root, so a page framed low in its host, as a window sample stands, read "the window's
top half" as the host's, and compared heading boxes in the frame's coordinates with
the host's bounds. Its root is now this document, as margin-projection's watchNear's
is. test_a_framed_page_s_current_section_is_read_against_its_own_window fails on the
old root.
FollowPosture now reports the disclosure's own open state as the form hides the
summary (Exposed{open}), and focus as it returns (Returned{keep}). A press's toggle is
a queued task the browser folds into the next toggle, so the form's opening could
overtake it and the reader's close was never heard, leaving the outline open on
return to flow; test_contents_disclosure_keeps_its_links_focus_and_open_state failed
there twice locally under load. A story covers the overtaken press.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
`leaf-dev bench contents` is `prose_sections(n)` in a sidebar whose track holds an lf-toc, so its rows, markers, fitting and reading position grow with the page; `page` takes the track a sidebar holds. No other generated page held lf-toc. What the port made easier (browser/AGENTS.md, "Renderers"): the disclosure's rules, the reader's choice against the forms that stand the outline open and the focused link that keeps it open on return, are now one `update` under Story tests (lf-toc-story.test.mjs), where they were split between the Lit view, the element's fields and a measure. A row keeps its nodes and focus by key, which retires holdFocus's restoring focus after a redraw. The reading position is an IntersectionObserver in a Mount rather than a measure of every destination on each scroll, and the module is typed. lf-toc.ts is 1121 lines against 1024 for lf-toc.js and toc-view.js, now with types. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
…o page link (#7505) Focus entering `main` and Go-to arming each restyled every link on the page again, so `test_entering_the_column_or_go_to_restyles_no_cell_or_link_it_passes` has failed on every push to `main` since #7457 (`{'20 rows': {'entering': 434, 'Go-to': 549}, '120 rows': {'entering': 534, 'Go-to': 649}}`: exactly one more restyle per row's link). The cause is the selector, not the port's `display: contents` wrappers. #7457 replaced `a[data-lf-toc-shown]` with `a:not([data-lf-toc-off])` in the two `toc.css` rules that let the map's labels take the pointer (one under `lf-toc:is(:hover, [data-lf-focus-within])`, one in the `body[data-lf-go-to-active]` scope). A `:not()` gives Chromium nothing to narrow its invalidation by, so the subject came down to the type `a`. When `main` gains `data-lf-focus-within` or `body` gains `data-lf-go-to-active`, Chromium restyles every `a` beneath it, whether or not the rule matches there. `browser/AGENTS.md`, "What a style rule costs", names this case and asks for a class only the targets carry. The subjects now read `.lf-toc-link:not([data-lf-toc-off])`. That class is on every label link the view draws (`lf-toc.ts`'s `link`) and on nothing else in the labels layer, so the rules match the same links and nothing on screen changes. Verification on the Tend runner: - The restyle test fails on `main` with the counts above and passes with this change. - The `lf-toc` label and reveal tests pass: `test_a_route_too_long_for_its_labels_leaves_its_deepest_level_off_the_map`, `test_the_outline_beside_the_body_marks_its_introduction_on_its_label`, and both directions of `test_a_contents_spine_rests_beside_the_prose_and_reveals_its_labels_over_it`. No other rule under `browser/` or `packages/` reads either mark before a type-only subject. Closes #7499 — automated triage --------- Co-authored-by: leaf-agent <[email protected]>
Requested by Maximilian · project thread
Ports
lf-tocfromLeafElementand Lit to an Effect UI component, written aslf-toc.tsand compiled to the servedlf-toc.js.toc-view.js, the Lit view, is deleted;toc-marks.jsstays as it was.inputsreads the outline (headings, destinations, lent ids), each row's marks from the threads, On Me and comparison readings, and theopenattribute. The Model holds the reader's disclosure choice, whether the form stands the outline open, the row the reader is in, and the rows the map leaves off. Three Mounts do the post-commit work:lf-layout,toggleandlf-presentation. It writes each row's place and the lens's scroll-driven keyframes, and reports the rows it leaves off the map. The fitting algorithm and the lens are unchanged.openis now controlled by the Model, which followstoggle. When the form hides the summary, the Mount reads the reader's choice from the disclosure itself, because the browser queuestoggleas a task it may fold into the form's opening.The registry schema (tag, attributes) is unchanged.
What the port made easier
This follows the port rule in
browser/AGENTS.md, "Renderers":updatecovered by Story tests (lf-toc-story.test.mjs). The rules are the reader's choice against the forms that stand the outline open, and the focused link that keeps it open on return. Before, they were split between the Lit view, the element's fields and a measure.holdFocus, which restored focus after a redraw.lf-toc.tsis 1121 lines, against 1024 forlf-toc.jsandtoc-view.jstogether.Bench
No generated page held
lf-toc, so this addscontentstoCOLLECTIONS:prose_sections(n)beside a sidebar track holding the outline. The figures come fromuv run leaf-dev bench contents --base(Chromium, base0ca1326against head4f68bd4) on a shared host at load 7 to 16. Scroll, key and resolve were read over 3 rounds, the rest over 1. These rows are the lowest reading:lf-tocfunction among its growing costs. Load's largest growing costs are the map's measuring (sizeOf) on both arms.Visible and behavioral differences
leaf-dev stills --base origin/mainoncontents-map-keyboard,contents-marks,contents-marks-changesandtopic-contentsshows no visible difference. The only style difference is the adapter'sdisplay: contentsbox around the nav. The differences are in behavior:aria-currentinstead of none. The outline is hidden then too, so nothing is perceivable. The hidden-destinations test no longer asserts "no aria-current while hidden". It still asserts the first revealed frame: no row off the map, start current.holdFocus), also matching by a lent id. Now a heading replaced by a new element, where neither it nor its destination has an authored id, gets a new row, and focus on its link is lost.data-lf-toc-off, written by the Mount. Before, the view drewdata-lf-toc-shownand the widget removed it.toc.cssand the tests follow. The empty outline is hidden vialf-toc:has(.lf-toc-nav[data-lf-toc-empty]), since the view can't set an attribute on the host.Checks
browser/types), the TypeScript build, pre-commit and the build tests ofpnpm run checknode --test:toc-marks,authored-captureand the newlf-toc-storylf-tocbrowser tests intest_contents_and_glosses.py(now with a framed page whose current section is read against its own window; it fails on the old root) andtest_render_toc_disclosure.py, plus thelf-toctests in go-to, aim, native layout, dial, initial delivery and render pages. All pass locally in Chromium and Firefox. WebKit isn't installed on this host.🤖 Generated with Claude Code
https://claude.ai/code/session_01V22NWd3erndyoj2G9LEP7y
Generated by Claude Code