-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssr): stop stripping comment nodes (#6123)
* fix(ssr): stop stripping comment nodes * Update test/wdio/ssr-hydration/cmp.test.tsx Co-authored-by: Christian Bromann <[email protected]> --------- Co-authored-by: John Jenkins <[email protected]> Co-authored-by: Christian Bromann <[email protected]>
- Loading branch information
1 parent
eb11d25
commit 5a7ab24
Showing
6 changed files
with
162 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { renderToString } from '../hydrate/index.mjs'; | ||
|
||
describe('ssr-shadow-cmp', () => { | ||
function getNodeNames(chidNodes: NodeListOf<ChildNode>) { | ||
return Array.from(chidNodes) | ||
.flatMap((node) => { | ||
if (node.nodeType === 3) { | ||
if (node.textContent?.trim()) { | ||
return 'text'; | ||
} else { | ||
return []; | ||
} | ||
} else if (node.nodeType === 8) { | ||
return 'comment'; | ||
} else { | ||
return node.nodeName.toLowerCase(); | ||
} | ||
}) | ||
.join(' '); | ||
} | ||
|
||
it('verifies all nodes are preserved during hydration', async () => { | ||
if (!document.querySelector('#stage')) { | ||
const { html } = await renderToString( | ||
` | ||
<ssr-shadow-cmp> | ||
A text node | ||
<!-- a comment --> | ||
<div>An element</div> | ||
<!-- another comment --> | ||
Another text node | ||
</ssr-shadow-cmp> | ||
`, | ||
{ | ||
fullDocument: true, | ||
serializeShadowRoot: true, | ||
constrainTimeouts: false, | ||
}, | ||
); | ||
const stage = document.createElement('div'); | ||
stage.setAttribute('id', 'stage'); | ||
stage.setHTMLUnsafe(html); | ||
document.body.appendChild(stage); | ||
} | ||
|
||
// @ts-expect-error resolved through WDIO | ||
const { defineCustomElements } = await import('/dist/loader/index.js'); | ||
defineCustomElements().catch(console.error); | ||
|
||
// wait for Stencil to take over and reconcile | ||
await browser.waitUntil(async () => customElements.get('ssr-shadow-cmp')); | ||
expect(typeof customElements.get('ssr-shadow-cmp')).toBe('function'); | ||
await expect(getNodeNames(document.querySelector('ssr-shadow-cmp').childNodes)).toBe( | ||
`text comment div comment text`, | ||
); | ||
|
||
document.querySelector('#stage')?.remove(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Component, h } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'ssr-shadow-cmp', | ||
shadow: true, | ||
}) | ||
export class SsrShadowCmp { | ||
render() { | ||
return ( | ||
<div> | ||
<slot /> | ||
</div> | ||
); | ||
} | ||
} |