diff --git a/src/wcc.js b/src/wcc.js index cbed750e..cc499058 100644 --- a/src/wcc.js +++ b/src/wcc.js @@ -29,11 +29,14 @@ async function renderComponentRoots(tree, includeShadowRoots = true) { const { tagName } = node; const { moduleURL } = definitions[tagName]; const elementInstance = await initializeCustomElement(moduleURL, tagName, node.attrs); - - const shadowRootHtml = elementInstance.getInnerHTML({ includeShadowRoots }); - const shadowRootTree = parseFragment(shadowRootHtml); - - node.childNodes = node.childNodes.length === 0 ? shadowRootTree.childNodes : [...shadowRootTree.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) { @@ -130,7 +133,9 @@ async function renderToString(elementURL, options = {}) { const elementTagName = await getTagName(elementURL); const elementInstance = await initializeCustomElement(elementURL); - const elementHtml = elementInstance.getInnerHTML({ includeShadowRoots }); + const elementHtml = elementInstance.shadowRoot + ? elementInstance.getInnerHTML({ includeShadowRoots }) + : elementInstance.innerHTML; const elementTree = getParse(elementHtml)(elementHtml); const finalTree = await renderComponentRoots(elementTree, includeShadowRoots); const html = !lightMode && elementTagName ? ` diff --git a/test/cases/light-dom/light-dom.spec.js b/test/cases/light-dom/light-dom.spec.js new file mode 100644 index 00000000..7f0a9cfd --- /dev/null +++ b/test/cases/light-dom/light-dom.spec.js @@ -0,0 +1,79 @@ +/* + * Use Case + * Run wcc against nested custom elements using just innerHTML to intentionally NOT render Shadow DOM. + * + * User Result + * Should return the expected HTML with no template tags or Shadow Roots. + * + * User Workspace + * src/ + * components/ + * navigation.js + * header.js + * pages/ + * index.js + */ +import chai from 'chai'; +import { JSDOM } from 'jsdom'; +import { renderToString } from '../../../src/wcc.js'; + +const expect = chai.expect; + +describe('Run WCC For ', function() { + const LABEL = 'Nested Custom Element using only innerHTML (no Shadow DOM)'; + let dom; + + before(async function() { + const { html } = await renderToString(new URL('./src/pages/index.js', import.meta.url)); + + dom = new JSDOM(html); + }); + + describe(LABEL, function() { + it('should not have any