Skip to content

Read a box's focus from its own marks, never through :has() - #5868

Merged
max-sixty merged 4 commits into
mainfrom
focus-marks-off-has
Nov 12, 2026
Merged

max-sixty merged 4 commits into
mainfrom
focus-marks-off-has

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

No :has() in Leaf's sheets now reads where focus is. After #5844, a focus move on pr-walkthrough still restyled 1,419 elements in Chromium (5.5 ms), and 7,345 (22 ms) once any rule, an author's included, put a :has() before a subject naming no element, because 25 rules asked with :has() for a focus mark, as .choice:has(> input[data-lf-focus-visible]) does. A box that shows a control's focus is now named by the control (--lf-focus-box, a selector), and focus.js marks that box data-lf-control-focus / data-lf-control-focus-visible. Rules for focus anywhere in a box read its existing -within marks. A move now restyles 18 elements (2.0 ms), with that authored rule or without it. The new test_no_has_reads_where_focus_is guards the rule; it fails on main.

Where to look:

  • focus.js re-reads the box a control names when focus reaches it, when its ancestry changes, and when one of the control's own attributes changes (a panel view's data-lf-leaving), so a repaint after a tree change forces no style pass. Typing in a comment field writes no attribute on it.
  • The obligation's location ring now stands down on --lf-obligation-ring: none declared by the focused control itself (locationStandsDown), and a margin card's transcript fade lifts on data-lf-transcript-focus, written by thread-preview.js.
  • One behavior changes, which you may want back: the band rules in surfaces.css treated a marked box as wearing a control's ring whenever any child held visible focus. They now do so only for a declared box, as their comment says, so a commented or traced paragraph keeps its brackets while a link in it holds focus. Keeping the old reading needs one more mark, on the focused node's parent.

The faces focus draws match main on each box from the control to the body, focused and blurred, for 20 controls across 8 examples. Max asked for this follow-up after #5844 and hasn't read it yet; an independent Codex review found a stale-cache case, now fixed and covered by a runtime test. Tests: the CSS guards in test_interact_layer.py, pnpm run test:runtime, pnpm run check:browser, and 24 browser tests by node id on rings, choices, obligations, diff folds, the file editor, the sample gutter and the thread card.

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

After #5844, a focus move on pr-walkthrough still restyled 1,419
elements in Chromium (5.5 ms), and 7,345 (22 ms) once any rule, an
author's included, put a `:has()` before a subject naming no element.
The cause was the rules that ask with `:has()` where focus is, such as
`.choice:has(> input[data-lf-focus-visible])`. Each makes every write of
a focus mark a `:has()` change, so Chromium restyles what lies under
every element whose `:has()` the write might change. Leaf's sheets held
25 such rules.

A box that shows the focus of a control inside it is now named by the
control. The control declares `--lf-focus-box`, a selector, and focus.js
marks the nearest box around the focused control that matches it
`data-lf-control-focus`, with `data-lf-control-focus-visible` while the
focus is visible. The box's rules read those marks:

- the rings boxes wear for a control in them: a comment box's and the
  panel's field for its words, a choice for its radio, a joined option
  row for its mark and the add row for its field, a gloss for its mark,
  a shot frame, a draft, a file editor, the panel's chooser and stage,
  a ring frame or pane for its child, and a margin card for its thread
  and messages. Each keeps `--lf-wears-ring` where it had it, so
  `ringBox` is unchanged;
- the comment box's ground and its edge under a carried or gripped box,
  read on the bar;
- a sample's gutter, a diff fold's keyboard closing, and a joined row's
  aim wash.

Rules for focus anywhere in a box read the box's `-within` marks: the
margin lanes rise on `data-lf-focus-within`, since they hold only rows,
and a video's controls show on `data-lf-focus-visible-within`.

Three rules move elsewhere:

- The obligation's location ring stands down when the control holding
  visible focus inside it declares `--lf-obligation-ring: none` on
  itself. `locationStandsDown` reads that control, where it read a value
  the decision computed through `:has()`.
- A non-joined option's mark warms on its own `data-lf-focus`.
- A margin card's transcript fade lifts on `data-lf-transcript-focus`,
  which thread-preview.js writes from `onCurrentLocation`. Only focus in
  the transcript lifts it, not the reply box, and no mark on the thread
  can say that.

The paint reads the box a control names when focus reaches the control,
when the control's ancestry changes, and when one of the control's own
attributes changes, as a panel view's does as it leaves. Reading it on
every paint would force a style pass after each change to the tree.
The watch ignores the paint's own marks and the control's inline style,
which CodeMirror rewrites as it redraws, so typing in a comment field or
the file editor reads no style that main doesn't. Visibility readers now run after the whole paint, so they read
the box and `-within` marks of the move they hear.

One behavior changes. The band rules in surfaces.css treated a marked
box as wearing a control's ring whenever a child of it held visible
focus; they now do so when it carries `data-lf-control-focus-visible`,
as their comment says ("a box wearing the ring for a control in it").
A commented or traced paragraph keeps its brackets in its own ink while
a link in it holds focus, and the link wears its own ring.

`test_no_has_reads_where_focus_is` holds the rule; it fails on main
with the 25 rules. `test_a_has_leads_only_to_a_subject_naming_an_element`
keeps guarding the states `:has()` still reads, such as hover.

Measured in Chromium on pr-walkthrough, moving focus between two links
in main (load average 8–17):

| | main | this branch |
|---|---|---|
| elements restyled a move | 1,419 (5.5 ms) | 18 (2.0 ms) |
| same, with `.zz:has(> .yy) > *` added | 7,345 (22 ms) | 18 (2.0 ms) |

The faces focus draws are identical on main and this branch, focused
and after a blur, on each box from the focused control to the body, for
20 controls across 8 examples: a choice's radio, an option's pick, the
add row's field, a gloss, a draft, a shot, the file editor, a diff's
fold summary, file summary and code frame, a tab panel, a pane's body,
the panel's field, chooser and stage, the comment box, a margin card's
thread and a control in its transcript (the fade), a sample frame and a
video. Only `--lf-obligation-ring` moved, from the decision to the
control, and the location ring stands down on the same Tab steps on
ship-review. The video bar's rule reads the `-within` mark that
`:has([data-lf-focus-visible])` asked for, which no probe reached.

Checked: tests/model/test_interact_layer.py's CSS guards, the runtime
suite (`pnpm run test:runtime`, with two new focus.test.mjs cases for
the box marks, the second failing without the attribute watch),
`pnpm run check:browser`, and by node id 24 browser tests on rings,
choices, obligations, diff folds, the file editor, the sample gutter,
the thread card and the label press.
# Conflicts:
#	browser/styles/components/controls.css
#	tests/journeys/test_render_controls.py
leaf-agent
leaf-agent previously approved these changes Nov 12, 2026

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

--lf-focus-box is now public package API (module-input.md), and a value that doesn't parse as a selector throws from inside the focus paint. A quoted value is the likely one, as in --lf-focus-box: ".row", since a selector stored in a property reads like a string. box.matches then throws a SyntaxError before boxRead and the box marks are written, and before the visibility readers this PR moved to the end of paintFocus. So every paint that lands on that control skips those readers, while the cause only reaches the console. The inline suggestion catches the error, reports it, and treats the control as naming no box.

Comment thread browser/runtime/focus.js Resolved
A control that names its box with something `matches` can't parse, such as
a quoted `--lf-focus-box: ".row"`, threw from the focus paint before the
box marks were written and before the visibility readers ran, so every
paint landing on that control skipped them. `focusBox` now reports the
error and treats the control as naming no box. A runtime test covers it
and fails without the fix.
leaf-agent
leaf-agent previously approved these changes Nov 12, 2026
# Conflicts:
#	browser/AGENTS.md
#	tests/model/test_interact_layer.py
@max-sixty
max-sixty merged commit 1136fa0 into main Nov 12, 2026
5 checks passed
@max-sixty
max-sixty deleted the focus-marks-off-has branch November 12, 2026 09:40
leaf-agent added a commit that referenced this pull request Nov 13, 2026
…focus paint does (#5923)

Four thread tests fail on main's write watch since #5868, and a fifth
fails on a stale rule assertion. This fixes both.

**Unchanged write of `data-lf-transcript-focus`.** #5868 removed the
`:has()` that lifted a margin card's transcript fade
(`.lf-page-thread:has(>
.lf-thread-transcript[data-lf-focus-within])::after`). In its place,
`thread-preview.js` writes `data-lf-transcript-focus` from the
`onCurrentLocation` reader. That reader runs synchronously on every
arrival, including intermediate ones. So when one script moved focus out
of the transcript and back, the mark came off and went back on, and
`tests/write_watch.js` reports that as an unchanged write. The old rule
read focus paint, which `focus.js` deliberately applies only after the
script ends, once focus has reached its final place. The reader now
records the location and writes the mark once through `afterScript`, so
it changes only when the script's final location does. #5868's intent,
no `:has()` reading where focus is, still holds.

**Margin card ring assertion.**
`test_a_margin_card_is_one_frame_that_rings_for_its_thread` checked that
the card's ring rule names `.lf-page-thread`. Since #5868 the focused
thread names the card as its `--lf-focus-box`, and the card rings
through `.lf-margin-preview-card[data-lf-control-focus-visible]`. The
assertion now checks that rule. What it protects is unchanged: the card
is the only element wearing a ring.

Verification: all five fail in main's `ci` runs, and I reproduced the
four write-watch failures locally on the base. With this change all five
pass locally, run by node id. `pnpm run test:runtime` (965 pass), `pnpm
run check:browser` and pre-commit over the changed files also pass.

-
`tests/browser/threads/test_rewrites.py::test_a_rewrite_of_a_comment_just_sent_is_the_reply_box`
-
`tests/browser/threads/test_rewrites.py::test_a_cards_message_controls_cover_its_head`
-
`tests/browser/threads/test_rewrites.py::test_a_rewrite_is_the_reply_box_where_the_words_stood[card]`
-
`tests/browser/test_render_floating_panel.py::test_a_thread_s_messages_read_alike_in_its_card_and_the_panel`
-
`tests/browser/margin/test_card_reply.py::test_a_margin_card_is_one_frame_that_rings_for_its_thread`

Closes #5919 — 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