]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtome-core): do not cache property access in beforeCreate hook
authorEvan You <yyx990803@gmail.com>
Mon, 3 Aug 2020 21:04:45 +0000 (17:04 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 3 Aug 2020 21:04:45 +0000 (17:04 -0400)
fix #1756

packages/runtime-core/src/componentOptions.ts
packages/runtime-core/src/componentProxy.ts

index 19e8f4bbba0873c29e966b1d43a3dc008ca65ab1..29b16f0ed89d2a2de068316b08c142ccec373cbc 100644 (file)
@@ -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)
   }
index 84f14ce462a3af3633253d0d6b70be04dab75da0..9c31246539f6ae852fb58841a2cde395249c4c79 100644 (file)
@@ -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<any> = {
       } 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
       }
     }