Skip to content

Commit d7ca1c5

Browse files
committed
fix(runtime-core): fix user attched public instance properties that start with "$"
1 parent 99fd158 commit d7ca1c5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ describe('component: proxy', () => {
117117
instanceProxy.foo = 1
118118
expect(instanceProxy.foo).toBe(1)
119119
expect(instance!.ctx.foo).toBe(1)
120+
121+
// should also allow properties that start with $
122+
const obj = (instanceProxy.$store = {})
123+
expect(instanceProxy.$store).toBe(obj)
124+
expect(instance!.ctx.$store).toBe(obj)
120125
})
121126

122127
test('globalProperties', () => {

packages/runtime-core/src/componentProxy.ts

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
184184
(cssModule = cssModule[key])
185185
) {
186186
return cssModule
187+
} else if (ctx !== EMPTY_OBJ && hasOwn(ctx, key)) {
188+
// user may set custom properties to `this` that start with `$`
189+
accessCache![key] = AccessTypes.CONTEXT
190+
return ctx[key]
187191
} else if (
188192
// global properties
189193
((globalProperties = appContext.config.globalProperties),

0 commit comments

Comments
 (0)