Web-Facing Change PSA: Fix Selection isCollapsed in Shadow DOM

247 views
Skip to first unread message

Di Zhang

unread,
Oct 15, 2024, 5:43:23 PM10/15/24
to blink-dev

Contact emails

dizh...@chromium.org

Specification

https://w3c.github.io/selection-api/#dom-selection-iscollapsed

Summary

Selection isCollapsed should return true if and only if the anchor and focus are the same. This should be true whether the selection starts/ends inside a light or a shadow tree. Currently, the chromium implementation returns true if selection's anchor node is in a shadow tree, even if the selection itself is not collapsed. We fix this by removing the erroneous shadow tree check.



Blink component

Blink>DOM>ShadowDOM

TAG review

None

TAG review status

Not applicable

Risks



Interoperability and Compatibility

This matches the standards definition of a collapsed selection. This matches Firefox/Gecko's implementation. Safari/Webkit still has this bug. Because Selection in and across shadow trees is not well supported yet, this bug has been in the code for a long time. We added a use counter to check how often the result for selection.isCollapsed will differ due to this shadow tree check (called SelectionIsCollapsedBehaviorChange). Currently, Selection::isCollapsed is high usage at 3% of all page loads [1]. On the other hand, the SelectionIsCollapsedBehaviorChange feature change is currently at a low usage of 0.001% of all page loads [2]. Overall, since the change usage is low and we are making this change to fix a bug with clear specification text, the compatibility risk is low. [1] https://chromestatus.com/metrics/feature/timeline/popularity/1001 [2] https://chromestatus.com/metrics/feature/timeline/popularity/5101



Gecko: Shipped/Shipping

WebKit: No signal Webkit has this bug, since this has existed for a long time.

Web developers: No signals

Other signals:

Ergonomics

There are no other APIs that this feature will used in tandem with.



Activation

It should not be challenging for developers to take advantage of this feature immediately.



Security

There are no security risks for this feature.



WebView application risks

Does this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications?

None



Debuggability

DevTools support for this feature is not needed.



Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, ChromeOS, Android, and Android WebView)?

Yes

All platforms support DOM selection.



Is this feature fully tested by web-platform-tests?

Yes

https://wpt.fyi/results/selection/shadow-dom/tentative/Selection-isCollapsed.html?label=experimental&label=master&aligned



Flag name on chrome://flags

SelectionIsCollapsedShadowDOMSupport

Finch feature name

None

Non-finch justification

This is a long term bug fix and is a no developer-visible change.



Requires code in //chrome?

False

Tracking bug

https://issues.chromium.org/issues/40400558

Sample links


https://codepen.io/Di-Zhang/pen/jOjdeoX

Estimated milestones

Shipping on desktop131
Shipping on Android131
Shipping on WebView131


Anticipated spec changes

Open questions about a feature may be a source of future web compat or interop issues. Please list open issues (e.g. links to known github issues in the project for the feature specification) whose resolution may introduce web compat/interop risk (e.g., changing to naming or structure of the API in a non-backward-compatible way).

None

Link to entry on the Chrome Platform Status

https://chromestatus.com/feature/5175599392620544?gate=5084420995022848

This intent message was generated by Chrome Platform Status.

Daniel Clark

unread,
Oct 15, 2024, 9:25:05 PM10/15/24
to Di Zhang, blink-dev
> WebKit: No signal Webkit has this bug, since this has existed for a long time.

Is there a bug filed in their issue tracker for this? If not maybe you could file one and see if there’s willingness on their side to fix it? It would be nice if there was alignment here since the current behavior is so clearly broken.

Thanks!
-- Dan

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CA%2BSS7eCxjhuVojPQe%2BFekbsR%2B8ttnGa2_9FbGM-t3uJPmS51Og%40mail.gmail.com.

Di Zhang

unread,
Oct 16, 2024, 1:25:36 PM10/16/24
to blink-dev, dan...@microsoft.com, Di Zhang
I couldn't find one, so I created: https://bugs.webkit.org/show_bug.cgi?id=281587
Thanks!

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.

Di Zhang

unread,
Dec 3, 2024, 11:33:14 AM12/3/24
to blink-dev, Di Zhang, dan...@microsoft.com
Correction for the original PSA that this bug fix was enabled in 132 instead of 131.
Reply all
Reply to author
Forward
0 new messages