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.

FOUC only in production on latest Firefox

See original GitHub issue

What version of Next.js are you using?

10.0.7

What version of Node.js are you using?

12.8.3

What browser are you using?

Firefox 85.0.1 (64-bit)

What operating system are you using?

Pop_OS! 20.04 (Ubuntu 20.04)

How are you deploying your application?

Vercel

Describe the Bug

I see a FOUC when accessing my production deployment on Firefox:

fouc

It seems to disappear when using Chrome or Firefox on mobile.

I also appear to get the same issue for my portfolio website on Firefox:

fouc-portfolio

Expected Behavior

There should be no FOUC.

To Reproduce

  1. Visit my production deployment.
  2. See FOUC.

Or, to reproduce locally:

  1. Clone this repository.
  2. Install dependencies (using yarn).
  3. Start a development server (using yarn dev:next).
  4. Visit http://localhost:3000 and see FOUC.

You’ll need some env files for that reproduction to work correctly. Instead, you can just reproduce the same FOUC using my portfolio website (which is a lot smaller than that repo anyways):

  1. Clone this repository.
  2. Install dependencies (using yarn).
  3. Start a development server (using yarn dev).
  4. Visit http://localhost:3000 and see FOUC.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:13
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
nicholaschiangcommented, Mar 28, 2021

After some investigation, I think there are a couple of bugs at play here:

  1. Firefox’s devtools inspector updates the layout of the page (so you can inspect stuff) before stylesheets have loaded. I’m guessing this is what causes the FOUC when devtools are open (and JavaScript is disabled). Note that this error seems to always occur if the React Developer Tools extension is active. Notice how the “forced layout” console warning doesn’t come from any of the page scripts, but from a node.js:354 Mozilla devtools source file (specifically view-source:resource://devtools/server/actors/inspector/node.js):

image

  1. Any other extension that updates the page before stylesheets have loaded will cause a FOUC. Similar to how the devtools inspector causes a FOUC, any other Firefox extension that tries to access the page layout before stylesheets have loaded will also cause a FOUC. This is why the FOUC goes away when using a private browsing window without any extensions installed.

  2. Next.js doesn’t wait for stylesheets to load before executing scripts. This causes a FOUC when one of those scripts tries to access the page layout before stylesheets have been loaded. This is the main issue here that should be addressed by Next.js maintainers. Notice how the “forced layout” console warning comes from one of my page scripts that tries to use window.innerWidth and window.innerHeight:

image image

4reactions
elinlutzcommented, Mar 2, 2021

This might help: After hours of troubleshooting sudden FOUC in my next.js app (deployed at Vercel with styled-jsx, problems in production mode only) I discovered that I had styled-jsx installed as a separate package in my app. This created some conflict with next.js built-in styled-jsx. Deleting the package fixed it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Various websites like GitHub load with flash of unstyled ...
Hi! I've just disabled my extension S3.Translator and then loaded the webpage https://wiki.mozilla.org/Release_Management/Calendar and it solves the problem.
Read more >
Flash of unstyled content (FOUC) in Firefox only - Stack Overflow
In my case the reason of FOUC in FF was the presence of iframe on page. If I removing iframe from markup then...
Read more >
Local 3 News - APP OF THE DAY: Firefox Focus is a web... | Facebook
APP OF THE DAY: Firefox Focus is a web browser app that gives you less clutter as ... of tabs open on Chrome...
Read more >
Firefox Fast & Private Browser - Apps on Google Play
Get the people-first browser that's backed by a non-profit. It's a new era in tech. Don't settle for a browser produced by giant, ......
Read more >
Mozilla - Wikipedia
The Mozilla community uses, develops, spreads and supports Mozilla products, thereby promoting exclusively free software and open standards, with only minor ...
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