Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(ssr): fix hydration mismatch caused by multi-line comments inside…
… slot

fix #5355
  • Loading branch information
yyx990803 committed May 19, 2022
1 parent 516bc54 commit e1bc268
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/server-renderer/__tests__/ssrSlot.spec.ts
Expand Up @@ -49,6 +49,36 @@ describe('ssr: slot', () => {
).toBe(`<div><!--[--><!--]--></div>`)
})

test('empty slot (manual comments)', async () => {
expect(
await renderToString(
createApp({
components: {
one: {
template: `<div><slot/></div>`
}
},
template: `<one><!--hello--></one>`
})
)
).toBe(`<div><!--[--><!--]--></div>`)
})

test('empty slot (multi-line comments)', async () => {
expect(
await renderToString(
createApp({
components: {
one: {
template: `<div><slot/></div>`
}
},
template: `<one><!--he\nllo--></one>`
})
)
).toBe(`<div><!--[--><!--]--></div>`)
})

test('multiple elements', async () => {
expect(
await renderToString(
Expand Down
2 changes: 1 addition & 1 deletion packages/server-renderer/src/helpers/ssrRenderSlot.ts
Expand Up @@ -82,7 +82,7 @@ export function ssrRenderSlotInner(
}
}

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

0 comments on commit e1bc268

Please sign in to comment.