Skip to content

Commit

Permalink
refactor out double getInnerHTML call
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed May 11, 2022
1 parent 4d7789d commit 667209b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ async function renderToString(elementURL, options = {}) {
const elementInstance = await initializeCustomElement(elementURL);
// invert includeShadowRoots at the top level to double `<template>` tag wrapping top level content
// this is useful in conjunction with a WC used as a page, where we only want its content, not necessarily its template
const elementHtml = elementInstance.getInnerHTML({ includeShadowRoots: unwrapTopLevelShadowRoot ? !unwrapTopLevelShadowRoot : unwrapTopLevelShadowRoot });
const elementHtml = elementInstance.getInnerHTML({ includeShadowRoots });
const elementTree = parseFragment(elementHtml);
const finalTree = await renderComponentRoots(elementTree, includeShadowRoots);

elementInstance.shadowRoot.innerHTML = serialize(finalTree);
// elementInstance.shadowRoot.innerHTML = serialize(finalTree);

console.debug(serialize(finalTree));

return {
html: elementInstance.getInnerHTML({ includeShadowRoots }),
html: serialize(finalTree),
metadata: definitions
};
}
Expand Down

0 comments on commit 667209b

Please sign in to comment.