Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssr): fix hydration for node with empty text node #7216

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,21 @@ describe('SSR hydration', () => {
expect((vnode as any).component?.subTree.children[0].el).toBe(text)
})

// #7215
test('empty text node', () => {
const Comp = {
render(this: any) {
return h('p', [''])
}
}
const { container } = mountWithHydration('<p></p>', () => h(Comp))
expect(container.childNodes.length).toBe(1)
const p = container.childNodes[0]
expect(p.childNodes.length).toBe(1)
const text = p.childNodes[0]
expect(text.nodeType).toBe(3)
})

test('app.unmount()', async () => {
const container = document.createElement('DIV')
container.innerHTML = '<button></button>'
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ export function createHydrationFunctions(
optimized
)
} else if (vnode.type === Text && !vnode.children) {
continue
// #7215 create a TextNode for empty text node
// because server rendered HTML won't contain a text node
insert((vnode.el = createText('')), container)
} else {
hasMismatch = true
if (__DEV__ && !hasWarned) {
Expand Down