Skip to content

Lend a heading one of two anchor names while its link shows, so reaching a heading runs no margin pass - #5379

Merged
max-sixty merged 2 commits into
mainfrom
agent-a6d0b8b87e0014cfc
Nov 4, 2026
Merged

max-sixty merged 2 commits into
mainfrom
agent-a6d0b8b87e0014cfc

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

The first time the pointer reached a heading, by a move or by a wheel step that scrolled one under it, the heading's link wrote an anchor name into the heading's inline style (anchor-name: --lf-aN). The margin's page observer hears every style change on a page box as a possible geometry change, so each such heading ran a full margin layout pass, about 108 ms at 512 sections of the asks page.

What changes

A shown link's heading borrows one of two constant names. marks.css names a box carrying data-lf-heading-link="1" or "2" as --lf-heading-link-1 or --lf-heading-link-2, and the link's control stands by that name. The attribute joins the runtime's paint attributes (page-paint.js), outside the margin observer's attributeFilter, so writing it restyles the heading alone. A link shows for two headings at most, the one under the pointer and the one the user is on, and nothing fades, so two names suffice: a link takes a free one as it shows and gives it back as it hides. A hidden link's control has no anchor, where before it stayed anchored to its heading at opacity 0.

Focus in a link's control counts as being on its heading. A press focuses the control's button in Chromium and Firefox, and the theme keeps a focused control shown after the pointer leaves. That showing now holds the heading's name too, so the control stays beside its heading.

A heading named already keeps its names. A rule can't add a name to the ones a box has, so a heading its author named, or one another owner named in its style, takes the link's name through its style as before (anchorReading), one heard write on its first showing, as on main. When another owner names a heading while it holds a lent name, as the anchored comment box does for words selected in it, anchorReading merges the lent name into the heading's style; giving the name back takes it out again. Without that, the next heading lent the same name could anchor to the earlier one.

A heading's names are read each time its link starts to show, not once when the control is made, so a heading a stylesheet starts naming later (a media query, a revision) keeps the author's name and the link adds its own beside it, where on main the link's inline name hid the author's. A third request for a lent name throws rather than taking a held one; no path reaches it.

block-controls.js splits watchNear, the near-window watch, out of anchorControl, so the heading's link watches its block without naming it.

Evidence

Margin passes, counted with a breakpoint on layoutMountedRows that never pauses, on the asks scaling page; main is 0da1f29.

input main 64 head 64 main 512 head 512
10 wheel steps, each bringing a new h2 under the pointer 10 0 10 0
10 hovers over headings not reached before 6 0 6 0
words selected in a paragraph 1 1 1 1
words selected in a heading the pointer is on 1 2 1 2

The last row is the merged name being taken out of the heading's style when the pointer leaves; a paragraph's row is the comment box naming the paragraph, on both.

Main-thread CPU per wheel step (threadTicks, less the page's idle rate), four rounds alternating main and head under taskpolicy -c utility, pooled:

wheel size main median / max head median / max
leaf-dev scaling's steps (height/30, pointer at 400,400), 120 64 4.8 / 37.9 ms 5.2 / 15.6 ms
same 512 12.5 / 202.1 ms, 13 over 60 ms 11.7 / 82.2 ms, 2 over 60 ms
a new h2 under the pointer each step, 40 64 27.4 / 44.4 ms 8.8 / 20.4 ms
same 512 121.0 / 206.8 ms 20.4 / 55.1 ms

Checks

  • Each shown link's box equals main's in 25 states (hovers over h2, h3, a wrapped heading, an author-named and an inline-named heading, each again after its link exists; the user on one heading with the pointer on another; a press then the pointer away; another owner naming a shown heading), in Chromium, Firefox and WebKit at 1440 px, and in Chromium and Firefox at 700 px, where the link stands at the heading's far end. The author's box anchored to the named heading stays put throughout.
  • test_each_shown_link_stands_by_its_heading covers two links at once, a press, an author-named heading and a box anchored to a shown heading. It fails with one name, with focus in the control not counted, with the author's name ignored, and without taking the merged name back out.
  • The heading-link tests pass, test_a_heading_copies_the_link_to_the_section_it_opens included, which also passes on main at 0da1f29. The code copy anchor tests, test_render_code_reading.py, the recording bar tests and the margin's authored-anchor-name pin tests pass.
  • pnpm run test:runtime passes 812 tests, and pnpm run check:browser passes.

A Codex review found the two-name pool sound; its one finding, the read-once ownership above, is fixed with a test.

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

…ing a heading runs no margin pass

The first time the pointer reached a heading, by a move or by a wheel step that
scrolled one under it, the heading's link wrote an anchor name into the
heading's inline style (`anchor-name: --lf-aN`). The margin's page observer
hears every `style` change on a page box as a possible geometry change, so each
such heading ran a full margin layout pass, about 108 ms at 512 sections of the
`asks` page.

## What changes

**A shown link's heading borrows one of two constant names.** marks.css names a
box carrying `data-lf-heading-link="1"` or `"2"` as `--lf-heading-link-1` or
`--lf-heading-link-2`, and the link's control stands by that name. The
attribute joins the runtime's paint attributes (`page-paint.js`), outside the
margin observer's `attributeFilter`, so writing it restyles the heading alone.
A link shows for two headings at most, the one under the pointer and the one
the user is on, and nothing fades, so two names suffice: a link takes a free one
as it shows and gives it back as it hides. A hidden link's control has no
anchor, where before it stayed anchored to its heading at opacity 0.

**Focus in a link's control counts as being on its heading.** A press focuses
the control's button in Chromium and Firefox, and the theme keeps a focused
control shown after the pointer leaves. That showing now holds the heading's
name too, so the control stays beside its heading.

**A heading named already keeps its names.** A rule can't add a name to the
ones a box has, so a heading its author named, or one another owner named in
its style, takes the link's name through its style as before
(`anchorReading`), one heard write on its first showing, as on main. When
another owner names a heading while it holds a lent name, as the anchored
comment box does for words selected in it, `anchorReading` merges the lent name
into the heading's style; giving the name back takes it out again. Without that,
the next heading lent the same name could anchor to the earlier one.

`block-controls.js` splits `watchNear`, the near-window watch, out of
`anchorControl`, so the heading's link watches its block without naming it.

## Evidence

Margin passes, counted with a breakpoint on `layoutMountedRows` that never
pauses, on the `asks` scaling page; main is 0da1f29.

| input | main 64 | head 64 | main 512 | head 512 |
|---|---|---|---|---|
| 10 wheel steps, each bringing a new `h2` under the pointer | 10 | 0 | 10 | 0 |
| 10 hovers over headings not reached before | 6 | 0 | 6 | 0 |
| words selected in a paragraph | 1 | 1 | 1 | 1 |
| words selected in a heading the pointer is on | 1 | 2 | 1 | 2 |

The last row is the merged name being taken out of the heading's style when the
pointer leaves; a paragraph's row is the comment box naming the paragraph, on
both.

Main-thread CPU per wheel step (threadTicks, less the page's idle rate), four
rounds alternating main and head under `taskpolicy -c utility`, pooled:

| wheel | size | main median / max | head median / max |
|---|---|---|---|
| `leaf-dev scaling`'s steps (height/30, pointer at 400,400), 120 | 64 | 4.8 / 37.9 ms | 5.2 / 15.6 ms |
| same | 512 | 12.5 / 202.1 ms, 13 over 60 ms | 11.7 / 82.2 ms, 2 over 60 ms |
| a new `h2` under the pointer each step, 40 | 64 | 27.4 / 44.4 ms | 8.8 / 20.4 ms |
| same | 512 | 121.0 / 206.8 ms | 20.4 / 55.1 ms |

## Checks

- Each shown link's box equals main's in 25 states (hovers over `h2`, `h3`,
  a wrapped heading, an author-named and an inline-named heading, each again
  after its link exists; the user on one heading with the pointer on another; a
  press then the pointer away; another owner naming a shown heading), in
  Chromium, Firefox and WebKit at 1440 px, and in Chromium and Firefox at 700 px,
  where the link stands at the heading's far end. The author's box anchored to
  the named heading stays put throughout.
- `test_each_shown_link_stands_by_its_heading` covers two links at once, a press,
  an author-named heading and a box anchored to a shown heading. It fails with
  one name, with focus in the control not counted, with the author's name
  ignored, and without taking the merged name back out.
- The heading-link tests pass, `test_a_heading_copies_the_link_to_the_section_it_opens`
  included, which also passes on main at 0da1f29. The code copy anchor tests,
  `test_render_code_reading.py`, the recording bar tests and the margin's
  authored-anchor-name pin tests pass.
- `pnpm run test:runtime` passes 812 tests, and `pnpm run check:browser` passes.
The link read once, as its control was made, whether its heading had an anchor
name. A heading the author's stylesheet started naming later, through a class,
a media query or a revision, was then lent `--lf-heading-link-1`, and the
author's more specific rule won, so the control stood by a name nothing carried
and fell to its -9999px fallback. The link now reads the heading's names each
time it starts to show, with no name lent, and a heading named by then keeps
its names and takes the link's beside them in its style.

A link that asks for a name while both are lent now throws, where it overwrote
the second borrower; no path reaches it, since a link shows for two headings at
most.

On the stylesheet case, Chromium and Firefox put the link where main does. Main
also loses the author's later name, because the link's inline name outranks it;
the author's box anchored to that name stands by the heading here and at its
fallback on main.

`test_each_shown_link_stands_by_its_heading` adds the case, which fails on the
previous commit. The heading-link tests, `pnpm run test:runtime` and
`pnpm run check:browser` pass.
@max-sixty
max-sixty merged commit 7b9c727 into main Nov 4, 2026
4 checks passed
@max-sixty
max-sixty deleted the agent-a6d0b8b87e0014cfc branch November 4, 2026 17:10
max-sixty pushed a commit that referenced this pull request Nov 7, 2026
…pares page markup (#5690)

`test_an_aimed_press_does_only_what_the_outline_promised` compares the
page's markup before and after each ⌥-click, with runtime paint removed.
#5379 moved a heading's link anchor name out of inline `anchor-name` and
into a `data-lf-heading-link` attribute, which a heading wears only
while the pointer is over it or focus sits on its link. The test still
removed inline `anchor-name` but not the new attribute. The press
doesn't reach the widget: in release-notes an `<h2>` dropped
`data-lf-heading-link="1"` between the two readings, and in ship-review
an `<h3>` gained it. Those were the only differences in either case.

`PAGE_MARKUP` (`tests/render_cases_layout.py`) now removes
`data-lf-heading-link` beside the inline anchor name it already removed.
The assertion still catches any widget state an aimed press changes, and
the log check after the sweep still catches a decision the press sends.

Verification: with `--run-nightly`, the release-notes and ship-review
cases fail on main at `754d6e3f0` and pass with this change, as do the
other cases of that journey test and the rest of
`tests/browser/test_render_aim.py`. The one exception,
`test_design_mode_leaves_the_chrome_working`, times out waiting for the
"Exit Design mode" button the same way on main without this change. It
doesn't read `PAGE_MARKUP`.

Closes #5681 — automated triage

Co-authored-by: leaf-agent <[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