Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jun 10, 2022
1 parent a83b9af commit c02c955
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ async function renderComponentRoots(tree, includeShadowRoots = true) {
const { tagName } = node;
const { moduleURL } = definitions[tagName];
const elementInstance = await initializeCustomElement(moduleURL, tagName, node.attrs);

if (elementInstance.shadowRoot) {
const shadowRootHtml = elementInstance.getInnerHTML({ includeShadowRoots });
const shadowRootTree = parseFragment(shadowRootHtml);

node.childNodes = node.childNodes.length === 0 ? shadowRootTree.childNodes : [...shadowRootTree.childNodes, ...node.childNodes];
} else {
const domTree = parseFragment(elementInstance.innerHTML);

node.childNodes = node.childNodes.length === 0 ? domTree.childNodes : [...domTree.childNodes, ...node.childNodes];
}
const elementHtml = elementInstance.shadowRoot
? elementInstance.getInnerHTML({ includeShadowRoots })
: elementInstance.innerHTML;
const elementTree = parseFragment(elementHtml);

node.childNodes = node.childNodes.length === 0
? elementTree.childNodes
: [...elementTree.childNodes, ...node.childNodes];
}

if (node.childNodes && node.childNodes.length > 0) {
Expand Down

0 comments on commit c02c955

Please sign in to comment.