Skip to content

Commit

Permalink
fix(warning): allow symbol as vdom key (#7271)
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme authored and yyx990803 committed Dec 19, 2017
1 parent c0d516c commit bacb911
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/vdom/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export function createPatchFunction (backend) {
createElm(children[i], insertedVnodeQueue, vnode.elm, null, true)
}
} else if (isPrimitive(vnode.text)) {
nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(vnode.text))
nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(String(vnode.text)))
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function isPrimitive (value: any): boolean %checks {
return (
typeof value === 'string' ||
typeof value === 'number' ||
// $flow-disable-line
typeof value === 'symbol' ||
typeof value === 'boolean'
)
}
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 @@ -215,6 +215,15 @@ describe('create-element', () => {
expect('Avoid using non-primitive value as key').not.toHaveBeenWarned()
})

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

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

0 comments on commit bacb911

Please sign in to comment.