Просмотр исходного кода

fix(hydration): avoid setting targetStart to placeholder when target is null (#14589)

edison 3 месяцев назад
Родитель
Сommit
5f38d7331a

+ 18 - 0
packages/runtime-vapor/__tests__/hydration.spec.ts

@@ -3933,6 +3933,24 @@ describe('Vapor Mode hydration', () => {
       )
     })
 
+    test('disabled teleport with null target hydration', async () => {
+      const { block, container } = await mountWithHydration(
+        '<!--teleport start--><div>content</div><!--teleport end-->',
+        `<teleport :to="undefined" :disabled="true">
+          <div>content</div>
+        </teleport>`,
+      )
+      expect(container.innerHTML).toBe(
+        `<!--teleport start--><div>content</div><!--teleport end-->`,
+      )
+      expect(`mismatch`).not.toHaveBeenWarned()
+
+      // targetStart must NOT be set when there's no target
+      const teleport = block as TeleportFragment
+      expect(teleport.targetStart).toBeNull()
+      expect(teleport.targetAnchor).toBeNull()
+    })
+
     test('enabled teleport with null target', async () => {
       const { container } = await mountWithHydration(
         '<!--teleport start--><!--teleport end-->',

+ 2 - 1
packages/runtime-vapor/src/components/Teleport.ts

@@ -376,7 +376,8 @@ export class TeleportFragment extends VaporFragment {
         }
       }
     } else if (disabled) {
-      this.hydrateDisabledTeleport(currentHydrationNode!)
+      // pass null as targetNode since there is no target
+      this.hydrateDisabledTeleport(null)
     } else {
       // enabled teleport with null target: init children without
       // hydration since there's no target to hydrate into.