Skip to content

Commit

Permalink
fix(runtime-core): v-memo work with v-if
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Sep 5, 2022
1 parent fa6556a commit b3b89bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/runtime-core/src/helpers/withMemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export function withMemo(

// shallow clone
ret.memo = memo.slice()

ret.cleanMemoCache = () => cache[index] = undefined

return (cache[index] = ret)
}

Expand Down
5 changes: 5 additions & 0 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,11 @@ function baseCreateRenderer(
setRef(ref, null, parentSuspense, vnode, true)
}

// #6593 should clean memo cache when unmount
if (vnode.cleanMemoCache) {
vnode.cleanMemoCache()
}

if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
;(parentComponent!.ctx as KeepAliveContext).deactivate(vnode)
return
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ export interface VNode<
* @internal attached by v-memo
*/
memo?: any[]
/**
* @internal clean v-memo cache
*/
cleanMemoCache?: Function
/**
* @internal __COMPAT__ only
*/
Expand Down

0 comments on commit b3b89bc

Please sign in to comment.