developit / htm

Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Apache License 2.0
8.73k stars 170 forks source link

Zero is translated as empty string when htm is bound to vhtml #241

Closed aral closed 1 year ago

aral commented 1 year ago

htm bound to vhtml translates a numeric zero value as an empty string.

To reproduce

import htm from 'htm'
import vhtml from 'vhtml'

const html = htm.bind(vhtml)

let count = 0
console.info(html`<h1>The count is →${count}←</h1>`)

count++
console.info(html`<h1>The count is →${count}←</h1>`)

Expected result

<h1>The count is →0←</h1>
<h1>The count is →1←</h1>

Actual result

<h1>The count is →←</h1>
<h1>The count is →1←</h1>

The (yucky) workaround

html`<h1>The count is →${count.toString()}←</h1>`

(I’m not sure if its htm or vhtml to blame here as I haven’t had a chance to dig into it; just strumbled on this while trying to reproduce a different issue.)

aral commented 1 year ago

This seems to be a problem with vhtml, not htm.

PR: https://github.com/developit/vhtml/compare/master...aral:vhtml:patch-1