Skip to content

Commit

Permalink
fix(runtome-core): do not cache property access in beforeCreate hook
Browse files Browse the repository at this point in the history
fix #1756
  • Loading branch information
yyx990803 committed Aug 3, 2020
1 parent d4c17fb commit f6afe70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ function createDuplicateChecker() {

type DataFn = (vm: ComponentPublicInstance) => any

export let isInBeforeCreate = false

export function applyOptions(
instance: ComponentInternalInstance,
options: ComponentOptions,
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions packages/runtime-core/src/componentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {
ComponentOptionsMixin,
OptionTypesType,
OptionTypesKeys,
resolveMergedOptions
resolveMergedOptions,
isInBeforeCreate
} from './componentOptions'
import { normalizePropsOptions } from './componentProps'
import { EmitsOptions, EmitFn } from './componentEmits'
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit f6afe70

Please sign in to comment.