Add support for CSS Sourcemaps without FOUC #3202
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CRA will now have "working" sourcemaps for CSS.
Background
The most recent previous attempt at solving sourcemaps was #591 which introduced other bunch of problems. TL;DR The major problem was FOUC (Flash of Unstyled Content) and messy relative paths.
The root cause of FOUC is
style-loader
and the way it works. Explanation - webpack-contrib/css-loader#613 (comment)Mechanism
css-visor
is a loader and plugin, the loader extracts the CSS during compile time and passes it on to plugin for injection before webpack compilation finishes. The rest is handled byHTMLWebpackPlugin
and once loaded, CSS will be HMR'd automatically by HMR code added tocss-loader
's output.Performance
200 CSS files were imported in
App.js
,style-loader
andcss-visor
both took ~15 seconds to render page afteryarn start
. Subsequent edits to random CSS files were equally responsive in both setups.Premise
For the past 2 years I've been working on an extension for chrome devtools that aims to speed up development of React and Angular apps, by keeping a million moving parts organized (development, collaboration etc.) It's internals depend on sourcemaps and
create-react-app
has been my primary target for taking dev experience to the next level and without working sourcemaps the fruit will never reap, but I'm confident that it will :)