]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(teleport): only inherit el for non-patched nodes
authorEvan You <yyx990803@gmail.com>
Thu, 20 Aug 2020 14:43:57 +0000 (10:43 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 20 Aug 2020 14:44:28 +0000 (10:44 -0400)
fix #1903

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

index eaa6e227ee37c1f8d4d43b524218e785623dba6a..44a08c6687ff0797a4e2169b19f69e5dd974a36f 100644 (file)
@@ -316,7 +316,7 @@ describe('renderer: teleport', () => {
       },
       render: compile(`
       <teleport :to="target" :disabled="disabled">
-        <div>teleported</div><span>{{ disabled }}</span>
+        <div>teleported</div><span>{{ disabled }}</span><span v-if="disabled"/>
       </teleport>
       <div>root</div>
       `)
@@ -326,13 +326,13 @@ describe('renderer: teleport', () => {
       `"<!--teleport start--><!--teleport end--><div>root</div>"`
     )
     expect(serializeInner(target)).toMatchInlineSnapshot(
-      `"<div>teleported</div><span>false</span>"`
+      `"<div>teleported</div><span>false</span><!--v-if-->"`
     )
 
     disabled.value = true
     await nextTick()
     expect(serializeInner(root)).toMatchInlineSnapshot(
-      `"<!--teleport start--><div>teleported</div><span>true</span><!--teleport end--><div>root</div>"`
+      `"<!--teleport start--><div>teleported</div><span>true</span><span></span><!--teleport end--><div>root</div>"`
     )
     expect(serializeInner(target)).toBe(``)
 
@@ -343,7 +343,7 @@ describe('renderer: teleport', () => {
       `"<!--teleport start--><!--teleport end--><div>root</div>"`
     )
     expect(serializeInner(target)).toMatchInlineSnapshot(
-      `"<div>teleported</div><span>false</span>"`
+      `"<div>teleported</div><span>false</span><!--v-if-->"`
     )
   })
 })
index ca885c3d9206df32c0ef27f65900975896896b85..1d6a996de0ef0b092be96c958cb61d844c8233a0 100644 (file)
@@ -146,7 +146,10 @@ export const TeleportImpl = {
           const oldChildren = n1.children as VNode[]
           const children = n2.children as VNode[]
           for (let i = 0; i < children.length; i++) {
-            children[i].el = oldChildren[i].el
+            // only inherit for non-patched nodes (i.e. static ones)
+            if (!children[i].el) {
+              children[i].el = oldChildren[i].el
+            }
           }
         }
       } else if (!optimized) {