diff --git a/.changeset/metal-bottles-play.md b/.changeset/metal-bottles-play.md new file mode 100644 index 00000000..f44ccd5e --- /dev/null +++ b/.changeset/metal-bottles-play.md @@ -0,0 +1,5 @@ +--- +'preact-render-to-string': patch +--- + +Allow any value for `class` + `className` as long as it's stringified to match browser behavior. diff --git a/src/index.js b/src/index.js index 5362a9ce..19771717 100644 --- a/src/index.js +++ b/src/index.js @@ -543,7 +543,9 @@ function _renderToString( for (let name in props) { let v = props[name]; - if (typeof v == 'function') continue; + if (typeof v == 'function' && name !== 'class' && name !== 'className') { + continue; + } switch (name) { case 'children': diff --git a/test/render.test.jsx b/test/render.test.jsx index 39521cc3..ba8e0289 100644 --- a/test/render.test.jsx +++ b/test/render.test.jsx @@ -1678,6 +1678,18 @@ describe('render', () => { } } }); + + // https://github.com/preactjs/preact-render-to-string/issues/390 + // The DOM API casts any value to a string here. + it('should cast "className" and "class" value to string', () => { + const proxy = new Proxy(() => {}, { + get() { + return () => 'foo'; + } + }); + let rendered = render(
); + expect(rendered).to.equal(`
`); + }); }); describe('precompiled JSX', () => {