Repository navigation
Hide and show annotations without restyling the whole page - #6245
Merged
Merged
Conversation
Hiding or showing annotations (`o`) restyled every element of the page. `annotation-layer.js` stated the hidden layer on `html`, and two rules read it there: one set a custom property on `html`, `--lf-change-bar: transparent`, which every element inherits, and one hid the margin's pins through a descendant combinator from `html`, which makes Firefox visit every element to find them. On #4781's shape, 1.5 million elements, each `o` took 2 to 3 s of Firefox's main thread. Everything those rules hide stands in the chrome, so the attribute now stands on the chrome's root, and both rules read it there. ## Change - `setAnnotationsHidden` (annotation-layer.js) toggles `data-lf-annotations-hidden` on the chrome's root (`chromeRoot`, chrome.js) instead of writing `data-lf-annotations="hidden"` on `html`. - The margin's change bars hide by a rule in the chrome's scope, `:scope[data-lf-annotations-hidden] .lf-change-bar` (chrome.css), and `--lf-change-bar` goes: it existed only as that switch. The pins' rule (annotation-theme.css) reads `.lf-chrome[data-lf-annotations-hidden]`. Firefox now visits only the chrome's elements, and Chromium restyles only the pins and bars. - The contents map's changed stretch (toc.css) read `var(--lf-change-bar, var(--lf-change))`, and with the switch gone it reads `var(--lf-change)`. ## Call Max may reverse **With annotations hidden and the changes view on, the contents map keeps its changed stretches.** They read the margin bar's custom property, so `o` made them transparent too, and the map's spine then showed a gap at each changed section, since the stretch stands where the rule would. The annotation layer is what Leaf draws over the page's content, and the rail, which covers nothing, stays (annotation-layer.js). The map's stretches stand in the map and cover nothing either. Keeping them hidden would need the hidden state read from `body` or `html` again, which costs a visit of the page in Firefox, or a widget API for it. `contents-marks-changes` with `o` pressed (`uv run leaf-dev probe --state contents-marks-changes --do press:o --base --shot`): the changed stretches' `::after` background reads `rgba(0, 0, 0, 0)` on main and the change's colour here, and the margin's change bars read transparent on both. Every other state reads the same on both arms. ## Evidence A scratch script (not committed) builds the bench's `side_documents(224)` with `DOCUMENT_STEPS = 25000`, 1,512,344 elements, as #6227 did, serves it from each arm, rests the pointer halfway down the open document, and presses `o` eight times, 400 ms apart. Main-thread CPU per press, as the bench reads it (`main_thread_clock`), less the idle rate: | | main (2685a32) | this branch | |---|---|---| | Firefox, Playwright's build | 2,059–2,949 ms | 8.6–18.3 ms | | Chromium | 64–74 ms, one recalc of 5,326 elements in 54 ms | 10–19 ms, the largest recalc 7 elements | With only the custom property removed, Firefox read 38–45 ms per press, so the descendant rule from `html` cost about 25 ms of it. Chromium's recalc counted 5,326 of the 1.5 million elements, which suggests it leaves the closed tabs' documents unstyled, where Firefox's 2 to 3 s suggests it restyled them all; no Gecko profile was taken to confirm that. ## Tests - `test_hiding_and_showing_annotations_restyles_only_the_chrome` (tests/browser/test_chrome_contracts.py) counts the elements Chromium restyles as `o` hides and shows the layer, against a custom property changed on `html`, and requires under a quarter of that. With main's annotation layer, chrome.css and annotation-theme.css it fails. Firefox's visit of the page is not visible to the suite, whose restyle counts come from Chromium's trace. - The tests that waited for `html[data-lf-annotations="hidden"]` wait for `CHROME_ROOT`'s (render_harness.py) `data-lf-annotations-hidden`: test_draft_editing.py, test_comment_marks.py, test_composing.py, margin/test_pins.py, and journeys/margin/test_pins.py. Ran `pnpm run test:runtime` (997 passed), `pnpm run check:browser`, pre-commit on the changed files; every browser and journey test that presses `o`, reads the annotations attribute or a change bar (20 passed, test_changes_in_place.py's three included); and the contents widget's browser tests (34 passed). `uv run leaf-dev stills --base` on `contents-marks-changes`, `contents-marks`, `margin-gallery` and `margin-reaction-mark`: unchanged in Chromium and Firefox. Not run: the whole suite, WebKit. Not checked: Max's own #4781 page rather than its generated shape, and a desktop Firefox other than Playwright's. Part of #5194.
leaf-agent
reviewed
Nov 17, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
The switch from data-lf-annotations="hidden" to a boolean attribute left one negative check that can't fail. In test_o_gives_marked_words_their_own_colours_back, the wait after the second o asserts the chrome root doesn't carry data-lf-annotations-hidden="hidden". The attribute is now written by toggleAttribute, so its value is always "". That assertion passes whether the layer is shown or still hidden, so the test no longer confirms that o brought the layer back before it reads the colours again.
The stretch is a change mark, and on main it hid with annotations through the custom property `o` set on `html`. With that property gone it stayed drawn. A `:root:has(> .lf-chrome[data-lf-annotations-hidden])` rule on the stretch makes it transparent again. Each of main's and this branch's captures of `contents-marks-changes` is pixel-identical, at rest and after `o`, at 1440, 900 and 600 px wide, in Chromium and Firefox. At 1.5 million elements, `o` reads 10.4-17.8 ms in Firefox and 10.1-19.4 ms in Chromium with the rule. test_contents_and_glosses.py reads the stretch transparent after `o` and drawn after a second `o`, and fails without the rule. test_comment_marks.py's absence check reads any value, since the attribute's value is empty whenever it stands.
max-sixty
marked this pull request as ready for review
November 17, 2026 05:16
leaf-agent
approved these changes
Nov 17, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 17, 2026
Two files conflicted, and main's #6234 broke the page-margin scenario without a textual conflict. - annotation-layer.js: this branch moved it from annotation-overlay/ to browser/runtime/ and rewrote it around watchAnnotationLayer; main's #6245 changed it in place so that setAnnotationsHidden toggles `data-lf-annotations-hidden` on the chrome's root instead of writing `data-lf-annotations="hidden"` on html. The moved file takes #6245's write (chromeRoot.toggleAttribute) and its header paragraph saying why, and the annotation-overlay/ copy stays deleted. The branch's readers of the old html attribute move to the chrome root's, as #6245 moved its tests: tests/runtime/annotation-layer.test.mjs, and the two `o` checks in test_thread_surfaces.py's page-presentation and gallery tests. The gallery's lf-x-margin reads the layer through its watcher, not the attribute, so it needed no change. - feature-gallery.html: main's #6237 took `layout-flow` out of the author vocabulary, so the #bg-page-margin section drops the class, and #bg-native-replies keeps main's plain section. - #6234 regrouped registry declarations and removed `choose` from lf-options. lf-x-margin's gallery entry moves to the new shape (`attributes`, `content`, `author.instructions`, `author.example`), and the scenario's and its test's option groups drop `choose`.
This was referenced Nov 17, 2026
max-sixty
added a commit
that referenced
this pull request
Nov 18, 2026
…6415) The macOS nightly's WebKit failure of `test_o_gives_marked_words_their_own_colours_back` is the test reading too early. After `o` shows the marks again, `lf-mark` is registered at once, but WebKit on macOS 15 can screenshot the link before it paints the re-registered mark, so the test reads the link in its own colours. The test now waits for the runtime's rendering update (`rendered`) before that last reading. Evidence, from the macOS 15 runner running only this test 20 times beside four busy loops: on current main 17 of 20 passed ([run 44359666959](https://github.com/max-sixty/leaf/actions/runs/44359666959)), and the three failures read the link in its own colours; they read the mark's colours correctly after two frames, 500 ms and 2 s. With this change 20 of 20 passed ([run 44385439622](https://github.com/max-sixty/leaf/actions/runs/44385439622)). The same loop at #6245's merge and its parent also failed 1 in 10 each, so #6245 isn't the cause. WebKit does repaint, so Safari users see the mark; no runtime change is needed. Refs #6303 > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hiding or showing annotations (
o) restyled every element of the page.annotation-layer.jsstated the hidden layer onhtml, and two rules read it there. One set a custom property onhtml,--lf-change-bar: transparent, which every element inherits; the margin's change bars and the contents map's changed stretches read it. The other hid the margin's pins through a descendant combinator fromhtml, which makes Firefox visit every element to find them. On #4781's shape, 1.5 million elements, eachotook 2 to 3 s of Firefox's main thread. The attribute now stands on the chrome's root, which holds the margin's pins and bars. The contents map, which stands in the page, reads it there through:root:has().Change
setAnnotationsHidden(annotation-layer.js) togglesdata-lf-annotations-hiddenon the chrome's root (chromeRoot, chrome.js) instead of writingdata-lf-annotations="hidden"onhtml.:scope[data-lf-annotations-hidden] .lf-change-bar(chrome.css), and the pins' rule (annotation-theme.css) reads.lf-chrome[data-lf-annotations-hidden].--lf-change-bargoes: it existed only as the switch.var(--lf-change), and:root:has(> .lf-chrome[data-lf-annotations-hidden]) lf-toc …[data-lf-toc-changed]::aftermakes it transparent, so it still hides with annotations, as its margin bar does. toc.css's header records that the stretch is a change mark.Firefox now visits only the chrome's elements for the margin's rules, and Chromium restyles only the pins, the bars and the stretches.
No look change
Each pair below is pixel-identical between main and this branch, at rest and after
o, in Chromium and Firefox:contents-marks-changesat 1440×900 (the side map), 900×700, and 600×900 (the column outline), fromuv run leaf-dev probe --state contents-marks-changes [--do press:o] --base --shot --browser B --viewport V. With annotations hidden, the map's changed stretches are transparent on both arms, and the spine's rule shows through them unbroken.uv run leaf-dev stills --baseoncontents-marks-changes,contents-marks,margin-galleryandmargin-reaction-mark: unchanged in Chromium and Firefox.Call Max could take instead
ocould leave change marks tov, keeping both the margin's bars and the map's stretches drawn while annotations are hidden. That would drop the map's:has()rule and the bars' rule, but it reverses #4890, which made a change's bar an annotation.Evidence
A scratch script (not committed) builds the bench's
side_documents(224)withDOCUMENT_STEPS = 25000, 1,512,344 elements, as #6227 did, serves it from each arm, rests the pointer halfway down the open document, and pressesoeight times, 400 ms apart. Main-thread CPU per press, as the bench reads it (main_thread_clock), less the idle rate:With only the custom property removed, Firefox read 38–45 ms, so the pins' descendant rule from
htmlcost about 25 ms of it. The map's:has()rule adds no cost these readings separate from noise: without it Firefox read 8.6–18.3 ms. Chromium's recalc on main counted 5,326 of the 1.5 million elements, which suggests it leaves the closed tabs' documents unstyled, where Firefox's 2 to 3 s suggests it restyled them all; no Gecko profile was taken to confirm that.Tests
test_hiding_and_showing_annotations_restyles_only_the_chrome(tests/browser/test_chrome_contracts.py) counts the elements Chromium restyles asohides and shows the layer, and requires under a quarter of what a custom property changed onhtmlrestyles. It guards againstosetting an inherited property onhtmlagain. Run against main's code it fails earlier, on waiting for the chrome root's attribute, which main never writes. Firefox visiting the page for a rule read through a descendant combinator restyles nothing, so no count here sees it.test_each_contents_row_marks_where_its_section_s_threads_on_me_and_changes_stand(widgets/test_contents_and_glosses.py) now pressesowith the changes view on and reads a changed row's stretch transparent, then drawn again after a secondo. It fails without the map's rule.html[data-lf-annotations="hidden"]wait forCHROME_ROOT's (render_harness.py)data-lf-annotations-hidden: test_draft_editing.py, test_comment_marks.py, test_composing.py, margin/test_pins.py, and journeys/margin/test_pins.py. Their absence checks read any value (re.compile(".*")) or the empty value, so each fails while the attribute stands.Ran
pnpm run test:runtime(997 passed),pnpm run check:browser, pre-commit on the changed files; every browser and journey test that presseso, reads the annotations attribute or a change bar (20 passed, test_changes_in_place.py's three included); and the contents widget's browser tests (34 passed).Not run: the whole suite, WebKit. Not checked: Max's own #4781 page rather than its generated shape, and a desktop Firefox other than Playwright's.
Part of #5194.