Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include react renderToString ouput in static html

See original GitHub issue

Currently 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

gaearoncommented, Nov 20, 2016

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.

kireerikcommented, Jun 11, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found