-
-
Notifications
You must be signed in to change notification settings - Fork 469
feat: add insertionTag option #377
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #377 +/- ##
=========================================
- Coverage 7.38% 7.05% -0.34%
=========================================
Files 6 6
Lines 298 312 +14
Branches 90 94 +4
=========================================
Hits 22 22
- Misses 210 220 +10
- Partials 66 70 +4
Continue to review full report at Codecov.
|
Hmmm... I think something is wrong with the codecov setup? It's showing no coverage for most of the tests... Circleci is doing the same thing. In the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want new option new version only support insert: <Function>
to allow developers write own complex logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also you break logic for other, please open issue and describe you problem
@evilebottnawi, the existing insertion options that are documented: Do you have specific cases that I broke the logic for? I was very careful to avoid making any backward incompatible changes here, the logic only changes if you pass the new |
Sorry we don't want this PR, we want keep loader as small as possible and as fast as possible, better create own loader for this purpose, anyway thanks and sorry for delay |
This PR contains a:
Motivation / Use-Case
There are numerous bug reports around the net about flashes of unstyled content (FOUC) when using style-loader with sourcemaps:
facebook/create-react-app#6399
webpack-contrib/css-loader#613
https://stackoverflow.com/questions/36453826/how-to-stop-fouc-when-using-css-loaded-by-webpack
webpack/webpack-dev-middleware#51
Ultimately, all of these are caused by two things:
<link>
elements when using sourcemaps, and those<link>
elements are evaluated async, so the HTML may be rendered before the CSS.<style>
elements, so if you want sourcemaps, you end up with FOUCs.This change allows you to explicitly specify that you want to use
<style>
elements or<link>
elements, or singleton<style>
elements. It also adds support for putting sourcemaps into<style>
elements, which works great in Chrome.Breaking Changes
None, existing behavior is preserved if you don't pass the
insertionTag
option.Additional Info
Other stuff I noticed:
There were no tests for
<link>
element rendering. I added one, and had to mock a couple of missing methods on URL from JSDOM to do so.Also, the documented
sourceMap
option didn't do anything. The only place sourceMaps were used was in the<link>
element code and it was looking at the object passed in from thecss-loader
and not the options. I left that as-is to preserve backward compatibility, but when adding support for source maps to<style>
tags, I made it work as per the docs, based on thesourceMap
option flag. I'm not sure if that's the right thing to do or to remove the do-nothingsourceMap
option from the docs entirely and just rely on the upstream loader having passed a sourcemap or not.Another question that might be worth discussion, if 'singleton' is only there for old IE, and modern browsers support sourcemaps in
<style>
tags, a "legacy free" version of this loader might be nice. It could cut down on the size and complexity and just support<style>
tags, necessitating less options and less code.