Skip to content
Snippets Groups Projects
Commit 0a118d11 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

slot templates: fix templates being created in the wrong shadow root

This makes problems with the new scoped elements polyfill, which now correctly
makes globally registered elements not visible in the shadow roots. Instead
we have to add the tempaltes at the level of the templates so they get their
global web components and only then transplant them into the light dom of the
nested web components with their own registries.
parent 6324718b
No related branches found
No related tags found
No related merge requests found
Pipeline #66539 failed
...@@ -4,6 +4,7 @@ export default class DBPLitElement extends AdapterLitElement { ...@@ -4,6 +4,7 @@ export default class DBPLitElement extends AdapterLitElement {
constructor() { constructor() {
super(); super();
this.htmlOverrides = ''; this.htmlOverrides = '';
this._rootContainer = null;
} }
/** /**
...@@ -26,6 +27,14 @@ export default class DBPLitElement extends AdapterLitElement { ...@@ -26,6 +27,14 @@ export default class DBPLitElement extends AdapterLitElement {
super.connectedCallback(); super.connectedCallback();
} }
disconnectedCallback() {
super.disconnectedCallback();
if (this._rootContainer !== null) {
this._rootContainer.remove();
}
}
_(selector) { _(selector) {
return this.shadowRoot === null ? this.querySelector(selector) : this.shadowRoot.querySelector(selector); return this.shadowRoot === null ? this.querySelector(selector) : this.shadowRoot.querySelector(selector);
} }
...@@ -86,6 +95,13 @@ export default class DBPLitElement extends AdapterLitElement { ...@@ -86,6 +95,13 @@ export default class DBPLitElement extends AdapterLitElement {
// if there is an override we again need to clone that template so we can access the content // if there is an override we again need to clone that template so we can access the content
const templateOverrideElemClone = templateOverrideElem.content.cloneNode(true); const templateOverrideElemClone = templateOverrideElem.content.cloneNode(true);
// Create a dummy node and add it to the the same shadow root the templates are from
// By adding it into the template we have the nice side effect that it is not visible
let container = document.createElement("div");
globalOverrideTemplateElem.append(container);
container.appendChild(templateOverrideElemClone);
this._rootContainer = container;
// now we need to look for slots in the override // now we need to look for slots in the override
slots.forEach((slot) => { slots.forEach((slot) => {
const slotName = slot.name; const slotName = slot.name;
...@@ -101,8 +117,11 @@ export default class DBPLitElement extends AdapterLitElement { ...@@ -101,8 +117,11 @@ export default class DBPLitElement extends AdapterLitElement {
} }
}); });
// append the cloned template to the light DOM // Now move the slots into the light dom of the target.
this.appendChild(templateOverrideElemClone); // The parent node in the other shadow root has to stay around for this to work
while (container.childNodes.length) {
this.appendChild(container.removeChild(container.childNodes[0]));
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment