Skip to content

Commit 420c8f4

Browse files
authored
fix(ssr/hydration): handle ending empty text node (#3246)
fix #3245
1 parent 47d87ca commit 420c8f4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
Suspense,
1010
onMounted,
1111
defineAsyncComponent,
12-
defineComponent
12+
defineComponent,
13+
createTextVNode
1314
} from '@vue/runtime-dom'
1415
import { renderToString, SSRContext } from '@vue/server-renderer'
1516

@@ -47,6 +48,14 @@ describe('SSR hydration', () => {
4748
expect(container.textContent).toBe('bar')
4849
})
4950

51+
test('empty text', async () => {
52+
const { container } = mountWithHydration('<div></div>', () =>
53+
h('div', createTextVNode(''))
54+
)
55+
expect(container.textContent).toBe('')
56+
expect(`Hydration children mismatch in <div>`).not.toHaveBeenWarned()
57+
})
58+
5059
test('comment', () => {
5160
const { vnode, container } = mountWithHydration('<!---->', () => null)
5261
expect(vnode.el).toBe(container.firstChild)

packages/runtime-core/src/hydration.ts

+2
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ export function createHydrationFunctions(
359359
slotScopeIds,
360360
optimized
361361
)
362+
} else if (vnode.type === Text && !vnode.children) {
363+
continue
362364
} else {
363365
hasMismatch = true
364366
if (__DEV__ && !hasWarned) {

0 commit comments

Comments
 (0)