expect(vnodeHooks.onVnodeUnmounted).toHaveBeenCalledTimes(1)
})
- test('with keepalive', async () => {
+ test('with KeepAlive', async () => {
const spy = jest.fn()
let resolve: (comp: Component) => void
})
)
+ const Bar = defineAsyncComponent(() => Promise.resolve(() => 'Bar'))
+
+ const toggle = ref(true)
const root = nodeOps.createElement('div')
const app = createApp({
- render: () => h(KeepAlive, [h(Foo)])
+ render: () => h(KeepAlive, [toggle.value ? h(Foo) : h(Bar)])
})
app.mount(root)
onActivated(() => {
spy()
})
- return () => 'resolved'
+ return () => 'Foo'
}
})
await timeout()
- expect(serializeInner(root)).toBe('resolved')
+ expect(serializeInner(root)).toBe('Foo')
expect(spy).toBeCalledTimes(1)
- })
+ toggle.value = false
+ await timeout()
+ expect(serializeInner(root)).toBe('Bar')
+ })
})
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'
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
}
// 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__ &&