From: underfin <2218301630@qq.com> Date: Thu, 30 Apr 2020 19:06:50 +0000 (+0800) Subject: fix(transition-group): should collect raw children with Fragment (#1046) X-Git-Tag: v3.0.0-beta.5~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ed3455251d721e62fd7f6f75a7ef04bc411c152;p=thirdparty%2Fvuejs%2Fcore.git fix(transition-group): should collect raw children with Fragment (#1046) fix #1045 --- diff --git a/packages/runtime-dom/src/components/TransitionGroup.ts b/packages/runtime-dom/src/components/TransitionGroup.ts index 0183644114..aa8adf1437 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 ret: VNode[] = [] + for (let i = 0; i < children.length; i++) { + const child = children[i] + // handle fragment children case, e.g. v-for + if (child.type === Fragment) { + ret = ret.concat(getTransitionRawChildren(child.children as VNode[])) + } else { + ret.push(child) + } + } + return ret +} + // remove mode props as TransitionGroup doesn't support it delete TransitionGroupImpl.props.mode