Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ace18d0

Browse files
committedFeb 25, 2025·
Fix shadowhost to adjusted current node
Signed-off-by: batu_hoang <longvatrong111@gmail.com>
1 parent da7d3f4 commit ace18d0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎html5ever/src/tree_builder/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ where
13771377
self.insert_element(Push, ns!(html), name, vec![])
13781378
}
13791379

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

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

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

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

1441+
// https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead
1442+
// A start tag whose tag name is "template"
14381443
fn attach_declarative_shadow(
14391444
&self,
14401445
tag: &Tag,

‎html5ever/src/tree_builder/rules.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ where
160160
self.template_modes.borrow_mut().push(InTemplate);
161161

162162
if (self.should_attach_declarative_shadow(&tag)) {
163-
let shadow_host = self.open_elems.borrow().last().unwrap().clone();
163+
let mut shadow_host = self.open_elems.borrow().last().unwrap().clone();
164+
if self.is_fragment() && self.open_elems.borrow().len() == 1 {
165+
shadow_host = self.context_elem.borrow().clone().unwrap();
166+
}
167+
164168
let template = self.insert_foreign_element(tag.clone(), ns!(html), true);
165169

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

0 commit comments

Comments
 (0)