fix(ssr/hydration): handle ending empty text node (#3246)

fix #3245
This commit is contained in:
HcySunYang 2021-03-26 23:45:28 +08:00 committed by GitHub
parent 47d87ca4ad
commit 420c8f4580
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -9,7 +9,8 @@ import {
Suspense,
onMounted,
defineAsyncComponent,
defineComponent
defineComponent,
createTextVNode
} from '@vue/runtime-dom'
import { renderToString, SSRContext } from '@vue/server-renderer'
@ -47,6 +48,14 @@ describe('SSR hydration', () => {
expect(container.textContent).toBe('bar')
})
test('empty text', async () => {
const { container } = mountWithHydration('<div></div>', () =>
h('div', createTextVNode(''))
)
expect(container.textContent).toBe('')
expect(`Hydration children mismatch in <div>`).not.toHaveBeenWarned()
})
test('comment', () => {
const { vnode, container } = mountWithHydration('<!---->', () => null)
expect(vnode.el).toBe(container.firstChild)

View File

@ -359,6 +359,8 @@ export function createHydrationFunctions(
slotScopeIds,
optimized
)
} else if (vnode.type === Text && !vnode.children) {
continue
} else {
hasMismatch = true
if (__DEV__ && !hasWarned) {