script: Skip clearing subtree layout boxes of detached element when attaching shadow to it (#44052)

There is no layout boxes to clear in this case. For the example in
#43998,
this skips the traversal many times.

Testing: Should not change visible behaviour.
[Try](https://github.com/servo/servo/actions/runs/24131782865).

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye
2026-04-10 08:12:07 +08:00
committed by GitHub
parent 8b61ca94fc
commit 560498923e
2 changed files with 4 additions and 3 deletions

View File

@@ -699,8 +699,9 @@ impl Element {
// non-shadow-tree children of `self` no longer have layout boxes as they are no
// longer in the flat tree.
let node = self.upcast::<Node>();
node.remove_layout_boxes_from_subtree();
if node.is_connected() {
node.remove_layout_boxes_from_subtree();
}
// Step 6. Set shadow's delegates focus to delegatesFocus
shadow_root.set_delegates_focus(delegates_focus);

View File

@@ -365,7 +365,7 @@ impl Node {
}
/// Clear this [`Node`]'s layout data and also clear the layout data of all children.
/// Note that clears layout data from all non-flat tree descendants and flat tree
/// Note that this clears layout data from all non-flat tree descendants and flat tree
/// descendants.
pub(crate) fn remove_layout_boxes_from_subtree(&self) {
for node in self.traverse_preorder(ShadowIncluding::Yes) {