Unverified Commit 67ff6250 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Do not remove no-FOUC styles too early (#14448)

We previously used to remove our FOUC helper inside of the style injection to ensure content was shown as fast as possible.

This behavior, however, was problematic for a few reasons:

1. Large JavaScript chunks would take longer than an animation frame to parse, causing FOUC
1. Rendering would sometimes complete before an animation frame, causing improper effects

To fix the latter, we started removing the no FOUC helper **before** rendering, however, we never fixed the former by removing the dead code.

There's not a great way to test this because the FOUC is so fast and flaky, however, this code really shouldn't exist and isn't likely to be re-added (regress).

Also, we already have FOUC tests that occasionally flake, probably due to this.


Fixes #12448
Fixes #13058
Fixes #11195
Fixes #10404
parent b560ac43
...@@ -29,25 +29,6 @@ export function getClientStyleLoader({ ...@@ -29,25 +29,6 @@ export function getClientStyleLoader({
// anchor. By inserting before and not after, we do not // anchor. By inserting before and not after, we do not
// need to track the last inserted element. // need to track the last inserted element.
parentNode.insertBefore(element, anchorElement) parentNode.insertBefore(element, anchorElement)
// Remember: this is development only code.
//
// After styles are injected, we need to remove the
// <style> tags that set `body { display: none; }`.
//
// We use `requestAnimationFrame` as a way to defer
// this operation since there may be multiple style
// tags.
;(self.requestAnimationFrame || setTimeout)(function () {
for (
var x = document.querySelectorAll('[data-next-hide-fouc]'),
i = x.length;
i--;
) {
x[i].parentNode!.removeChild(x[i])
}
})
}, },
}, },
} }
......
// This function is used to remove Next.js' no-FOUC styles workaround for using
// `style-loader` in development. It must be called before hydration, or else
// rendering won't have the correct computed values in effects.
export function displayContent(callback) { export function displayContent(callback) {
// This is the fallback helper that removes Next.js' no-FOUC styles when
// CSS mode is enabled. This only really activates if you haven't created
// _any_ styles in your application yet.
;(window.requestAnimationFrame || setTimeout)(function () { ;(window.requestAnimationFrame || setTimeout)(function () {
for ( for (
var x = document.querySelectorAll('[data-next-hide-fouc]'), i = x.length; var x = document.querySelectorAll('[data-next-hide-fouc]'), i = x.length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment