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

Force render mismatches style between the server and client #126

Conversation

hdnha11
Copy link

@hdnha11 hdnha11 commented Dec 13, 2019

Gatsby renders the page without knowing the viewport of the device it displays towards.

We can detect and set defaultScreenClass config on the client-side (https://github.com/sealninja/react-ssr-example/blob/master/client.js), but React expects that the rendered content is identical between the server and the client. It can patch up differences in text content, but not object (https://reactjs.org/docs/react-dom.html#hydrate). Therefore the style mismatch between the server-side and client-side will not get re-render.

One possible solution that I have found is doing a two-pass rendering facebook/react#8017 (comment). Doing so will introduce a flashing effect when reloading the page. We can overcome this issue by introducing a small splash screen long enough to load the correct viewport (https://stackoverflow.com/questions/57188179/show-overlay-only-once-on-page-entrance-not-route-change-howto).

@hdnha11 hdnha11 force-pushed the fix-gatsby-default-screen-class-issue branch from 5de8643 to fe8ce0d Compare December 13, 2019 07:39
@gerbenmeyer
Copy link
Contributor

This is fixed now like proposed in this PR, but then by applying the two-pass-rendering in ScreenClassProvider.

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

Successfully merging this pull request may close these issues.

2 participants