vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.09k stars 26.72k forks source link

FOUC on page load with SSR #25487

Open nitroo88 opened 3 years ago

nitroo88 commented 3 years ago

What version of Next.js are you using?

10.2.3

What version of Node.js are you using?

14.16.0

What browser are you using?

Chrome

What operating system are you using?

Windows

How are you deploying your application?

next start

Describe the Bug

After creating a web app with SSR and run on the server, there is a problem with FUOC (Flash Of Unused Content). We're using CSS modules for every React Component (written in SCSS). At the beginning of loading the whole page there's no CSS styles. How can we fix it? To create our own stylesheet from all sass files and put into the head is could be a workaround, but with this modules make no sense.

Expected Behavior

Maybe is there an option to fix it from server side or something else?

To Reproduce

  1. Build a few React components with SCSS modules styles to each of them.
  2. Run next start and watch FUOC
taduuu commented 3 years ago

i have the same problem bro, anyone have a solution?

mohamedGamalAbuGalala commented 3 years ago

I have the same problem.

kmsomebody commented 3 years ago

Adding <script>0</script> as the first child of the <body> in _document.js fixed it for me.

mohamedGamalAbuGalala commented 3 years ago

@DarthSomebody Didn't solve my problem.

taduuu commented 3 years ago

it`s not next bug, it is chrome bug, try disable transitions on start, like ex:

{typeof window === 'undefined' && (