From 8d4c569e299e554aa086c8ebdfcd37b70168e702 Mon Sep 17 00:00:00 2001 From: liulinboyi <814921718@qq.com> Date: Thu, 26 May 2022 21:03:08 +0800 Subject: [PATCH 1/2] fix(runtime-core): hydrate Static vnode --- packages/runtime-core/src/hydration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime-core/src/hydration.ts b/packages/runtime-core/src/hydration.ts index 3637a09b2aa..5eb37d457f2 100644 --- a/packages/runtime-core/src/hydration.ts +++ b/packages/runtime-core/src/hydration.ts @@ -150,7 +150,7 @@ export function createHydrationFunctions( } break case Static: - if (domType !== DOMNodeTypes.ELEMENT) { + if (domType !== DOMNodeTypes.ELEMENT && domType !== DOMNodeTypes.TEXT) { nextNode = onMismatch() } else { // determine anchor, adopt content From 03289f9d64f26c45aea8b314d68cc9df264a32e0 Mon Sep 17 00:00:00 2001 From: liulinboyi <814921718@qq.com> Date: Fri, 27 May 2022 23:38:26 +0800 Subject: [PATCH 2/2] test: add test for hydrate Static vnode --- .../runtime-core/__tests__/hydration.spec.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/runtime-core/__tests__/hydration.spec.ts b/packages/runtime-core/__tests__/hydration.spec.ts index c3976a8f076..0c1f4a166d5 100644 --- a/packages/runtime-core/__tests__/hydration.spec.ts +++ b/packages/runtime-core/__tests__/hydration.spec.ts @@ -1050,4 +1050,31 @@ describe('SSR hydration', () => { expect(`Hydration children mismatch`).toHaveBeenWarned() }) }) + + // #6008 + describe('hydrate Static vnode', () => { + test('domType is ELEMENT should match', () => { + const html = ` A 0 B 1 C 2 D E` + const { vnode, container } = mountWithHydration(html, () => + createStaticVNode( + ` A 0 B 1 C 2 D E`, + 18 + ) + ) + expect(vnode.el).toBe(container.firstChild) + expect(`Hydration node mismatch`).not.toHaveBeenWarned() + }) + + test('domType is TEXT should match', () => { + const html = `A0 B 1 C 2 D E` + const { vnode, container } = mountWithHydration(html, () => + createStaticVNode( + `A0 B 1 C 2 D E`, + 18 + ) + ) + expect(vnode.el).toBe(container.firstChild) + expect(`Hydration node mismatch`).not.toHaveBeenWarned() + }) + }) })