question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nextjs SSR sometimes not rendering styles

See original GitHub issue
  • emotion 10.0.7:
  • react 16.8.0:

Relevant code: All the project styles are styled components.

export const Span = styled.span`
  color: white;
  background: black;
`;

What you did: Server-side rendered the project, including styles.

What happened: Eventually the SSR stops returning any styles, causing a whole-page FOUC.

Reproduction: This is a minimal reproduction of the codebase: https://codesandbox.io/s/5xx25mvv1p

Problem description: At first everything works fine. Style tags are rendered inline, as siblings, on the server and then moved to the head on client-side re-render. The problem is that eventually the SSR stops returning any styles, causing whole-page FOUC. Unfortunately, the code-base I provided does not replicate this issue, because I can’t consistently get it to happen, and haven’t been able to track down any specific contributing factor. We have several projects, structured this same way, and since the update to emotion 10, all are having this FOUC issue at various points. However Next and React were also updated around the same time so these could definitely be factors or even the cause. One note is the global styles seem to be consistently returning, just not the styled components.

Suggested solution: The styles consistently return.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
Andaristcommented, Oct 29, 2019

I’d love to help with fixing your problem - but no exact repro case was given and without such, I cannot do much.

4reactions
Andaristcommented, Oct 31, 2019

I’m going to close this then - assuming the issue could already have been fixed by OP. If not - please share repro steps, if you do that I will take a look at your problem shortly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nextjs is not rendering CSS in Server Side Rendering
When I update react 17 to react 18 in the nextjs project. Nextjs is not rendering CSS in Server-Side Rendering. How can I...
Read more >
Next.js and Styled-Components: style loading issue
js app but can't get the styles to load properly? This is because the server-side rendering does not fetch the styles before rendering...
Read more >
react-hydration-error - Next.js
The first render is called Hydration which is a feature of React. ... are not set up for pre-rendering (SSR/SSG) it will often...
Read more >
Basic Features: Built-in CSS Support - Next.js
These styles ( styles. css ) will apply to all pages and components in your application. Due to the global nature of stylesheets,...
Read more >
Basic Features: Layouts - Next.js
Many of these components are often reused between pages. ... Because this file is not a Page, you cannot use getStaticProps or getServerSideProps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found