Skip to content

Stand anchored marks on widened tables in Firefox - #3113

Merged
max-sixty merged 5 commits into
mainfrom
comment-box-placement
Oct 17, 2026
Merged

max-sixty merged 5 commits into
mainfrom
comment-box-placement

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

In Firefox, every box Leaf anchors inside a table granted room landed the table's translation away from what it marked. At 1728px, the comment box for a wide table's header opened over the row headers. Its pin sat between the columns, and the Alt outline and key chips stood 300px left of their targets. A narrow table that fits the column is off by the whole free room, 480px at that width.

The theme places a widened table with a margin and a translate (layouts.css). That is the only CSS that can offset a box by its own width. Leaf writes each anchored box as calc(anchor(left) + offset), measuring the offset from the anchor's client rectangle. The spec, Chromium 153 and WebKit 26.6 count transforms in anchor(). Firefox 155 leaves out the transforms on the anchor and its ancestors, so every offset came up short by the translation.

anchorBox in css-anchors.js is now the one measurement every inset starts from: anchorAt, headerLevels, target paint, floating surfaces, and margin carriers and frames. It checks once whether the engine drops transforms. Only there does it take off how far each translation on the anchor or an ancestor moves its box, read from offsetLeft/offsetTop, which also leave transforms out. A scale, rotation or CSS zoom moves each point of a box differently, so those keep the pre-branch reading.

An earlier version read the corner from a hidden probe anchored to the same name. Review ran three cases where the probe was wrong. Placed straight after a scroll, it returned where the anchor stood before, because Firefox compensates a scroll from its last anchor snapshot. A probe in the chrome also can't reach an anchor in a native layer.

A code block's Copy stands by CSS anchor() alone, so each reveal writes the same shift into --lf-code-copy-dx/dy, which its insets add (code-copy.js).

test_marks_stand_on_a_widened_table_in_every_engine runs in Chromium, Firefox and WebKit. It holds a comment's pin on a widened table's header through a 120px scroll, checks that the Alt outline stands on the table, and holds a code block's Copy in its corner. It fails in Firefox without the correction. notes/browser-support.md records the gap.

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

max-sixty and others added 4 commits October 16, 2026 23:38
…dened tables

In Firefox, every box Leaf anchors inside a table granted room landed the
table's translation away from what it marked: at 1728px the comment box for a
wide table's header opened over the row headers, its pin sat between the
columns, and the Alt outline and key chips stood 300px left of their targets.

The theme places a widened table with a margin and a `translate`
(layouts.css), the only CSS that can offset a box by its own width. Leaf
writes each anchored box as `calc(anchor(left) + offset)`, with the offset
measured from the anchor's client rectangle. The spec, Chromium 153 and WebKit
26.6 count transforms in `anchor()`; Firefox 155 leaves out those on the
anchor and its ancestors, so every offset was short by the translation (480px
for a narrow table that fits the column).

`anchorBox` in css-anchors.js is now the one measurement every inset starts
from: `anchorAt`, `headerLevels`, target paint, floating surfaces and margin
carriers and frames. It reads once whether the engine drops transforms, and
only there, for an anchor with a transform on it or an ancestor, reads the
corner `anchor()` resolves from a hidden probe anchored the same way.

`test_marks_stand_on_a_widened_table_in_every_engine` holds a comment's pin on
a widened table's header through a scroll, and the Alt outline on the table,
in Chromium, Firefox and WebKit; it fails in Firefox without the probe.
notes/browser-support.md records the gap.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Review of the probe found three cases it still got wrong in Firefox, each
run: placed straight after a scroll, the probe returned where the anchor
stood before it (Firefox resolves `anchor()` from its last scroll snapshot),
so the inset kept a 150px error; a probe in the chrome reaches no anchor in a
native layer, so a translated anchor and its follower in one modal stayed
50px apart; and an `offset-path` anchor was not counted as transformed.

`anchorBox` now takes off how far each transform on the anchor or an
ancestor moves its box, read from `offsetLeft`/`offsetTop` against the offset
parent's box and the scrolls between. Offsets leave transforms out, as
Firefox's `anchor()` does, and they are current after a scroll and in any
layer. It only reads layout, so no write falls between its reads, and the
one-time check of whether the engine drops transforms leaves nothing behind.
All three cases now land on their anchors.

The test's page now scrolls (it was a single screen, so the scroll it
asserted never happened), and it checks that the scroll moved the header.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ffsets

Review of the offset reading ran four more Firefox cases. A scale or
rotation on an ancestor moves each point of its box differently, so one
corner shift misplaced descendants; a fixed ancestor has no offset parent,
so it fell back uncorrected; a positioned body's offsets count from its own
box, not the document's corner; and CSS zoom puts offsets in other units.

`anchorBox` now corrects only translations (`transform` with no linear part,
`translate`, and `offset-path` with `offset-rotate: 0deg`), reads a fixed box
from the window's corner and a positioned body like any offset parent, and
keeps the script's reading for a scale, rotation or zoom, as before this
branch. A table granted room, the case Leaf itself creates, is a translation.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

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

The CSS-only Copy control remains detached from transformed code blocks in Firefox.

A code block's Copy stands by CSS `anchor()` alone, with no inset a script
measures, so `anchorBox` never reached it: in Firefox, Copy for a block in a
table granted room showed 454px left of the block at 1728px (leaf-agent's
review). Each reveal now writes how far `anchor()` reads the block from where
it shows into `--lf-code-copy-dx/dy`, which the control's insets add; it is
zero in Chromium and WebKit. The widened-table test hovers a code block in the
table and holds Copy in its corner, and fails in Firefox without the shift.

The branch's JavaScript is formatted as pre-commit expects, and the matrix
reads through `window.DOMMatrixReadOnly`, as eslint's globals require.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit e7538dc into main Oct 17, 2026
5 checks passed
@max-sixty
max-sixty deleted the comment-box-placement branch October 17, 2026 07:36
max-sixty added a commit that referenced this pull request Nov 2, 2026
In Firefox, every box Leaf anchors to content inside a scaled box stood
away from what it marked: comment pins and rows, the thread card, the
Alt outline, Go-to chips and Copy. reveal.js translates and scales its
`.slides` box to fit its stage, so marks on a deck's slides hit this. A
scroll inside a scaled box, such as the long `pre code` reveal's theme
makes a scroller, then carried rows off their words in Firefox and
WebKit. An agent found the first while working on #5024, and #5042
recorded it as the part of #5024 that PR left open.

Part of #5024

## The cause

Firefox resolves `anchor()` and `anchor-size()` against the box layout
gave the anchor, leaving out every transform on it and its ancestors:
Playwright's Firefox 157, and release Firefox 159. It keeps CSS zoom.
Chromium 156 and WebKit 27.2 read the transformed bounding box.
`anchorBox` (css-anchors.js) is the one measurement every anchored inset
starts from. It corrected only translations, added for widened tables in
#3113; where an ancestor scaled or rotated, it kept the box as shown.

A scroll inside a scaled box is a separate gap. Firefox 157 and WebKit
27.2 carry an anchored box by the scroll's layout pixels, not the
smaller or larger distance the words move on screen. Chromium 156
follows the words. Firefox's bug is 2055371, and it remains with
Firefox's own transform support on.

## What changed

**`anchorBox` reads the laid-out box where the engine drops
transforms.** Each box from the anchor up to the outermost transform
stands at its offset from its offset parent's laid-out box (`laidOut`).
The walk ends at the first box no transform moves, whose client
rectangle is exact. One walk covers translation, scale, rotation and
nested transforms, and it replaces the translation-only path
(`translationOf`, `movement`). A scroller's first words or an SVG
drawing has no offsets, so it maps through its nearest HTML box in
proportion, which holds for a translation or a scale. Other engines take
the early return they took before. That includes Firefox Nightly 160
with `layout.css.anchor-positioning.follows-transforms.enabled` on,
since `anchorDropsTransforms()` then finds transforms kept.

**Block controls add the size difference.** Copy, a heading's link and a
recording's bar read their block's far edges and size in CSS
(`anchor(right)`, `anchor(bottom)`, `anchor-size(width)`). A scale moves
those differently from the corner, so `readInsets` also writes
`--lf-block-control-dw` and `-dh`, which those three rules add. Both are
zero except in Firefox under a transform, so other engines write nothing
new.

**The margin runs a pass when a scroll inside a scaled box ends.** The
margin already hears every scroll in capture. It now also hears
`scrollend`, and runs a pass where a row's carrier is anchored inside
the box that scrolled and that box shows a layout pixel as more or less
than a screen pixel (`scrollMisplacesAnchors`: its on-screen width
differs from `offsetWidth` × `currentCSSZoom`, so a CSS zoom, which
anchors follow, doesn't count). WebKit 27.2's Linux build (Playwright
build 2370, which CI runs) has no `currentCSSZoom`, unlike its macOS
build of the same number, so a missing zoom counts as 1: a zoomed box
there reads as scaled and costs one pass that leaves the rows where they
stood. Rows drift while the scroll runs and stand on their words a frame
after it ends. The check reads the box's scale on screen rather than the
engine, so it covers WebKit, which `anchorDropsTransforms()` doesn't
flag. In Chromium, where it runs, the pass also moves a row whose
carrier scrolls with something its target doesn't back to where a fresh
pass puts it: review found a pin on a `pre` whose `code` scrolled
carried 45px with the code without the pass, a mismatch older than this
PR, and the pass snaps it back to the block's corner. The css-anchors.js
header, which rejects a script that places boxes again after each
scroll, now says where this pass runs and why.

**`notes/browser-support.md`** rewrites "An anchor's transforms in
Firefox": the engines, bugs 2059840 (the pref, on in Nightly 160) and
2059841 (enabling it in release: no milestone, blocked on 2055371,
2057633 and 2060883), the inner-scroll gap, and when to delete each
part.

## Evidence

Real reveal.js 5.1 (vendored into `.tmp/` for the probe only) in a
`layout-workspace` page at 1280x800, `leaf-dev probe --browser firefox
--base`: the quoted comment's pin stood at `[974, 913]` on the merge
base, 315px below its passage and outside the window, and stands at
`[714, 566]` on this branch. Chromium puts it at `[714, 567]`. Review
drove the same deck in Firefox 157 through slide changes, resizes,
narrow windows and reveal's overview mode (scale 0.19, 3D transforms),
and every mark landed within 1–3px of Chromium.

A fixture with the same transform at 0.6 (`translate(-50%, -50%)
scale(0.6)`), at 1440x900, each mark's top-left corner:

| Mark | Firefox, merge base | Firefox, branch | Chromium |
| --- | --- | --- | --- |
| Quoted comment's row | 1126, 549 | 1126, 287 | 1126, 287 |
| Copy | 1592, 624 | 944, 329 | 944, 329 |
| Heading link | 748, 489 | 436, 244 | 436, 244 |
| Alt outline | 780, 539 | 468, 277 | 468, 277 |
| Link's Go-to chip | 801, 572 | 477, 293 | 477, 293 |
| Thread card | 1220, 533 | 908, 270 | 908, 271 |

A scroll of 60px inside a box scaled to 0.6, holding the quoted words,
measured as the row's offset from its words after `scrollend`: Firefox
moved from 0 to −24px and WebKit from 0 to −24px with no pass after the
scroll; with the `scrollend` pass all three engines stay at 0, after one
pass each.

`test_marks_stand_on_a_scaled_slide_in_every_engine`
(tests/browser/margin/test_scrollers.py) runs in Chromium, Firefox and
WebKit. On a slide translated and scaled to 0.6, the quoted words stand
in a scrolling box holding only words, so the row anchors to the box's
first words and exercises `anchorBox`'s proportional mapping. The test
holds the row level with its words through a 120px page scroll, then
through a 60px scroll of that box, after `scrollend` and without
announcing a layout change, and checks that the Alt outline stands on
the box and Copy inside its block's corner. On the merge base it fails
in Firefox, with the row 257px below its words. With `anchorBox` fixed
but no size insets, it fails at Copy, 380px past the block. With the
`scrollend` listener disabled, it fails in Firefox and WebKit, each row
24px off. Its outline and Copy assertions, shared with the widened-table
test, move into one helper.

Cost: in Firefox, timing copies of both versions on the fixture's DOM,
one `anchorBox` call took 2.4 µs against 3.0–3.3 µs on main for an
anchor under no transform, and 5.1–6.2 µs against 3.3–3.6 µs for one in
the scaled box, where main returned the wrong box. A margin pass makes
one call per carrier, frame level and shown control. In every engine, a
scroll's end checks the margin's carriers against the box that scrolled,
reads that box's width only where one stands in it, and runs one margin
pass only where the box is scaled by a transform, not a zoom. Under
`zoom: 0.6`, a 60px scroll in the slide ran no pass in any of the three
engines and the row stayed on its words; with one comment elsewhere on
the scaled slide, scrolling the box beside it ran no pass in Firefox.

Before/after screenshots are in the worktree's `.tmp/evidence/`
(`firefox-*-before.png`, `firefox-*-after.png`, `chromium-*.png`).

## What remains

- While a scroll inside a scaled box runs, Firefox and WebKit carry its
rows by the scroll's layout pixels; they stand on their words a frame
after it ends. Only the margin's rows are placed again then; other marks
anchored inside the scrolled box, such as Go-to chips raised before the
scroll, were not checked after one.
- Offsets are whole pixels, so a mark in Firefox can stand up to a pixel
off (the thread card above).
- Inside a rotated box, a mark anchored to an SVG drawing or a
scroller's first words stands off by the rotation.
- Once bug 2059841 ships in release Firefox, the offset walk and the
size insets can go. The `scrollend` pass can go once release Firefox and
WebKit both keep a row on its words through that scroll. The test passes
whatever the engines do while the pass is in place, so recheck with the
`scrollend` listener removed (Firefox 157 left the row −24.1px from its
words that way, WebKit 27.2 −24.0px), or by reading the row in the frame
after the scroll, before `scrollend`.

## Calls Max may reverse

- The laid-out box comes from offset chains rather than composing
`DOMMatrix`es from computed transforms. Offsets already leave transforms
out, so one walk handles every transform kind without parsing
`transform`, `translate`, `rotate`, `scale`, origins or perspective; the
price is the whole-pixel rounding above.
- Block controls get two more custom properties rather than staying off
by the scale on a scaled block.
- The `scrollend` pass keys on the scrolled box's scale on screen, not
on `anchorDropsTransforms()`, because WebKit drifts the same way and
keeps transforms at rest. Chromium pays one pass at the end of each
scroll inside a scaled box that carries a row.

## Checks run

- `uv run pytest tests/browser/margin/test_scrollers.py -k "scaled_slide
or widened_table or every_engine or pane or slide_the_reader or carrier"
-n 2`: 16 passed, all three engines of both transformed-box tests
included, after merging main at a300990 (which brought #5042's stir
reading beside the new listener). Evaluated in Playwright 1.64.1's Linux
browsers (Docker), the check reads a `scale(0.6)` scroller as scaled in
WebKit, Chromium and Firefox, where WebKit read it as unscaled before
the `?? 1` default; CI's WebKit case had failed that way, the row 24px
off. With the `scrollend` listener disabled, the scaled-slide test fails
in Firefox and WebKit.
- Firefox and WebKit cases of `test_tabs.py`, `test_rings.py`,
`test_focus.py`, `threads/test_layout.py`, `test_comment_marks.py`,
`test_render_drawing.py`, `test_suggestions.py`, `test_send_corner.py`,
`test_render_pages.py` (`-k "firefox or webkit" -n 2`): 43 passed, 2
failed. The two are
`test_words_scrolled_past_a_card_head_show_nowhere_above_it[firefox_browser-*]`,
which fail the same way with current main's `browser/` and `dist/`
(`travel` 246, wants over 300).
- Chromium tests for Copy, heading links and anchors
(`test_render_heading_links.py`, `test_render_code_reading.py`,
`test_render_anchors.py`), run before the `scrollend` commit: 109
passed. Eight failed and four errored, all in `test_render_anchors.py`:
`test_thread_travel_keeps_its_passage_above_the_bottom_reading_clearance`
and the `lf-diff` cases (`deferred_diff_renders_only_opened_files`,
`native_file_metadata_without_empty_disclosures`,
`inline_version_diff_indexes_astral_text`,
`hunk_step_waiting_on_a_file`, which throw `Cannot read properties of
null (reading 'path')` in `lf-diff.js`). The same eight fail and the
same four error with main's `browser/` and `dist/` at 1f49b64.
- `pnpm run test:runtime`: 742 passed. `pnpm run build:browser` (type
check and kernel rebuild), `pnpm run check:browser`, pre-commit on the
changed files.

## Not verified

- A recording's bar and a heading link's far-end placement on a scaled
block were not driven; their CSS takes the same size inset as Copy,
which was.
- A box-motion animation that scales an anchor's ancestor mid-motion.
- A real trackpad scroll inside a scaled `pre code`; the test and probes
scroll by setting `scrollTop`.

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

---------

Co-authored-by: Claude Opus 5.5 <[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