From f6afe7000efb964355c439b7963087ab8e42d6b1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 3 Aug 2020 17:04:45 -0400 Subject: [PATCH] fix(runtome-core): do not cache property access in beforeCreate hook fix #1756 --- packages/runtime-core/src/componentOptions.ts | 4 ++++ packages/runtime-core/src/componentProxy.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 19e8f4bbba0..29b16f0ed89 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -364,6 +364,8 @@ function createDuplicateChecker() { type DataFn = (vm: ComponentPublicInstance) => any +export let isInBeforeCreate = false + export function applyOptions( instance: ComponentInternalInstance, options: ComponentOptions, @@ -407,7 +409,9 @@ export function applyOptions( // applyOptions is called non-as-mixin once per instance if (!asMixin) { + isInBeforeCreate = true callSyncHook('beforeCreate', options, publicThis, globalMixins) + isInBeforeCreate = false // global mixins are applied first applyMixins(instance, globalMixins, deferredData, deferredWatch) } diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 84f14ce462a..9c31246539f 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -26,7 +26,8 @@ import { ComponentOptionsMixin, OptionTypesType, OptionTypesKeys, - resolveMergedOptions + resolveMergedOptions, + isInBeforeCreate } from './componentOptions' import { normalizePropsOptions } from './componentProps' import { EmitsOptions, EmitFn } from './componentEmits' @@ -254,7 +255,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { } else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) { accessCache![key] = AccessTypes.CONTEXT return ctx[key] - } else { + } else if (!__FEATURE_OPTIONS_API__ || !isInBeforeCreate) { accessCache![key] = AccessTypes.OTHER } }