Skip to content

Commit 3c16737

Browse files
committed
fix(hydrate): do not add html comments inside inline scripts
1 parent 33a8556 commit 3c16737

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/runtime/test/hydrate-no-encapsulation.spec.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@ import { Component, Host, h } from '@stencil/core';
22
import { newSpecPage } from '@stencil/core/testing';
33

44
describe('hydrate no encapsulation', () => {
5+
it('no script annotations', async () => {
6+
@Component({ tag: 'cmp-a' })
7+
class CmpA {
8+
render() {
9+
return (
10+
<Host>
11+
<script>console.log('script')</script>
12+
</Host>
13+
);
14+
}
15+
}
16+
// @ts-ignore
17+
const serverHydrated = await newSpecPage({
18+
components: [CmpA],
19+
html: `<cmp-a></cmp-a>`,
20+
hydrateServerSide: true,
21+
});
22+
expect(serverHydrated.root).toEqualHtml(`
23+
<cmp-a class="hydrated" s-id="1">
24+
<!--r.1-->
25+
<script c-id="1.0.0.0">console.log('script')</script>
26+
</cmp-a>
27+
`);
28+
});
29+
530
it('root element, no slot', async () => {
631
@Component({ tag: 'cmp-a' })
732
class CmpA {

src/runtime/vdom/vdom-annotations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ const insertChildVNodeAnnotations = (doc: Document, vnodeChild: d.VNode, cmpData
140140
childElm.setAttribute(HYDRATE_CHILD_ID, childId);
141141
} else if (childElm.nodeType === NODE_TYPE.TextNode) {
142142
const parentNode = childElm.parentNode;
143-
if (parentNode.nodeName !== 'STYLE') {
143+
const nodeName = parentNode.nodeName;
144+
if (nodeName !== 'STYLE' && nodeName !== 'SCRIPT') {
144145
const textNodeId = `${TEXT_NODE_ID}.${childId}`;
145146

146147
const commentBeforeTextNode = doc.createComment(textNodeId);

0 commit comments

Comments
 (0)