preactjs/preact-render-to-string

Empty class attribute duplicated with preact/compat and SSR

siancatalyst opened this issue · 1 comments

Describe the bug
When an element is created in preact/compat with className="", rendering it to a string causes two class attributes to be output.

This can happen when using conditional classes returned from the npm classnames function, for example.

To Reproduce

const { createElement } = require("preact/compat");
const render = require("preact-render-to-string");
console.log(render(createElement("a", { className: "" })));

Tested with preact v10.6.4 and preact-render-to-string v5.1.19

Observed behavior
<a class class></a>

Expected behavior
<a class></a> or <a class=""></a>

Thanks for the issue, found the offending bit of code:

} else if (name === 'className') {
if (props.class) continue;
name = 'class';

Will get a PR together here