Skip to content
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

SSR react hydrate mismatch problem #29

Open
izzappel opened this issue Apr 1, 2019 · 0 comments
Open

SSR react hydrate mismatch problem #29

izzappel opened this issue Apr 1, 2019 · 0 comments

Comments

@izzappel
Copy link

izzappel commented Apr 1, 2019

If using the currentBreakpoint for rendering different elements dependent on the breakpoint react cannot hydrate correctly if the guessedBreakpoint does not match with the client. (I use the user-agent from the request to guess the breakpoint on server side. Obviously this does not get always the correct breakpoint.)

Related react issues:

It would be nice if the library supports this case. I think it should not calculate the currentBreakpoint dependent on the window width in the constructor if there is a guessedBreakpoint. If there is a guessedBreakpoint the currentBreakpoint should be calculated from the window width in componentDidMount.

What do you think?

ValentinH pushed a commit to ValentinH/react-breakpoints that referenced this issue Feb 23, 2020
As explained in ehellman#29, when the breapoint is wrongly guessed on the server, there will be an HTML mismatch during `ReactDom.hydrate()`. When using a CSS-in-JSS technique, this can lead to a completely broken page due to wrong CSS classnames being used.

This PR simply solves this issue by letting the developer set the `guessedBreakpoint` on the client as well. Thanks to this, there will no mismatch during hydratation. Once the app is hydrated, it will be rerenderd using the real breakpoint (during `componentDidMount()` ).

There will be a "blinking" effect on load when switching between the guesss breakpoint and the real one (as with current version) but now, there is no mismatch so no risk of unfortunate side-effects anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant