Skip to content

Commit 81351dc

Browse files
authoredAug 7, 2024··
fix(keep-alive): fix render error in cached is undefined (#11496)
fix #11427 close #11431
1 parent 6c90324 commit 81351dc

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed
 

‎packages/runtime-core/__tests__/components/Suspense.spec.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ describe('Suspense', () => {
20362036
expect(serializeInner(root)).toBe(`<div>sync</div>`)
20372037
})
20382038

2039-
// #10899
2039+
// #10899 / #11427
20402040
test('KeepAlive + Suspense switch before branch resolves', async () => {
20412041
const Async1 = defineAsyncComponent({
20422042
render() {
@@ -2053,14 +2053,20 @@ describe('Suspense', () => {
20532053
const root = nodeOps.createElement('div')
20542054
const App = {
20552055
render() {
2056-
return h(KeepAlive, null, {
2057-
default: () => {
2058-
return h(Suspense, null, {
2059-
default: h(components[viewRef.value]),
2060-
fallback: h('div', 'loading'),
2061-
})
2056+
return h(
2057+
KeepAlive,
2058+
{
2059+
max: 1,
20622060
},
2063-
})
2061+
{
2062+
default: () => {
2063+
return h(Suspense, null, {
2064+
default: h(components[viewRef.value]),
2065+
fallback: h('div', 'loading'),
2066+
})
2067+
},
2068+
},
2069+
)
20642070
},
20652071
}
20662072
render(h(App), root)

‎packages/runtime-core/src/components/KeepAlive.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const KeepAliveImpl: ComponentOptions = {
206206

207207
function pruneCacheEntry(key: CacheKey) {
208208
const cached = cache.get(key) as VNode
209-
if (!current || !isSameVNodeType(cached, current)) {
209+
if (cached && (!current || !isSameVNodeType(cached, current))) {
210210
unmount(cached)
211211
} else if (current) {
212212
// current active instance should no longer be kept-alive.

0 commit comments

Comments
 (0)
Please sign in to comment.