i-like-robots / hyperons

🔥 The fastest JSX to string renderer on the server and in the browser.
https://www.npmjs.com/package/hyperons
MIT License
45 stars 4 forks source link

Apply undefined/null property logic to className #32

Closed rowanmanning closed 5 years ago

rowanmanning commented 5 years ago

Currently because class and className are handled differently to other attributes, they are rendering undefined and null as strings rather than ignoring the attributes entirely.

I've reduced my code down to bare-bones to demonstrate. Didn't want to actually commit, but running this in the repo:

const {h, render} = require('.');
const el = h('div', {className: undefined});
console.log(render(el));

results in:

<div class="undefined"></div>

I don't know whether my solution is ideal. Or whether this is even considered a bug, I'm new to all this fancy stuff 🤷‍♂️

Let me know if you'd like anything changed.

i-like-robots commented 5 years ago

Thanks for this @rowanmanning, it's definitely not the correct behaviour to render undefined or null for any attribute. Your solution does the trick and pulls it into line with that.

I need to add a comment to this code as the most straightforward solution is probably to remove this condition entirely but because it's the most common case that would slow everything down!

i-like-robots commented 5 years ago

Published as 1.0.0-beta.2