dom icon indicating copy to clipboard operation
dom copied to clipboard

Steps of removing a node definition about live range do not match with browsers if the range is in a shadow DOM and the shadow itself is removed

Open masayuki-nakano opened this issue 1 year ago • 4 comments

What is the issue with the DOM Standard?

https://dom.spec.whatwg.org/#concept-node-remove

  1. For each live range whose start node is an inclusive descendant of node, set its start to (parent, index).
  2. For each live range whose end node is an inclusive descendant of node, set its end to (parent, index).

"inclusive descendant" is defined as: https://dom.spec.whatwg.org/#concept-tree-inclusive-descendant

An object A is called a descendant of an object B, if either A is a child of B or A is a child of an object C that is a descendant of B. An inclusive descendant is an object or one of its descendants.

Although the latter definition does not mention about shadow DOM boundaries, these definitions sound like that when a shadow containing a live range is deleted, the range is collapsed at the removed node position in the parent (or ancestor) tree. I wrote a test for this and now merged into the WPT tree that expects that Range is not collapsed to outside the shadow DOM tree. Then, all browsers now pass all tests.

  • https://wpt.fyi/results/dom/ranges/Range-in-shadow-after-the-shadow-removed.html%3Fmode%3Dclosed?label=experimental&label=master&aligned
  • https://wpt.fyi/results/dom/ranges/Range-in-shadow-after-the-shadow-removed.html%3Fmode%3Dopen?label=experimental&label=master&aligned

So I think that the former definition should mention about that when the live range is in a subtree, removable of inclusive ancestor of the host does not affect to the range.

Cc: @sefeng211, @smaug----, @zcorpan

masayuki-nakano avatar Apr 04 '24 01:04 masayuki-nakano

cc @mfreed7 @domfarolino

annevk avatar Apr 09 '24 10:04 annevk

See also https://github.com/w3c/selection-api/issues/168

smaug---- avatar Apr 09 '24 10:04 smaug----

An inclusive descendant is an object or one of its descendants. An object A is called a descendant of an object B, if either A is a child of B or A is a child of an object C that is a descendant of B.

vs

A shadow-including inclusive descendant is an object or one of its shadow-including descendants. An object A is a shadow-including descendant of an object B, if A is a descendant of B, or A’s root is a shadow root and A’s root’s host is a shadow-including inclusive descendant of B.

spec source

My understanding of the spec is that since the above Node remove steps are for "inclusive descendants", they should be scoped to be within the tree scope and not cross shadow trees. I don't think the steps need to mention shadow host specific behavior.

dizhang168 avatar Oct 17 '24 18:10 dizhang168

@masayuki-nakano I think I agree with @dizhang168 that the current specification is okay for the scenario you wrote a test for. What exactly do you think is wrong?

(There's certainly issues when the selection crosses the boundary, but that's a separate topic.)

annevk avatar Oct 19 '24 12:10 annevk