Skip to content

Commit fa7ab0a

Browse files
committed
fix(runtime-core): warn reserved prefix for setup return properties and ensure consistent dev/prod behavior
close #2042
1 parent 95c07d8 commit fa7ab0a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/runtime-core/src/componentPublicInstance.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,16 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
299299
// to infinite warning loop
300300
key.indexOf('__v') !== 0)
301301
) {
302-
if (data !== EMPTY_OBJ && key[0] === '$' && hasOwn(data, key)) {
302+
if (
303+
data !== EMPTY_OBJ &&
304+
(key[0] === '$' || key[0] === '_') &&
305+
hasOwn(data, key)
306+
) {
303307
warn(
304308
`Property ${JSON.stringify(
305309
key
306310
)} must be accessed via $data because it starts with a reserved ` +
307-
`character and is not proxied on the render context.`
311+
`character ("$" or "_") and is not proxied on the render context.`
308312
)
309313
} else {
310314
warn(
@@ -474,6 +478,15 @@ export function exposeSetupStateOnRenderContext(
474478
) {
475479
const { ctx, setupState } = instance
476480
Object.keys(toRaw(setupState)).forEach(key => {
481+
if (key[0] === '$' || key[0] === '_') {
482+
warn(
483+
`setup() return property ${JSON.stringify(
484+
key
485+
)} should not start with "$" or "_" ` +
486+
`which are reserved prefixes for Vue internals.`
487+
)
488+
return
489+
}
477490
Object.defineProperty(ctx, key, {
478491
enumerable: true,
479492
configurable: true,

0 commit comments

Comments
 (0)