From: HcySunYang Date: Fri, 26 Mar 2021 15:45:28 +0000 (+0800) Subject: fix(ssr/hydration): handle ending empty text node (#3246) X-Git-Tag: v3.0.8~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=420c8f4580dddea9a724cfadc4cc2c272181c24d;p=thirdparty%2Fvuejs%2Fcore.git fix(ssr/hydration): handle ending empty text node (#3246) fix #3245 --- diff --git a/packages/runtime-core/__tests__/hydration.spec.ts b/packages/runtime-core/__tests__/hydration.spec.ts index 4c7aa911bc..3f9feb4ea7 100644 --- a/packages/runtime-core/__tests__/hydration.spec.ts +++ b/packages/runtime-core/__tests__/hydration.spec.ts @@ -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('
', () => + h('div', createTextVNode('')) + ) + expect(container.textContent).toBe('') + expect(`Hydration children mismatch in
`).not.toHaveBeenWarned() + }) + test('comment', () => { const { vnode, container } = mountWithHydration('', () => null) expect(vnode.el).toBe(container.firstChild) diff --git a/packages/runtime-core/src/hydration.ts b/packages/runtime-core/src/hydration.ts index cad23524eb..8f30cadb29 100644 --- a/packages/runtime-core/src/hydration.ts +++ b/packages/runtime-core/src/hydration.ts @@ -359,6 +359,8 @@ export function createHydrationFunctions( slotScopeIds, optimized ) + } else if (vnode.type === Text && !vnode.children) { + continue } else { hasMismatch = true if (__DEV__ && !hasWarned) {