-
-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FOUC creates unreliable JS style calculations on page load #293
Comments
<head>
<style id="1">CSS</style>
</head>
<body>
<div id="app"></div>
<style data-id="1">SourceMap</style>
</body> Any other suggestions are highly welcome :) |
What if style-loader and HMR worked in tandem with ExtractTextPlugin? You could use the ExtractTextPlugin to inline a |
We are reworking the CSS Pipeline in general, |
Related
Style-loader uses a
<link>
to include styles when sourcemaps are enabled. Since injecting a<link>
tag into the page via JS, after page-load, results in the the stylesheet being downloaded asynchronously, other JS has time to execute before that stylesheet is downloaded and applied to the page.The resulting FOUC causes problems when JS needs to read styles from the DOM and is expecting a fully styled page. For example, let's say you have the following page built for production, that uses HTMLWebpackPlugin to inline a
<link>
tag at build-time.styles.css
index.html
The height logged will always be 100px because a
<link>
tag that is included on page load is synchronous and render-blocking.The same page when using style-loader with source-maps will always end up with another value (the unstyled page value) because the JS executes before the stylesheet has loaded.
The unreliability produces big problems for features like sticky elements in development, which need access to the styled page values to function correctly.
This problem is identical to those encountered when working with asynchronous stylesheets, e.g. using a lib like LoadCSS. One solution would be to check if the stylesheet has loaded before executing the JS, but that kind of sucks since this problem only exists in dev.
The text was updated successfully, but these errors were encountered: