Browse Source

fix(runtime-core): properly get keepAlive child (#10772)

close #10771
edison 2 years ago
parent
commit
3724693a25
1 changed files with 10 additions and 8 deletions
  1. 10 8
      packages/runtime-core/src/components/BaseTransition.ts

+ 10 - 8
packages/runtime-core/src/components/BaseTransition.ts

@@ -470,15 +470,17 @@ function getKeepAliveChild(vnode: VNode): VNode | undefined {
 
   const { shapeFlag, children } = vnode
 
-  if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
-    return (children as VNodeArrayChildren)[0] as VNode
-  }
+  if (children) {
+    if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
+      return (children as VNodeArrayChildren)[0] as VNode
+    }
 
-  if (
-    shapeFlag & ShapeFlags.SLOTS_CHILDREN &&
-    isFunction((children as any).default)
-  ) {
-    return (children as any).default()
+    if (
+      shapeFlag & ShapeFlags.SLOTS_CHILDREN &&
+      isFunction((children as any).default)
+    ) {
+      return (children as any).default()
+    }
   }
 }