Skip to content

Commit 4e3f82f

Browse files
authored
fix(runtime-core/teleport): ensure the nested teleport can be unmounted correctly (#3629)
fix #3623
1 parent 2010607 commit 4e3f82f

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts

+42
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
h,
33
Fragment,
4+
Teleport,
45
createVNode,
56
createCommentVNode,
67
openBlock,
@@ -578,6 +579,47 @@ describe('renderer: optimized mode', () => {
578579
expect(inner(root)).toBe('<div>World</div>')
579580
})
580581

582+
//#3623
583+
test('nested teleport unmount need exit the optimization mode', () => {
584+
const target = nodeOps.createElement('div')
585+
const root = nodeOps.createElement('div')
586+
587+
render(
588+
(openBlock(),
589+
createBlock('div', null, [
590+
(openBlock(),
591+
createBlock(
592+
Teleport as any,
593+
{
594+
to: target
595+
},
596+
[
597+
createVNode('div', null, [
598+
(openBlock(),
599+
createBlock(
600+
Teleport as any,
601+
{
602+
to: target
603+
},
604+
[createVNode('div', null, 'foo')]
605+
))
606+
])
607+
]
608+
))
609+
])),
610+
root
611+
)
612+
expect(inner(target)).toMatchInlineSnapshot(
613+
`"<div><!--teleport start--><!--teleport end--></div><div>foo</div>"`
614+
)
615+
expect(inner(root)).toMatchInlineSnapshot(
616+
`"<div><!--teleport start--><!--teleport end--></div>"`
617+
)
618+
619+
render(null, root)
620+
expect(inner(target)).toBe('')
621+
})
622+
581623
// #3548
582624
test('should not track dynamic children when the user calls a compiled slot inside template expression', () => {
583625
const Comp = {

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,13 @@ export const TeleportImpl = {
243243
hostRemove(anchor!)
244244
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
245245
for (let i = 0; i < (children as VNode[]).length; i++) {
246+
const child = (children as VNode[])[i]
246247
unmount(
247-
(children as VNode[])[i],
248+
child,
248249
parentComponent,
249250
parentSuspense,
250251
true,
251-
optimized
252+
!!child.dynamicChildren
252253
)
253254
}
254255
}

0 commit comments

Comments
 (0)