Repository navigation
Let the command reference dismiss contextual popovers - #894
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
Nesting the dialog works — the ancestor popover does survive showModal(), and the layer stack is genuinely smaller for it. But the new parent is a node whose owner hides and reparents it on its own schedule, and neither owner knows a modal is inside. Both of those moves take the reference off the screen while it still claims the keyboard.
The reference disappears when its host popover is hidden or moved
A covering auxiliary surface. auxiliary-modality.js hides every popover the new boundary excludes (for (const popover of openPopovers()) if (!layerAllowedBy(controller, popover)) popover.hidePopover();). With the reference nested inside one of them, hiding the popover takes the dialog's box away while the dialog stays modal. Measured at the point the PR's own test_reference_keeps_its_popover_only_inside_the_current_modal_boundary reaches after resized(page, 500, 800):
open |
dialog:modal |
checkVisibility() |
getClientRects().length |
parent | |
|---|---|---|---|---|---|
base 910e858a |
True |
True |
True |
1 | lf-chrome |
head e652e3d6 |
True |
True |
False |
0 | lf-ui lf-version-menu |
The test presses Escape immediately afterwards, so it never looks at this window. A reader who narrows the viewport with the reference up sees it vanish and then has every key swallowed by a modal that isn't on screen.
A publication. banner-status-view.present() hides the detail popover and then moves it into the publication layout:
if (model.publication && this.#detail.matches(":popover-open")) this.#detail.hidePopover();
...
render(html`${this.#dot}${this.#text}${this.#detail}`, this);Reparenting an ancestor removes the nested dialog from the document and back, which drops it out of the top layer. Opening the reference from the status disclosure and then presenting a publication gives {open: True, modal: False, visible: False} — the reference is now neither visible nor modal, while commandReferenceIsOpen is still true. Escape recovers it, but nothing tells the reader to press it.
That file's own header states the invariant this breaks: "no outside code writes or reparents anything inside it." The PR makes command-reference.js append into #detail without changing that sentence or telling its owner.
The widened handBack guard is the tell. atClose === document.body with the comment "Closing an ancestor popover while its descendant modal remains up can leave focus on body" is this same situation, caught at the focus symptom and settled there — the reference losing its box and its modality goes unhandled. Per Stage in CLAUDE.md, that is the patch the next reader has to undo first.
What produced it is the ownership split: .lf-chrome is the one parent for a shared chrome node, and the surfaces that can now hold the reference are Lit-rendered views that hide and reparent their own popovers. Either the reference needs a declared handoff from a host popover about to move or hide, or the ancestry it needs has to come from something other than co-parenting. getRootNode() === document picks the wrong axis for the same reason — it asks which tree the popover is in, when the question is which owner controls its lifetime and styling. (chrome.css is one @scope (.lf-chrome), so a document-tree popover outside the chrome root would also strip every rule off the dialog; nothing in the tree builds one today, which is luck rather than a guard.)
How these were measured
Both readings come from probe cases run against the PR head and, for the first, against merge base 910e858a, using tests/test_render_navigation.py's own fixtures (LONG_PAGE, open_page, resized, panel_settled) and tests/test_render_controls.py's SUGGESTION_PAGE. The first reproduces the PR's modified navigation test up to the resize and reads open / dialog:modal / checkVisibility() / getClientRects().length / parentElement off .lf-command-reference; the second opens the status disclosure, presses ? twice, then calls present() with a frozen publication model and reads the same fields.
One candidate was checked and refuted: the new ancestry does not leak the host popover's scope into the reference's. With the reference open inside the versions menu, the key line still reads ['command.reference.close', 'command.reference.focus.walk'].
leaf-agent
left a comment
There was a problem hiding this comment.
The rewrite dissolves both findings from my earlier review. There is no reparenting for an ancestor to take away, no restoration pass, and no suspended entry — prune and pushNativeLayer are plain again. The four cases the PR changes pass here at 36d02ec8.
One thing the removal took with it, on the path the PR claims.
The origin is read before the dismissal that invalidates it
showCommandReference records commandReferenceOrigin from focused() and then hides the popover that node stands in. At close, handBackTo finds the origin connected but not visible, concedes, and calls letGo() — so a reader who opened the reference from inside a contextual popover is handed back the page rather than a place.
Measured at 36d02ec8 with tests/test_render_navigation.py's fixtures: Threads open, a .lf-thread focused, g Shift+V, ?, ?, Escape.
document.activeElement after Escape |
|
|---|---|
head 36d02ec8 |
body |
| same, with the origin read moved below the dismissal loop | div.lf-thread-compact.lf-thread |
The second row is the platform's own answer rather than a new rule: hiding a popover with focus inside it restores focus to where the reader stood when it opened — calling hidePopover() on .lf-version-menu directly moves focus from .lf-version-row to that same .lf-thread. So by the time the dismissal loop finishes, the scene the reference will leave standing already names the place the reference owes the reader. Reading the origin one statement earlier throws that away and substitutes a node the same function is about to hide.
That it is a regression and not the intended half of the change is what the deleted assertions say: on base the reader came back into the menu (expect(versions).to_be_visible(), then ArrowUp focusing row 2). This PR is right that the menu should not come back. Landing on body instead of on the thread the menu was opened from is the separate loss.
Moving the two statements below the loop is the whole fix, and the four changed cases still pass with it — suggestion inline.
Left behind
auxiliaryAllowsNativeLayer in register.js and the allowsNativeLayer reading backing it in auxiliary-modality.js lose their last caller in this diff, as does coveringAuxiliaryFocus (coveringFocus itself stays live through leaf.js's landing). Worth going out with the approach that needed them.
The popover set unions openPopovers() with document.querySelectorAll(":popover-open"), which reads as a caller covering for a gap in its callee: querySelectorAll does not cross a shadow boundary, so the second term can only add a light-DOM popover the stack missed — and auxiliary-modality.js runs the same loop over openPopovers() alone, so it still misses it. The PR's own selection does not distinguish the two: the four changed cases also pass with the second term dropped. If the stack can miss one, that belongs in openPopovers().
How these were measured
Both readings come from probe cases run against head 36d02ec8 using tests/test_render_navigation.py's LONG_PAGE, _publish, open_page, resized, and panel_settled. The first reproduces the sequence above and reads the deep document.activeElement after Escape settles; the second opens the version menu the same way and calls .lf-version-menu.hidePopover() from page context, reading document.activeElement synchronously after it.
The candidate is the two statements const at = focused(); and commandReferenceOrigin = at === document.body ? null : at; moved below the hidePopover() loop, nothing else. With it applied, test_reference_accepts_native_popover_dismissal_across_modal_entry, test_the_key_line_says_what_a_press_will_do, test_native_top_layers_bound_the_keyboard_stack, and test_banner_status_is_compact_with_accessible_details pass.
leaf-agent
left a comment
There was a problem hiding this comment.
The approach is the right one and 497a7069 closes out what the earlier rounds raised. Two things the rewrite carried in that the diff does not account for.
The layer-stack test loses its popover-over-modal step
test_native_top_layers_bound_the_keyboard_stack stands a shadow-root auto popover over a nested modal, and the new reference block dismisses that popover before the assertions that were reading it. What went with it is the whole stack-ordering step:
page.keyboard.press("Escape")
expect(popover).to_be_hidden()
expect(modal).to_be_visible()
assert page.locator("#around-native-layer").get_attribute("data-fired") is None
page.keyboard.press("Escape")That was the suite's only proof that an auto popover over a modal is the layer Escape takes first, with the modal surviving underneath and the widget ancestor outside the dialog still unfired. The only other test that puts a popover and a showModal() in one scene is test_authored_page_paints_but_durable_controls_wait_for_first_replay, which uses manual popovers to check deferred promotion and never presses Escape. The surviving comment — "The popover is nonmodal, but the modal below it remains a hard floor" — now stands over a scene with no popover in it, so the l press beneath it reads the modal alone.
This PR rewrites layer-stack.js and deletes its suspension machinery, so that is coverage worth keeping rather than coverage to spend on the new case. Reopening the popover between the two blocks keeps both; suggestion inline. With it applied to 497a7069 merged onto 1334c114, the fifteen navigation and control cases covering the reference, the native stack, the key line, the status banner, and the covering workspace pass.
The invoker-commands cutover leaves with no reason given
TODO.md and notes/dependency-survey.md both drop the Invoker commands candidate — command/commandfor replacing imperative dialog and popover invocation once Leaf's Chromium floor reaches 135. That deletion is from e652e3d6, whose approach 36d02ec8 replaced, and nothing in the final diff bears on it: deferred-modals.js still patches HTMLDialogElement.prototype.showModal and HTMLElement.prototype.showPopover, and the reference still opens with commandReferenceDialog.showModal(). Since the merge squashes this description into main's commit message, a standing platform-cutover candidate would leave the priority list with nothing recording why. Either restore it or say what retires it.
… rows, and move six nightly tests onto #894 and #895 (#910) `ci` on `main` went red at b7bd021 (#904): [`lint` and `test` passed, and the complete suite in `nightly` failed on eleven cases](https://github.com/max-sixty/leaf/actions/runs/35670525383). One is fixed on today's `main` by e291a95, four are #903's and still open, and this PR is the other six. None of them is #904's. They come from two features that landed earlier the same day and were validated against the everyday gate rather than the nightly selection, so the first run to reach them was this one. **#894 made the command reference dismiss the popover it is opened over. Three cases still assert the restoration it removed.** Opening the reference now follows the platform's modal transition: auto popovers close and are not rebuilt. `test_the_version_menu_is_worked_by_pointer_and_key`, `test_the_versions_menu_suspends_the_pages_own_keys` and `test_a_row_the_platform_activates_names_both_of_its_keys` each ran the reference round trip mid-case and carried on working the menu behind it. They now assert the dismissal where they asserted the return, and stand the menu up again through `open_versions` where the rest of the case needs it. The pair of boundary rows in the third case needed the runtime instead, and is the second fault below. **#895 hoisted a thread's first message head out of the message and onto the card. Two cases still read it from the message.** `ThreadView` renders `messages[0].header` into a `.lf-thread-root-meta` row that carries the thread's Resolve beside the author, so `.lf-edited` and `.lf-conversation-head` are no longer inside `.lf-conversation-msg`. `test_an_agent_message_edit_updates_the_panel_and_its_inline_conversation` read the edit disclosure from the message node on both surfaces and found nothing; it now reads it from the card holding that message. `test_the_margin_groups_meanings_at_one_destination_without_moving_the_page` resolved the head to `null` and raised on its box. Its selector now names the row, which is what has a box — the head itself is `display: contents` there, so keeping the old selector shape would have left that assertion reading zeros and passing vacuously. **#895 moved `--thread-card` from 460px to 380px. One case's viewport was tuned to 460.** `test_a_thread_beside_its_cluster_takes_the_room_to_the_visible_edge` is the narrowing case in a ladder of three: at 1440 the rail used to fall a few pixels short of the card's measure. Against 380 it leaves 453px of room, so the card takes its preferred width with room to spare and never reaches the visible edge. The case runs at 1220 now, where the room is 343px, and asserts that arrangement against `--thread-card-min` and `--thread-card` before it asserts the outcome — so the next move of either token reddens the premise and names the width to re-pick rather than reading as a layout regression. **One fault in the layer: the card's Dismiss lost the row it shares.** Before #895 the margin preview's thread head was absolutely positioned at `inset-block-start: 12px`, the same inset as the card's own head, and Resolve and Dismiss sat on one line. #895 replaced it with the sticky `.lf-thread-root-meta`, which starts inside the thread's own 4px of padding, while the card's head stayed at 12px — so the two icon actions in that corner are 4px out. The stylesheet still states the arrangement they are meant to keep (`The retained settlement action is positioned against the card, alongside Dismiss`), and the nightly case is the reading of it. The head now starts at the card inset plus that padding, so Dismiss lands on the row Resolve rides; the comment beside it is updated to say which of the two is positioned against which, since #895 reversed that. **A second fault: the versions menu's two Tab rows can no longer be read anywhere.** `version.leave-forward` and `version.leave-backward` declare `when: () => atVersionBoundary(…)`, which compares `document.activeElement` against the menu's stops. That is a dispatch question — the press closes the menu only from the end it is held to — and since #894 the reference asks it of a menu the modal has just dismissed, so it answers no for both and the catalogue drops them. They are the only rows in `In the versions menu` that vanish: the other seven stay, each with `data-lf-available="false"`, which is the reading `test_reference_accepts_native_popover_dismissal_across_modal_entry` already asserts for `version.open-v*`. `?` is the only door into the reference and it always dismisses the menu, so no scene is left in which either row can be read, and the shortcut bar names only the one direction the reader can take from where they stand. Both rows now carry `commandReferenceWhen: () => true`, the hook `command-reference.js` offers for this exact split and that its own rows and `margin-projection.js` use, and the third case asserts both directions again, each marked unreachable. ## Verification The six cases pass on this branch and all six fail on `main` without it, along with the neighbouring short-rail case the narrowing one shares its fixture with. Run whole under `--run-nightly` on this head: `tests/test_render_anchors.py` 93 passed; `tests/test_render_navigation.py` and `tests/test_render_controls.py` together 240 passed with one failure, `test_every_shadow_the_layer_lifts_a_box_with_is_cast_in_the_scheme_s_own_ink`, which is #903's; `tests/test_render_margin.py` 125 passed with one failure, `test_a_forced_inline_thread_keeps_its_control_inside_the_margin_budget`, which is #903's too. `tests/test_render_widgets.py` was 179 passed before the reference commit, which does not touch it. `npm run test:runtime` is 33 passed, and pre-commit is clean on the changed files. The reference reading was measured directly in a browser both ways: without the row change the version scope shows seven commands and neither boundary row; with it, nine, both boundary rows reading `data-lf-available="false"` beside `version.open-v1` and `version.open-v2`. PR CI's `lint` and `test` do not reach any of these cases, since the nightly selection is what holds them. <details><summary>Attribution, and what this leaves</summary> **Attribution.** Each failure was placed by running the case against the runtime and tests at the commits between the two nightly runs. The three versions-menu cases fail with #904's assets reverted to 517c4c2, so #904 is not their cause; 1888c6e (#894) is, and its own diff moved `tests/test_render_navigation.py` and `tests/test_render_controls.py` onto the new contract while these three sat in a third file. `git show 39d9cad -- skills/leaf/assets/theme.css` is the `--thread-card` move, and `git log -S externalHeader -- skills/leaf/assets/runtime/conversation/messages.js` returns 39d9cad alone. **The measured geometry.** The narrowing case needs the width left for the card — the gap between the cluster and the visible edge, less the 8px either side — to fall between `--thread-card-min` and `--thread-card`. Measured on the gallery, that width is half the viewport less 267px while the viewport is at or above 1160, below which the rail's own breakpoint moves it: 453px at 1440, 373px at 1280, 343px at 1220, 313px at 1160, and 148px at 1120. The two tokens leave a window from 1174 to 1294, and 1220 sits near its middle. On the alignment fix, Dismiss and Resolve read `top: 523.3` and `527.3` before and `527.3` for both after. **Not in this PR.** Four of the run's eleven belong elsewhere. `test_a_widgets_native_control_names_the_press_the_platform_makes` was repaired on `main` by e291a95, which renamed it; the other four — the elevation shadow, the printed-page word, the widget-root projection and the forced inline thread's margin budget — are #903's, which is open and based on 5854f06. That PR also rewrites the case e291a95 has since replaced and drops the `NATIVE_CONTROL_PAGE` fixture `main` still uses, so it needs a look at `main` before it lands; noted on that thread. **What produced all six.** Both features changed a contract that the everyday gate does not reach and the nightly selection does, and both were validated against the gate that runs before merge. Nothing here changes that; it is the same shape #903 names, one nightly run later. </details> --------- Co-authored-by: leaf-agent <[email protected]>
The command reference is global chrome. Opening it now follows the platform's modal transition: auto and hint popovers close and are not reconstructed, while manual popovers retain their native behavior. Leaf closes those transient popovers before taking the ordinary command-route snapshot, so commands belonging only to a dismissed context are no longer offered as actions.
This removes the dialog reparenting, popover restoration, suspended layer-stack state, and the auxiliary-layer readings that restoration alone consumed. The complete branch has 72 fewer production-runtime lines and 15 fewer lines overall. Browser journeys cover Status, Versions, margin cards, focus return, light-DOM and shadow-root popovers, and the native layer stack.
Tests:
uv run pytest tests(1206 passed);npm run test:runtime(28 passed); affected-file pre-commit hooks; focused browser journeys (5 passed). The complete navigation/control browser files also passed 237 cases; their two existingpr-walkthroughfocus-ring failures reproduced unchanged on merge base910e858a.