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.

Pages render without styles for a brief second

See original GitHub issue

Bug report

Describe the bug

Pages render without any styles for a brief second before the CSS is loaded:

Jul-29-2020 20-54-52

This only happens in production. In development everything is fine and pages render perfectly styled immediately.

To Reproduce

I try to load some global styles in _app.tsx like:

// _app.tsx
import '../assets/styles/global.scss';

const MyApp = () => { ... }

export default MyApp;
// global.scss
@mixin system-font() {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  @include system-font();
  background: white;
  color: $text-color;
  line-height:1.5;
}

Then all my pages and components follow this pattern:

// my-page.tsx
import './my-page.scss'

const MyPage = () => { ... }

export default MyPage;
// my-component.tsx
import './my-component.scss'

const MyComponent = () => { ... }

export default MyComponent;

Expected behavior

I expect pages to render with styles without such flickering.

System information

  • OS: macOS Catalina 10.15.5
  • Browser: Firefox 78.0.2
  • Version of Next.js: 9.4.4
  • Version of Node.js: 12.18.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:47 (5 by maintainers)

github_iconTop GitHub Comments

31reactions
Timercommented, Nov 12, 2020

Closing as there was no full reproduction provided.

7reactions
muntasirsyedcommented, Mar 30, 2021

Agree somewhat with @osequi 's sentiment.

This issue has been reported multiple times by multiple different people. Every time the issue is closed with a version release referenced, yet the issue remains for all of those who originally reported the issue.

It would be better to, upon releasing any potential fix, checking with the original bug reporter to see if their issue has actually fixed or not before closing these issues down prematurely.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FOUC: Initial page loaded without any styles - Stack Overflow
But the issue is, styles are not getting pre-applied on page load. Because of which FOUC happens for all the initial page render....
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 >
Server-side rendered styled-components with Nextjs
Server-side rendering the styles. To enable server side rendering of the styles, we will need to do two things: hook into the renderPage...
Read more >
Advanced Usage - styled-components
This example renders our above themed Button and a second one that uses a second ThemeProvider to invert the background and foreground colors....
Read more >
Render Blocking CSS - web.dev
What would happen if we try to render a typical page without blocking rendering on CSS? Summary #. By default, CSS is treated...
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