fix(warning): allow symbol as vdom key (#7271)

This commit is contained in:
Herrington Darkholme 2017-12-19 22:35:50 +08:00 committed by Evan You
parent c0d516c283
commit bacb911f7d
3 changed files with 12 additions and 1 deletions

View File

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

View File

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

View File

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