Skip to content

Commit

Permalink
Minor cleanup for #90
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Sep 4, 2024
1 parent d165193 commit ea09909
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions client/reload-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,19 @@ class EleventyReload {
},
addChild: function(parent, child) {
// Declarative Shadow DOM https://github.com/11ty/eleventy-dev-server/issues/90
if(child.nodeName === "TEMPLATE" && child.hasAttribute("shadowrootmode") && parent.shadowRoot) {
for(let oldChild of parent.shadowRoot?.childNodes || []) {
oldChild.remove();
if(child.nodeName === "TEMPLATE" && child.hasAttribute("shadowrootmode")) {
let root = parent.shadowRoot;
if(root) {
// remove all shadow root children
while(root.firstChild) {
root.removeChild(root.firstChild);
}
}
for(let newChild of child.content.childNodes) {
parent.shadowRoot.appendChild(newChild);
root.appendChild(newChild);
}
} else {
parent.appendChild(child);
}
},
onNodeAdded: function (node) {
Expand Down

0 comments on commit ea09909

Please sign in to comment.