Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): AsyncComponent work with KeepAlive #5459

Merged
merged 4 commits into from
May 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: add test case
edison1105 committed Feb 19, 2022
commit 90d2ddd608b9195b908222cf4ae02df20884fe5d
38 changes: 37 additions & 1 deletion packages/runtime-core/__tests__/apiAsyncComponent.spec.ts
Original file line number Diff line number Diff line change
@@ -4,9 +4,11 @@ import {
Component,
ref,
nextTick,
Suspense
Suspense,
KeepAlive
} from '../src'
import { createApp, nodeOps, serializeInner } from '@vue/runtime-test'
import { onActivated } from '../src/components/KeepAlive'

const timeout = (n: number = 0) => new Promise(r => setTimeout(r, n))

@@ -799,4 +801,38 @@ describe('api: defineAsyncComponent', () => {
expect(vnodeHooks.onVnodeBeforeUnmount).toHaveBeenCalledTimes(1)
expect(vnodeHooks.onVnodeUnmounted).toHaveBeenCalledTimes(1)
})

test('with keepalive', async () => {
const spy = jest.fn()
let resolve: (comp: Component) => void

const Foo = defineAsyncComponent(
() =>
new Promise(r => {
resolve = r as any
})
)

const root = nodeOps.createElement('div')
const app = createApp({
render: () => h(KeepAlive, [h(Foo)])
})

app.mount(root)
await nextTick()

resolve!({
setup() {
onActivated(() => {
spy()
})
return () => 'resolved'
}
})

await timeout()
expect(serializeInner(root)).toBe('resolved')
expect(spy).toBeCalledTimes(1)
})

})
1 change: 0 additions & 1 deletion packages/runtime-core/src/apiAsyncComponent.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import {
isInSSRComponentSetup,
ComponentOptions
} from './component'

import { isFunction, isObject, ShapeFlags } from '@vue/shared'
import { ComponentPublicInstance } from './componentPublicInstance'
import { createVNode, VNode } from './vnode'