Empty string instead of space for falsy elements
guregu opened this issue ยท 3 comments
Hello, thanks for this library! I'm enjoying using it to make a little worker.
I noticed that falsy values become a space instead of an empty string.
This can produce unexpected results when using variables in HTML attributes, for example:
let foo: string | null = request.searchParams.get("foo");
return html`<input type="text" value="${foo}" placeholder="hello world">`;
This gets rendered as:
<input type="text" value=" " placeholder="hello world">
which hides the placeholder and makes 1-1 correlation with <form method=GET>
difficult.
Desired result:
<input type="text" value="" placeholder="hello world">
I was wondering if I am doing something wrong. It seems like there isn't a way to embed an empty string at the moment.
Apologizes if I missed something!
Ah yes, the space was a fix for odd behavior of streams in older versions of cloudflare workers. I'll investigate if this is still necessary.
There appears to be no issue with the latest version of cloudflare workers, so I'll fix this behavior now. Note that this only applies to the latest preview version v2.0.0-pre.12.
Thanks a bunch! I was able to remove some hacks in my project and it works perfectly now. Much appreciated!