mini-css-extract-plugin icon indicating copy to clipboard operation
mini-css-extract-plugin copied to clipboard

fix(index): dynamic css loading support for older browsers

Open gaterking opened this issue 7 years ago • 18 comments

This PR contains a:

  • [ ] bugfix
  • [x] new feature
  • [ ] code refactor
  • [ ] test update
  • [ ] typo fix
  • [ ] metadata update

Motivation / Use-Case

Breaking Changes

Additional Info

In old browser, such as android 4.3, link tag not support 4.3. Although these devices is few, the onload callback resolve function will not be called. This PR ignore onload for these devices and resolve immediately.

gaterking avatar May 08 '18 08:05 gaterking

CLA assistant check
All committers have signed the CLA.

jsf-clabot avatar May 08 '18 08:05 jsf-clabot

@gaterking can you provide minimum reproducible test repo and browser version to ensure it is does not works for all, thanks!

alexander-akait avatar May 08 '18 09:05 alexander-akait

@evilebottnawi http://pie.gd/test/script-link-events/ From this test page, we can see many old browsers not support link tag onload event.

gaterking avatar May 08 '18 10:05 gaterking

@gaterking also please accept CLA

alexander-akait avatar May 08 '18 10:05 alexander-akait

@gaterking can you faced this problem ?

alexander-akait avatar May 08 '18 10:05 alexander-akait

@evilebottnawi Yes, I faced it in my vue project. Android 4.3 browser will fail, bescause some lazy load modules with css chunk not resolve.

gaterking avatar May 08 '18 10:05 gaterking

@gaterking looks good solution, but i think we should search better solution for detecting this

alexander-akait avatar May 08 '18 10:05 alexander-akait

This also happened to be a blocker for a smartphone-specific project at work. I'll link this to the person involved so he can check if this works 🤔

Jessidhia avatar May 09 '18 07:05 Jessidhia

Note that it's important to know when a dynamically inserted style is loaded. Not knowing this leads to FOUC, which can be disastrous if you're doing things like getBoundingClientRect on component mount if it happens before the load is done.

Jessidhia avatar May 09 '18 07:05 Jessidhia

index.js @evilebottnawi Can you review my new code? If OK, I will create a new PR. Refer to RequieJS plugin, it use regex to check browser, but it don't check webkit version. In new solution, I refer to Dojo plugin and xstyle. I use setInterval to check css file is loaded in this case. I am sure we need to support webkit < 536 only, Becase of Webpack 4.

gaterking avatar May 12 '18 11:05 gaterking

what the next step for this PR?

gaterking avatar May 16 '18 15:05 gaterking

may be this is a better solution: https://stackoverflow.com/a/5371426

hxlniada avatar Aug 23 '18 08:08 hxlniada

/cc @gaterking

alexander-akait avatar Aug 23 '18 09:08 alexander-akait

I think this PR is not necessary for most developer, maybe we can close it. If somebody need to support old browser, I suggest to clone own repo.

gaterking avatar Sep 20 '18 09:09 gaterking

@evilebottnawi what do you think?

lili21 avatar Oct 16 '18 05:10 lili21

@hxlniada It's a neat solution, just need a little change.

...
var img = document.createElement('img');
img.onerror = function (e) {
  var request = event && event.target && event.target.src || fullhref;
  var i = document.styleSheets.length;
  while(i--) {
    if (document.styleSheets[i].href === request) {
      return resolve();
    }
  }
  var err = new Error('Loading CSS chunk ' + chunkId + ' failed.\n(' + request + ')');
  err.request = request;
  reject(err);
};
img.src = fullhref;
...

lili21 avatar Oct 16 '18 06:10 lili21

#299 similar PR

gaterking avatar Nov 14 '18 13:11 gaterking

Codecov Report

Merging #134 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #134   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files           3       3           
  Lines         241     241           
  Branches       49      49           
======================================
  Misses        198     198           
  Partials       43      43           
Impacted Files Coverage Δ
src/index.js 0.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 41347f7...bd891a0. Read the comment docs.

codecov[bot] avatar May 03 '20 16:05 codecov[bot]