Skip to content

Commit

Permalink
fix(BaseTransition): collect correct children with slot passthrough i…
Browse files Browse the repository at this point in the history
…n `Transition` (#1456)

fix #1455
  • Loading branch information
underfin authored Jun 29, 2020
1 parent afe13e0 commit d4cd128
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
32 changes: 30 additions & 2 deletions packages/runtime-core/src/components/BaseTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
Comment,
isSameVNodeType,
VNode,
VNodeArrayChildren
VNodeArrayChildren,
Fragment
} from '../vnode'
import { warn } from '../warning'
import { isKeepAlive } from './KeepAlive'
Expand Down Expand Up @@ -135,7 +136,10 @@ const BaseTransitionImpl = {
const state = useTransitionState()

return () => {
const children = slots.default && slots.default()
const children = getTransitionRawChildren(
slots.default ? slots.default() : [],
true
)
if (!children || !children.length) {
return
}
Expand Down Expand Up @@ -417,3 +421,27 @@ export function setTransitionHooks(vnode: VNode, hooks: TransitionHooks) {
vnode.transition = hooks
}
}

export function getTransitionRawChildren(
children: VNode[],
keepComment: boolean = false
): 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[], keepComment)
)
}
// comment placeholders should be skipped, e.g. v-if
else if (
child.type !== Comment ||
(child.type === Comment && keepComment)
) {
ret.push(child)
}
}
return ret
}
3 changes: 2 additions & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export { registerRuntimeCompiler } from './component'
export {
useTransitionState,
resolveTransitionHooks,
setTransitionHooks
setTransitionHooks,
getTransitionRawChildren
} from './components/BaseTransition'

// Types -----------------------------------------------------------------------
Expand Down
18 changes: 1 addition & 17 deletions packages/runtime-dom/src/components/TransitionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
} from './Transition'
import {
Fragment,
Comment,
VNode,
warn,
resolveTransitionHooks,
useTransitionState,
getTransitionRawChildren,
getCurrentInstance,
setTransitionHooks,
createVNode,
Expand Down Expand Up @@ -129,22 +129,6 @@ 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[]))
}
// comment placeholders should be skipped, e.g. v-if
else if (child.type !== Comment) {
ret.push(child)
}
}
return ret
}

// remove mode props as TransitionGroup doesn't support it
delete TransitionGroupImpl.props.mode

Expand Down

0 comments on commit d4cd128

Please sign in to comment.