Skip to content

Automatic serialization of object attribute values in Snabbdom attrs

Latest
Compare
Choose a tag to compare
@tdumitrescu tdumitrescu released this 15 Apr 22:44
· 30 commits to master since this release

When using Snabbdom attrs to set HTML element attributes, values which are objects are now automatically serialized to JSON. Previously, since HTML attributes are always strings, trying to set a raw object value with setAttribute() resulted in the attribute value [object Object].

For example, in

div(attrs={foo: {hello: 'world'}})

the foo attr will end up in HTML as JSON: "{"hello":"world"}".

This behavior can be controlled with the serializeAttrsObjects option, which defaults to true when using Snabbdom.