Skip to content

Draw the contents map's spine and markers in their first frame - #3931

Merged
max-sixty merged 3 commits into
mainfrom
fix/toc-map-first-frame
Oct 25, 2026
Merged

max-sixty merged 3 commits into
mainfrom
fix/toc-map-first-frame

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

In the margin, lf-toc's map showed nothing until its module upgraded: the initial drawing gave the widget its final box and rows, but the disclosure holding them stayed closed until the module opened it, so the spine and its markers first appeared at upgrade. Opening it earlier would not have been enough, since each row's flex share and each crowded label's fitted shift came from the module's own measurement.

The map's layout now lives in the drawing both renderers share (toc-view.js): the disclosure's posture (posture, with the in-flow open choice it holds), each row's span, and the label fitting that shifts crowded markers (measure, fitLabels). The initial renderer lays the map out once the document has parsed, and the module lays it out again whenever the document moves, keeping only the lens and the current entry.

That exposed a second difference. .lf-ui's box-sizing: border-box reset lived in runtime/chrome.css, which the document adopts only at boot, so before upgrade the map's title label measured content-box, fitted one line, and after upgrade wrapped onto two, moving the title's marker 14px. The reset now stands in the render-blocking theme (components/surfaces.css), under :where(:root) like the face beside it, so it reaches the same document elements as before and no declared shadow tree. On the feature gallery after upgrade, every one of 4,240 elements computes the same box-sizing on main and with this change; the reset is now layered, and no Leaf rule sets another box-sizing on a .lf-ui element.

Evidence: test_the_reading_map_first_paints_its_spine_where_it_keeps_it holds leaf.js and checks that the margin map is open with a marker per section at its section's share of the page, and that the upgrade leaves every marker where it stood. It fails on main (the disclosure is closed at first paint) and passes with this change in Chromium, Firefox and WebKit. A probe of the same page loads the same 41 requests before presentation on main and with this change.

Ran: the lf-toc tests in test_contents_and_glosses.py, test_render_initial_delivery.py, test_initial_drawings_keep_their_nodes_and_wrapped_geometry_on_upgrade, the widget quality checks for every package, tests/model/test_interact_layer.py, test_a_coined_class_cannot_reach_the_chromes_rules, pnpm run test:runtime and pnpm run check:browser.

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

In the margin, `lf-toc`'s map showed nothing until its module upgraded: the initial drawing gave the widget its final box and rows, but the disclosure holding them stayed closed until the module opened it, so the spine and its markers first appeared at upgrade. Opening it earlier would not have been enough, since each row's flex share and each crowded label's fitted shift came from the module's own measurement.

The map's layout now lives in the drawing both renderers share (`toc-view.js`): the disclosure's posture (`posture`, with the in-flow open choice it holds), each row's span, and the label fitting that shifts crowded markers (`measure`, `fitLabels`). The initial renderer lays the map out once the document has parsed, and the module lays it out again whenever the document moves, keeping only the lens and the current entry.

That exposed a second difference. `.lf-ui`'s `box-sizing: border-box` reset lived in `runtime/chrome.css`, which the document adopts only at boot, so before upgrade the map's title label measured content-box, fitted one line, and after upgrade wrapped onto two, moving the title's marker 14px. The reset now stands in the render-blocking theme (`components/surfaces.css`), under `:where(:root)` like the face beside it, so it reaches the same document elements as before and no declared shadow tree. On the feature gallery after upgrade, every one of 4,240 elements computes the same `box-sizing` on main and with this change; the reset is now layered, and no Leaf rule sets another `box-sizing` on a `.lf-ui` element.

Evidence: `test_the_reading_map_first_paints_its_spine_where_it_keeps_it` holds `leaf.js` and checks that the margin map is open with a marker per section at its section's share of the page, and that the upgrade leaves every marker where it stood. It fails on main (the disclosure is closed at first paint) and passes with this change in Chromium, Firefox and WebKit. A probe of the same page loads the same 41 requests before presentation on main and with this change.

Ran: the `lf-toc` tests in `test_contents_and_glosses.py`, `test_render_initial_delivery.py`, `test_initial_drawings_keep_their_nodes_and_wrapped_geometry_on_upgrade`, the widget quality checks for every package, `tests/model/test_interact_layer.py`, `test_a_coined_class_cannot_reach_the_chromes_rules`, `pnpm run test:runtime` and `pnpm run check:browser`.

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

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Oct 25, 2026
The comment on `fitLabels` now says which labels compact the map and which open it as an outline.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 8143581 into main Oct 25, 2026
3 checks passed
@max-sixty
max-sixty deleted the fix/toc-map-first-frame branch October 25, 2026 15:16
max-sixty added a commit that referenced this pull request Oct 27, 2026
Reverts #3931 (8143581), which laid out `lf-toc`'s margin map (its
open disclosure, each row's share of the page and the fitted labels) in
the initial drawing, before the module upgrades.

**Why.** The theme's pre-upgrade rule, `html[data-lf-interactive]
body:not([data-lf-upgraded]) > main .lf-ui {visibility: hidden
!important}`, hides every row and marker of that map until upgrade, so
the early layout drew nothing a reader could see. The user chose to keep
that rule and take the early layout out rather than narrow the rule
(#3962): the map keeps appearing when the page's code loads.

**What it removes.** 477 lines deleted and 200 added, net −277:

| | added | deleted |
|---|---:|---:|
| Hand-written source and test | 191 | 300 |
| Generated (`lf-toc-initial.js` bundle, `shadow.css`,
`runtime/chrome.css`) | 9 | 177 |

- The layout (`posture`, `measure`, `fitLabels`) moves back from
`toc-view.js` into `widgets/lf-toc.js`, and `initial/lf-toc.js` again
only draws the outline.
- `.lf-ui`'s `box-sizing` reset returns from the render-blocking theme
(`components/surfaces.css`) to `styles/chrome.css`, where it stood
before #3931 moved it for the early measurement.
- `test_the_reading_map_first_paints_its_spine_where_it_keeps_it` goes
with the behavior it held.

No later commit built on the reverted code. Two files conflicted. In
`TODO.md`, #3931 had deleted the "Draw the contents map's spine in its
first frame" item; the backlog has since moved to issues, and the user
decided against the feature, so the item is not restored. In the test
file, main had since changed the deleted test's teardown.

**Verified.**

- `pnpm run build:browser` leaves the committed bundles unchanged, and
`pnpm run check` passes.
- The `lf-toc` tests in `test_contents_and_glosses.py` pass in Chromium.
In Firefox, through a temporary fixture override, the same three tests
fail on this branch and on the base, and none of them is about the map.
- `test_render_initial_delivery.py`,
`test_initial_drawings_keep_their_nodes_and_wrapped_geometry_on_upgrade`,
`test_bundled_widgets_meet_the_widget_quality_checks`,
`tests/model/test_interact_layer.py` and
`test_a_coined_class_cannot_reach_the_chromes_rules` pass.
- `leaf-dev probe docs/extending.html --base` at 1440x900, in Chromium
and Firefox. After upgrade, the map's seven markers stand at the same
positions on both arms, and the viewport stills are pixel-identical.
With `leaf.js` held, every row and marker computes `visibility: hidden`
on both arms in both engines, and Chromium's held stills are
pixel-identical. The one difference is invisible: on this branch the
held map's disclosure is closed and its hidden markers are evenly
spaced.

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

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.

2 participants