Skip to content

Read only the attached element when a command scope attaches, in live pages and exports - #2549

Merged
max-sixty merged 4 commits into
mainfrom
agent-abdc615db9c371bd5
Oct 12, 2026
Merged

max-sixty merged 4 commits into
mainfrom
agent-abdc615db9c371bd5

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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 called paintKeys(), which made the next frame re-read the aria-keyshortcuts of 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 by reflectFirstScopes). So attachScope now only schedules that frame, the same rule #2504 gave a commandsOn re-render. commandsOn's two attach branches become one attachScope call, standScope folds into attachScope, and the directive's withdrawal schedules a frame instead of a page-wide pass, since detachScope already re-reads the element.

Interactive exports now take that reading too. An export's repaint frame mounted only reflectKeys, so it never drained unpainted or ran the head-of-frame button passes. Before this PR, the attach's own paintKeys() was what read a late scope there. Even then, a commandsOn re-render or withdrawal in an export was read only if another owner dirtied the frame. The export now mounts reflectFirstScopes as well (leaf.js), and repaint.js records 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-keyshortcuts at the head of the next frame rather than at the tail of the current one.

Measured:

paintKeys() on attach (main) this PR
happy-dom, one keys() attach beside 300 scoped elements: getAttribute calls 1,813 7
happy-dom, same, time per attach 1.4 ms 0.19 ms
Chrome, full reflectKeys passes over one key journey (review-a-plan / triage-board / pr-walkthrough / ship-review / command-hub) 9 / 3 / 6 / 10 / 4 9 / 3 / 6 / 10 / 4

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() called repaint() until #1788 changed it to paintKeys(), the same commit that added the button-availability pass to reflectFirstScopes. That commit gives no reason for the switch, and that button pass now runs at the head of every frame either way.

Line deltas:

source tests
#51 (keyboard/scopes.js, repaint.js, leaf.js) −9 (+21 −30) +8 (+9 −1)

Checks: all 361 runtime tests. The extended command-controls case attaches imperatively beside another scoped element and asserts that the other element isn't read; that assertion fails on main. Also 63 browser cases that assert aria-keyshortcuts, the shortcut bar or the command reference, run from test_render_navigation, _controls, _anchors, _options, _widgets, _margin, _threads, _reactions, _drafts, _projection and _semantic_selection, plus six interactive-export cases in test_render_export.

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

max-sixty and others added 4 commits October 12, 2026 01:02
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]>
@max-sixty
max-sixty merged commit 8326d74 into main Oct 12, 2026
3 checks passed
@max-sixty
max-sixty deleted the agent-abdc615db9c371bd5 branch October 12, 2026 08:23
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