Skip to content

Commit d4cd128

Browse files
authored
fix(BaseTransition): collect correct children with slot passthrough in Transition (vuejs#1456)
fix vuejs#1455
1 parent afe13e0 commit d4cd128

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

packages/runtime-core/src/components/BaseTransition.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
Comment,
99
isSameVNodeType,
1010
VNode,
11-
VNodeArrayChildren
11+
VNodeArrayChildren,
12+
Fragment
1213
} from '../vnode'
1314
import { warn } from '../warning'
1415
import { isKeepAlive } from './KeepAlive'
@@ -135,7 +136,10 @@ const BaseTransitionImpl = {
135136
const state = useTransitionState()
136137

137138
return () => {
138-
const children = slots.default && slots.default()
139+
const children = getTransitionRawChildren(
140+
slots.default ? slots.default() : [],
141+
true
142+
)
139143
if (!children || !children.length) {
140144
return
141145
}
@@ -417,3 +421,27 @@ export function setTransitionHooks(vnode: VNode, hooks: TransitionHooks) {
417421
vnode.transition = hooks
418422
}
419423
}
424+
425+
export function getTransitionRawChildren(
426+
children: VNode[],
427+
keepComment: boolean = false
428+
): VNode[] {
429+
let ret: VNode[] = []
430+
for (let i = 0; i < children.length; i++) {
431+
const child = children[i]
432+
// handle fragment children case, e.g. v-for
433+
if (child.type === Fragment) {
434+
ret = ret.concat(
435+
getTransitionRawChildren(child.children as VNode[], keepComment)
436+
)
437+
}
438+
// comment placeholders should be skipped, e.g. v-if
439+
else if (
440+
child.type !== Comment ||
441+
(child.type === Comment && keepComment)
442+
) {
443+
ret.push(child)
444+
}
445+
}
446+
return ret
447+
}

packages/runtime-core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export { registerRuntimeCompiler } from './component'
9191
export {
9292
useTransitionState,
9393
resolveTransitionHooks,
94-
setTransitionHooks
94+
setTransitionHooks,
95+
getTransitionRawChildren
9596
} from './components/BaseTransition'
9697

9798
// Types -----------------------------------------------------------------------

packages/runtime-dom/src/components/TransitionGroup.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {
99
} from './Transition'
1010
import {
1111
Fragment,
12-
Comment,
1312
VNode,
1413
warn,
1514
resolveTransitionHooks,
1615
useTransitionState,
16+
getTransitionRawChildren,
1717
getCurrentInstance,
1818
setTransitionHooks,
1919
createVNode,
@@ -129,22 +129,6 @@ const TransitionGroupImpl = {
129129
}
130130
}
131131

132-
function getTransitionRawChildren(children: VNode[]): VNode[] {
133-
let ret: VNode[] = []
134-
for (let i = 0; i < children.length; i++) {
135-
const child = children[i]
136-
// handle fragment children case, e.g. v-for
137-
if (child.type === Fragment) {
138-
ret = ret.concat(getTransitionRawChildren(child.children as VNode[]))
139-
}
140-
// comment placeholders should be skipped, e.g. v-if
141-
else if (child.type !== Comment) {
142-
ret.push(child)
143-
}
144-
}
145-
return ret
146-
}
147-
148132
// remove mode props as TransitionGroup doesn't support it
149133
delete TransitionGroupImpl.props.mode
150134

0 commit comments

Comments
 (0)