Skip to content

Commit f6afe70

Browse files
committed
fix(runtome-core): do not cache property access in beforeCreate hook
fix #1756
1 parent d4c17fb commit f6afe70

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/runtime-core/src/componentOptions.ts

+4
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ function createDuplicateChecker() {
364364

365365
type DataFn = (vm: ComponentPublicInstance) => any
366366

367+
export let isInBeforeCreate = false
368+
367369
export function applyOptions(
368370
instance: ComponentInternalInstance,
369371
options: ComponentOptions,
@@ -407,7 +409,9 @@ export function applyOptions(
407409

408410
// applyOptions is called non-as-mixin once per instance
409411
if (!asMixin) {
412+
isInBeforeCreate = true
410413
callSyncHook('beforeCreate', options, publicThis, globalMixins)
414+
isInBeforeCreate = false
411415
// global mixins are applied first
412416
applyMixins(instance, globalMixins, deferredData, deferredWatch)
413417
}

packages/runtime-core/src/componentProxy.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {
2626
ComponentOptionsMixin,
2727
OptionTypesType,
2828
OptionTypesKeys,
29-
resolveMergedOptions
29+
resolveMergedOptions,
30+
isInBeforeCreate
3031
} from './componentOptions'
3132
import { normalizePropsOptions } from './componentProps'
3233
import { EmitsOptions, EmitFn } from './componentEmits'
@@ -254,7 +255,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
254255
} else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
255256
accessCache![key] = AccessTypes.CONTEXT
256257
return ctx[key]
257-
} else {
258+
} else if (!__FEATURE_OPTIONS_API__ || !isInBeforeCreate) {
258259
accessCache![key] = AccessTypes.OTHER
259260
}
260261
}

0 commit comments

Comments
 (0)