markfinger / python-react

Server-side rendering of React components
MIT License
1.62k stars 116 forks source link

What happens if RENDER is False in production? #83

Closed aguynamedben closed 6 years ago

aguynamedben commented 6 years ago

Hi, thanks for the time you spend working on this great library. It's making integrating React into my project really easy. I like the way the docs and examples provide a method for sharing state between my views and my React components. In fact, I'm using it more for code organization and a good pattern for passing between views and React components than I am for server-side rendering.

That leads me to this question... in order to kick the tires and build faith with my dev team before requiring that a separate process being managed by my ops team, I want to put this into production without (yet) running a separate render process. What exactly happens if I have RENDER set to False in production?

Based on https://github.com/markfinger/python-react/blob/master/react/render_server.py#L15 and the behavior I'm observing, it seems that server-side rendering simply doesn't happen, and on the client side when the React component mount everything still "just works" with client-side rending only.

I'm following the frontend-rending-with-webpack example, so this code seems to load the React component in a working state:

    ReactDOM.unmountComponentAtNode(domContainerNode);
    ReactDOM.render(React.createFactory(component)(props), domContainerNode);

Is it dangerous to have RENDER set to False in production, even if I'm okay with not having server-side rendering yet? I.e. does having RENDER set to False in production use an inordinate amount of resources? Or does React break in some way? Or are there other problems? It seems like everything is fine and that server-side rendering is simply no-op and client-side rendering picks up on the blank element.

markfinger commented 6 years ago

No, it shouldn't be a problem at all.

As you indicated, with RENDER = False the system will mimic much of the wiring and data (serialized props that you can render in a template, etc), but wont actually perform any rendering.

The RENDER flag was intended for situations where running a Node process is unnecessary (tests, back-end dev work, etc) so it sounds quite suitable for your use case.

aguynamedben commented 6 years ago

Great, thanks for confirming. This helps me organize my code in a sane, known way, then later I can just flip on RENDER to add server-side rendering. Thanks again for this great library.