Material-ui: next.js example breaks SSR for styled-jsx

Created on 15 Jun 2019  路  1Comment  路  Source: mui-org/material-ui

here's the reproduction: https://codesandbox.io/s/nextjs-inufq

you can see when loading the index page, the red background color flashes into the screen after loading

bug 馃悰 docs good first issue

Most helpful comment

@lifeiscontent Thank you for reporting the problem. The fix is as simple as:

diff --git a/examples/nextjs/pages/_document.js b/examples/nextjs/pages/_document.js
index 9f17317e6..80f4aa91b 100644
--- a/examples/nextjs/pages/_document.js
+++ b/examples/nextjs/pages/_document.js
@@ -70,8 +70,8 @@ MyDocument.getInitialProps = async ctx => {
     // Styles fragment is rendered after the app and page rendering finish.
     styles: (
       <React.Fragment>
+        {initialProps.styles}
         {sheets.getStyleElement()}
-        {flush() || null}
       </React.Fragment>
     ),
   };

Do you want to submit a pull request to update the examples? :)

>All comments

@lifeiscontent Thank you for reporting the problem. The fix is as simple as:

diff --git a/examples/nextjs/pages/_document.js b/examples/nextjs/pages/_document.js
index 9f17317e6..80f4aa91b 100644
--- a/examples/nextjs/pages/_document.js
+++ b/examples/nextjs/pages/_document.js
@@ -70,8 +70,8 @@ MyDocument.getInitialProps = async ctx => {
     // Styles fragment is rendered after the app and page rendering finish.
     styles: (
       <React.Fragment>
+        {initialProps.styles}
         {sheets.getStyleElement()}
-        {flush() || null}
       </React.Fragment>
     ),
   };

Do you want to submit a pull request to update the examples? :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reflog picture reflog  路  3Comments

pola88 picture pola88  路  3Comments

ryanflorence picture ryanflorence  路  3Comments

revskill10 picture revskill10  路  3Comments

chris-hinds picture chris-hinds  路  3Comments