]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(hydration): handle text nodes with 0 during hydration (#11772)
authoredison <daiwei521@126.com>
Mon, 2 Sep 2024 09:09:38 +0000 (17:09 +0800)
committerGitHub <noreply@github.com>
Mon, 2 Sep 2024 09:09:38 +0000 (17:09 +0800)
close #11771

packages/runtime-core/__tests__/hydration.spec.ts
packages/runtime-core/src/hydration.ts

index 142a171f7cf6adcd96a426d536b0e239eba5636c..a2ea72638f9aa6bc8dfa4afe9d73b82a45e2fcf6 100644 (file)
@@ -152,10 +152,10 @@ describe('SSR hydration', () => {
   // #7285
   test('element with multiple continuous text vnodes', async () => {
     // should no mismatch warning
-    const { container } = mountWithHydration('<div>fooo</div>', () =>
-      h('div', ['fo', createTextVNode('o'), 'o']),
+    const { container } = mountWithHydration('<div>foo0o</div>', () =>
+      h('div', ['fo', createTextVNode('o'), 0, 'o']),
     )
-    expect(container.textContent).toBe('fooo')
+    expect(container.textContent).toBe('foo0o')
   })
 
   test('element with elements children', async () => {
index 8060f9475b7dce9ceb339d114f8a7f320052a138..15a460f99b4b92021031d2bde22cde2e12766095 100644 (file)
@@ -554,8 +554,7 @@ export function createHydrationFunctions(
           // JSX-compiled fns, but on the client the browser parses only 1 text
           // node.
           // look ahead for next possible text vnode
-          let next = children[i + 1]
-          if (next && (next = normalizeVNode(next)).type === Text) {
+          if (i + 1 < l && normalizeVNode(children[i + 1]).type === Text) {
             // create an extra TextNode on the client for the next vnode to
             // adopt
             insert(