Skip to content

Commit

Permalink
Remove getHTML() shouldn't branch on shadow root's mode
Browse files Browse the repository at this point in the history
As with clonable and delegatesFocus, serializable is an explicit API and therefore fine from an encapsulation point of view.

For whatwg/html#10260.
  • Loading branch information
annevk authored Apr 10, 2024
1 parent 94be77b commit dd2e51d
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions shadow-dom/declarative/gethtml.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
}

let shadowRoot;
const isOpen = mode === 'open';
let initDict = {mode: mode, delegatesFocus: delegatesFocus, clonable};
let expectedSerializable = null;
switch (serializable) {
Expand All @@ -47,12 +46,8 @@
`shadowrootmode=${mode}${delegatesAttr}${serializableAttr}` +
`${clonableAttr}>`;
wrapper.setHTMLUnsafe(html);
if (isOpen) {
shadowRoot = wrapper.firstElementChild.shadowRoot;
} else {
// For closed shadow root, we rely on the behavior of attachShadow to return it to us
shadowRoot = wrapper.firstElementChild.attachShadow(initDict);
}
// Get hold of the declarative shadow root in a way that works when its mode is "closed"
shadowRoot = wrapper.firstElementChild.attachShadow(initDict);
} else {
// Imperative shadow dom
const element = document.createElement(elementType);
Expand All @@ -78,22 +73,14 @@
assert_equals(shadowRoot.clonable,clonable);
shadowRoot.appendChild(document.createElement('slot'));
const emptyElement = `<${elementType}>${lightDOMContent}</${elementType}>`;
if (isOpen) {
if (expectedSerializable) {
assert_equals(wrapper.getHTML({serializableShadowRoots: true}),
correctHtml);
assert_equals(wrapper.firstElementChild.getHTML({
serializableShadowRoots: true}),
`${correctShadowHtml}${lightDOMContent}`);
} else {
assert_equals(wrapper.getHTML({serializableShadowRoots: true}), emptyElement);
}
} else {
// Closed shadow roots should not be returned unless shadowRoots specifically contains the shadow root:
if (expectedSerializable) {
assert_equals(wrapper.getHTML({serializableShadowRoots: true}),
emptyElement);
assert_equals(wrapper.getHTML({serializableShadowRoots: true,
shadowRoots: []}), emptyElement);
correctHtml);
assert_equals(wrapper.firstElementChild.getHTML({
serializableShadowRoots: true}),
`${correctShadowHtml}${lightDOMContent}`);
} else {
assert_equals(wrapper.getHTML({serializableShadowRoots: true}), emptyElement);
}
// If we provide the shadow root, serialize it, regardless of serializableShadowRoots.
assert_equals(wrapper.getHTML({serializableShadowRoots: true, shadowRoots:
Expand Down

0 comments on commit dd2e51d

Please sign in to comment.