preact-render-to-string icon indicating copy to clipboard operation
preact-render-to-string copied to clipboard

`preact/debug` warnings not thrown because `vnode.__k` is not set

Open marvinhagemeister opened this issue 2 years ago • 0 comments

In preact/debug we have a branch for detecting invalid children being passed to a vnode:

vnode._children.forEach(child => {
  if (typeof child === 'object' && child && child.type === undefined) {
    const keys = Object.keys(child).join(',');
    throw new Error(
      `Objects are not valid as a child. Encountered an object with the keys {${keys}}.` +
      `\n\n${getOwnerStack(vnode)}`
    );
  }
});

But we never set that property when rendering on the server, so this check is never called.

Steps to reproduce

import "preact/debug";
import { renderToString } from "preact-render-to-string";

// This should throw
renderToString(<div>{{ foo: 123 }}</div>)

marvinhagemeister avatar Oct 07 '23 11:10 marvinhagemeister