S
SolidJS•11mo ago
mb21

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
Alex Lohr
Alex Lohr•11mo ago
You can use <NoHydration> to mark code blocks that should not be hydrated and thus need no markers.
mb21
mb21OP•11mo ago
Nice, thanks! That got rit of the data-attributes. The html comments are still there though 🤔
Alex Lohr
Alex Lohr•11mo ago
Yes, those are used by insertion, not by hydration. It should be trivial to hook up an HTML minifier that removes the comments, though.
mb21
mb21OP•11mo ago
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...
Alex Lohr
Alex Lohr•11mo ago
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.
ryansolid
ryansolid•11mo ago
You can turn off hydration in the babel plugin and they will be all gone hydratable: false
Want results from more Discord servers?
Add your server