-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Silently fails with HTML comments #79
Comments
I think @jviide has been toying with this. Since comments aren't supported in JSX, we didn't feel the need to support them in HTM. Not sure if this is old news, but you can use standard JSX style comments in HTM: const Page = ({ name }) => {
return html`
<div class="page">
${/* a standard JS comment */}
<h1>${name}</h1>
<p>This page is all about ${name}.</p>
</div>
`;
}; The benefit of doing so is that they'll be stripped from your JS bundle when you do a production build, and they have no cost at runtime (they evaluate to |
This has gotten me in the past too; took a while to track down the first time it happened! Note that @developit's "standard JSX" workaround might be okay when compiled somehow, but in direct JS usage an empty block like |
@developit If i do a JSX style comment I get I think it would be nice to support |
Parsing HTML comments seems the cleanest solution to me as well, assuming it can be done without too much extra code. With JSX (and the earlier E4X ;-) the philosophy is to handle the syntax needs in "code", whereas with |
Opened PR #84 that suggests one way to support comments. |
PR #84 has now been merged and released as a part of HTM 2.2 🎉 |
Hi there,
Neat library! I really like developing components but don't like shipping large bundle files to the browser. For simple apps, it would be nice to do server-side components that get rendered as strings.
I've been playing around with htm recently (inspired by @timarney's htm-ssr-demo), and got a pretty minimal proof-of-concept up and running. (Most of the code is from a
preact-render-to-string
example.)package.json
index.js
So that works well enough to prove the concept.
However, if I change
Page
to this:then I just get a white page, and if I open devtools, I see
<undefined></undefined>
in the markup.There's no warning message or anything, so I'm wondering
Any help or suggestions would be appreciated! I'd like to build a little prototype using htm, but if it fails silently on syntax issues then it probably won't scale very well once you started nesting components inside each other.
The text was updated successfully, but these errors were encountered: