Repository navigation
Read only the attached element when a command scope attaches, in live pages and exports - #2549
Merged
Merged
Conversation
An imperative `keys()` attach called `paintKeys()`, so the next frame re-read the `aria-keyshortcuts` of every scoped element on the page. A declaration changes no other element's shortcuts, and every attachment's own element was already read at the head of the next frame (`unpainted`, drained by `reflectFirstScopes`), so `attachScope` now only schedules that frame. `commandsOn` already did this on a re-render (#2504); its two branches collapse into one `attachScope` call, and its withdrawal schedules a frame rather than a page-wide pass, since `detachScope` re-reads the element itself. Behaviour change: an attach no longer marks the page's shortcuts dirty. A scope a painter attaches mid-frame (the banner's touch controls) gets its `aria-keyshortcuts` at the head of the following frame instead of the tail of the current one. In happy-dom, one attach beside 300 scoped elements went from 1,813 attribute reads to 7. On five shipped examples driven through the same key journey, the number of full reflections was identical with and without the change, because another owner always dirties the frame an attach lands in. The command-controls re-render test now also attaches imperatively and asserts that no other scoped element is read; that assertion fails on main. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
An export's repaint frame mounted only `reflectKeys`, so it never drained `unpainted` or ran the head's button passes. A scope attached after the first frame was read there only if some other owner happened to call `paintKeys()`, and a withdrawn `commandsOn` control was never handed its native `disabled` back. Both documents now mount both key slots, so an attachment's own reading is taken at the next frame's head wherever the runtime runs. Also corrects the stale `unpainted` comment. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 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.
From the review of the Lit survey PRs (item #51 in that review's numbering, not a GitHub issue).
#51: a command scope's attachment reads its own element only. An imperative
keys()attach calledpaintKeys(), which made the next frame re-read thearia-keyshortcutsof every scoped element on the page. A declaration changes no other element's shortcuts, and the attached element was already read on its own at the head of the next frame (unpainted, drained byreflectFirstScopes). SoattachScopenow only schedules that frame, the same rule #2504 gave acommandsOnre-render.commandsOn's two attach branches become oneattachScopecall,standScopefolds intoattachScope, and the directive's withdrawal schedules a frame instead of a page-wide pass, sincedetachScopealready re-reads the element.Interactive exports now take that reading too. An export's repaint frame mounted only
reflectKeys, so it never drainedunpaintedor ran the head-of-frame button passes. Before this PR, the attach's ownpaintKeys()was what read a late scope there. Even then, acommandsOnre-render or withdrawal in an export was read only if another owner dirtied the frame. The export now mountsreflectFirstScopesas well (leaf.js), andrepaint.jsrecords that the two key slots go together. I found no shipped page where an export showed the gap: a test exporting a screenshot comparison, whose divider attaches after presentation, passed with and without this change, because another owner dirties that frame. So the PR adds no browser test for it.Behaviour that changed: an attach no longer marks the whole page's shortcuts for re-reading. A scope that a painter attaches mid-frame (the banner's touch controls, 18 per page) now gets its
aria-keyshortcutsat the head of the next frame rather than at the tail of the current one.Measured:
paintKeys()on attach (main)keys()attach beside 300 scoped elements:getAttributecallsreflectKeyspasses over one key journey (review-a-plan / triage-board / pr-walkthrough / ship-review / command-hub)On the shipped pages, the change saves no full passes: in each frame where an attach lands, another owner has already called
paintKeys(). The saving is for an attach in an otherwise quiet frame on a page with many scoped elements. The case for the change is that both attachment paths now follow one rule, which removes a branch.History:
keys()calledrepaint()until #1788 changed it topaintKeys(), the same commit that added the button-availability pass toreflectFirstScopes. That commit gives no reason for the switch, and that button pass now runs at the head of every frame either way.Line deltas:
keyboard/scopes.js,repaint.js,leaf.js)Checks: all 361 runtime tests. The extended
command-controlscase attaches imperatively beside another scoped element and asserts that the other element isn't read; that assertion fails onmain. Also 63 browser cases that assertaria-keyshortcuts, the shortcut bar or the command reference, run fromtest_render_navigation,_controls,_anchors,_options,_widgets,_margin,_threads,_reactions,_drafts,_projectionand_semantic_selection, plus six interactive-export cases intest_render_export.