Skip to content

Commit

Permalink
warn against non-primitive key (#5816)
Browse files Browse the repository at this point in the history
  • Loading branch information
coolzjy authored and yyx990803 committed Jun 6, 2017
1 parent 68522cf commit 7561b94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/vdom/create-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ export function _createElement (
// in case of component :is set to falsy value
return createEmptyVNode()
}
// warn against non-primitive key
if (process.env.NODE_ENV !== 'production' &&
isDef(data) && isDef(data.key) && !isPrimitive(data.key)
) {
warn(
'Avoid using non-primitive value as key, ' +
'use string/number value instead.',
context
)
}
// support single function children as default scoped slot
if (Array.isArray(children) &&
typeof children[0] === 'function'
Expand Down
9 changes: 9 additions & 0 deletions test/unit/modules/vdom/create-element.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ describe('create-element', () => {
expect('Avoid using observed data object as vnode data').toHaveBeenWarned()
})

it('warn non-primitive key', () => {
new Vue({
render (h) {
return h('div', { key: {}})
}
}).$mount()
expect('Avoid using non-primitive value as key').toHaveBeenWarned()
})

it('nested child elements should be updated correctly', done => {
const vm = new Vue({
data: { n: 1 },
Expand Down

0 comments on commit 7561b94

Please sign in to comment.