Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next js static export unstyled html flash. [FOUC]

I am working with next.js and everything seems to be fine when I am using app with npm run dev.

But when I am exporting my next.js app to a static files with command npm run build and trying to open my project for part of the second the screen is unstyled, this cause verry bad user experience.

I know this is called FOUC but how to avoid it on next.js static export?

P.S I am using styled-components library, not sure if that affecting the final result.

like image 681
Robertas Ankudovicius Avatar asked May 30 '26 07:05

Robertas Ankudovicius


1 Answers

If you are using styled-components, I would look into modifying your _document.js file per these instructions: https://styled-components.com/docs/advanced#server-side-rendering

That's how I managed to get out FOUC after trying a bunch of random stuff like:

  • putting a loader
  • putting a <script>0</script> tag
  • etc..
like image 84
thinkjustin Avatar answered Jun 01 '26 22:06

thinkjustin