@@ -16,7 +16,7 @@ import { warn } from '../warning'
1616import { isKeepAlive } from './KeepAlive'
1717import { toRaw } from '@vue/reactivity'
1818import { ErrorCodes , callWithAsyncErrorHandling } from '../errorHandling'
19- import { PatchFlags , ShapeFlags , isArray } from '@vue/shared'
19+ import { PatchFlags , ShapeFlags , isArray , isFunction } from '@vue/shared'
2020import { onBeforeUnmount , onMounted } from '../apiLifecycle'
2121import type { RendererElement } from '../renderer'
2222
@@ -459,15 +459,27 @@ function emptyPlaceholder(vnode: VNode): VNode | undefined {
459459}
460460
461461function getKeepAliveChild ( vnode : VNode ) : VNode | undefined {
462- return isKeepAlive ( vnode )
463- ? // #7121 ensure get the child component subtree in case
464- // it's been replaced during HMR
465- __DEV__ && vnode . component
466- ? vnode . component . subTree
467- : vnode . children
468- ? ( ( vnode . children as VNodeArrayChildren ) [ 0 ] as VNode )
469- : undefined
470- : vnode
462+ if ( ! isKeepAlive ( vnode ) ) {
463+ return vnode
464+ }
465+ // #7121 ensure get the child component subtree in case
466+ // it's been replaced during HMR
467+ if ( __DEV__ && vnode . component ) {
468+ return vnode . component . subTree
469+ }
470+
471+ const { shapeFlag, children } = vnode
472+
473+ if ( shapeFlag & ShapeFlags . ARRAY_CHILDREN ) {
474+ return ( children as VNodeArrayChildren ) [ 0 ] as VNode
475+ }
476+
477+ if (
478+ shapeFlag & ShapeFlags . SLOTS_CHILDREN &&
479+ isFunction ( ( children as any ) . default )
480+ ) {
481+ return ( children as any ) . default ( )
482+ }
471483}
472484
473485export function setTransitionHooks ( vnode : VNode , hooks : TransitionHooks ) {
0 commit comments