From 26a50ce67f64439cfc242fba59b1e7129e59ba40 Mon Sep 17 00:00:00 2001 From: underfin <2218301630@qq.com> Date: Mon, 4 May 2020 22:41:48 +0800 Subject: [PATCH] fix(transitionGroup): inner children should skip comment node (#1105) --- .../runtime-dom/src/components/TransitionGroup.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/runtime-dom/src/components/TransitionGroup.ts b/packages/runtime-dom/src/components/TransitionGroup.ts index aa8adf143..734ba6934 100644 --- a/packages/runtime-dom/src/components/TransitionGroup.ts +++ b/packages/runtime-dom/src/components/TransitionGroup.ts @@ -101,7 +101,8 @@ const TransitionGroupImpl = { const cssTransitionProps = resolveTransitionProps(rawProps) const tag = rawProps.tag || Fragment prevChildren = children - children = getTransitionRawChildren(slots.default ? slots.default() : []) + const slotChildren = slots.default ? slots.default() : [] + children = getTransitionRawChildren(slotChildren) for (let i = 0; i < children.length; i++) { const child = children[i] @@ -110,7 +111,7 @@ const TransitionGroupImpl = { child, resolveTransitionHooks(child, cssTransitionProps, state, instance) ) - } else if (__DEV__ && child.type !== Comment) { + } else if (__DEV__) { warn(` children must be keyed.`) } } @@ -126,7 +127,7 @@ const TransitionGroupImpl = { } } - return createVNode(tag, null, children) + return createVNode(tag, null, slotChildren) } } } @@ -138,7 +139,9 @@ function getTransitionRawChildren(children: VNode[]): VNode[] { // handle fragment children case, e.g. v-for if (child.type === Fragment) { ret = ret.concat(getTransitionRawChildren(child.children as VNode[])) - } else { + } + // comment should be skip, e.g. v-if + if (child.type !== Comment) { ret.push(child) } }