Don't drain ranges across shadow boundaries (#37281)

The [live range pre remove
steps](https://dom.spec.whatwg.org/#live-range-pre-remove-steps) state
that:

> 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).

Elements in a shadow tree are not inclusive descendants of their hosts -
meaning we should not bubble ranges across shadow boundaries.

Includes a small fix to `Node::ranges_is_empty` which makes servo do
less work on DOM mutations, as well as some changes to `range.rs` to
match the spec better. I made these changes during debugging and they
don't feel like they're worth their own PR.

Testing: Covered by WPT

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-06-06 09:54:02 +02:00 committed by GitHub
parent 836316c844
commit 430f65584d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 80 additions and 55 deletions

View file

@ -1,14 +0,0 @@
[Range-in-shadow-after-the-shadow-removed.html?mode=closed]
[Range in shadow should stay in the shadow after the host is removed]
expected: FAIL
[Range in shadow should stay in the shadow after the host parent is removed]
expected: FAIL
[Range-in-shadow-after-the-shadow-removed.html?mode=open]
[Range in shadow should stay in the shadow after the host is removed]
expected: FAIL
[Range in shadow should stay in the shadow after the host parent is removed]
expected: FAIL