React Server Rendering
See also Client vs. Server Rendering
What is Server Rendering?
Here's a decent article to introduce you to server rendering. Note, React on Rails takes care of calling the methods in ReactDOMServer.
See this note
How do you do Server Rendering with React on Rails?
react_componentview helper method provides the
prerender:option to switch on or off server rendering.
- Configure your Webpack setup to create a different server bundle per your needs. While you may reuse the same bundle as for client rendering, this is not common in larger apps for many reasons, such as as code splitting, handling CSS and images, different code paths for React Router on the server vs. client, etc.
- You need to configure
config.server_bundle_js_file = "my-server-bundle.js"in your
Do you need server rendering?
Server rendering is used for either SEO or performance reasons.
Considerations for what code can run on in server rendering
- Never access
clearIntervalsimilarly don't make sense when server rendering.
- Promises don't work when server rendering. Anything to be done in a promise will never complete. This includes concepts such as asynchronous code loading and AJAX calls. If you want to do server rendering with asynchronous calls, get in touch as we're working on a Node renderer that handles asynchronous calls.