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(hydration): vnode is of Text type and with empty text should be skipped when hydrateChildren #3246

Merged
merged 2 commits into from
Mar 26, 2021
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
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 @@ -348,6 +348,8 @@ export function createHydrationFunctions(
parentSuspense,
optimized
)
} else if (vnode.type === Text && !vnode.children) {
continue
} else {
hasMismatch = true
if (__DEV__ && !hasWarned) {
Expand Down