Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BaseTransition): collect correct children with Transition slot #1456

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be exported from @vue/runtime-core - we can't do cross package relative imports.


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