Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): ensure the nested teleport can be unmounted correctly #3629

Merged
merged 7 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
h,
Fragment,
Teleport,
createVNode,
openBlock,
createBlock,
Expand Down Expand Up @@ -576,4 +577,45 @@ describe('renderer: optimized mode', () => {
await nextTick()
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('')
})
})
5 changes: 3 additions & 2 deletions packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand Down