Skip to content

Commit

Permalink
Fix shadowhost to adjusted current node
Browse files Browse the repository at this point in the history
Signed-off-by: batu_hoang <longvatrong111@gmail.com>
  • Loading branch information
longvatrong111 committed Feb 25, 2025
1 parent da7d3f4 commit ace18d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion html5ever/src/tree_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,7 @@ where
self.insert_element(Push, ns!(html), name, vec![])
}

// https://html.spec.whatwg.org/multipage/parsing.html#insert-an-element-at-the-adjusted-insertion-location
fn insert_foreign_element(
&self,
tag: Tag,
Expand All @@ -1397,6 +1398,8 @@ where
}
//§ END

// https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead
// A start tag whose tag name is "template"
fn should_attach_declarative_shadow(&self, tag: &Tag) -> bool {
let adjusted_insertion_location = self.appropriate_place_for_insertion(None);

Expand All @@ -1411,7 +1414,7 @@ where
// template start tag's shadowrootmode is not in the none state
let is_shadow_root_mode = tag.attrs.iter().any(|attr| {
attr.name.local == local_name!("shadowrootmode")
&& (attr.value.to_string() == *"open" || attr.value.to_string() == *"close")
&& (attr.value.to_string() == *"open" || attr.value.to_string() == *"closed")
});

// Check if intended_parent's document allows declarative shadow roots
Expand All @@ -1435,6 +1438,8 @@ where
is_shadow_root_mode && allow_declarative_shadow_roots && adjusted_current_node_not_topmost
}

// https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead
// A start tag whose tag name is "template"
fn attach_declarative_shadow(
&self,
tag: &Tag,
Expand Down
6 changes: 5 additions & 1 deletion html5ever/src/tree_builder/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ where
self.template_modes.borrow_mut().push(InTemplate);

if (self.should_attach_declarative_shadow(&tag)) {
let shadow_host = self.open_elems.borrow().last().unwrap().clone();
let mut shadow_host = self.open_elems.borrow().last().unwrap().clone();
if self.is_fragment() && self.open_elems.borrow().len() == 1 {
shadow_host = self.context_elem.borrow().clone().unwrap();
}

let template = self.insert_foreign_element(tag.clone(), ns!(html), true);

if self.attach_declarative_shadow(&tag, &shadow_host, &template).is_err() {
Expand Down

0 comments on commit ace18d0

Please sign in to comment.