]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): should allow empty string and 0 as valid vnode key (#807)
authordjy0 <krivergo3@gmail.com>
Mon, 9 Mar 2020 20:03:57 +0000 (04:03 +0800)
committerGitHub <noreply@github.com>
Mon, 9 Mar 2020 20:03:57 +0000 (16:03 -0400)
packages/runtime-core/__tests__/vnode.spec.ts
packages/runtime-core/src/vnode.ts

index 1a500ac7c8ec6eed67b13b1f5adf498191f3b81f..8895938182ffe64b7c861f0ddd544e0fb5c3192a 100644 (file)
@@ -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' })
index 568052a4b073397f4a7c205623f395140e94b33d..46089491191b9f330d79ed095f76e2cb4d3572c1 100644 (file)
@@ -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,