Skip to content

Commit 7fe6c79

Browse files
authored
fix(runtime-core): properly update async component nested in KeepAlive (#11917)
close #11916
1 parent 0e7bc71 commit 7fe6c79

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

packages/runtime-core/__tests__/apiAsyncComponent.spec.ts

+33
Original file line numberDiff line numberDiff line change
@@ -843,4 +843,37 @@ describe('api: defineAsyncComponent', () => {
843843
await timeout()
844844
expect(serializeInner(root)).toBe('Bar')
845845
})
846+
847+
// 11916
848+
test('with KeepAlive + include', async () => {
849+
const spy = vi.fn()
850+
let resolve: (comp: Component) => void
851+
852+
const Foo = defineAsyncComponent(
853+
() =>
854+
new Promise(r => {
855+
resolve = r as any
856+
}),
857+
)
858+
859+
const root = nodeOps.createElement('div')
860+
const app = createApp({
861+
render: () => h(KeepAlive, { include: 'Foo' }, [h(Foo)]),
862+
})
863+
864+
app.mount(root)
865+
await nextTick()
866+
867+
resolve!({
868+
name: 'Foo',
869+
setup() {
870+
onActivated(spy)
871+
return () => 'Foo'
872+
},
873+
})
874+
875+
await timeout()
876+
expect(serializeInner(root)).toBe('Foo')
877+
expect(spy).toBeCalledTimes(1)
878+
})
846879
})

packages/runtime-core/src/apiAsyncComponent.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { warn } from './warning'
1414
import { ref } from '@vue/reactivity'
1515
import { ErrorCodes, handleError } from './errorHandling'
1616
import { isKeepAlive } from './components/KeepAlive'
17-
import { queueJob } from './scheduler'
1817
import { markAsyncBoundary } from './helpers/useId'
1918
import { type HydrationStrategy, forEachElement } from './hydrationStrategies'
2019

@@ -210,7 +209,7 @@ export function defineAsyncComponent<
210209
if (instance.parent && isKeepAlive(instance.parent.vnode)) {
211210
// parent is keep-alive, force update so the loaded component's
212211
// name is taken into account
213-
queueJob(instance.parent.update)
212+
instance.parent.update()
214213
}
215214
})
216215
.catch(err => {

0 commit comments

Comments
 (0)