From 4e3f82f6835472650741896e19fbdc116d86d1eb Mon Sep 17 00:00:00 2001 From: edison Date: Wed, 26 May 2021 22:51:55 +0800 Subject: [PATCH] fix(runtime-core/teleport): ensure the nested teleport can be unmounted correctly (#3629) fix #3623 --- .../__tests__/rendererOptimizedMode.spec.ts | 42 +++++++++++++++++++ .../runtime-core/src/components/Teleport.ts | 5 ++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts b/packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts index 82f6f02fb1e..8c28d88102d 100644 --- a/packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts +++ b/packages/runtime-core/__tests__/rendererOptimizedMode.spec.ts @@ -1,6 +1,7 @@ import { h, Fragment, + Teleport, createVNode, createCommentVNode, openBlock, @@ -578,6 +579,47 @@ describe('renderer: optimized mode', () => { expect(inner(root)).toBe('
World
') }) + //#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( + `"
foo
"` + ) + expect(inner(root)).toMatchInlineSnapshot( + `"
"` + ) + + render(null, root) + expect(inner(target)).toBe('') + }) + // #3548 test('should not track dynamic children when the user calls a compiled slot inside template expression', () => { const Comp = { diff --git a/packages/runtime-core/src/components/Teleport.ts b/packages/runtime-core/src/components/Teleport.ts index 764e9a86dc8..78aee9481e0 100644 --- a/packages/runtime-core/src/components/Teleport.ts +++ b/packages/runtime-core/src/components/Teleport.ts @@ -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 ) } }