Skip to content

Keep the thread panel from taking focus off the control that opened it - #141

Merged
max-sixty merged 1 commit into
mainfrom
fix/ci-33327519405
Aug 30, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/ci-33327519405

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Problem

ci run 33327519405 on e7299eb failed with 33 tests red. One of them is test_render_controls.py::test_esc_hands_the_page_back_after_it_has_closed_the_last_panel, which #133 lists among the unowned remainder ("esc handback"). It still reproduces deterministically on main at 1ca4f40, in about 7 seconds.

The test's first assertion after a pointer open is the one that fails: the panel is visible and the toggle is no longer focused.

FAILED tests/test_render_controls.py::test_esc_hands_the_page_back_after_it_has_closed_the_last_panel
E       AssertionError: Locator expected to be focused
E       Actual value: inactive
E         - waiting for locator(".lf-threads-toggle")
E           14 × locator resolved to <button aria-expanded="true" class="lf-btn lf-threads-toggle" ...>
tests/test_render_controls.py:2089

syncPanelLayer raises the panel with panel.show() beside the page and panel.showModal() over it. Both run the dialog focusing steps, so the browser moves focus into the dialog whichever one is called — the panel takes the focus off whatever raised it. The function already knew to put focus back, but only for a focus it found inside the panel: active is null whenever the reader was standing outside it, and the restore arm reads active. So the pointer route lost the toggle, and what the test's docstring bills for lands: the button holds aria-expanded with no ring on it, and the reader's next Space is that button rather than the page's scroll — the panel they dismissed comes back and nothing says why.

Solution

Carry the element that was standing outside the layer alongside the one found inside it, and restore that too when nothing else claims the focus. Beside the page a panel is a column that arrived, so the reader stays where they were; a covering panel is a mode and still takes them in, which is the existing focusEnteredLayer arm and is unchanged. Body is not somewhere to put anyone back, so it is not carried.

This is syncPanelLayer's own restore, extended to the case it did not name — not a second focus policy beside it, and not a call at the press site, which would have to be repeated at every door the panel has.

Scope

Not the other 32. Measured against the current tip, they are owned or out of reach here:

#121 8 of them (scrollbar-gutter: stable on the root scroller)
#132 test_example_renders[command-hub], test_example_renders[corpus]
#137 the four version-menu cases in test_render_anchors.py
#134 / #133 the catalog preview digest
this PR esc handback

I reached the version-menu focus break independently and had the same one-line fix (versionBtn.focus() before showPopover) before #137 appeared; #137 covers it and the two contracts around it, so nothing of it is here.

How the split was measured

Each row is a local -n0 or -n3 run on the named tree, not an inference from the failure text.

Testing

test_esc_hands_the_page_back_after_it_has_closed_the_last_panel is the regression: it asserts both halves the docstring names — the ring the pointer reader never asked for, and the Space that reopens what they just dismissed — and it goes from red to green here. No new test, because that one already owns the behaviour.

Runs on this branch, against the same files on clean 1ca4f40
uv run pytest tests -q -n3                      723 passed, 6 skipped
uv run pytest tests/test_render_controls.py \
             tests/test_render_conversations.py 10 failed, 101 passed
uv run pytest tests/test_render_outbox.py \
             tests/test_render_margin.py \
             tests/test_render_drafts.py         3 failed, 108 passed

Every remaining failure above reproduces on clean main; test_esc_hands_the_page_back_after_it_has_closed_the_last_panel is the only test whose result this change moves. Earlier on 26dbf42 the wider render set (anchors, gate, navigation, widgets, projection, startup, drafts, outbox, options, pages, aim, reactions, margin, semantic_selection, commands, export, site) ran the same way with the same result.


Automated fix for failed run

Raising the panel is not a request to leave the control that raised it. Both
dialog.show() and dialog.showModal() run the dialog focusing steps, so the panel
took focus off the toggle: the button kept aria-expanded with no ring on it, and
the reader's next Space went to a control they never chose.

syncPanelLayer already restored a focus it found inside the panel. Carry the one
it finds outside too, so a panel that arrives beside the page leaves the reader
where they were standing. A covering panel is a mode and still takes them in.
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Dispatched for ci run 33328441364 (24759a0, 35 red — the same standing set). I reached syncPanelLayer's restore arm independently before this PR existed, and wrote the same change; the only difference is that mine carried document.body back and this one declines to, which is the better half. So there is nothing to add to the diff, and this is a second reading of it plus one fact it does not have.

The residual is not fixed by this, and it is in the same test. On this branch at d675de5, test_esc_hands_the_page_back_after_it_has_closed_the_last_panel is green 19 runs in 22 at -n0, and the three failures are all at the same later line — test_render_controls.py:2100, where the Space that should re-activate the ringed toggle produces no activation at all and the panel stays shut. That is a different assertion from the one this PR fixes (2089, deterministic before it), and it is not pre-existing either: at 01ec4f4, the commit before 335bf9a, the whole test is 6 for 6. So the fix is right and the test will still be able to come back red.

What I measured, and on which tree

Every row is a local run on this sandbox's Playwright, --run-nightly.

tree the test
01ec4f4 (before 335bf9a) 6/6 pass the pre-regression control
0d7e0d0 (main, unchanged) 0/5 pass deterministic, at 2089 — the assertion this PR is about
0d7e0d0 + my equivalent of this diff 22/22 pass, then 5 failures in a separate 19, all at 2100 rate moves with machine load
d675de5 (this branch) 19/22 pass, 3 failures, all at 2100

The residual is timing-sensitive in the way tests/CLAUDE.md describes rather than in the fix's arithmetic: instrumenting the page at all — one extra page.evaluate anywhere before the press, or the listeners installed through open_page(init_script=…) — took it to 8/8 twice over. In the failing case the toggle keeps focus and aria-expanded="false", the panel's open stays false, and nothing in the log says the press arrived; in the passing case the click lands and the panel opens. I did not chase it further, since it is a second question from this one.

Beside that, no new red from the change. On 0d7e0d0 with it applied: uv run pytest tests is 723 passed / 6 skipped, and tests/test_render_controls.py tests/test_render_anchors.py --run-nightly -n2 is 13 red — the run's own set for those two files, minus this test, plus test_covering_panel_takes_the_page_scroll_with_it, which fails identically with the change stashed and which #121 accounts for.

Two rows of #133's board have also moved on their own since the reading it was last given, both measured on 0d7e0d0: test_the_composed_corpus_declares_every_control_row_archetype passes, and of #132's pair test_example_renders[command-hub] passes while [corpus] still fails. And the row that files this test with #137's Escape group is now this PR's.

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

#144 overlaps this one and should be resolved against it before either lands.

It takes the same test, by removing the modality rather than working around it: showModal() is what makes the banner, the workspace toggle beside it, and the strip of page still showing all inert, which is five more red tests (#139's unowned six). Once the panel is never modal, the restore this PR adds falls out of a function with one branch instead of four, and panelModal, ignoreNextClose, the close-and-reopen across the covering breakpoint and the close listener go with it.

This PR is the smaller change if the modal question is to stay open. Leaving it open leaves the other five red.

@max-sixty
max-sixty merged commit 996ae23 into main Aug 30, 2026
3 checks passed
@max-sixty
max-sixty deleted the fix/ci-33327519405 branch August 30, 2026 20:57
max-sixty pushed a commit that referenced this pull request Aug 30, 2026
)

## Problem

`test_render_gate.py::test_example_renders[corpus]` has been red on
every `ci` run since
[26dbf42](26dbf42)
"Add external link treatment", in both colour schemes, and it still
reproduces deterministically on `1ca4f40` in 11 seconds. #132 diagnosed
it as "a different finding, from 26dbf42's external-link treatment
rather than from 335bf9a" and left it; no PR or issue owns it.

```
assert ['[light] <lf-tab id=corpus-pr-walkthrough> puts "opens in a new tab" under .lf-ui, where no comment can reach it',
        '[dark] ...same...'] == []
```

The subject is not the example. `render_version` is the pass `version
check --render` runs on an agent-authored page, so any page with a
cross-origin link inside a widget now fails handover on a word the
reader is never shown.


[`unreachableWords`](https://github.com/max-sixty/leaf/blob/03b4a0b2776102041a2d48580046fbf03b5e3446/skills/leaf/scripts/leaf/render-checks/reachability.js#L208)
walks every text node under a widget's `.lf-ui` and reports the ones no
declaration claims. Its excuse list held `.lf-quiet` and nothing else.
26dbf42's `renderExternalLinks` writes a note beside each external link
— `class="lf-ui lf-external-note"`, `hidden`, textContent "opens in a
new tab" — as the `aria-describedby` target for the link, and the walk
found it: not `data-lf-said`, not inside the link's own `CONTROL` box (a
describedby target is referenced by id, so it sits beside the link
rather than in it), not `.lf-quiet`.

## Solution

Excuse `[hidden]` beside `.lf-quiet`, one line and its comment. The
check's own opening sentence is "Words the page shows that no user can
select", and a `[hidden]` subtree shows none.

The note cannot simply become a `.lf-quiet` word instead — which would
have been the tidier answer, since `quietWord` is the repo's one idiom
for "a word for a reader listening, silent on screen".
`renderExternalLinks` is enrolled on declared shadow roots as well as
the document, and the note is placed inside whatever root its link
stands in, while `.lf-quiet`'s clip is a rule in the document stylesheet
that no shadow tree adopts (only `MARK_RULES` is adopted, in
`shadow.js`). A `.lf-quiet` note in an `x-shadow` widget would render as
visible text next to the link. `hidden` is the silence available in
every root.

`[hidden]` is safe for this reading to trust rather than a hole for
hidden-but-revealable words: the browser removes the attribute when it
reveals `hidden="until-found"` content, so a word the reader finds is a
word this check sees again, at the moment it is on screen. The two
sibling gate readings that ask what a box shows already spell the same
pair —
[`widgets.js`](https://github.com/max-sixty/leaf/blob/03b4a0b2776102041a2d48580046fbf03b5e3446/skills/leaf/scripts/leaf/render-checks/widgets.js#L146)
and
[`standalone.js`](https://github.com/max-sixty/leaf/blob/03b4a0b2776102041a2d48580046fbf03b5e3446/skills/leaf/scripts/leaf/render-checks/standalone.js#L34).

No assertion is loosened and no runtime file is touched.
`skills/leaf/CLAUDE.md`'s row for this gate already reads "**visible**
page words remain in reachable flow".

## Testing

- `test_example_renders[corpus]` and
`test_example_renders[pr-walkthrough]` — pass with `--run-nightly`; the
first fails on `origin/main` unchanged at the two findings above.
- `test_render_reports_words_a_widget_puts_out_of_reach` gains the pair:
the same `.lf-ui` note inside `lf-option` reports nothing when `hidden`
and is still reported when shown. Bug-back: with the `[hidden]` excuse
reverted, the hidden half fails with exactly the corpus's finding.
- `uv run pytest tests` — 723 passed, 6 skipped, on this branch rebased
onto `c7b3706`.
- `uv run pytest tests/test_render_commands.py tests/test_render_gate.py
--run-nightly` — 77 passed, 4 failed, and all four are in the failed
run's own list and owned elsewhere:
`test_the_render_gate_measures_sideways_room_at_the_root_scrollport`,
`test_the_reader_draws_an_edge_to_the_width_they_want[comments]` and
`test_a_window_with_no_room_for_a_chosen_width_does_not_un_choose_it[comments]`
are #121's `-15`, and
`test_a_reader_arrives_at_what_they_left_rather_than_watching_it_arrive`
is the intermittent one #121 documents.
- `node --check`, pinned `prettier --check`, `ruff check` and `ruff
format --check` pass on the two touched files. `pre-commit` is not on
this sandbox's PATH, so its remaining hooks went unrun here.

The preview digest is unmoved: `capture_input_files()` hashes
`examples/`, `skills/leaf/assets`, the selected packages and three site
scripts, and `skills/leaf/scripts/` is in none of them.

## What this does not fix

The failed run had 32 red. Everything else in it sits with an open PR or
issue — #121, #132, #134, #136, #137, #138, #140, #141, and issues #133
and #139 — with two exceptions I did not reach:

-
`test_render_controls.py::test_every_ring_the_layer_draws_is_shown_whole_somewhere_in_the_corpus`
reports one unlit ring, `version-diff
(.lf-version-diff:is(:focus-visible, .lf-focus-visible))`. That control
is inside the versions menu #137 is rewriting, so it is likely
downstream of that branch rather than its own cause; I have not verified
it against #137's tree.
-
`test_render_navigation.py::test_a_widget_that_renames_its_role_keeps_the_press_offer_gave_it`
is the generic-press question #132 raised and deliberately left as a
product decision.

---
Automated fix for [failed
run](https://github.com/max-sixty/leaf/actions/runs/33330752582)

Co-authored-by: leaf-agent <[email protected]>
max-sixty pushed a commit that referenced this pull request Aug 30, 2026
## Problem


[335bf9a](335bf9a)
made `.lf-panel` a `<dialog>` and `syncPanelLayer` raised it with
`showModal()` whenever it covers the page. A modal dialog makes the rest
of the document inert, and covering is the posture in which the page
most needs to stay live — so the banner toggle that opened the panel
stopped closing it, the decisions toggle beside it stopped switching
workspace, and the strip of page still showing beside the sheet stopped
answering a selection hint. Separately, both `show()` and `showModal()`
run the browser's dialog focusing steps, so opening the panel took focus
off the control that opened it.

Those are the six unowned tests in #139. Five are the inertness; the
sixth is the focus.

## Solution

The panel is shown, never shown modally, at either posture, and the
invoker gets its focus back. What modality was carrying is already owned
elsewhere and stays: the covering sheet's root scroll lock is the
stylesheet's `overflow-y: hidden` under `COVERING`, and Escape is the
ladder's — `browserDismissesTopLayer` hands Escape to the platform only
for layers the platform really owns, which the keyboard reference and
the page map sheet still are. `skills/leaf/CLAUDE.md` already states the
same reading from the other direction: `presentPage` demotes authored
`showModal()` calls to non-modal dialogs precisely so a modal's
top-layer inertness cannot disable the recovery chrome.

That deletes rather than adds machinery: `panelModal`,
`ignoreNextClose`, the close-and-reopen across the covering breakpoint,
the `resize` and `change` re-syncs that existed only to switch modality,
the `panelFocusTarget` wiring, and the `close` listener that only a
native modal dismissal could reach. `syncPanelLayer` becomes
`showPanelLayer`, called once from `setPanel` — still before
`renderPanel`, for the reason #138 gave it.

The one user-visible consequence is the scrim: a non-modal dialog paints
no `::backdrop`, so the `.lf-panel::backdrop` rule goes with it. That
reads as the point rather than a cost — a scrim over a page the reader
can now press would be saying the opposite of what the page does.

## Which of the six this closes

Measured on this branch, rebased on `main` at 0b7f148 (so #121, #138 and
#141 are in the base).

| test | |
| --- | --- |
|
`test_selection_hints_do_not_name_page_content_behind_a_covering_panel`
| green |
| `test_workspaces_replace_each_other_instead_of_stacking[500]` | green
|
| `test_coarse_pointer_chrome_gives_its_compact_controls_humane_aims` |
green |
| `test_esc_hands_the_page_back_after_it_has_closed_the_last_panel` |
green — already fixed on `main` by #141, kept green here |
| `test_the_responsive_action_shelf_keeps_primary_actions_in_reach` |
green |
|
`test_coarse_pointer_resize_reach_stays_reachable_without_trapping_scroll`
| past its modal failure, red on one that is now `main`'s — see below |

## What this does not fix


`test_coarse_pointer_resize_reach_stays_reachable_without_trapping_scroll`
needed both this and #121, and with both it is still red — on a
different, earlier failure that #121 brought and this change does not
touch. Walking it forward, each row a local `-n0` run:

| tree | first failure |
| --- | --- |
| `main` at 1ca4f40 (pre-#121) | line 1017, `.lf-decisions` click —
`<dialog … class="lf-ui lf-panel open"> intercepts pointer events` |
| 1ca4f40 + this | line 1077, `assert edge["left"] >= -0.1` → `-12` |
| 1ca4f40 + #121 | line 1006, `wait_for_function` on `.lf-threads`
`scrollTop` after a touch swipe |
| `main` post-#121 | line 1006, same |
| `main` at 0b7f148 + this | line 1006, same |

Line 1006 is *earlier* than the failures the modal caused, so it was
masked until #121 landed; it is green on 1ca4f40 and on 1ca4f40 + this.
It belongs to #121's `overflow-y: scroll`, is live on `main` now, and
needs its own fix.

## Relation to #141

#141 landed while this was being measured. It fixed the focus half by
extending `syncPanelLayer`'s restore arm while keeping `showModal()`, so
`test_esc_hands_the_page_back_after_it_has_closed_the_last_panel` is
already green on `main`; this rebases onto it and replaces that arm
rather than competing with it. With modality gone the restore has one
case instead of four, and `focusEnteredLayer`, `panelFocusTarget` and
`returning` all go with it.

## Testing

<details><summary>Runs</summary>

On `main` at 0b7f148:

```
uv run pytest tests -q                                     724 passed, 6 skipped
uv run pytest --run-nightly -n2 <the six, 7 node ids>      6 passed, 1 failed
```

The one failure is the row above. Earlier, on the pre-rebase base
(1ca4f40), the owning files ran `5 failed, 77 passed` for
`test_render_controls.py` + `test_render_semantic_selection.py` and `2
failed, 45 passed` for `test_render_conversations.py`; every one of
those seven reproduced identically on clean `main` — five of the
reserved-gutter shape #121 has since taken, plus
`test_a_settlement_in_a_reply_leaves_its_own_anchor_on_the_page` and
`test_a_mark_in_the_layer_promises_no_press_the_layer_will_not_take`,
which are unrelated and untouched here.

No new test: the six already own the behaviour, and each names it in its
own docstring.

</details>

<details><summary>The visual delta, measured rather than
described</summary>

Same fixture, same viewport, same state — `LONG_PAGE` at 700×900 with
the Threads panel open, which is the covering posture. Panel geometry is
identical across the two (`x=265 y=96 w=420 h=804`); `dialog:modal`
reads `true` before and `false` after.

Every pixel outside the panel changes, and only by the scrim coming off:

```
left-of-panel differing px: 238500 of 238500   (222,221,219) -> (250,249,246)
panel-region differing px:   43380 of 391500   the banner band above the panel, same two colours
```

`(222,221,219)` is paper under `color-mix(in srgb, var(--ink) 12%,
transparent)`; `(250,249,246)` is paper. The banner was inside the
dimmed area too, which is the visible half of the bug: the chrome the
reader closes the panel from was drawn as if it were unavailable, and it
was.

</details>

---
Closes #139

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