Skip to content

Commit

Permalink
fix(ssr/hydration): handle ending empty text node (#3246)
Browse files Browse the repository at this point in the history
fix #3245
  • Loading branch information
HcySunYang authored Mar 26, 2021
1 parent 47d87ca commit 420c8f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
Suspense,
onMounted,
defineAsyncComponent,
defineComponent
defineComponent,
createTextVNode
} from '@vue/runtime-dom'
import { renderToString, SSRContext } from '@vue/server-renderer'

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ export function createHydrationFunctions(
slotScopeIds,
optimized
)
} else if (vnode.type === Text && !vnode.children) {
continue
} else {
hasMismatch = true
if (__DEV__ && !hasWarned) {
Expand Down

0 comments on commit 420c8f4

Please sign in to comment.