[whatwg/dom] 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 (Issue #1274)

### What is the issue with the DOM Standard?

https://dom.spec.whatwg.org/#concept-node-remove
> 4. For each [live range](https://dom.spec.whatwg.org/#concept-live-range) whose [start node](https://dom.spec.whatwg.org/#concept-range-start-node) is an [inclusive descendant](https://dom.spec.whatwg.org/#concept-tree-inclusive-descendant) of node, set its [start](https://dom.spec.whatwg.org/#concept-range-start) to (parent, index).
> 5. For each [live range](https://dom.spec.whatwg.org/#concept-live-range) whose [end node](https://dom.spec.whatwg.org/#concept-range-end-node) is an [inclusive descendant](https://dom.spec.whatwg.org/#concept-tree-inclusive-descendant) of node, set its [end](https://dom.spec.whatwg.org/#concept-range-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](https://dom.spec.whatwg.org/#concept-tree-child) of B or A is a [child](https://dom.spec.whatwg.org/#concept-tree-child) of an object C that is a [descendant](https://dom.spec.whatwg.org/#concept-tree-descendant) of B.
> An inclusive descendant is an object or one of its [descendants](https://dom.spec.whatwg.org/#concept-tree-descendant).

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](https://github.com/web-platform-tests/wpt/blob/0d75348206dc25ee759f46f94587ce86d81647a8/dom/ranges/Range-in-shadow-after-the-shadow-removed.html) 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 

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1274
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1274@github.com>

Received on Thursday, 4 April 2024 01:15:40 UTC