Unexpected flash of unstyled content when using with next.js
See original GitHub issueVersion
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:
- Created 7 years ago
- Reactions:4
- Comments:13 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
We’re working on this @luisrudge, see #214 and #227. Soon!