Include react renderToString ouput in static html
See original GitHub issueCurrently CRA renders SPA formatted apps, with an empty div in the html which gets populated when react boots on the client. For performance (and accessibility) reasons it would be a better default if we could serve useful html. While there would be apps who would do everything in lifecycle methods and hence have no benefit of the statically rendered app markup, I believe most apps would benefit from it.
We could do this by using react-dom/server.renderToString
, calling it with the main App.js
component, then inlining the result in the html during the build.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top Results From Across the Web
ReactDOMServer – React
The ReactDOMServer object enables you to render components to static markup. ... Returns a Node.js Readable stream that outputs an HTML string.
Read more >Creating a static website with ReactJS and ... - Codemzy's Blog
If you already know ReactJS, you can use it to create your static HTML content. It's quick and easy, and you won't even...
Read more >Static site generation with React from scratch - LogRocket Blog
At its core, we use the renderToString function from react-dom/server instead of render from react-dom . Assuming we have a page nested in...
Read more >how to import css file in react when generating static html and ...
I want to import css in my React components like css-modules (import styles from './style.css'). And then inject that loaded css into generated ......
Read more >How to Enable Server-Side Rendering for a React App
ReactDOMServer 's renderToString is used to render the app to a static HTML string. The static index.html file from the built client app...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the suggestion. This would be very hard to implement right, and we won’t try.
React enforces that if checksum between HTML on the server and HTML on the client doesn’t match, React throws away all the DOM and replaces it. Which can produce observable side effects like deleting user’s input when DOM is replaced.
This is why if you want this feature, you really want full server rendering. And we don’t try to support it in Create React App. So this is out of scope as far as I can see.
Hi all, I can highly recommend Razzle along with my Razzle Material UI Styled Example for those who need Server Side Rendering right now and the easy way.