]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core/teleport): ensure the nested teleport can be unmounted correctly...
authoredison <daiwei521@126.com>
Wed, 26 May 2021 14:51:55 +0000 (22:51 +0800)
committerGitHub <noreply@github.com>
Wed, 26 May 2021 14:51:55 +0000 (10:51 -0400)
fix #3623

packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts
packages/runtime-core/src/components/Teleport.ts

index 82f6f02fb1e51c6a94e0f19616aa5eb4b8096454..8c28d88102dab531ca29cbadf64603d00e7a185e 100644 (file)
@@ -1,6 +1,7 @@
 import {
   h,
   Fragment,
+  Teleport,
   createVNode,
   createCommentVNode,
   openBlock,
@@ -578,6 +579,47 @@ describe('renderer: optimized mode', () => {
     expect(inner(root)).toBe('<div>World</div>')
   })
 
+  //#3623
+  test('nested teleport unmount need exit the optimization mode', () => {
+    const target = nodeOps.createElement('div')
+    const root = nodeOps.createElement('div')
+
+    render(
+      (openBlock(),
+      createBlock('div', null, [
+        (openBlock(),
+        createBlock(
+          Teleport as any,
+          {
+            to: target
+          },
+          [
+            createVNode('div', null, [
+              (openBlock(),
+              createBlock(
+                Teleport as any,
+                {
+                  to: target
+                },
+                [createVNode('div', null, 'foo')]
+              ))
+            ])
+          ]
+        ))
+      ])),
+      root
+    )
+    expect(inner(target)).toMatchInlineSnapshot(
+      `"<div><!--teleport start--><!--teleport end--></div><div>foo</div>"`
+    )
+    expect(inner(root)).toMatchInlineSnapshot(
+      `"<div><!--teleport start--><!--teleport end--></div>"`
+    )
+
+    render(null, root)
+    expect(inner(target)).toBe('')
+  })
+
   // #3548
   test('should not track dynamic children when the user calls a compiled slot inside template expression', () => {
     const Comp = {
index 764e9a86dc80ab5193092a81f6427ad91e8e4e35..78aee9481e0e6ae3393d78081d355ee266f2add7 100644 (file)
@@ -243,12 +243,13 @@ export const TeleportImpl = {
       hostRemove(anchor!)
       if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
         for (let i = 0; i < (children as VNode[]).length; i++) {
+          const child = (children as VNode[])[i]
           unmount(
-            (children as VNode[])[i],
+            child,
             parentComponent,
             parentSuspense,
             true,
-            optimized
+            !!child.dynamicChildren
           )
         }
       }