mirror of https://github.com/vuejs/core.git
fix(runtime-core): fix stale v-memo after v-if toggle (#6606)
close #6593
This commit is contained in:
parent
293cf4e131
commit
edf263847e
|
@ -148,6 +148,17 @@ describe('v-memo', () => {
|
||||||
// should update
|
// should update
|
||||||
await nextTick()
|
await nextTick()
|
||||||
expect(el.innerHTML).toBe(`<div>3 3</div>`)
|
expect(el.innerHTML).toBe(`<div>3 3</div>`)
|
||||||
|
|
||||||
|
vm.ok = true
|
||||||
|
await nextTick()
|
||||||
|
vm.ok = false
|
||||||
|
await nextTick()
|
||||||
|
expect(el.innerHTML).toBe(`<div>3 3</div>`)
|
||||||
|
|
||||||
|
vm.y++
|
||||||
|
// should update
|
||||||
|
await nextTick()
|
||||||
|
expect(el.innerHTML).toBe(`<div>4 3</div>`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('on v-for', async () => {
|
test('on v-for', async () => {
|
||||||
|
|
|
@ -322,7 +322,7 @@ export interface ComponentInternalInstance {
|
||||||
* after initialized (e.g. inline handlers)
|
* after initialized (e.g. inline handlers)
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
renderCache: (Function | VNode)[]
|
renderCache: (Function | VNode | undefined)[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolved component registry, only for components with mixins or extends
|
* Resolved component registry, only for components with mixins or extends
|
||||||
|
|
|
@ -15,6 +15,8 @@ export function withMemo(
|
||||||
|
|
||||||
// shallow clone
|
// shallow clone
|
||||||
ret.memo = memo.slice()
|
ret.memo = memo.slice()
|
||||||
|
ret.memoIndex = index
|
||||||
|
|
||||||
return (cache[index] = ret)
|
return (cache[index] = ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2110,12 +2110,18 @@ function baseCreateRenderer(
|
||||||
shapeFlag,
|
shapeFlag,
|
||||||
patchFlag,
|
patchFlag,
|
||||||
dirs,
|
dirs,
|
||||||
|
memoIndex,
|
||||||
} = vnode
|
} = vnode
|
||||||
// unset ref
|
// unset ref
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
setRef(ref, null, parentSuspense, vnode, true)
|
setRef(ref, null, parentSuspense, vnode, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #6593 should clean memo cache when unmount
|
||||||
|
if (memoIndex != null) {
|
||||||
|
parentComponent!.renderCache[memoIndex] = undefined
|
||||||
|
}
|
||||||
|
|
||||||
if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
|
if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
|
||||||
;(parentComponent!.ctx as KeepAliveContext).deactivate(vnode)
|
;(parentComponent!.ctx as KeepAliveContext).deactivate(vnode)
|
||||||
return
|
return
|
||||||
|
|
|
@ -228,6 +228,10 @@ export interface VNode<
|
||||||
* @internal attached by v-memo
|
* @internal attached by v-memo
|
||||||
*/
|
*/
|
||||||
memo?: any[]
|
memo?: any[]
|
||||||
|
/**
|
||||||
|
* @internal index for cleaning v-memo cache
|
||||||
|
*/
|
||||||
|
memoIndex?: number
|
||||||
/**
|
/**
|
||||||
* @internal __COMPAT__ only
|
* @internal __COMPAT__ only
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue