Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn against non-primitive key #5816

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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