fix(runtime-core): avoid script setup bindings overwriting reserved ctx properties (#4570)
This commit is contained in:
@@ -538,20 +538,22 @@ export function exposeSetupStateOnRenderContext(
|
||||
) {
|
||||
const { ctx, setupState } = instance
|
||||
Object.keys(toRaw(setupState)).forEach(key => {
|
||||
if (!setupState.__isScriptSetup && (key[0] === '$' || key[0] === '_')) {
|
||||
warn(
|
||||
`setup() return property ${JSON.stringify(
|
||||
key
|
||||
)} should not start with "$" or "_" ` +
|
||||
`which are reserved prefixes for Vue internals.`
|
||||
)
|
||||
return
|
||||
if (!setupState.__isScriptSetup) {
|
||||
if (key[0] === '$' || key[0] === '_') {
|
||||
warn(
|
||||
`setup() return property ${JSON.stringify(
|
||||
key
|
||||
)} should not start with "$" or "_" ` +
|
||||
`which are reserved prefixes for Vue internals.`
|
||||
)
|
||||
return
|
||||
}
|
||||
Object.defineProperty(ctx, key, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get: () => setupState[key],
|
||||
set: NOOP
|
||||
})
|
||||
}
|
||||
Object.defineProperty(ctx, key, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get: () => setupState[key],
|
||||
set: NOOP
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user