Skip to content

Commit ce78eac

Browse files
authored
fix(runtime-core): check if the key is string on undefined property warning (#1731)
1 parent 848d9ce commit ce78eac

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,24 @@ describe('component: proxy', () => {
217217
`was accessed during render but is not defined`
218218
).not.toHaveBeenWarned()
219219
})
220+
221+
test('should allow symbol to access on render', () => {
222+
const Comp = {
223+
render() {
224+
if ((this as any)[Symbol.unscopables]) {
225+
return '1'
226+
}
227+
return '2'
228+
}
229+
}
230+
231+
const app = createApp(Comp)
232+
app.mount(nodeOps.createElement('div'))
233+
234+
expect(
235+
`Property ${JSON.stringify(
236+
Symbol.unscopables
237+
)} was accessed during render ` + `but is not defined on instance.`
238+
).toHaveBeenWarned()
239+
})
220240
})

packages/runtime-core/src/componentProxy.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
hasOwn,
77
isGloballyWhitelisted,
88
NOOP,
9-
extend
9+
extend,
10+
isString
1011
} from '@vue/shared'
1112
import {
1213
ReactiveEffect,
@@ -286,9 +287,10 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
286287
} else if (
287288
__DEV__ &&
288289
currentRenderingInstance &&
289-
// #1091 avoid internal isRef/isVNode checks on component instance leading
290-
// to infinite warning loop
291-
key.indexOf('__v') !== 0
290+
(!isString(key) ||
291+
// #1091 avoid internal isRef/isVNode checks on component instance leading
292+
// to infinite warning loop
293+
key.indexOf('__v') !== 0)
292294
) {
293295
if (data !== EMPTY_OBJ && key[0] === '$' && hasOwn(data, key)) {
294296
warn(

0 commit comments

Comments
 (0)