From c399df91f16706d820fa9db7ea0036f4e79d1a8a Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 10 May 2022 14:17:04 +0800 Subject: [PATCH] fix(runtime-core): ensure consistent identity of $forceUpdate and $nextTick instance methods fix #5556 --- packages/runtime-core/src/component.ts | 9 +++++++++ packages/runtime-core/src/componentPublicInstance.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index b04d8fefcd0..11a6cafbcf1 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -440,6 +440,15 @@ export interface ComponentInternalInstance { * @internal */ [LifecycleHooks.SERVER_PREFETCH]: LifecycleHook<() => Promise> + + /** + * For caching bound $forceUpdate on public proxy access + */ + f?: () => void + /** + * For caching bound $nextTick on public proxy access + */ + n?: () => Promise } const emptyAppContext = createAppContext() diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index faae5312d30..33e8ce5fac0 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -252,8 +252,8 @@ export const publicPropertiesMap: PublicPropertiesMap = $root: i => getPublicInstance(i.root), $emit: i => i.emit, $options: i => (__FEATURE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type), - $forceUpdate: i => () => queueJob(i.update), - $nextTick: i => nextTick.bind(i.proxy!), + $forceUpdate: i => i.f || (i.f = () => queueJob(i.update)), + $nextTick: i => i.n || (i.n = nextTick.bind(i.proxy!)), $watch: i => (__FEATURE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP) } as PublicPropertiesMap)