Skip to content

Commit e8a8117

Browse files
committed
fix(hydration): properly handle empty text node
1 parent ec28c43 commit e8a8117

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

packages/runtime-vapor/__tests__/hydration.spec.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ describe('Vapor Mode hydration', () => {
237237
data,
238238
)
239239
expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
240-
`"<div> </div>"`,
240+
`"<div></div>"`,
241241
)
242242

243243
data.txt = 'foo'
@@ -259,7 +259,7 @@ describe('Vapor Mode hydration', () => {
259259
expect(formatHtml(container.innerHTML)).toMatchInlineSnapshot(
260260
`
261261
"
262-
<!--[--> <!--]-->
262+
<!--[--><!--]-->
263263
<!--slot-->"
264264
`,
265265
)
@@ -3036,14 +3036,16 @@ describe('Vapor Mode hydration', () => {
30363036
// expect(container.innerHTML).toBe('<div><span>foo</span></div>')
30373037
// expect(`Hydration children mismatch`).toHaveBeenWarned()
30383038
// })
3039-
// test('complete mismatch', () => {
3040-
// const { container } = mountWithHydration(
3041-
// `<div><span>foo</span><span>bar</span></div>`,
3042-
// () => h('div', [h('div', 'foo'), h('p', 'bar')]),
3043-
// )
3044-
// expect(container.innerHTML).toBe('<div><div>foo</div><p>bar</p></div>')
3045-
// expect(`Hydration node mismatch`).toHaveBeenWarnedTimes(2)
3046-
// })
3039+
test.todo('complete mismatch', async () => {
3040+
const data = ref('span')
3041+
const { container } = await mountWithHydration(
3042+
`<div>foo</div><!--dynamic-component-->`,
3043+
`<component :is="data">foo</component>`,
3044+
data,
3045+
)
3046+
expect(container.innerHTML).toBe('<span>foo</span>')
3047+
expect(`Hydration node mismatch`).toHaveBeenWarned()
3048+
})
30473049
// test('fragment mismatch removal', () => {
30483050
// const { container } = mountWithHydration(
30493051
// `<div><!--[--><div>foo</div><div>bar</div><!--]--></div>`,
@@ -3334,7 +3336,7 @@ describe('Vapor Mode hydration', () => {
33343336
// })
33353337
})
33363338

3337-
describe('data-allow-mismatch', () => {
3339+
describe.todo('data-allow-mismatch', () => {
33383340
// test('element text content', () => {
33393341
// const { container } = mountWithHydration(
33403342
// `<div data-allow-mismatch="text">foo</div>`,

packages/runtime-vapor/src/dom/hydration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function adoptTemplateImpl(node: Node, template: string): Node | null {
109109
isComment(node, ']') &&
110110
isComment(node.previousSibling!, '[')
111111
) {
112-
node = parentNode(node)!.insertBefore(createTextNode(' '), node)
112+
node = parentNode(node)!.insertBefore(createTextNode(), node)
113113
break
114114
}
115115
}

packages/runtime-vapor/src/dom/node.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ const __txt: typeof __child = (node: ParentNode): Node => {
3939
// since SSR doesn't generate whitespace placeholder text nodes, if firstChild
4040
// is null, manually insert a text node as the first child
4141
if (!n) {
42-
node.textContent = ' '
43-
return node.firstChild!
42+
return node.appendChild(createTextNode())
4443
}
4544

4645
return n

0 commit comments

Comments
 (0)