fix(keep-alive): invoke initial activated hook for async components

revert #5459
fix #5095
fix #5651
This commit is contained in:
Evan You
2022-05-12 11:29:26 +08:00
parent 9d815d28ad
commit 20ed16f68c
3 changed files with 22 additions and 12 deletions

View File

@@ -6,7 +6,7 @@ import {
isInSSRComponentSetup,
ComponentOptions
} from './component'
import { isFunction, isObject, ShapeFlags } from '@vue/shared'
import { isFunction, isObject } from '@vue/shared'
import { ComponentPublicInstance } from './componentPublicInstance'
import { createVNode, VNode } from './vnode'
import { defineComponent } from './apiDefineComponent'
@@ -211,14 +211,13 @@ export function defineAsyncComponent<
function createInnerComp(
comp: ConcreteComponent,
{ vnode: { ref, props, children }, parent }: ComponentInternalInstance
{
vnode: { ref, props, children, shapeFlag },
parent
}: ComponentInternalInstance
) {
const vnode = createVNode(comp, props, children)
// ensure inner component inherits the async wrapper's ref owner
vnode.ref = ref
if (parent && isKeepAlive(parent.vnode)) {
vnode.shapeFlag |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
}
return vnode
}

View File

@@ -1420,7 +1420,12 @@ function baseCreateRenderer(
// activated hook for keep-alive roots.
// #1742 activated hook must be accessed after first render
// since the hook may be injected by a child keep-alive
if (initialVNode.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
if (
initialVNode.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE ||
(parent &&
isAsyncWrapper(parent.vnode) &&
parent.vnode.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE)
) {
instance.a && queuePostRenderEffect(instance.a, parentSuspense)
if (
__COMPAT__ &&