refactor(runtime-core): remove the deactivated branch in unmountComponent method (#2012)
This commit is contained in:
parent
691a4b9530
commit
0d0970f9cd
@ -347,21 +347,33 @@ describe('KeepAlive', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('max', async () => {
|
test('max', async () => {
|
||||||
const spyA = jest.fn()
|
const spyAC = jest.fn()
|
||||||
const spyB = jest.fn()
|
const spyBC = jest.fn()
|
||||||
const spyC = jest.fn()
|
const spyCC = jest.fn()
|
||||||
const spyAD = jest.fn()
|
const spyAA = jest.fn()
|
||||||
const spyBD = jest.fn()
|
const spyBA = jest.fn()
|
||||||
const spyCD = jest.fn()
|
const spyCA = jest.fn()
|
||||||
|
const spyADA = jest.fn()
|
||||||
|
const spyBDA = jest.fn()
|
||||||
|
const spyCDA = jest.fn()
|
||||||
|
const spyAUM = jest.fn()
|
||||||
|
const spyBUM = jest.fn()
|
||||||
|
const spyCUM = jest.fn()
|
||||||
|
|
||||||
function assertCount(calls: number[]) {
|
function assertCount(calls: number[]) {
|
||||||
expect([
|
expect([
|
||||||
spyA.mock.calls.length,
|
spyAC.mock.calls.length,
|
||||||
spyAD.mock.calls.length,
|
spyAA.mock.calls.length,
|
||||||
spyB.mock.calls.length,
|
spyADA.mock.calls.length,
|
||||||
spyBD.mock.calls.length,
|
spyAUM.mock.calls.length,
|
||||||
spyC.mock.calls.length,
|
spyBC.mock.calls.length,
|
||||||
spyCD.mock.calls.length
|
spyBA.mock.calls.length,
|
||||||
|
spyBDA.mock.calls.length,
|
||||||
|
spyBUM.mock.calls.length,
|
||||||
|
spyCC.mock.calls.length,
|
||||||
|
spyCA.mock.calls.length,
|
||||||
|
spyCDA.mock.calls.length,
|
||||||
|
spyCUM.mock.calls.length
|
||||||
]).toEqual(calls)
|
]).toEqual(calls)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,18 +381,24 @@ describe('KeepAlive', () => {
|
|||||||
const views: Record<string, ComponentOptions> = {
|
const views: Record<string, ComponentOptions> = {
|
||||||
a: {
|
a: {
|
||||||
render: () => `one`,
|
render: () => `one`,
|
||||||
created: spyA,
|
created: spyAC,
|
||||||
unmounted: spyAD
|
activated: spyAA,
|
||||||
|
deactivated: spyADA,
|
||||||
|
unmounted: spyAUM
|
||||||
},
|
},
|
||||||
b: {
|
b: {
|
||||||
render: () => `two`,
|
render: () => `two`,
|
||||||
created: spyB,
|
created: spyBC,
|
||||||
unmounted: spyBD
|
activated: spyBA,
|
||||||
|
deactivated: spyBDA,
|
||||||
|
unmounted: spyBUM
|
||||||
},
|
},
|
||||||
c: {
|
c: {
|
||||||
render: () => `three`,
|
render: () => `three`,
|
||||||
created: spyC,
|
created: spyCC,
|
||||||
unmounted: spyCD
|
activated: spyCA,
|
||||||
|
deactivated: spyCDA,
|
||||||
|
unmounted: spyCUM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,26 +410,26 @@ describe('KeepAlive', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(h(App), root)
|
render(h(App), root)
|
||||||
assertCount([1, 0, 0, 0, 0, 0])
|
assertCount([1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
||||||
|
|
||||||
viewRef.value = 'b'
|
viewRef.value = 'b'
|
||||||
await nextTick()
|
await nextTick()
|
||||||
assertCount([1, 0, 1, 0, 0, 0])
|
assertCount([1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0])
|
||||||
|
|
||||||
viewRef.value = 'c'
|
viewRef.value = 'c'
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// should prune A because max cache reached
|
// should prune A because max cache reached
|
||||||
assertCount([1, 1, 1, 0, 1, 0])
|
assertCount([1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0])
|
||||||
|
|
||||||
viewRef.value = 'b'
|
viewRef.value = 'b'
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// B should be reused, and made latest
|
// B should be reused, and made latest
|
||||||
assertCount([1, 1, 1, 0, 1, 0])
|
assertCount([1, 1, 1, 1, 1, 2, 1, 0, 1, 1, 1, 0])
|
||||||
|
|
||||||
viewRef.value = 'a'
|
viewRef.value = 'a'
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// C should be pruned because B was used last so C is the oldest cached
|
// C should be pruned because B was used last so C is the oldest cached
|
||||||
assertCount([2, 1, 1, 0, 1, 1])
|
assertCount([2, 2, 1, 1, 1, 2, 2, 0, 1, 1, 1, 1])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2096,7 +2096,7 @@ function baseCreateRenderer(
|
|||||||
unregisterHMR(instance)
|
unregisterHMR(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { bum, effects, update, subTree, um, da, isDeactivated } = instance
|
const { bum, effects, update, subTree, um } = instance
|
||||||
// beforeUnmount hook
|
// beforeUnmount hook
|
||||||
if (bum) {
|
if (bum) {
|
||||||
invokeArrayFns(bum)
|
invokeArrayFns(bum)
|
||||||
@ -2116,14 +2116,6 @@ function baseCreateRenderer(
|
|||||||
if (um) {
|
if (um) {
|
||||||
queuePostRenderEffect(um, parentSuspense)
|
queuePostRenderEffect(um, parentSuspense)
|
||||||
}
|
}
|
||||||
// deactivated hook
|
|
||||||
if (
|
|
||||||
da &&
|
|
||||||
!isDeactivated &&
|
|
||||||
instance.vnode.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
|
|
||||||
) {
|
|
||||||
queuePostRenderEffect(da, parentSuspense)
|
|
||||||
}
|
|
||||||
queuePostRenderEffect(() => {
|
queuePostRenderEffect(() => {
|
||||||
instance.isUnmounted = true
|
instance.isUnmounted = true
|
||||||
}, parentSuspense)
|
}, parentSuspense)
|
||||||
|
Loading…
Reference in New Issue
Block a user