Warning: React attempted to reuse markup in a container but the checksum was invalid
Note: This applies to older versions of React. If you're using React 16, you should use ReactDOM.hydrate()
Also, the below suggestion will result in a client-side re-render, as suggested by one of the answers below.
This may sound crazily simple, but in your server-side template, wrap your React markup in an extra <div>
:
<!-- hypothetical handlebars template --><section role="main" class="react-container"><div>{{{reactMarkup}}}</div></section>
Why does this work? On the client, React has a propensity to wrap its rendering of your root component with a superfluous div. ReactDOMServer.render
doesn't seem to behave in this manner, thus when one renders into the same container isomorphically, the Adler-32 checksum of your DOM differs.
For those googling and coming here, one weird way of ending up with this issue is where you're not even using isomorphic rendering (i.e. not rendering anything on the server side). This happened with me when using a template with the HtmlWebpackPlugin
to process an index.html
file.
In my index.html
file I already included the bundle.js
file myself, and the above plugin also includes another bundle.js
via a script-src. Make sure you're setting inject: false
to your HtmlWebpackPlugin
constructor.
For me killing nodejs completely and restarting worked