diff options
author | Taym Haddadi <haddadi.taym@gmail.com> | 2025-01-10 10:18:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-10 09:18:38 +0000 |
commit | 73c0701c83a54ab0e134ea80ef320beddaf6a405 (patch) | |
tree | 222f24c8e0edccb4b72f5f4987fb131db780d133 /components | |
parent | bbb255d81c2f39e7e6b04eb4da3fdfe2318c1f97 (diff) | |
download | servo-73c0701c83a54ab0e134ea80ef320beddaf6a405.tar.gz servo-73c0701c83a54ab0e134ea80ef320beddaf6a405.zip |
Fix shadow root binding children to the tree (#34909)
* Fix Shadow roots bind children to the tree
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
* Avoid iterate over the shadow root itself
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
* Update test expectation
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
* Fix clippy
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
Diffstat (limited to 'components')
-rw-r--r-- | components/script/dom/shadowroot.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index f6ccd7c9477..da0d010c7f8 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -29,7 +29,7 @@ use crate::dom::node::{ }; use crate::dom::stylesheetlist::{StyleSheetList, StyleSheetListOwner}; use crate::dom::types::EventTarget; -use crate::dom::virtualmethods::VirtualMethods; +use crate::dom::virtualmethods::{vtable_for, VirtualMethods}; use crate::dom::window::Window; use crate::script_runtime::CanGc; use crate::stylesheet_set::StylesheetSetRef; @@ -326,9 +326,18 @@ impl VirtualMethods for ShadowRoot { let shadow_root = self.upcast::<Node>(); shadow_root.set_flag(NodeFlags::IS_CONNECTED, context.tree_connected); - for node in shadow_root.children() { + + // avoid iterate over the shadow root itself + for node in shadow_root.traverse_preorder(ShadowIncluding::Yes).skip(1) { node.set_flag(NodeFlags::IS_CONNECTED, context.tree_connected); - node.bind_to_tree(context); + + // Out-of-document elements never have the descendants flag set + debug_assert!(!node.get_flag(NodeFlags::HAS_DIRTY_DESCENDANTS)); + vtable_for(&node).bind_to_tree(&BindContext { + tree_connected: context.tree_connected, + tree_is_in_a_document_tree: false, + tree_is_in_a_shadow_tree: true, + }); } } |