html_of_jsx
html_of_jsx copied to clipboard
Improve type-safety of string-based props
Many attributes are defined as string
when in reality (the HTML spec) doesn't allow any string and it defines an enum. There's the case of attributes defined also as a polymorphic typeint
or bool
as well or more strange
The benefit from moving away from string-based API are:
- Safety, within a string there could be a typo without noticing it.
- Learnability. Users might be able to learn about HTML and their APIs.
- Correctness, generate valid HTML isn't crazy important but it's nice to have a feedback on compile time, also have a positive impact on on-page SEO.
There have been a few efforts on rescript-react
to push that direction but didn't land yet (a few comments by @dodomorandi in https://github.com/rescript-lang/syntax/pull/235) and I'm not sure if there's a positive intent to do so.
We have the possibility to do it
Other references:
- https://github.com/rescript-lang/rescript-react/issues/10
- https://github.com/rescript-lang/rescript-react/pull/12/files
- https://github.com/rescript-lang/syntax/pull/235
The plan for this is to check TyXML and https://html.spec.whatwg.org/#global-attributes and manually ensure that most of our attributes make sense.
Doubts
- How to provide a way to override/discard the issue?
- How easy is to discover the attrs values?
- How we can expose
Ppx_static_attributes
on both the ppx and the runtime? (Maybe mergingJsx.Attributes
andPpx_static_attributes