-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hydration breaks the HTML (class) #11336
Comments
This is not a correct understanding. With React 16 it is not supported to render different things on secret and the client for performance reasons. You need to fix the cases where markup differs. React 16 does patch up in some cases (such as text content) but it will not attempt to patch up attributes. Text content is an exception here because it is often different from the server due to, for example, timestamps. See reactjs/react.dev#25 and #10591 for more information about this. |
Note that if you're okay with an extra re-render and really need to render something different on the client, you can use this approach: #8017 (comment). Render what's on the server first and then |
Thanks 🍻 the new behaviour of React 16 makes sense! I was confused by the documentation:
I guess it'll be fixed by reactjs/react.dev#25 :) Maybe the warning in the console can be improved, currently it logs something like I'll find a solution to stop using |
We'll track better docs in reactjs/react.dev#25 and better warnings in #10085. |
@gaearon same problem. Maybe there is an opportunity to say to the react that it rerender this block? Otherwise we will have to roll back to 15 react |
As it says in the documentation:
Hope this helps. |
This is required by ReactDOM.hydrate, see facebook/react#11336 (comment) for details.
We've updated an application to React 16, this app is using
react-responsive
.Since we've updated to React 16, we have bugs related to invalid HTML being outputted by React hydration.
Our server generates an HTML for the desktop, but if the client has a mobile, the rendering mismatch. Previously it was causing a full re-render by
ReactDOM.render
, it was not perfect, but it worked.With React 16,
ReactDOM.hydrate
is supposed to not-rerender everything but only the mismatching parts. But after we runReactDOM.hydrate
, the HTML is an invalid mix of both (class
are sliced).1) HTML generated by the server (desktop mode)
This is the HTML being served by the server (before hydration):
2) HTML generated by the client without SSR (normal mobile mode)
This is the HTML being rendered by React, when we disable SSR:
3) Wrong HTML generated by hydration of 1) in client (mobile mode)
This is the invalid HTML being rendered by React when it tries to hydrate 1) with 2). The expected HTML is 2).
Versions
Chrome 61.0.3163.100
React v16.0.0
The text was updated successfully, but these errors were encountered: