You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
anchorNode & focusNode can never be in shadow tree? #361
The spec is probably wrong here. Chromium and Firefox both pass the test, Safari fails. But the test is not directly focused on all the cases we might care about here, it's more focused on selection collapsing. In particular, there is a a question of whether anchorNode/focusNode should be retarget their result into the light DOM before returning (which is probably more correct), or whether they should just return a shadow node directly (which is what Chromium and Firefox seem to do).
The next step would be to write a WPT focused on these scenarios:
When selection is in a shadow DOM, including cases with nested shadow DOMs, what do focusNode/anchorNode return? The node itself, null, or the node retargeted into the light DOM?
When selection is on a node that's <slot>ted into a shadow DOM, what gets returned for focusNode/anchorNode? The slotted node, the slot, the shadow host, null?
Selection is not allowed to bypass encapsulation so if the selection is returned from window.getSelection() you should not be able to get shadow root nodes from it.
I agree with that, but a question here is that would changing the behavior break lots of sites. I guess we need some telemetry.
And if we do retargeting, what kind of retargeting? selection is a weird beast, where APIs tend to deal with DOM tree, but visually it is a flat tree (and because of slots and such, ordering in those trees might be different).
RESOLVED: @smaug---- will write tentative WPTs, including more interesting slotting cases etc. Chromium will also add telemetry to see how often these focus getters are called for selections in shadow roots.
Activity
dandclark commentedon Sep 10, 2026
Discussed in September meeting:
The spec is probably wrong here. Chromium and Firefox both pass the test, Safari fails. But the test is not directly focused on all the cases we might care about here, it's more focused on selection collapsing. In particular, there is a a question of whether
anchorNode/focusNodeshould be retarget their result into the light DOM before returning (which is probably more correct), or whether they should just return a shadow node directly (which is what Chromium and Firefox seem to do).The next step would be to write a WPT focused on these scenarios:
focusNode/anchorNodereturn? The node itself, null, or the node retargeted into the light DOM?<slot>ted into a shadow DOM, what gets returned forfocusNode/anchorNode? The slotted node, the slot, the shadow host, null?annevk commentedon Sep 11, 2026
Selection is not allowed to bypass encapsulation so if the selection is returned from
window.getSelection()you should not be able to get shadow root nodes from it.smaug---- commentedon Oct 8, 2026
I agree with that, but a question here is that would changing the behavior break lots of sites. I guess we need some telemetry.
And if we do retargeting, what kind of retargeting? selection is a weird beast, where APIs tend to deal with DOM tree, but visually it is a flat tree (and because of slots and such, ordering in those trees might be different).
dandclark commentedon Oct 29, 2026
From TPAC 2026 Editing WG meeting:
RESOLVED: @smaug---- will write tentative WPTs, including more interesting slotting cases etc. Chromium will also add telemetry to see how often these focus getters are called for selections in shadow roots.
smaug---- commentedon Nov 12, 2026
I'm adding tests in https://bugzilla.mozilla.org/show_bug.cgi?id=2092098