rapscallion icon indicating copy to clipboard operation
rapscallion copied to clipboard

Boolean attributes are not rendered

Open mijamo opened this issue 7 years ago • 3 comments

Consider this React component:

<video autoPlay />

The expected output when rendering is:

<video autoplay="" />

But Rapscallion actually returns

<video />

Note that the autoplay attribute is gone.

After quickly looking at the code, it seems like https://github.com/FormidableLabs/rapscallion/blob/master/src/render/attrs/index.js#L31 is responsible. If the value is true Object.keys(attrVal).length is indeed 0 but it is still a perfectly valid attribute. Checking if (attrVal === true) afterwards if then useless as it would have called continue previously, and the value is never inserted.

This is also illustrated by the failing test for attributes in the pull request #58 . If you look at the CI result here you will see many tests prop with no value failing for that reason. I am not quite sure of the purpose of the Object.keys(attrVal).length check so I did not submit a pull request because I am unsure of the best way to fix it, but it should be an easy fix in any case.

mijamo avatar Apr 20 '17 10:04 mijamo

Hey @mijamo, could you update your ticket with the expected/actual output? Thanks!

divmain avatar Apr 20 '17 17:04 divmain

Sorry, they were actually in my issue but a wrong formatting made them invisible. Updated now.

mijamo avatar Apr 20 '17 17:04 mijamo

This should be fixed by #85

mijamo avatar May 22 '17 10:05 mijamo