Skip to content

Commit

Permalink
fix(BaseTransition): collect correct children with Transition slot
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Jun 27, 2020
1 parent 0dd5cde commit 9dc9947
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
23 changes: 21 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,9 @@ const BaseTransitionImpl = {
const state = useTransitionState()

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

export 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
}
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,7 +9,6 @@ import {
} from './Transition'
import {
Fragment,
Comment,
VNode,
warn,
resolveTransitionHooks,
Expand All @@ -22,6 +21,7 @@ import {
} from '@vue/runtime-core'
import { toRaw } from '@vue/reactivity'
import { extend } from '@vue/shared'
import { getTransitionRawChildren } from '../../../runtime-core/src/components/BaseTransition'

interface Position {
top: number
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 9dc9947

Please sign in to comment.