Skip to content

Commit aac0466

Browse files
committed
fix(runtime-core): fix component public instance has check for accessed non-existent properties
close #4962
1 parent 89b2f92 commit aac0466

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/runtime-core/__tests__/componentPublicInstance.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ describe('component: proxy', () => {
195195
expect('$foobar' in instanceProxy).toBe(false)
196196
expect('baz' in instanceProxy).toBe(false)
197197

198+
// #4962 triggering getter should not cause non-existent property to
199+
// pass the has check
200+
instanceProxy.baz
201+
expect('baz' in instanceProxy).toBe(false)
202+
198203
// set non-existent (goes into proxyTarget sink)
199204
instanceProxy.baz = 1
200205
expect('baz' in instanceProxy).toBe(true)

packages/runtime-core/src/componentPublicInstance.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ if (__COMPAT__) {
248248
}
249249

250250
const enum AccessTypes {
251+
OTHER,
251252
SETUP,
252253
DATA,
253254
PROPS,
254-
CONTEXT,
255-
OTHER
255+
CONTEXT
256256
}
257257

258258
export interface ComponentRenderContext {
@@ -437,7 +437,7 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
437437
) {
438438
let normalizedProps
439439
return (
440-
accessCache![key] !== undefined ||
440+
!!accessCache![key] ||
441441
(data !== EMPTY_OBJ && hasOwn(data, key)) ||
442442
(setupState !== EMPTY_OBJ && hasOwn(setupState, key)) ||
443443
((normalizedProps = propsOptions[0]) && hasOwn(normalizedProps, key)) ||

0 commit comments

Comments
 (0)