Skip to content

Commit

Permalink
Bug 1877025 - Make declarative shadow roots of custom elements availa…
Browse files Browse the repository at this point in the history
…ble to element internals. r=peterv,dom-core

Differential Revision: https://phabricator.services.mozilla.com/D200177
  • Loading branch information
avandolder committed Feb 6, 2024
1 parent 33b8a28 commit 8765190
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11380,6 +11380,10 @@ nsIContent* nsContentUtils::AttachDeclarativeShadowRoot(nsIContent* aHost,

RefPtr shadowRoot = host->AttachShadow(init, IgnoreErrors(),
Element::ShadowRootDeclarative::Yes);
if (shadowRoot) {
// https://html.spec.whatwg.org/#parsing-main-inhead:available-to-element-internals
shadowRoot->SetAvailableToElementInternals();
}
return shadowRoot;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Declarative Shadow DOM</title>
<link rel="author" href="mailto:[email protected]">
<link rel="help" href="https://html.spec.whatwg.org/#parsing-main-inhead:available-to-element-internals">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<custom-element>
<template shadowrootmode="open">
</template>
</custom-element>

<script>
let internals;
customElements.define("custom-element", class extends HTMLElement {
constructor() {
super();
internals = this.attachInternals();
}
});

window.onload = () => {
test(() => {
assert_true(!!internals);
assert_true(!!internals.shadowRoot);
assert_equals(internals.shadowRoot, document.querySelector("custom-element").shadowRoot);
}, "Declarative Shadow DOM: shadow root should be available to element internals");
};
</script>

0 comments on commit 8765190

Please sign in to comment.