mirror of https://github.com/vuejs/core.git
fix(keep-alive): fix render error in cached is undefined (#11496)
fix #11427 close #11431
This commit is contained in:
parent
6c90324870
commit
81351dc7fb
|
@ -2036,7 +2036,7 @@ describe('Suspense', () => {
|
||||||
expect(serializeInner(root)).toBe(`<div>sync</div>`)
|
expect(serializeInner(root)).toBe(`<div>sync</div>`)
|
||||||
})
|
})
|
||||||
|
|
||||||
// #10899
|
// #10899 / #11427
|
||||||
test('KeepAlive + Suspense switch before branch resolves', async () => {
|
test('KeepAlive + Suspense switch before branch resolves', async () => {
|
||||||
const Async1 = defineAsyncComponent({
|
const Async1 = defineAsyncComponent({
|
||||||
render() {
|
render() {
|
||||||
|
@ -2053,14 +2053,20 @@ describe('Suspense', () => {
|
||||||
const root = nodeOps.createElement('div')
|
const root = nodeOps.createElement('div')
|
||||||
const App = {
|
const App = {
|
||||||
render() {
|
render() {
|
||||||
return h(KeepAlive, null, {
|
return h(
|
||||||
|
KeepAlive,
|
||||||
|
{
|
||||||
|
max: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
default: () => {
|
default: () => {
|
||||||
return h(Suspense, null, {
|
return h(Suspense, null, {
|
||||||
default: h(components[viewRef.value]),
|
default: h(components[viewRef.value]),
|
||||||
fallback: h('div', 'loading'),
|
fallback: h('div', 'loading'),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
render(h(App), root)
|
render(h(App), root)
|
||||||
|
|
|
@ -206,7 +206,7 @@ const KeepAliveImpl: ComponentOptions = {
|
||||||
|
|
||||||
function pruneCacheEntry(key: CacheKey) {
|
function pruneCacheEntry(key: CacheKey) {
|
||||||
const cached = cache.get(key) as VNode
|
const cached = cache.get(key) as VNode
|
||||||
if (!current || !isSameVNodeType(cached, current)) {
|
if (cached && (!current || !isSameVNodeType(cached, current))) {
|
||||||
unmount(cached)
|
unmount(cached)
|
||||||
} else if (current) {
|
} else if (current) {
|
||||||
// current active instance should no longer be kept-alive.
|
// current active instance should no longer be kept-alive.
|
||||||
|
|
Loading…
Reference in New Issue