Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): do not treat non-existent property as available #4962

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions packages/runtime-core/src/componentOptions.ts
Expand Up @@ -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) {
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 1 addition & 5 deletions packages/runtime-core/src/componentPublicInstance.ts
Expand Up @@ -32,7 +32,6 @@ import {
OptionTypesType,
OptionTypesKeys,
resolveMergedOptions,
shouldCacheAccess,
MergedComponentOptionsOverride
} from './componentOptions'
import { EmitsOptions, EmitFn } from './componentEmits'
Expand Down Expand Up @@ -251,8 +250,7 @@ const enum AccessTypes {
SETUP,
DATA,
PROPS,
CONTEXT,
OTHER
CONTEXT
}

export interface ComponentRenderContext {
Expand Down Expand Up @@ -321,8 +319,6 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
} 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
}
}

Expand Down