fix(teleport): only inherit el for non-patched nodes

fix #1903
This commit is contained in:
Evan You 2020-08-20 10:43:57 -04:00
parent 69cfed6b31
commit d4cc7b2496
2 changed files with 8 additions and 5 deletions

View File

@ -316,7 +316,7 @@ describe('renderer: teleport', () => {
}, },
render: compile(` render: compile(`
<teleport :to="target" :disabled="disabled"> <teleport :to="target" :disabled="disabled">
<div>teleported</div><span>{{ disabled }}</span> <div>teleported</div><span>{{ disabled }}</span><span v-if="disabled"/>
</teleport> </teleport>
<div>root</div> <div>root</div>
`) `)
@ -326,13 +326,13 @@ describe('renderer: teleport', () => {
`"<!--teleport start--><!--teleport end--><div>root</div>"` `"<!--teleport start--><!--teleport end--><div>root</div>"`
) )
expect(serializeInner(target)).toMatchInlineSnapshot( expect(serializeInner(target)).toMatchInlineSnapshot(
`"<div>teleported</div><span>false</span>"` `"<div>teleported</div><span>false</span><!--v-if-->"`
) )
disabled.value = true disabled.value = true
await nextTick() await nextTick()
expect(serializeInner(root)).toMatchInlineSnapshot( 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(``) expect(serializeInner(target)).toBe(``)
@ -343,7 +343,7 @@ describe('renderer: teleport', () => {
`"<!--teleport start--><!--teleport end--><div>root</div>"` `"<!--teleport start--><!--teleport end--><div>root</div>"`
) )
expect(serializeInner(target)).toMatchInlineSnapshot( expect(serializeInner(target)).toMatchInlineSnapshot(
`"<div>teleported</div><span>false</span>"` `"<div>teleported</div><span>false</span><!--v-if-->"`
) )
}) })
}) })

View File

@ -146,7 +146,10 @@ export const TeleportImpl = {
const oldChildren = n1.children as VNode[] const oldChildren = n1.children as VNode[]
const children = n2.children as VNode[] const children = n2.children as VNode[]
for (let i = 0; i < children.length; i++) { 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) { } else if (!optimized) {