From 77b4e08e124ea02a9599bdb6a083ae56e25eeac1 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Tue, 19 Dec 2017 11:06:55 +0800 Subject: [PATCH 1/3] feat(warning): allow symbol as vdom key fix #7157 --- 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 b5296db3c9d..00c67a5b108 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 fe1c025e494..a0bc957ee93 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 3bec065f312..f2fddcf6d14 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 }, From b61340d34e9e2e3234ba208d91e48af1f76f2fbc Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Dec 2017 09:32:40 -0500 Subject: [PATCH 2/3] Update util.js --- src/shared/util.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/shared/util.js b/src/shared/util.js index a0bc957ee93..545e74fa1bb 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -24,12 +24,13 @@ export function isFalse (v: any): boolean %checks { * Check if value is primitive */ export function isPrimitive (value: any): boolean %checks { + const type = typeof value return ( - typeof value === 'string' || - typeof value === 'number' || + type === 'string' || + type === 'number' || // $flow-disable-line - typeof value === 'symbol' || - typeof value === 'boolean' + type === 'symbol' || + type === 'boolean' ) } From edeba186ecc005b8394c8aad26323f0620bff0e0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 19 Dec 2017 09:35:25 -0500 Subject: [PATCH 3/3] Update util.js --- src/shared/util.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/shared/util.js b/src/shared/util.js index 545e74fa1bb..a0bc957ee93 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -24,13 +24,12 @@ export function isFalse (v: any): boolean %checks { * Check if value is primitive */ export function isPrimitive (value: any): boolean %checks { - const type = typeof value return ( - type === 'string' || - type === 'number' || + typeof value === 'string' || + typeof value === 'number' || // $flow-disable-line - type === 'symbol' || - type === 'boolean' + typeof value === 'symbol' || + typeof value === 'boolean' ) }