From: djy0 Date: Mon, 9 Mar 2020 20:03:57 +0000 (+0800) Subject: fix(runtime-core): should allow empty string and 0 as valid vnode key (#807) X-Git-Tag: v3.0.0-alpha.9~49 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=54a0e93c276f95a35b3bd6510a7f52d967fd3b7f;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-core): should allow empty string and 0 as valid vnode key (#807) --- diff --git a/packages/runtime-core/__tests__/vnode.spec.ts b/packages/runtime-core/__tests__/vnode.spec.ts index 1a500ac7c8..8895938182 100644 --- a/packages/runtime-core/__tests__/vnode.spec.ts +++ b/packages/runtime-core/__tests__/vnode.spec.ts @@ -38,6 +38,14 @@ describe('vnode', () => { expect(vnode.props).toBe(null) }) + test('valid vnode keys', () => { + let vnode + for (const key in ['', '1', -1, 0, 1, null]) { + vnode = createVNode('div', { key }) + expect(vnode.key).toBe(key) + } + }) + describe('class normalization', () => { test('string', () => { const vnode = createVNode('p', { class: 'foo baz' }) diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 568052a4b0..4608949119 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -251,7 +251,7 @@ export function createVNode( _isVNode: true, type, props, - key: (props !== null && props.key) || null, + key: props !== null && props.key !== undefined ? props.key : null, ref: (props !== null && props.ref) || null, scopeId: currentScopeId, children: null,