renderToString without hydration markers?
Hello! Is there a way to use solid's renderToString such that it doesn't output the hydration markers (data-attributes and html comments)? Would be nice, then I could use the same JSX I already have in my project to send HTML emails.... Should I open up a feature request on GitHub?
6 Replies
You can use
<NoHydration>
to mark code blocks that should not be hydrated and thus need no markers.Nice, thanks! That got rit of the data-attributes. The html comments are still there though 🤔
Yes, those are used by insertion, not by hydration.
It should be trivial to hook up an HTML minifier that removes the comments, though.
right... or a regex 🙈 (as I don't want to add another npm dependency just for that)
but perhaps worth considering adding this behaviour to
renderToString
as an option?
Or why does <NoHydration
not remove the comments? I don't understand how you can do insertion without doing hydration...Parsing HTML with a regular expression is prone to errors.
The comments are there to divide JSX expressions. I.e. if you have
<time>{hour()}:{minute()}</time>
, then the comments divides the text into multiple nodes that can be updated separately.You can turn off hydration in the babel plugin and they will be all gone
hydratable: false