From 0442ce49a380b960976f88553fb236fd60e9e26e Mon Sep 17 00:00:00 2001 From: likui <2218301630@qq.com> Date: Sat, 25 Apr 2020 16:05:55 +0800 Subject: [PATCH] fix(TransitionGroup): should collect raw children with Fragment fix #1045 --- .../src/components/TransitionGroup.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/runtime-dom/src/components/TransitionGroup.ts b/packages/runtime-dom/src/components/TransitionGroup.ts index 01836441145..328f9aa15e1 100644 --- a/packages/runtime-dom/src/components/TransitionGroup.ts +++ b/packages/runtime-dom/src/components/TransitionGroup.ts @@ -101,12 +101,7 @@ const TransitionGroupImpl = { const cssTransitionProps = resolveTransitionProps(rawProps) const tag = rawProps.tag || Fragment prevChildren = children - children = slots.default ? slots.default() : [] - - // handle fragment children case, e.g. v-for - if (children.length === 1 && children[0].type === Fragment) { - children = children[0].children as VNode[] - } + children = getTransitionRawChildren(slots.default ? slots.default() : []) for (let i = 0; i < children.length; i++) { const child = children[i] @@ -136,6 +131,20 @@ const TransitionGroupImpl = { } } +function getTransitionRawChildren(children: VNode[]): VNode[] { + let array: VNode[] = [] + for (const child of children) { + const { type, children } = child + // handle fragment children case, e.g. v-for + if (type === Fragment) { + array = array.concat(getTransitionRawChildren(children as VNode[])) + } else { + array.push(child) + } + } + return array +} + // remove mode props as TransitionGroup doesn't support it delete TransitionGroupImpl.props.mode