Skip to content

Commit

Permalink
fix(runtime-core): fix component public instance has check for access…
Browse files Browse the repository at this point in the history
…ed non-existent properties

close #4962
  • Loading branch information
yyx990803 committed Nov 25, 2021
1 parent 89b2f92 commit aac0466
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -195,6 +195,11 @@ describe('component: proxy', () => {
expect('$foobar' in instanceProxy).toBe(false)
expect('baz' in instanceProxy).toBe(false)

// #4962 triggering getter should not cause non-existent property to
// pass the has check
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
6 changes: 3 additions & 3 deletions packages/runtime-core/src/componentPublicInstance.ts
Expand Up @@ -248,11 +248,11 @@ if (__COMPAT__) {
}

const enum AccessTypes {
OTHER,
SETUP,
DATA,
PROPS,
CONTEXT,
OTHER
CONTEXT
}

export interface ComponentRenderContext {
Expand Down Expand Up @@ -437,7 +437,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
) {
let normalizedProps
return (
accessCache![key] !== undefined ||
!!accessCache![key] ||
(data !== EMPTY_OBJ && hasOwn(data, key)) ||
(setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||
Expand Down

0 comments on commit aac0466

Please sign in to comment.