From b0617e5a330a5d208e71997998c282572fe67cb9 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 7 Jun 2024 17:26:42 +0800 Subject: [PATCH] refactor: use index instead of function --- packages/runtime-core/src/component.ts | 2 +- packages/runtime-core/src/helpers/withMemo.ts | 3 +-- packages/runtime-core/src/renderer.ts | 5 +++-- packages/runtime-core/src/vnode.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index f2ca0464142..70a3716a3e3 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -322,7 +322,7 @@ export interface ComponentInternalInstance { * after initialized (e.g. inline handlers) * @internal */ - renderCache: (Function | VNode)[] + renderCache: (Function | VNode | undefined)[] /** * Resolved component registry, only for components with mixins or extends diff --git a/packages/runtime-core/src/helpers/withMemo.ts b/packages/runtime-core/src/helpers/withMemo.ts index 6f31182663b..72ef814eefa 100644 --- a/packages/runtime-core/src/helpers/withMemo.ts +++ b/packages/runtime-core/src/helpers/withMemo.ts @@ -15,8 +15,7 @@ export function withMemo( // shallow clone ret.memo = memo.slice() - - ret.cleanMemoCache = () => (cache[index] = undefined) + ret.memoIndex = index return (cache[index] = ret) } diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index e498c56fc2a..2a35a5e1925 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -2110,6 +2110,7 @@ function baseCreateRenderer( shapeFlag, patchFlag, dirs, + memoIndex, } = vnode // unset ref if (ref != null) { @@ -2117,8 +2118,8 @@ function baseCreateRenderer( } // #6593 should clean memo cache when unmount - if (vnode.cleanMemoCache) { - vnode.cleanMemoCache() + if (memoIndex != null) { + parentComponent!.renderCache[memoIndex] = undefined } if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) { diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 9bab0e7f4ec..7abd45c7fa5 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -229,9 +229,9 @@ export interface VNode< */ memo?: any[] /** - * @internal clean v-memo cache + * @internal index for cleaning v-memo cache */ - cleanMemoCache?: Function + memoIndex?: number /** * @internal __COMPAT__ only */