Repository navigation
Stop a focus move restyling every block before it in Chromium - #5876
Merged
Merged
Conversation
A focus move near the end of a long page restyled every block before the focused one in Chromium: 7,152 elements a Tab on a column page of 1,024 sections, 1,131 in a `main` with no Layout. Two shapes combined. The parts layout named what stands before the parts as `:where(main > *):has(~ [data-lf-views="parts"])`, asked of every child of every `main`. Chromium flags each later sibling of an element it asks a `:has(~ …)` of, and on each write to an attribute some `:has()` reads, focus marks among them, walks back through every earlier sibling and restyles each one a `:has()` names as its subject. `main` now states `--lf-holds-parts`, which doesn't inherit, and its children read it with a style query; the sidebar's `aside:has(~ …)`, asked of every `aside` in a page's content, is gated to the sidebar's own children. With that gone, a column page still restyled everything under `main`: `main` is asked a `:has()` again as focus moves, and Chromium counted the column's room, a registered `<length-percentage>` mixing a length with a percentage, as changed on each restyle, though the property doesn't inherit. The column now resolves the room's lengths in registered `<length>`s (`--lf-room-span`, `--lf-room-note`) and keeps the percentage in `--lf-room-start` and `--lf-room-end`, registered `*`; readers resolve the same expressions. A focus move now restyles 1,014 elements on the column page at 64 and at 1,024 sections (40 ms of style down to 9 ms), and 108 in the plain `main`. Firefox restyled a constant 405 elements a move before and after. `test_a_has_reads_no_sibling_of_an_element_most_selectors_reach` holds the first shape off the shipped CSS, and `test_a_focus_move_near_a_long_pages_end_restyles_what_focus_marks` fails with either fix reverted.
`--lf-room-start` and `--lf-room-end` only passed the room to `--lf-free-start` and `--lf-free-end`, so the column now states it there and both registrations go. The length the room is made of keeps one registered slot, `--lf-room-length`: the shell less the gutters on a centred column, the end room itself beside a sidebar. A focus move still restyles 1,014 elements on the column page at 64 and at 1,024 sections, where main restyles 1,392 and 7,152. The parts contract in page-layout.md now says what the layout does with anything else in `main`: the header is the only element there besides the parts. The browser-support note gives the room's cost at one size and names the recheck that still applies, registering `--lf-free-start` `<length-percentage>`, which fails the focus-move test (1,225 against 2,185 at 8 and 48 sections).
max-sixty
marked this pull request as ready for review
November 12, 2026 09:01
leaf-agent
approved these changes
Nov 12, 2026
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.
In Chromium, a focus move near the end of a long page restyled every block before the focused one. One Tab between the last two sections' links of a column page of 1,024 sections restyled 7,152 elements (40 ms of style), and 1,131 (27 ms) in a
mainwith no Layout. #5844 fixed the shape that restyled the whole page on any focus move; two others remained, and they combine::has(~ …)asked of every child ofmain. The parts layout named what stands before the parts as:where(main > *):has(~ [data-lf-views="parts"]), which Chromium asked of every child of everymain, flagging each later sibling. On each write to an attribute some:has()reads, focus marks among them, Chromium walks back from a flagged element through every earlier sibling and restyles each one a:has()names as its subject.mainnow states--lf-holds-parts, registered and not inherited, and its children read it with a style query..layout-sidebar > aside:has(~ …), which Chromium asked of everyasidein a page's content, is gated to the sidebar's own children.main:mainis asked a:has()again as focus moves (:has(> [data-lf-track])names no element before it), and Chromium counted--lf-room-start, a registered<length-percentage>mixing a length with a percentage, as changed each time.notes/browser-support.mdrecorded this for an inheriting property; it holds for this non-inheriting one too. The column now resolves the room's lengths in registered<length>s (--lf-room-length,--lf-room-note) and states the room, percentage and all, only in--lf-free-startand its kin, registered*;--lf-room-startand--lf-room-endare gone. Readers resolve the same expressions as before.Restyled elements per focus move, from a Chromium 158 trace, median of 6 Tab/Shift+Tab moves per arm, arms interleaved, load average 12–16 on 18 cores; ms is the summed
UpdateLayoutTreeduration:main, 64 sectionsmain, 1,024 sectionsWhat remains on the column page doesn't grow with it: about 880 of the 1,014 are four restyles of the chrome as the margin projects the focused link. Firefox, read from the Gecko profiler's
Stylesmarkers, restyles the same elements a move on both arms at both sizes: 405 on the column page (about 9 ms, 24 moves per arm) and 26 in the plainmain.test_a_has_reads_no_sibling_of_an_element_most_selectors_reachholds the first shape off the shipped CSS: on main'slayouts.cssit names exactly the parts rule (three copies) and the sidebar'sasiderule, and nothing else.test_a_focus_move_near_a_long_pages_end_restyles_what_focus_markscounts a move's restyle on pages of 8 and 48 sections; it fails on main'slayouts.css(1,093 against 1,333), with either fix reverted alone, and with--lf-free-startregistered<length-percentage>again (1,225 against 2,185), which is the recheck the note now names.Where to look. The parts title rule now selects whatever
mainholds besides the parts' holder, where it used to exclude anything after the holder.page-layout.mdsaid the header is the only element written before the parts; it now says the header is the only element inmainbesides the parts, which is what the layout assumes, and a live parts page'smainholds only those two. The title's computed styles match main's in Chromium and Firefox, desktop and phone.What I ran.
tests/model/test_interact_layer.py; by name, the focus, resolve, send and floating-box restyle tests intest_chrome_contracts.py, and the parts, sidebar-track, note, breakout (includingtest_a_column_stated_in_font_units_gives_every_breakout_the_same_room), workspace-part and rail tests intest_native_document_layout.py,test_render_pages.py,widgets/test_tabs.py,controls/test_rings.py,margin/test_rail.pyanddrafts/test_reading_place.py(220 passed).leaf-dev stills --base origin/mainonroot-parts,pr-walkthrough,triage-board,sidebar-contents,feature-gallery,alert-thresholds,lost-update,shadow-scale,gallery-wide-passage,gallery-wide-schedule,frame-edgesandmargin-gallery: all unchanged in Chromium. In Firefox, 9 unchanged;margin-galleryandgallery-wide-schedulediffer by 0 px, only in the margin rows' offsets, which differ between two runs of identical code;sidebar-contentsnever settles in Firefox on either arm. At phone width,root-parts,pr-walkthroughandfeature-galleryare unchanged. Element boxes and block margins matched the base on ten examples and the corpus. An independent review also found no visible change in WebKit.Not in this PR. Part of #5194's other follow-up, the insertion cost in Firefox from the frame-edge trims'
:nth-*-child(1 of …)and the reading theme's.eyebrow + :is(h1, h2, h3), needs a decision on the look and stays out of this change.Part of #5194.