Skip to content

Commit 54a0e93

Browse files
authored
fix(runtime-core): should allow empty string and 0 as valid vnode key (#807)
1 parent b13886b commit 54a0e93

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/runtime-core/__tests__/vnode.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ describe('vnode', () => {
3838
expect(vnode.props).toBe(null)
3939
})
4040

41+
test('valid vnode keys', () => {
42+
let vnode
43+
for (const key in ['', '1', -1, 0, 1, null]) {
44+
vnode = createVNode('div', { key })
45+
expect(vnode.key).toBe(key)
46+
}
47+
})
48+
4149
describe('class normalization', () => {
4250
test('string', () => {
4351
const vnode = createVNode('p', { class: 'foo baz' })

packages/runtime-core/src/vnode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export function createVNode(
251251
_isVNode: true,
252252
type,
253253
props,
254-
key: (props !== null && props.key) || null,
254+
key: props !== null && props.key !== undefined ? props.key : null,
255255
ref: (props !== null && props.ref) || null,
256256
scopeId: currentScopeId,
257257
children: null,

0 commit comments

Comments
 (0)