Browse Source

warn against non-primitive key (#5816)

dev
Zhang Visper 8 years ago
committed by Evan You
parent
commit
7561b94eeb
  1. 10
      src/core/vdom/create-element.js
  2. 9
      test/unit/modules/vdom/create-element.spec.js

10
src/core/vdom/create-element.js

@ -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'

9
test/unit/modules/vdom/create-element.spec.js

@ -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 },

Loading…
Cancel
Save