Skip to content

Commit e1bc268

Browse files
committed
fix(ssr): fix hydration mismatch caused by multi-line comments inside slot
fix #5355
1 parent 516bc54 commit e1bc268

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/server-renderer/__tests__/ssrSlot.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ describe('ssr: slot', () => {
4949
).toBe(`<div><!--[--><!--]--></div>`)
5050
})
5151

52+
test('empty slot (manual comments)', async () => {
53+
expect(
54+
await renderToString(
55+
createApp({
56+
components: {
57+
one: {
58+
template: `<div><slot/></div>`
59+
}
60+
},
61+
template: `<one><!--hello--></one>`
62+
})
63+
)
64+
).toBe(`<div><!--[--><!--]--></div>`)
65+
})
66+
67+
test('empty slot (multi-line comments)', async () => {
68+
expect(
69+
await renderToString(
70+
createApp({
71+
components: {
72+
one: {
73+
template: `<div><slot/></div>`
74+
}
75+
},
76+
template: `<one><!--he\nllo--></one>`
77+
})
78+
)
79+
).toBe(`<div><!--[--><!--]--></div>`)
80+
})
81+
5282
test('multiple elements', async () => {
5383
expect(
5484
await renderToString(

packages/server-renderer/src/helpers/ssrRenderSlot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function ssrRenderSlotInner(
8282
}
8383
}
8484

85-
const commentRE = /<!--.*?-->/g
85+
const commentRE = /<!--[^]*?-->/gm
8686
function isComment(item: SSRBufferItem) {
8787
return (
8888
typeof item === 'string' &&

0 commit comments

Comments
 (0)