Skip to content

Commit

Permalink
fix(runtime-core): handle initial undefined attrs (#5017)
Browse files Browse the repository at this point in the history
fix #5016
  • Loading branch information
edison1105 committed Dec 6, 2021
1 parent 34985fe commit 6d887aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/runtime-core/__tests__/componentProps.spec.ts
Expand Up @@ -573,4 +573,26 @@ describe('component props', () => {
render(h(Comp, { foo: null }), root)
}).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)
)
})
})
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentProps.ts
Expand Up @@ -369,7 +369,7 @@ function setFullProps(
continue
}
}
if (value !== attrs[key]) {
if (!(key in attrs) || value !== attrs[key]) {
attrs[key] = value
hasAttrsChanged = true
}
Expand Down

0 comments on commit 6d887aa

Please sign in to comment.