Skip to content

Commit

Permalink
fix(teleport): only inherit el for non-patched nodes
Browse files Browse the repository at this point in the history
fix #1903
  • Loading branch information
yyx990803 committed Aug 20, 2020
1 parent 69cfed6 commit d4cc7b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/runtime-core/__tests__/components/Teleport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
`)
Expand All @@ -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(``)

Expand All @@ -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-->"`
)
})
})
5 changes: 4 additions & 1 deletion packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d4cc7b2

Please sign in to comment.