Intent to Ship: Dispatch selectionchange event per element

494 views
Skip to first unread message

Shuangshuang Zhou

unread,
May 22, 2024, 10:21:58 AMMay 22
to blink-dev
Contact emailsshuangsh...@intel.com

ExplainerNone

Specificationhttps://w3c.github.io/selection-api/#selectionchange-event

Summary

Dispatches selectionchange event per element when this element(input/textarea) provides a text selection or its selection changes. This is to match the latest specification of selectionchange event. This also matches Safari behavior.



Blink componentBlink>Editing>Selection

TAG reviewNone

TAG review statusIssues addressed

Risks


Interoperability and Compatibility

Interoperability risk is low because Firefox and Safari have shipped this according to the specification. Compatibility risk is low because the selectionchange event targeting input/textarea would bubble up, and existing codes listening on Document will work well as ever.



Gecko: Shipped/Shipping

WebKit: Shipped/Shipping (https://commits.webkit.org/276238@main)

Web developers: No signals

Other signals:

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?

Low WebView application risks.



Debuggability

None



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

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

https://wpt.fyi/results/selection/onselectionchange-on-distinct-text-controls.html



Flag name on chrome://flagsNone

Finch feature nameDispatchSelectionchangeEventPerElement

Requires code in //chrome?False

Tracking bughttps://issues.chromium.org/issues/330766600

Estimated milestones
Shipping on desktop

127


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 Statushttps://chromestatus.com/feature/5255454895898624?gate=6043023317401600

This intent message was generated by Chrome Platform Status.

Daniel Clark

unread,
May 22, 2024, 12:28:45 PMMay 22
to Shuangshuang Zhou, blink-dev

The Gecko status is marked as Shipped/Shipping and the Interop/Compat section mentions Firefox having shipped this, but Firefox is still failing the WPTs at https://wpt.fyi/results/selection/onselectionchange-on-distinct-text-controls.html.

Can you help me understand the discrepancy there?

 

Thanks,

Dan

 

From: blin...@chromium.org <blin...@chromium.org> On Behalf Of Shuangshuang Zhou
Sent: Tuesday, May 21, 2024 10:24 PM
To: blink-dev <blin...@chromium.org>
Subject: [blink-dev] Intent to Ship: Dispatch selectionchange event per element

 

You don't often get email from shuangsh...@intel.com. Learn why this is important

--
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/de18f3c4-df5a-4423-80ec-e505e0c9fb2bn%40chromium.org.

Olli Pettay

unread,
May 22, 2024, 12:53:49 PMMay 22
to blink-dev, Daniel Clark, Shuangshuang Zhou
I think it is because of this rather surprising non-backwards compatible recent change.

Daniel Clark

unread,
May 22, 2024, 6:43:20 PMMay 22
to Olli Pettay, blink-dev, Shuangshuang Zhou

Yeah, that’s what I was trying to get at – the Intent implies that Gecko has also shipped the breaking change but it seems that might not be the case.

 

If not, we should send a Request for Position to figure out whether there would be cross-browser alignment on shipping this.

 

-- Dan

 

From: Olli Pettay <ope...@mozilla.com>
Sent: Wednesday, May 22, 2024 9:53 AM
To: blink-dev <blin...@chromium.org>
Cc: Daniel Clark <dan...@microsoft.com>; Shuangshuang Zhou <shuangsh...@intel.com>
Subject: Re: [blink-dev] Intent to Ship: Dispatch selectionchange event per element

 

You don't often get email from ope...@mozilla.com. Learn why this is important

Mike Taylor

unread,
May 22, 2024, 9:29:59 PMMay 22
to Shuangshuang Zhou, Daniel Clark, Olli Pettay, blink-dev

Shuangshuang Zhou

unread,
May 22, 2024, 10:07:43 PMMay 22
to blink-dev, mike...@chromium.org, dan...@microsoft.com, Olli Pettay, blink-dev, Shuangshuang Zhou
Hi Dan&Mike, for your concern that Firefox is still failing the WPTs at https://wpt.fyi/results/selection/onselectionchange-on-distinct-text-controls.html, that might be another issue. Let me make more explanation.

Actually, the final goal of w3c modifys the spec of selectionchange event is to avoid firing duplicated selectionchange event which are not executed yet on the same element(as Rniwa commented in his comment). Then in WebKit/WebCore, Rniwa submitted 2 CLs to achieve this ieda. The first CL in WebKit is 276238@main, and in this CL they just modified the logic to fire selectionchange event on input/textarea for the first step. Then the second CL in WebKit is 276388@main, which finally avoided to fire duplicated selectionchange events according to the latest spec on firing selectionchange event.

So for this feature in Blink here , we also want to take 2 steps like WebKit does that in the first CL we change to fire on input/textarea and then sovle the duplicated events in the second CL. And those tests are already modified to what both CLs are merged. So in the above test of onselectionchange-on-distinct-text-controls.html, chrome and firefox should be failed because only Safari has landed 2 CLs to avoid duplicated selectionchange events. Or in other words, firefox might already dispatch selectionchange event on elements but doesn't have the logic to avoid to fire scheduled-but-not-executed events. 

For WebKit, currently the two CLs are both landed in Safari Technology Preview 192(link), but it might need some time to ship in Safari because Safari is updated within OS updates.
For the status in FireFox, I'll double-check and confirm with Tkent(one reviewer of my first CL).

Thanks,
Shuangshuang

TAMURA, Kent

unread,
May 23, 2024, 9:20:33 PMMay 23
to Shuangshuang Zhou, blink-dev, mike...@chromium.org, dan...@microsoft.com, Olli Pettay
LGTM1.
Firefox and Safari statuses are strong signals, and the compatibility risk looks very low.




--
TAMURA Kent
Software Engineer, Google


Shuangshuang Zhou

unread,
May 24, 2024, 3:05:47 AMMay 24
to blink-dev, tk...@chromium.org, mike...@chromium.org, dan...@microsoft.com, Olli Pettay, Shuangshuang Zhou
Hi Dan&Mike, I think we could submit a standard-position issue to Mozilla for reducing duplicated events in our second CL(mentioned in my last comment) for this feature. Because in the second CL, we might change the current logic of dispatching selectionchange event. For this time, we might just do it in chromium. WDYT?

Thanks!

Olli Pettay

unread,
May 24, 2024, 10:22:40 AMMay 24
to blink-dev, Shuangshuang Zhou, tk...@chromium.org, mike...@chromium.org, dan...@microsoft.com, Olli Pettay
FWIW, I'm implementing the change in https://bugzilla.mozilla.org/show_bug.cgi?id=1898343
Need to still fix some tests, which do reveal how the spec change indeed isn't fully backwards compatible.
Hopefully it doesn't break any real web sites.



-Olli

Daniel Clark

unread,
May 24, 2024, 12:55:44 PMMay 24
to Olli Pettay, blink-dev, Shuangshuang Zhou, tk...@chromium.org, mike...@chromium.org

Thanks Shuangshuang for clarifying what’s going on with these two separate but related changes, and Olli for the update on https://bugzilla.mozilla.org/show_bug.cgi?id=1898343.

 

Since Gecko already implements the behavior of firing selectionchange on input/textarea (confirmed here), sounds good to me to go ahead with shipping this change in Chromium (I’m not an API owner though).

 

Separately, for the behavior of not firing duplicate selectionchange, it might not hurt to go ahead and request an official Mozilla position on that since it sounds like there’s still a bit of uncertainty about landing that change given back compat concerns, unless Olli confirms here that the plan is to go ahead and ship it.

Olli Pettay

unread,
May 24, 2024, 1:05:59 PMMay 24
to blink-dev, Daniel Clark, Shuangshuang Zhou, tk...@chromium.org, mike...@chromium.org, Olli Pettay
I am trying to land the change, so it should be in FF 128 Nightly soon, next week at latest. So hopefully we'll get feedback if it breaks something.
I don't think there is need for a standards-position for this particular small tweak.
(But the process of making this kind of breaking spec change was rather unusual.)


-Olli

Shuangshuang Zhou

unread,
May 26, 2024, 8:19:32 PMMay 26
to blink-dev, Olli Pettay, dan...@microsoft.com, Shuangshuang Zhou, tk...@chromium.org, mike...@chromium.org
Thanks Olli for the implement in Gecko side, and also Dan's comment!

Hi Mike, would you please take a look and give some suggestion? Also, seems we need 3 LGTMs, Kent or Mike, would you add another reviewer to to take a review?

Thanks!

Yoav Weiss (@Shopify)

unread,
May 27, 2024, 3:08:29 AMMay 27
to Shuangshuang Zhou, blink-dev, Olli Pettay, dan...@microsoft.com, tk...@chromium.org, mike...@chromium.org
Given Olli's comments on this change being backwards-incompatible, do we have any data on how many sites would be impacted? Any usecounters to that effect?

Shuangshuang Zhou

unread,
May 27, 2024, 7:54:30 PMMay 27
to blink-dev, yoav...@chromium.org, blink-dev, Olli Pettay, dan...@microsoft.com, tk...@chromium.org, mike...@chromium.org, Shuangshuang Zhou
Hi Yoav, thanks for the question! From chromium's side, currently I don't have any usecounters to trace how many sites would be impacted. I checked WebKit' status, seems they don't have any data. Maybe Olli could comment this from Gecko's side.

Since the first CL doesn't change the original logic, we might collect some data in the second CL(avoid to dispatch events that are already scheduled but not executed).

Thanks!

Yoav Weiss (@Shopify)

unread,
May 29, 2024, 4:43:00 AMMay 29
to Shuangshuang Zhou, blink-dev, Olli Pettay, dan...@microsoft.com, tk...@chromium.org, mike...@chromium.org
I'm sorry, but re-reading this, I realized that I don't fully understand this change and the plan here.
Can you elaborate on:
* What is the behavior change that we want to drive here?
* Which part of that would be covered by the first CL? which by the second?
* Where do we predict compat risk here? How can we estimate it?

Thanks! :)

Alex Russell

unread,
May 29, 2024, 11:52:57 AMMay 29
to blink-dev, Yoav Weiss, blink-dev, Olli Pettay, dan...@microsoft.com, Kent Tamura, Mike Taylor, shuangsh...@intel.com
hey folks,

We spent a lot of time in API OWNERs today trying to understand this change, and we couldn't crisply describe:

  • What the old behaviour was
  • What the new behaviour is going to be
  • If we've analysed the potential for site breakage, and if not, if we should be adding usecounters ahead of the change
Most of this is stuff we'd expect to see in an Explainer. Is it possible to produce one? Seeing example code for whatw this improves would be helpful.

Best,

Alex

Shuangshuang Zhou

unread,
May 30, 2024, 3:52:23 AMMay 30
to blink-dev, sligh...@chromium.org, yoav...@chromium.org, blink-dev, Olli Pettay, dan...@microsoft.com, tk...@chromium.org, mike...@chromium.org, Shuangshuang Zhou
Hi Yoav&Alex, thanks for the feedback. I'll make it more clear.

Generally speaking, the final goal is that, we want to avoid queuing a task to dispatch a selectionchange event when there is already a task scheduled to do that. This is to catch up the latest spec: https://w3c.github.io/selection-api/#scheduling-selectionhange-event.
Currently we divide this into 2 steps with one CL for each step to impelment this goal.

In this issue, we'd like to land the first CL that updates the implementation of selectionchange event to be fired on input element and textarea element instead of document. So the difference in the first CL is:
  1. The old behaviour:  When the element(input/textarea) provides a text selectionchange or its selection changes, we dispatch a selectionchange event on the document directly.
  2. The new behaviour: The new codes goes to that, in the same situations, if the selection changes, we fire this event first on the element(input/textarea) itself, and then it would be bubbled to the doument.

So, the final results are the same that, we finally get a selectionchange event on the document. The feature in this issue is mainly to do this change. After the first CL is landed, then we come to the second CL. The main change of the behaviour would be in the second CL.

In the second CL, we will change the behaviour:
  1. The old behaviour: When the element(input/textarea) provides a text selectionchange or its selection changes, we dispatch a selectionchange event on the element. We don't care whether this event is executed, and we just dipatch it.
  2. The new behaviour: Now based on the new spec(https://w3c.github.io/selection-api/#scheduling-selectionhange-event), we dispatch this event only when there is no scheduled one in the queue. If we have already scheduled one but not get callbacked, we would skip to dispatch this event.
To sum up, in this issue or mail thread, we only focus on what we did in the first CL. So previouly we think this is low-risk because we don't change anything at all. The real impact would happen in the second CL. So for the compat risk or maybe the potential for site breakage, maybe we could collect these data in the second CL.

These are the main difference between the first CL and the second CL. If you have any other concerns, feel free to ping me!

Thanks!

Domenic Denicola

unread,
May 30, 2024, 9:22:31 PMMay 30
to blink-dev, shuangsh...@intel.com, Alex Russell, Yoav Weiss, blink-dev, Olli Pettay, dan...@microsoft.com, Kent Tamura, Mike Taylor
LGTM2, to land the first CL.

Thanks for explaining. It sounds like the first CL, which this Intent is covering, is purely additive and should not have significant compatibility risk. It also brings us in line with the behavior Firefox has had for a long time, and the behavior that WebKit has recently adopted.

I look forward to your second Intent to Ship for the second CL, which will require more caution.

Chris Harrelson

unread,
May 31, 2024, 3:46:08 PMMay 31
to Domenic Denicola, blink-dev, shuangsh...@intel.com, Alex Russell, Yoav Weiss, Olli Pettay, dan...@microsoft.com, Kent Tamura, Mike Taylor

Shuangshuang Zhou

unread,
Jun 4, 2024, 3:11:11 AMJun 4
to blink-dev, Chris Harrelson, blink-dev, Shuangshuang Zhou, sligh...@chromium.org, yoav...@chromium.org, Olli Pettay, dan...@microsoft.com, tk...@chromium.org, mike...@chromium.org, dom...@chromium.org
Hi all, thanks for all the comments and LGTMs.

Let's moving on to the second CL.

Thanks!

Gaurang Tandon

unread,
Jun 13, 2024, 1:25:05 PM (9 days ago) Jun 13
to blink-dev, shuangsh...@intel.com, Chris Harrelson, blink-dev, sligh...@chromium.org, yoav...@chromium.org, Olli Pettay, dan...@microsoft.com, tk...@chromium.org, mike...@chromium.org, dom...@chromium.org
Hi all! I believe this CL has an unintentional behavior change for <input> elements inside shadow roots (open/closed). I have filed a detailed bug report here https://issues.chromium.org/issues/346898523 In brief, the issue is: when an <input> element is inside a shadow root, then its selectionchange event does not reach the top-level document. It stops at the shadow root itself. This is a new change in Chrome 127 (it worked fine in Chrome 126).

This behavior change is an issue for existing Chrome extensions that depend on this behavior. Considering the urgency of this issue, I thought its best to email the group directly to ask if this change is intentional. I hope this is the right place to highlight this issue.

Thanks,
Gaurang

Shuangshuang Zhou

unread,
Jun 14, 2024, 2:35:04 AM (8 days ago) Jun 14
to blink-dev, gau...@blaze.today, Shuangshuang Zhou, Chris Harrelson, blink-dev, sligh...@chromium.org, yoav...@chromium.org, Olli Pettay, dan...@microsoft.com, tk...@chromium.org, mike...@chromium.org, dom...@chromium.org
Thanks Gaurang for reporting this. We're now looking into this issue. It seems that the fired selectionchange event on the shadow node cannot propagate across the shadow DOM boundary into the standard DOM. We'll update directlty in the attached issue.

Thanks!
Reply all
Reply to author
Forward
0 new messages