False arguments serialized as strings
See original GitHub issueSuppose use-case for conditional applying classes:
import { render } from "preact";
import { html } from "htm/preact";
let el = document.createElement("div");
render(
html`
<div class="${false} ${null} ${undefined} ${"foo"}" />
`,
el
);
console.log(el.innerHTML);
// <div class="false null undefined foo"></div>
That’s unexpected that the htm serializes false/null class values literally. That can be worked around with clsx or alike, but.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
boolean serializing to string error - Stack Overflow
when you write JsonDeserializer<String> , probably you say that it is going to be your class which deserializes String -s from JSON.
Read more >Parameter Serialization - Swagger
explode (true/false) specifies whether arrays and objects should generate separate parameters for each array item or object property. OpenAPI serialization ...
Read more >All serialized values are strings, should be integers/booleans ...
Problem/Motivation JSON produced by the HAL and JSON normalizers provides all data values as strings. This makes it difficult for strongly ...
Read more >JSON.stringify() - JavaScript - MDN Web Docs
The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or ...
Read more >Fields — marshmallow 3.19.0 documentation
A double as an IEEE-754 double precision string. Function ([serialize, deserialize]) ... falsy – Values that will (de)serialize to False .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is not addressable, since the behaviour described would be specific to a given attribute. For example, htm explicitly cannot treat falsy (combined or otherwise) values within some attributes as empty:
While I can see the convenience of special-casing DOMTokenList values in HTM, it’s not feasible to implement a scalable solution for doing so.
In terms of my own preference or recommendation, it seems like this would be nicer to address at the pragma layer. Personally I’d just co-opt
classList
for the purpose:The problem is not false/null values, but string attributes - htm does rendering part here, meaningless for classes and possibly all string attributes in general: