Skip to content

Commit 2eb0af5

Browse files
cwaltenevilebottnawi
authored andcommitted
fix(index): allow requesting failed async css files (#292)
1 parent eb218cc commit 2eb0af5

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

Diff for: src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ class MiniCssExtractPlugin {
359359
'var request = event && event.target && event.target.src || fullhref;',
360360
'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");',
361361
'err.request = request;',
362+
'delete installedCssChunks[chunkId]',
363+
'linkTag.parentNode.removeChild(linkTag)',
362364
'reject(err);',
363365
]),
364366
'};',

Diff for: test/manual/index.html

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<p>But turn orange, when <button class="lazy-button2">pressing this button</button>. Additional clicks have no effect.</p>
3535
<p>Refresh and press buttons in reverse order: This should turn green instead.</p>
3636
</div>
37+
<div class="test lazy-failure-css">
38+
<p>Lazy CSS: Turn off the network and <button class="lazy-failure-button">press this button</button>.</p>
39+
<p>An error should have appeared.</p>
40+
<p>Now if you turn the network back on and click it again, it should turn aqua.</p>
41+
</div>
3742
<div class="test preloaded-css1">
3843
<p>Preloaded CSS: Must be green.</p>
3944
<p><button class="preloaded-button1">Pressing this button</button> displays an alert and should turn red.</p>

Diff for: test/manual/src/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const handleError = (err) => {
55
console.error(err);
66
}
77

8-
const makeButton = (className, fn) => {
8+
const makeButton = (className, fn, shouldDisable = true) => {
99
const button = document.querySelector(className);
1010
button.addEventListener("click", () => {
11-
button.disabled = true;
11+
if(shouldDisable) {
12+
button.disabled = true;
13+
}
1214
fn().then(() => {
1315
button.disabled = false;
1416
}).catch(handleError);
@@ -20,3 +22,5 @@ makeButton(".lazy-button2", () => import('./lazy2.css'));
2022

2123
makeButton(".preloaded-button1", () => import(/* webpackChunkName: "preloaded1" */ './preloaded1'));
2224
makeButton(".preloaded-button2", () => import(/* webpackChunkName: "preloaded2" */ './preloaded2'));
25+
26+
makeButton(".lazy-failure-button", () => import('./lazy-failure.js'), false);

Diff for: test/manual/src/lazy-failure.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.lazy-failure-css {
2+
background: aqua;
3+
}

Diff for: test/manual/src/lazy-failure.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './lazy-failure.css';

0 commit comments

Comments
 (0)