Skip to content

Commit

Permalink
fix(runtime-core): should allow empty string and 0 as valid vnode key (
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangying000 authored Mar 9, 2020
1 parent b13886b commit 54a0e93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/runtime-core/__tests__/vnode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 54a0e93

Please sign in to comment.