Skip to content

Commit 6d887aa

Browse files
authored
fix(runtime-core): handle initial undefined attrs (#5017)
fix #5016
1 parent 34985fe commit 6d887aa

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

+22
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,26 @@ describe('component props', () => {
573573
render(h(Comp, { foo: null }), root)
574574
}).not.toThrow()
575575
})
576+
577+
// #5016
578+
test('handling attr with undefined value', () => {
579+
const Comp = {
580+
render(this: any) {
581+
return JSON.stringify(this.$attrs) + Object.keys(this.$attrs)
582+
}
583+
}
584+
const root = nodeOps.createElement('div')
585+
586+
let attrs: any = { foo: undefined }
587+
588+
render(h(Comp, attrs), root)
589+
expect(serializeInner(root)).toBe(
590+
JSON.stringify(attrs) + Object.keys(attrs)
591+
)
592+
593+
render(h(Comp, (attrs = { foo: 'bar' })), root)
594+
expect(serializeInner(root)).toBe(
595+
JSON.stringify(attrs) + Object.keys(attrs)
596+
)
597+
})
576598
})

packages/runtime-core/src/componentProps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ function setFullProps(
369369
continue
370370
}
371371
}
372-
if (value !== attrs[key]) {
372+
if (!(key in attrs) || value !== attrs[key]) {
373373
attrs[key] = value
374374
hasAttrsChanged = true
375375
}

0 commit comments

Comments
 (0)