Bladeren bron

fix(hydration): handle text nodes with 0 during hydration (#11772)

close #11771
edison 1 jaar geleden
bovenliggende
commit
c756da24b2
2 gewijzigde bestanden met toevoegingen van 4 en 5 verwijderingen
  1. 3 3
      packages/runtime-core/__tests__/hydration.spec.ts
  2. 1 2
      packages/runtime-core/src/hydration.ts

+ 3 - 3
packages/runtime-core/__tests__/hydration.spec.ts

@@ -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 () => {

+ 1 - 2
packages/runtime-core/src/hydration.ts

@@ -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(