)
})
- test('empty text nodes', async () => {
+ test('empty text node', async () => {
const data = reactive({ txt: '' })
const { container } = await testHydration(
`<template><div>{{ data.txt }}</div></template>`,
await nextTick()
expect(container.innerHTML).toMatchInlineSnapshot(`"<div>foo</div>"`)
})
+
+ test('empty text node in slot', async () => {
+ const data = reactive({ txt: '' })
+ const { container } = await testHydration(
+ `<template><components.Child>{{data.txt}}</components.Child></template>`,
+ {
+ Child: `<template><slot/></template>`,
+ },
+ data,
+ )
+ expect(container.innerHTML).toMatchInlineSnapshot(
+ `"<!--[--> <!--]--><!--slot-->"`,
+ )
+
+ data.txt = 'foo'
+ await nextTick()
+ expect(container.innerHTML).toMatchInlineSnapshot(
+ `"<!--[-->foo<!--]--><!--slot-->"`,
+ )
+ })
})
describe('element', () => {
import {
__next,
__nthChild,
+ createTextNode,
disableHydrationNodeLookup,
enableHydrationNodeLookup,
} from './node'
*/
function adoptTemplateImpl(node: Node, template: string): Node | null {
if (!(template[0] === '<' && template[1] === '!')) {
- while (node.nodeType === 8) node = node.nextSibling!
+ while (node.nodeType === 8) {
+ node = node.nextSibling!
+
+ // empty text node in slot
+ if (
+ template === ' ' &&
+ isComment(node, ']') &&
+ isComment(node.previousSibling!, '[')
+ ) {
+ node = node.parentNode!.insertBefore(createTextNode(' '), node)
+ break
+ }
+ }
}
if (__DEV__) {