anthonyshort / deku

Render interfaces using pure functions and virtual DOM
https://github.com/anthonyshort/deku/tree/master/docs
3.42k stars 131 forks source link

null nodes don't work anymore v2.0.0-rc5 #320

Closed rstacruz closed 8 years ago

rstacruz commented 8 years ago

Here's a simple component that uses the ternary operator to show something conditionally.

module.exports = { render }

function render ({ props }) {
  return <div>
    { props.featured ? <span>Featured</span> : null }
  </div>
}

This now results in:

Uncaught TypeError: Cannot read property 'parentNode' of undefined

The workaround is to use an empty array instead:

  return <div>
    { props.featured ? <span>Featured</span> : [] }
  </div>
anthonyshort commented 8 years ago

I tried to fix this up this morning, but I think it's going to take a little more work. For now, just replacing it with something like a <noscript/> should work. null should render as <noscript/> tags when I get it working correctly.

rstacruz commented 8 years ago

oh.. so thats what those noscript tags are for

rstacruz commented 8 years ago

couldn't nulls be handled in the same way as []? empty arrays are common:

items = [] // has nothing
<ul>
  { items.map((item) => <li>{ item }</li>) }
</ul>

(or do those turn out to be noscript's too?)

anthonyshort commented 8 years ago

Fixed in https://github.com/dekujs/deku/commit/9b9a26e094c97f91bd86559a2d9c127dfaaff1c8