Skip to content

Commit

Permalink
fix(runtime-core): check if the key is string on undefined property w…
Browse files Browse the repository at this point in the history
…arning (#1731)
  • Loading branch information
pikax authored Jul 29, 2020
1 parent 848d9ce commit ce78eac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
20 changes: 20 additions & 0 deletions packages/runtime-core/__tests__/componentProxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,24 @@ describe('component: proxy', () => {
`was accessed during render but is not defined`
).not.toHaveBeenWarned()
})

test('should allow symbol to access on render', () => {
const Comp = {
render() {
if ((this as any)[Symbol.unscopables]) {
return '1'
}
return '2'
}
}

const app = createApp(Comp)
app.mount(nodeOps.createElement('div'))

expect(
`Property ${JSON.stringify(
Symbol.unscopables
)} was accessed during render ` + `but is not defined on instance.`
).toHaveBeenWarned()
})
})
10 changes: 6 additions & 4 deletions packages/runtime-core/src/componentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
hasOwn,
isGloballyWhitelisted,
NOOP,
extend
extend,
isString
} from '@vue/shared'
import {
ReactiveEffect,
Expand Down Expand Up @@ -286,9 +287,10 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
} else if (
__DEV__ &&
currentRenderingInstance &&
// #1091 avoid internal isRef/isVNode checks on component instance leading
// to infinite warning loop
key.indexOf('__v') !== 0
(!isString(key) ||
// #1091 avoid internal isRef/isVNode checks on component instance leading
// to infinite warning loop
key.indexOf('__v') !== 0)
) {
if (data !== EMPTY_OBJ && key[0] === '$' && hasOwn(data, key)) {
warn(
Expand Down

0 comments on commit ce78eac

Please sign in to comment.