FormidableLabs / component-playground

A component for rendering React components with editable source and live preview
MIT License
1.19k stars 117 forks source link

Potentially unnecessary usage of ReactDOMServer #90

Closed kitten closed 7 years ago

kitten commented 7 years ago

I noticed that in the Preview the generated component is being rendered to a string, but the result is never actually used. I'm wondering if this is this on purpose, since ReactDOM/Server further contributes to the bundle size?

https://github.com/FormidableLabs/component-playground/blob/master/src/components/preview.jsx#L81

        ReactDOMServer.renderToString(React.createElement(previewComponent, {}, Comp));
        render(
          React.createElement(previewComponent, {}, Comp),
          mountNode
        );
kitten commented 7 years ago

I dug through the commit history and actually found the commit that was adding this 😄

https://github.com/FormidableLabs/component-playground/commit/2eaedb4

I actually managed to get this to work by wrapping the element differently, in some separate code I'm experimenting with, so I'd imagine that this should be solvable without ReactDOMServer:

https://github.com/philpl/rxjs-guide/blob/master/utils/transpile.js#L16

kenwheeler commented 7 years ago

Well, this is late, but the reason I use render to string is to catch runtime render errors. I can probably use boundaries now though.