Skip to content

Name the track's element in the contents map's scope, so a write no longer restyles the whole page - #5363

Merged
max-sixty merged 1 commit into
mainfrom
agent-aa9e1c6c855e164e3
Nov 4, 2026
Merged

max-sixty merged 1 commit into
mainfrom
agent-aa9e1c6c855e164e3

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

#5309 moved a track's status line clear of the contents map's spine with @scope (:has(> lf-toc)) { :scope > :not(lf-toc) { … } }. In Chromium, a :has() that is its compound's only selector, standing as a scope's root or leading to a subject that names no element, makes any write to an element's text, or to an attribute another :has() reads, restyle the whole document. The rule cost that on every page, including pages it never matches. On the asks page of leaf-dev scaling at 64 sections, a Tab that showed six key badges ran 16 style recalcs, each restyling the whole page: 938 ms of recalc in a trace, against 26 ms at #5309's parent. Most of those recalcs are forced by the key badge loop in command-hints.js, which measures each badge right after writing it.

The scope's root is now div:has(> lf-toc), the track's element in page-layout.md, page-authoring.md and every example. Behavior change: a track written as another element, such as <section class="layout-track">, leaves its status line on the spine again. lf-toc ~ :not(lf-toc) places the status the same way in every case the references and #5309's test describe, with no :has(), but Chromium matches it by reading each child's earlier siblings: a full restyle of a 4,000-paragraph column took 30 ms against 2.5 ms for the typed scope, and 438 ms against 10 ms at 16,000.

test_an_untyped_has_leads_only_to_a_typed_subject refuses the shape in every shipped stylesheet. A :has() that is its compound's only selector, with no compound naming an element before it, may not be an @scope root, and may lead only to a subject that names a type, class, id or attribute. It flags nothing else in the shipped CSS today. With the old rule restored it names toc.css, and it names each shape a Chromium trace showed restyling the whole document (:has() > :not(.y), :is(:has()) > *, :not(:has()) :first-child, :has() ~ *) while passing those that stayed local (:has() > pre, .a :has() > *, div:has() > *, @scope (div) to (:has())).

Main-thread CPU on the asks page, two rounds interleaved against main
9164433 (Tab: median of six Tabs from load; click: median of four clicks on an option):

main this
Tab, 64 sections 395 / 678 ms 70 / 57 ms
Tab, 512 sections 4.61 / 3.60 s 517 / 281 ms
Click, 64 sections 291 / 438 ms 73 / 67 ms
Click, 512 sections 3.39 / 1.56 s 517 / 284 ms

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

…onger restyles the whole page

#5309 moved a track's status line clear of the contents map's spine with
`@scope (:has(> lf-toc)) { :scope > :not(lf-toc) { … } }`. In Chromium, a
`:has()` that is its compound's only selector, standing as a scope's root
or leading to a subject that names no element, makes any write to an
element's text, or to an attribute another `:has()` reads, restyle the
whole document. The rule cost that on every page, including pages it
never matches. On the `asks` page of `leaf-dev scaling` at 64 sections,
a Tab that showed six key badges ran 16 style recalcs, each restyling the
whole page: 938 ms of recalc in a trace, against 26 ms at #5309's
parent. Most of those
recalcs are forced by the key badge loop in `command-hints.js`, which
measures each badge right after writing it.

The scope's root is now `div:has(> lf-toc)`, the track's element in
page-layout.md, page-authoring.md and every example. Behavior change: a
track written as another element, such as `<section class="layout-track">`,
leaves its status line on the spine again. `lf-toc ~ :not(lf-toc)` places
the status the same way in every case the references and #5309's test
describe, with no `:has()`, but Chromium matches it by reading each
child's earlier siblings: a full restyle of a 4,000-paragraph column took
30 ms against 2.5 ms for the typed scope, and 438 ms against 10 ms at
16,000.

`test_an_untyped_has_leads_only_to_a_typed_subject` refuses the shape in
every shipped stylesheet. A `:has()` that is its compound's only selector,
with no compound naming an element before it, may not be an `@scope`
root, and may lead only to a subject that names a type, class, id or
attribute. It flags nothing else in the shipped CSS today. With the old
rule restored it names toc.css, and it names each shape a Chromium trace
showed restyling the whole document (`:has() > :not(.y)`,
`:is(:has()) > *`, `:not(:has()) :first-child`, `:has() ~ *`) while passing
those that stayed local (`:has() > pre`, `.a :has() > *`,
`div:has() > *`, `@scope (div) to (:has())`).

Main-thread CPU on the `asks` page, two rounds interleaved against main
9164433 (Tab: median of six Tabs from load; click: median of four
clicks on an option):

| | main | this |
|---|---|---|
| Tab, 64 sections | 395 / 678 ms | 70 / 57 ms |
| Tab, 512 sections | 4.61 / 3.60 s | 517 / 281 ms |
| Click, 64 sections | 291 / 438 ms | 73 / 67 ms |
| Click, 512 sections | 3.39 / 1.56 s | 517 / 284 ms |

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

@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.

Rooting the scope at div ties the margin to an element type the references never promise. page-layout.md ("A sidebar page") defines the track by its class: "the sidebar's layout-track holds everything that should stick and scroll together", and it tells authors to "Style its blocks by their classes or ids, or as .layout-track > p". The div only appears in the examples. So an author who writes <section class="layout-track"> gets a track that sticks and scrolls, but its status line silently sits back on the spine, where a press on its first words opens the map. This PR accepts that as its behavior change.

.layout-track:has(> lf-toc) avoids the trade. The rule's container query requires --lf-sidebar-slot: margin, which layouts.css sets only on .layout-sidebar:has(> .layout-column) > aside > .layout-track, so the class root covers every track the rule can apply to, whatever its element. It names a class, which the new test already counts as naming an element, so it should stay local just as div does. Your trace covered div:has() and .a :has() > *, so one trace of the class root on the asks page would confirm it. I checked that the new test passes with the class root, and that it still names toc.css with the old root restored. If you take the suggestion, the PR description's "Behavior change" paragraph goes too.

Comment thread packages/default/styles/toc.css Resolved

@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.

My one finding is withdrawn. CI is green at 0ed6a00.

@max-sixty
max-sixty merged commit 9328f61 into main Nov 4, 2026
7 checks passed
@max-sixty
max-sixty deleted the agent-aa9e1c6c855e164e3 branch November 4, 2026 11:30
max-sixty added a commit that referenced this pull request Nov 4, 2026
…ne layout for its faces (#5366)

`paint` in command-hints.js lent each route's face, read it, then wore
or withheld it before moving to the next route, so each face it lent
forced two style recalcs and a layout. #5309 showed what that costs:
under a rule that widened every restyle to the whole page, a Tab that
lent six faces spent 715 ms in the loop's 11 recalcs (root AGENTS.md,
"Responsiveness").

The faces now go in passes over every route: which controls the window
shows, then each face lent, then each face read as it stands, then each
worn or withheld. The chips read where each goes before writing any
digit, and the badge placement writes each chip's visibility once every
chip is placed; a chip takes no presses, so none was in the stack
another chip's place reads.

With every face lent before any is read, a face lent in the same pass no
longer counts as covering another. `reserve` already gives two faces
whose boxes overlap to the earlier route. Before, whether one face
covered another depended on paint order: an earlier route's face always
did, and a later one only while still lent from the previous paint, so
two faces over each other could both be withheld. None of the pages
compared below shows a case where the two orders differ.

Every face's digit, worn state, opacity, display and box, and every
command chip's digit, visibility and box, matched main after each of 15
inputs (Tabs, Shift+Tab, `m` and `t` walks, option focus) on the `asks`
page of `leaf-dev scaling` at 8 and 64 sections, alert-review,
release-notes, heat-loss, and the developer deck, feature gallery and
playground (`leaf-dev probe --base`, reduced motion; 527 face and 24
chip readings).

A hit test names a shadow tree's host for whatever that tree holds, so a
host over a face is now read again inside its tree: it covers the face
unless all its tree holds there is faces lent in the same pass. Without
that, a later route's face in a shadow tree, lent before the earlier
face was read, covered it through its host and took the slot `reserve`
gives the earlier route (`an earlier route keeps its face under a later
route's face in another shadow tree`, a runtime test).

On the `asks` page at 64 sections, a Tab that lends six faces ran 18
style recalcs and 7 layouts on main, 11 and 6 of them forced by the hint
loop; it now runs 8 and 2, 1 and 1 of them the loop's. A Tab that lends
none is unchanged. Main-thread CPU, two rounds interleaved against main
9328f61, moved within the host's noise now that #5363 keeps each
recalc local (Tab: median of six Tabs from load; click: median of four):

| | main | this |
|---|---|---|
| Tab, 64 sections | 43 / 42 ms | 43 / 33 ms |
| The Tab lending six faces, 64 sections | 51 / 50 ms | 40 / 34 ms |
| Tab, 512 sections | 272 / 160 ms | 220 / 224 ms |
| Click, 64 sections | 60 / 54 ms | 53 / 51 ms |
| Click, 512 sections | 302 / 210 ms | 243 / 259 ms |

Tests: `pnpm run test:runtime` (782 passed), `pnpm run check:browser`,
and the 29 browser tests that read binding faces or chips, in
test_command_routes, test_card_placement, test_clusters, test_pins,
test_obligation_walk, test_render_options, test_render_options_addition,
test_render_widgets and test_obligations (33 cases passed).

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit that referenced this pull request Nov 4, 2026
…hrome no longer restyles the page (#5370)

On the 512-section asks page of `leaf-dev scaling`, most of a wheel
step's main thread went to restyling the page. Each heading that
scrolled under the pointer showed its link, the link moved into the
chrome, and Chromium restyled 20,255 of the page's 28,335 elements. The
rule behind it is toc.css's `@scope (div:has(> lf-toc))` from #5363.
Chromium tests a scope root's `:has()` on every element the rest of its
compound matches, here every `div`, the chrome's among them, and adding
or removing a node inside any of them restyled the page. Bisecting the
shipped sheets rule by rule found that rule alone.

The block after the map now clears the spine by `lf-toc + *`, which asks
only for the element just before each one. Behavior change: a second
loose block in the track stands by the spine; page-layout.md's sidebar
holds the map and one block, page-authoring.md asks for a short status,
and a page with several blocks wraps them in one element, which
page-layout.md, "A sidebar page", now states. Each wider form costs
pages with no map as well: `lf-toc ~ :not(lf-toc)` reads every earlier
sibling for each element tested, and a full restyle of a column of 4,000
paragraphs took 82 ms against 54 ms with no rule, and 55 ms with `lf-toc
+ *`. Naming the track's class in the scope would have the default
package read a Layout
(`test_layout_style_and_widgets_never_read_each_other`).

annotation-chrome.css's `html:has(.lf-margin-preview
leaf-text:focus-within, …)` goes too. Chromium matched its argument
against the document again at each write in the chrome, which took about
5 ms of style recalc instead of 1 ms. floating.js now writes
`data-lf-floating-editor` on the root while the user is in a `leaf-text`
inside a box it stands in a plane, read as the user moves and as a box
takes or leaves its plane, and the root's scroll padding drops on it as
before. Checked in the response bar and in a thread's card: set while
the user writes, cleared when focus moves to the card's Close and on
Escape.

`test_an_untyped_has_leads_only_to_a_typed_subject` now also refuses an
`@scope` root whose `:has()` names its element by a type alone. With the
old rule put back it names toc.css.

Against main 9328f61 on the 512-section asks page, interleaved, a
fresh tab each:

| | main | this |
|---|---|---|
| A node added to the chrome and removed: style recalc, largest restyle
| 182.6 ms, 20,199 elements | 1.5 ms, 27 elements |
| A heading hover: style recalc, largest restyle | 93.7 ms, 20,255
elements | 2.0 ms, 58 elements |
| A `leaf-dev scaling` wheel step, pointer at 400, 400: main thread,
style recalc | 60.7 ms, 28.3 ms | 33.4 ms, 1.9 ms |

Medians of 3 rounds for the first two rows and 5 for the wheel step.
Style recalc was 47% of the step and is now 6%. #5309's
`test_a_status_line_in_the_map_s_track_stands_clear_of_its_spine`
passes, and fails with the rule removed.

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

---------

Co-authored-by: leaf-agent <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 7, 2026
In margin form the contents map was a fixed 24px spine that revealed its labels over
the body on hover, focus or the go-to sequence. Drawing outside the box its Layout
gave it took a patch on each side: the sidebar Layout stacked its aside over the
body and isolated the body (#5117), toc.css pushed the next block in the track
clear of the spine (#5309, reworked in #5363 and #5370), the render gate exempted a
"resting overlay" from its width floor (#3109), and the sidebar's reserved width
stood blank beside the spine (#5619).

The map is now an ordinary block in its track, with its labels always shown at the
track's width. It keeps the proportional rows, the markers and the lens, and sticks
with the track. Its height fits the stuck track at the document's end, so the map's
start never leaves the window.

Removed: the aside z-index and body isolation in layouts.css, the reveal machinery
in toc.css (hover/focus/go-to widening, the press strip, pointer-events toggling,
the label fade, the `lf-toc + :not(.lf-ui)` clearance rule), and `restsOverPage` in
the render checks.

Behavior changes the tests now hold:
- The map no longer rests as a bare spine; its labels always show, and a press on a
  label follows it directly.
- A block after the map in the track follows it below and is reached by scrolling
  the track (was: beside the map at the track's top, clear of the spine).
- Long labels wrap at the track's width (was ~320px), so close sections pack one
  label apart sooner.
- Once its sidebar ends, the map scrolls away with it, as any sticky block does.

Tests: reveal and overlay assertions rewritten to the in-track map; the overlay
stacking test, the resting-spine render-gate test and the contents-over-reading
state are deleted; contents-spine-keyboard is renamed contents-map-keyboard.

Closes #5619

Co-Authored-By: Claude <[email protected]>
leaf-agent added a commit that referenced this pull request Nov 7, 2026
The contents map in a document sidebar is now an ordinary block in its
track, with its labels always shown, instead of a fixed 24px spine that
revealed labels over the body on hover. That deletes the overlay and the
patches each side carried for it, and the sidebar's reserved width now
holds the labels instead of standing blank (#5619). Approved direction:
[#5619
(comment)](#5619 (comment)).

**Before** (`contents-map-keyboard`, 1440×900, focus on a map link): the
labels lie over the first words of the prose.


![Before](https://github.com/user-attachments/assets/6f8dfbe7-3976-42e1-892e-35afa111b033)

**After**: the same map in its own track. Nothing covers the prose, and
the column starts where it did.


![After](https://github.com/user-attachments/assets/1539b02b-af76-4a06-8a51-842ff6dac939)

**Removed**
- `layouts.css`: the aside's `z-index` and the body's `isolation`, which
existed only so the revealed labels covered the body (#5117).
- `toc.css`: the reveal machinery (`:hover` / `[data-lf-focus-within]` /
go-to widening, the press strip on the spine, `pointer-events` toggling,
the label fade) and the `lf-toc + :not(.lf-ui)` clearance rule with its
restyle-cost notes (#5309, #5363, #5370).
- Render checks: `restsOverPage`, the resting-overlay exemption from the
width floor and from the margin readings (#3109).

**What users see change**
- No quiet resting state: the labels always show, and pressing a label
follows it directly.
- The map's height fits the stuck track at the document's end, so its
start stays in the window (about 700px at a 900px window, was 828). Once
its sidebar ends, the map scrolls away with it, as any sticky block
does.
- A block after the map in the track now follows it below, where
scrolling the track reaches it. Before, it stood at the track's top
beside the spine. `page-layout.md` and `page-authoring.md` now say this
and suggest putting a status the reader should see at once at the top of
the body. No example or `docs/` page puts anything after the map.
- Labels wrap at the track's width (~210px, was ~320px), so close
sections pack together one label apart sooner.

`--lf-sidebar-slot` stays. It still tells the map (margin) apart from
the open outline (beside); merging the two is a separate call.

**Verification**: I ran these locally and they pass: the rewritten
journey
`test_a_margin_table_of_contents_maps_the_document_in_its_track`,
`tests/browser/test_render_toc_disclosure.py`, the contents tests in
`test_contents_and_glosses.py`, the go-to hints test, and the render
gate on `sidebar-contents`. The npm-based gates (`pnpm run check`,
prettier, eslint) have no `node_modules` in this sandbox, so they're
left to CI.

<details><summary>Test changes</summary>

- Rewritten to the in-track map: the margin-map journey (the reveal,
hover and spine-width steps are gone; it now checks the map stays clear
of the body, stays put while its track is stuck, and stays clear of the
panel's room), the history, hidden-sidebar and crowded-map tests, the
"map only beside the body" test, and the go-to hints test.
- The status-line test now asserts the status follows the map and a
press on it reaches it.
- Deleted, since their subject is gone:
`test_the_revealed_margin_map_covers_every_box_the_body_paints` and
`test_the_gate_passes_a_contents_map_resting_as_its_spine`.
- Stills: `contents-over-reading` is deleted, and
`contents-spine-keyboard` is renamed `contents-map-keyboard`.

</details>

Closes #5619

---------

Co-authored-by: leaf-agent <[email protected]>
Co-authored-by: Claude <[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