Fixed
Status Update
Comments
ha...@chromium.org <ha...@chromium.org> #2
[Empty comment from Monorail migration]
[Deleted User] <[Deleted User]> #3
Changing the Status and Adding MileStone so that Issue can be further triaged.
sh...@gmail.com <sh...@gmail.com> #4
I'm running into this issue. My workaround is to use range.collapsed. I made a jsfiddle to display this issue.
http://jsfiddle.net/7zgegoda/2/
am...@chromium.org <am...@chromium.org> #5
[AUTO] Moving all non essential bugs to the next Milestone. (This decision is based on the labels attached to your ticket.)
Ref:https://sites.google.com/a/chromium.org/dev/developers/ticket-milestone-punting-1
Ref:
pe...@google.com <pe...@google.com> #6
[AUTO] This issue has already been moved once and is lower than Priority 1,therefore removing mstone.
yo...@chromium.org <yo...@chromium.org> #7
It seems an implementation of DOMSelection::isCollapsed() is broken.
It always returns true for selection in shadow tree.
bool DOMSelection::isCollapsed() const
{
if (!m_frame || selectionShadowAncestor(m_frame))
return true;
return !m_frame->selection().isRange();
}
We should compute a range in the specified shadow tree then check it, like workaround described in #3,
without creating Range object, to avoid temporary Range object registration to Document.
It always returns true for selection in shadow tree.
bool DOMSelection::isCollapsed() const
{
if (!m_frame || selectionShadowAncestor(m_frame))
return true;
return !m_frame->selection().isRange();
}
We should compute a range in the specified shadow tree then check it, like workaround described in #3,
without creating Range object, to avoid temporary Range object registration to Document.
ha...@chromium.org <ha...@chromium.org> #8
[Empty comment from Monorail migration]
ha...@chromium.org <ha...@chromium.org> #9
[Empty comment from Monorail migration]
[Monorail components: -Blink>WebComponents Blink>DOM>ShadowDOM]
[Monorail components: -Blink>WebComponents Blink>DOM>ShadowDOM]
tk...@chromium.org <tk...@chromium.org> #10
[Empty comment from Monorail migration]
[Monorail components: -Blink>TextSelection Blink>Editing>Selection]
[Monorail components: -Blink>TextSelection Blink>Editing>Selection]
lu...@chromium.org <lu...@chromium.org> #11
It seems like this happens whenever the selection starts inside a shadow root and ends somewhere else. In DevTools, this bug causes selection to trigger editing in the Elements' styles sidebar even when it should not.
A small repro here (selecting from the shadow into the light results in a collapsed selection):
http://jsfiddle.net/7zgegoda/3/
A small repro here (selecting from the shadow into the light results in a collapsed selection):
lu...@chromium.org <lu...@chromium.org> #12
[Empty comment from Monorail migration]
yo...@chromium.org <yo...@chromium.org> #13
[Empty comment from Monorail migration]
ha...@chromium.org <ha...@chromium.org> #15
[Empty comment from Monorail migration]
[Monorail components: -Blink>DOM>ShadowDOM]
[Monorail components: -Blink>DOM>ShadowDOM]
yo...@chromium.org <yo...@chromium.org> #16
[Empty comment from Monorail migration]
sh...@chromium.org <sh...@chromium.org> #17
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.
Sorry for the inconvenience if the bug really should have been left as Available.
For more details visithttps://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Sorry for the inconvenience if the bug really should have been left as Available.
For more details visit
yo...@chromium.org <yo...@chromium.org> #18
[Empty comment from Monorail migration]
sh...@chromium.org <sh...@chromium.org> #19
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.
Sorry for the inconvenience if the bug really should have been left as Available.
For more details visithttps://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Sorry for the inconvenience if the bug really should have been left as Available.
For more details visit
ea...@chromium.org <ea...@chromium.org> #20
[Empty comment from Monorail migration]
pc...@microsoft.com <pc...@microsoft.com> #21
[Empty comment from Monorail migration]
pc...@microsoft.com <pc...@microsoft.com> #22
[Empty comment from Monorail migration]
[Deleted User] <[Deleted User]> #23
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.
Sorry for the inconvenience if the bug really should have been left as Available.
For more details visithttps://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Sorry for the inconvenience if the bug really should have been left as Available.
For more details visit
si...@microsoft.com <si...@microsoft.com> #24
[Empty comment from Monorail migration]
ma...@chromium.org <ma...@chromium.org> #25
[Empty comment from Monorail migration]
is...@google.com <is...@google.com> #26
This issue was migrated from crbug.com/chromium/447523?no_tracker_redirect=1
[Monorail blocked-on:crbug.com/chromium/762799 ]
[Monorail blocking:crbug.com/chromium/654163 ]
[Monorail mergedwith:crbug.com/chromium/1096446 , crbug.com/chromium/1271619 ]
[Monorail components added to Component Tags custom field.]
[Monorail blocked-on:
[Monorail blocking:
[Monorail mergedwith:
[Monorail components added to Component Tags custom field.]
rl...@chromium.org <rl...@chromium.org> #27
Hi, I found this bug when I was reading through the Anki source code:
https://github.com/ankitects/anki/blob/b1bf1c3141863585989d5d541a73edb0265f866a/ts/lib/tslib/cross-browser.ts#L33-L40
/**
* Avoid using selection.isCollapsed: it will always return
* true in shadow root in Gecko
* (this bug seems to also happens in Blink)
*/
export function isSelectionCollapsed(selection: Selection): boolean {
return getRange(selection)!.collapsed;
}
So this is another example (in addition to comment #4 ) of a real-world app that contains a workaround for the behavior described in this bug (obviously it seems pretty easy to work around, if you know how). It seems fairly straightforward to fix if we know the correct behavior.
The W3C Editor's Draft 20 March 2024 of the Selection API spec says:
https://w3c.github.io/selection-api/#dom-selection-iscollapsed
> isCollapsed
> The attribute must return true if and only if the anchor and focus are the same (including if both are null). Otherwise it must return false.
There’s also a note:
https://w3c.github.io/selection-api/#h-note-3
> anchor and focus of selection need not to be in the document tree. It could be in a shadow tree of the same document.
The current code for DOMSelection::isCollapsed is as follows:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/dom_selection.cc;l=163-180;drc=91084df601702769cfc64fcba6f2e6d00558d2dd
bool DOMSelection::isCollapsed() const {
if (!IsAvailable())
return true;
Node* node = Selection()
.ComputeVisibleSelectionInDOMTreeDeprecated()
.Anchor()
.AnchorNode();
if (node && node->IsInShadowTree() &&
DomWindow()->document()->AncestorInThisScope(node)) {
return true;
}
TemporaryRange temp_range(this, PrimaryRangeOrNull());
if (temp_range.GetRange()) {
return temp_range.GetRange()->collapsed();
}
return true;
}
I haven’t tested this yet, but it seems like we could fix this by taking out the code that returns true if the selection starts in a shadow tree, since checking whether the associated range is collapsed seems to work properly. Does this seem reasonable? Of course, I don’t know if anyone is depending on the current behavior (which seems to be incorrect according to the spec).
/**
* Avoid using selection.isCollapsed: it will always return
* true in shadow root in Gecko
* (this bug seems to also happens in Blink)
*/
export function isSelectionCollapsed(selection: Selection): boolean {
return getRange(selection)!.collapsed;
}
So this is another example (in addition to
The W3C Editor's Draft 20 March 2024 of the Selection API spec says:
> isCollapsed
> The attribute must return true if and only if the anchor and focus are the same (including if both are null). Otherwise it must return false.
There’s also a note:
> anchor and focus of selection need not to be in the document tree. It could be in a shadow tree of the same document.
The current code for DOMSelection::isCollapsed is as follows:
bool DOMSelection::isCollapsed() const {
if (!IsAvailable())
return true;
Node* node = Selection()
.ComputeVisibleSelectionInDOMTreeDeprecated()
.Anchor()
.AnchorNode();
if (node && node->IsInShadowTree() &&
DomWindow()->document()->AncestorInThisScope(node)) {
return true;
}
TemporaryRange temp_range(this, PrimaryRangeOrNull());
if (temp_range.GetRange()) {
return temp_range.GetRange()->collapsed();
}
return true;
}
I haven’t tested this yet, but it seems like we could fix this by taking out the code that returns true if the selection starts in a shadow tree, since checking whether the associated range is collapsed seems to work properly. Does this seem reasonable? Of course, I don’t know if anyone is depending on the current behavior (which seems to be incorrect according to the spec).
ma...@chromium.org <ma...@chromium.org>
di...@chromium.org <di...@chromium.org> #28
That looks like a valid change that would still follow the spec. I can try it out behind a flag.
ap...@google.com <ap...@google.com> #29
Project: chromium/src
Branch: main
commit bea8eb7a19a95504aefa04632f822c9cf06db5aa
Author: Di Zhang <dizhangg@chromium.org>
Date: Wed Aug 21 23:09:47 2024
[Selection API] Fix selection isCollapsed in ShadowDOM
Selection isCollapsed should return true if and only if the anchor
and focus are the same [1]. This should be true even if the selection
is not in the light tree, but in the shadow tree [2].
Note that if selection is across multiple shadow trees, it will still
return true because the range endpoints are not valid and were
collapsed. That should be re-evaluated in SelectionAcrossShadowDOM.
[1]https://w3c.github.io/selection-api/#dom-selection-iscollapsed
[2]https://w3c.github.io/selection-api/#h-note-3
Change-Id: I4aaaef288ac1879644a3f719386d58c6025302bf
Bug: 40400558
Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/5792085
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Di Zhang <dizhangg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1345127}
M third_party/blink/renderer/core/editing/dom_selection.cc
M third_party/blink/renderer/platform/runtime_enabled_features.json5
A third_party/blink/web_tests/external/wpt/selection/shadow-dom/tentative/Selection-isCollapsed.html
https://chromium-review.googlesource.com/5792085
Branch: main
commit bea8eb7a19a95504aefa04632f822c9cf06db5aa
Author: Di Zhang <dizhangg@chromium.org>
Date: Wed Aug 21 23:09:47 2024
[Selection API] Fix selection isCollapsed in ShadowDOM
Selection isCollapsed should return true if and only if the anchor
and focus are the same [1]. This should be true even if the selection
is not in the light tree, but in the shadow tree [2].
Note that if selection is across multiple shadow trees, it will still
return true because the range endpoints are not valid and were
collapsed. That should be re-evaluated in SelectionAcrossShadowDOM.
[1]
[2]
Change-Id: I4aaaef288ac1879644a3f719386d58c6025302bf
Bug: 40400558
Reviewed-on:
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Di Zhang <dizhangg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1345127}
M third_party/blink/renderer/core/editing/dom_selection.cc
M third_party/blink/renderer/platform/runtime_enabled_features.json5
A third_party/blink/web_tests/external/wpt/selection/shadow-dom/tentative/Selection-isCollapsed.html
ap...@google.com <ap...@google.com> #30
Project: chromium/src
Branch: main
commit ce3c3b8dfd036eea308a24a53321fc84b8e60aeb
Author: Di Zhang <dizhangg@chromium.org>
Date: Fri Sep 13 22:25:06 2024
Add usecounter to assess SelectionIsCollapsedShadowDOMSupport effect
Feature SelectionIsCollapsedShadowDOMSupport fixes selection.isCollapsed
to not always return true if anchor node is in shadow DOM.
selection.isCollapsed() has a high usage, close to 3% of page loads [1].
Before we can ship this fix, we want to evaluate how many sites will
be affected by this change.
Here, we only count if anchor node is in a shadow tree, but the
selected range.collapsed() returns false.
[1]https://chromestatus.com/metrics/feature/timeline/popularity/1001
Change-Id: Ifd16d8446245ca251bb2b37872a91fca5872c8a0
Bug: 40400558
Reviewed-on:https://chromium-review.googlesource.com/c/chromium/src/+/5855799
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Auto-Submit: Di Zhang <dizhangg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1355454}
M third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom
M third_party/blink/renderer/core/editing/dom_selection.cc
M tools/metrics/histograms/enums.xml
https://chromium-review.googlesource.com/5855799
Branch: main
commit ce3c3b8dfd036eea308a24a53321fc84b8e60aeb
Author: Di Zhang <dizhangg@chromium.org>
Date: Fri Sep 13 22:25:06 2024
Add usecounter to assess SelectionIsCollapsedShadowDOMSupport effect
Feature SelectionIsCollapsedShadowDOMSupport fixes selection.isCollapsed
to not always return true if anchor node is in shadow DOM.
selection.isCollapsed() has a high usage, close to 3% of page loads [1].
Before we can ship this fix, we want to evaluate how many sites will
be affected by this change.
Here, we only count if anchor node is in a shadow tree, but the
selected range.collapsed() returns false.
[1]
Change-Id: Ifd16d8446245ca251bb2b37872a91fca5872c8a0
Bug: 40400558
Reviewed-on:
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Auto-Submit: Di Zhang <dizhangg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1355454}
M third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom
M third_party/blink/renderer/core/editing/dom_selection.cc
M tools/metrics/histograms/enums.xml
di...@chromium.org <di...@chromium.org> #31
We are adding a use counter to assess how safe it is to ship this bug fix since selection.isCollapsed is used by close to 3% of all page loads. If it seems safe, we will work on landing it in a future milestone (M131+).
ap...@google.com <ap...@google.com> #32
Project: chromium/src
Branch: main
Author: Di Zhang <
Link:
Enable SelectionIsCollapsedShadowDOMSupport to stable
Expand for full commit details
Enable SelectionIsCollapsedShadowDOMSupport to stable
Per PSA [1], we are shipping the feature
SelectionIsCollapsedShadowDOMSupport in M131.
[1] https://groups.google.com/a/chromium.org/g/blink-dev/c/a4luSiYQ2zs
Change-Id: Ida9d922116b12271ce68d365833284d8c909bb95
Bug: 40400558
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5939857
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Di Zhang <dizhangg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1370227}
Files:
- M
third_party/blink/renderer/platform/runtime_enabled_features.json5
Hash: e16c86f61d100d488770da8efa5d4ac28bc0e8a4
Date: Thu Oct 17 20:24:05 2024
di...@chromium.org <di...@chromium.org> #33
This bug was fixed and enabled in Chrome version 131.
ld...@google.com <ld...@google.com> #34
One note: the fix missed Chrome 131, but should be in Chrome 132.
ap...@google.com <ap...@google.com> #35
Project: chromium/src
Branch: main
Author: Di Zhang <
Link:
Remove feature SelectionIsCollapsedShadowDOMSupport
Expand for full commit details
Remove feature SelectionIsCollapsedShadowDOMSupport
This feature was landed in 132 and there were no regression reported
so far. It can be removed in 135.
Change-Id: Ia2aa72cb463173dbaaf7ea8891dcbf37a937b8ab
Bug: 40400558
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6062569
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Auto-Submit: Di Zhang <dizhangg@chromium.org>
Reviewed-by: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1415714}
Files:
- M
third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom
- M
third_party/blink/renderer/core/editing/dom_selection.cc
- M
third_party/blink/renderer/platform/runtime_enabled_features.json5
- M
tools/metrics/histograms/metadata/blink/enums.xml
Hash: c2cfc2057e74878f7c8031e975a3b46bbe9dd0a4
Date: Tue Feb 04 11:31:54 2025
Description