mirror of https://github.com/vuejs/core.git
fix(keep-alive): avoid cache suspense comment root (#11479)
This commit is contained in:
parent
536f62332c
commit
a917c0539c
|
@ -8,6 +8,7 @@ import {
|
||||||
KeepAlive,
|
KeepAlive,
|
||||||
Suspense,
|
Suspense,
|
||||||
type SuspenseProps,
|
type SuspenseProps,
|
||||||
|
createCommentVNode,
|
||||||
h,
|
h,
|
||||||
nextTick,
|
nextTick,
|
||||||
nodeOps,
|
nodeOps,
|
||||||
|
@ -2085,6 +2086,35 @@ describe('Suspense', () => {
|
||||||
expect(serializeInner(root)).toBe(`<div>async2</div>`)
|
expect(serializeInner(root)).toBe(`<div>async2</div>`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('KeepAlive + Suspense + comment slot', async () => {
|
||||||
|
const toggle = ref(false)
|
||||||
|
const Async = defineAsyncComponent({
|
||||||
|
render() {
|
||||||
|
return h('div', 'async1')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const App = {
|
||||||
|
render() {
|
||||||
|
return h(KeepAlive, null, {
|
||||||
|
default: () => {
|
||||||
|
return h(Suspense, null, {
|
||||||
|
default: toggle.value ? h(Async) : createCommentVNode('v-if'),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const root = nodeOps.createElement('div')
|
||||||
|
render(h(App), root)
|
||||||
|
expect(serializeInner(root)).toBe(`<!--v-if-->`)
|
||||||
|
|
||||||
|
toggle.value = true
|
||||||
|
await nextTick()
|
||||||
|
await Promise.all(deps)
|
||||||
|
expect(serializeInner(root)).toBe(`<div>async1</div>`)
|
||||||
|
})
|
||||||
|
|
||||||
// #6416 follow up / #10017
|
// #6416 follow up / #10017
|
||||||
test('Suspense patched during HOC async component re-mount', async () => {
|
test('Suspense patched during HOC async component re-mount', async () => {
|
||||||
const key = ref('k')
|
const key = ref('k')
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
getCurrentInstance,
|
getCurrentInstance,
|
||||||
} from '../component'
|
} from '../component'
|
||||||
import {
|
import {
|
||||||
|
Comment,
|
||||||
type VNode,
|
type VNode,
|
||||||
type VNodeProps,
|
type VNodeProps,
|
||||||
cloneVNode,
|
cloneVNode,
|
||||||
|
@ -287,6 +288,12 @@ const KeepAliveImpl: ComponentOptions = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let vnode = getInnerChild(rawVNode)
|
let vnode = getInnerChild(rawVNode)
|
||||||
|
// #6028 Suspense ssContent maybe a comment VNode, should avoid caching it
|
||||||
|
if (vnode.type === Comment) {
|
||||||
|
current = null
|
||||||
|
return vnode
|
||||||
|
}
|
||||||
|
|
||||||
const comp = vnode.type as ConcreteComponent
|
const comp = vnode.type as ConcreteComponent
|
||||||
|
|
||||||
// for async components, name check should be based in its loaded
|
// for async components, name check should be based in its loaded
|
||||||
|
|
Loading…
Reference in New Issue