From bacb911f7df09ff4868b4c848a6d7778872dff5c Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Tue, 19 Dec 2017 22:35:50 +0800 Subject: [PATCH] fix(warning): allow symbol as vdom key (#7271) --- src/core/vdom/patch.js | 2 +- src/shared/util.js | 2 ++ test/unit/modules/vdom/create-element.spec.js | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index b5296db3c..00c67a5b1 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -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))) } } diff --git a/src/shared/util.js b/src/shared/util.js index fe1c025e4..a0bc957ee 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -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' ) } diff --git a/test/unit/modules/vdom/create-element.spec.js b/test/unit/modules/vdom/create-element.spec.js index 3bec065f3..f2fddcf6d 100644 --- a/test/unit/modules/vdom/create-element.spec.js +++ b/test/unit/modules/vdom/create-element.spec.js @@ -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 },