From ab2451f8e9e5853c6d98a5640634aaff3221e362 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Thu, 18 Nov 2021 02:53:43 +0200 Subject: [PATCH] fix(runtime-core): do not treat non-existent property as available PublicComponentInstance should not consider property as available on instance if it was accessed but was not found --- .../__tests__/componentPublicInstance.spec.ts | 4 ++++ packages/runtime-core/src/componentOptions.ts | 8 -------- packages/runtime-core/src/componentPublicInstance.ts | 6 +----- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/packages/runtime-core/__tests__/componentPublicInstance.spec.ts b/packages/runtime-core/__tests__/componentPublicInstance.spec.ts index c4c456b5f7a..1c0f300ddaa 100644 --- a/packages/runtime-core/__tests__/componentPublicInstance.spec.ts +++ b/packages/runtime-core/__tests__/componentPublicInstance.spec.ts @@ -195,6 +195,10 @@ describe('component: proxy', () => { expect('$foobar' in instanceProxy).toBe(false) expect('baz' in instanceProxy).toBe(false) + // triggering getter + instanceProxy.baz + expect('baz' in instanceProxy).toBe(false) + // set non-existent (goes into proxyTarget sink) instanceProxy.baz = 1 expect('baz' in instanceProxy).toBe(true) diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 41e02c5da0a..f0e8fbc7fcb 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -537,16 +537,11 @@ function createDuplicateChecker() { } } -export let shouldCacheAccess = true - export function applyOptions(instance: ComponentInternalInstance) { const options = resolveMergedOptions(instance) const publicThis = instance.proxy! as any const ctx = instance.ctx - // do not cache property access on public proxy during state initialization - shouldCacheAccess = false - // call beforeCreate first before accessing other options since // the hook may mutate resolved options (#2791) if (options.beforeCreate) { @@ -680,9 +675,6 @@ export function applyOptions(instance: ComponentInternalInstance) { } } - // state initialization complete at this point - start caching access - shouldCacheAccess = true - if (computedOptions) { for (const key in computedOptions) { const opt = (computedOptions as ComputedOptions)[key] diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index dd385a815c9..387027338d8 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -32,7 +32,6 @@ import { OptionTypesType, OptionTypesKeys, resolveMergedOptions, - shouldCacheAccess, MergedComponentOptionsOverride } from './componentOptions' import { EmitsOptions, EmitFn } from './componentEmits' @@ -251,8 +250,7 @@ const enum AccessTypes { SETUP, DATA, PROPS, - CONTEXT, - OTHER + CONTEXT } export interface ComponentRenderContext { @@ -321,8 +319,6 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { } else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) { accessCache![key] = AccessTypes.CONTEXT return ctx[key] - } else if (!__FEATURE_OPTIONS_API__ || shouldCacheAccess) { - accessCache![key] = AccessTypes.OTHER } }