fix(runtime-core): handle initial undefined attrs (#5017)

fix #5016
This commit is contained in:
edison 2021-12-06 13:58:45 +08:00 committed by GitHub
parent 34985fee6b
commit 6d887aaf59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -573,4 +573,26 @@ describe('component props', () => {
render(h(Comp, { foo: null }), root) render(h(Comp, { foo: null }), root)
}).not.toThrow() }).not.toThrow()
}) })
// #5016
test('handling attr with undefined value', () => {
const Comp = {
render(this: any) {
return JSON.stringify(this.$attrs) + Object.keys(this.$attrs)
}
}
const root = nodeOps.createElement('div')
let attrs: any = { foo: undefined }
render(h(Comp, attrs), root)
expect(serializeInner(root)).toBe(
JSON.stringify(attrs) + Object.keys(attrs)
)
render(h(Comp, (attrs = { foo: 'bar' })), root)
expect(serializeInner(root)).toBe(
JSON.stringify(attrs) + Object.keys(attrs)
)
})
}) })

View File

@ -369,7 +369,7 @@ function setFullProps(
continue continue
} }
} }
if (value !== attrs[key]) { if (!(key in attrs) || value !== attrs[key]) {
attrs[key] = value attrs[key] = value
hasAttrsChanged = true hasAttrsChanged = true
} }