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.

Unexpected flash of unstyled content when using with next.js

See original GitHub issue

Version

1.0.10

Reproduction

https://github.com/jimthedev/next-styled-components-fouc

Steps to reproduce

mkdir next-styled-components-fouc
cd next-styled-components-fouc
git init
npm init
npm install --save next styled-components
mkdir pages
touch pages/index.js
Copy the following to pages/index.js

import React from 'react'
import style from 'styled-components'
import css from 'next/css'

// Example of a component styled by styled-components
const StyledComponent = style.div`
  background-color: #000000;
  color: white;
`;

// Example from Next's home page
const glamorStyle = css({
  color: 'red',
  ':hover': {
    color: 'blue'
  },
  '@media (max-width: 500px)': {
    color: 'rebeccapurple'
  }
})

export default () => {
  return (
    <div>
      <div style={{color:'green'}}>I am being styled by React's built in styling</div>
      <StyledComponent>I am being styled by styled components</StyledComponent>
      <div className={glamorStyle}>I am being styled by next & glamor</div>
    </div>
  )
}

Add a script to the package.json like this:

{
  "scripts": {
    "dev": "next"
  }
}
and run:

npm run dev

Expected Behavior

I would expect the styled-components styles to be rendered in the same way (without FOUC) as the glamor and react built in styling.

Actual Behavior

There is a FOUC before the styled-components are applied. Specifically the component with the black background color takes longer to apply styles than the other components.

Tweet for reference: https://twitter.com/JimTheDev/status/792849817907007488 Corresponding next.js issue: https://github.com/zeit/next.js/issues/184

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

13reactions
geelencommented, Nov 3, 2016

Ah ok you get the flash when loading from the client after rendering on the server. Yep, that sounds like something we haven’t considered yet. I’ll take a look.

5reactions
mxstbrcommented, Dec 4, 2016

We’re working on this @luisrudge, see #214 and #227. Soon!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected flash of unstyled content when using with styled ...
I am attempting to use next.js with styled-components. ... Here is my example repo that shows the FOUC when using next and sc...
Read more >
Flash of Unstyled Content (FOUC) for Nextjs using Mantine
This bug is only in production, in development it works fine. Example: https://gotrip.vercel.app If you don't see the flash, copy the link and ......
Read more >
Solve flash of unstyled content (FOUC) on NexJS and GatsbyJS
This guide will help you solve the issue known as “flash of unstyled content” (FOUC) on your Nextjs or Gatbsyjs site that was...
Read more >
Flash Of Unstyled Text (Fout) On Reload Using Next.Js And ...
A flash of unstyled content is an instance where a web page appears briefly with the browser's default styles prior to loading an...
Read more >
NextJS F.O.U.C : r/nextjs - Reddit
Hello everyone! I'm having trouble solving some FOUC (flash of un-styled content) issues on a project I'm currently working on.
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