From 30c2789a2ab01166a635af8f72441dca2e371b1e Mon Sep 17 00:00:00 2001 From: Christian Alten Date: Fri, 5 Oct 2018 09:30:47 -0500 Subject: [PATCH 1/4] fix(index): update to allow requesting failed async css files --- src/index.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/index.js b/src/index.js index 49d458ff..f6905f75 100644 --- a/src/index.js +++ b/src/index.js @@ -334,22 +334,6 @@ class MiniCssExtractPlugin { Template.indent([ `var href = ${linkHrefPath};`, `var fullhref = ${mainTemplate.requireFn}.p + href;`, - 'var existingLinkTags = document.getElementsByTagName("link");', - 'for(var i = 0; i < existingLinkTags.length; i++) {', - Template.indent([ - 'var tag = existingLinkTags[i];', - 'var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href");', - 'if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return resolve();', - ]), - '}', - 'var existingStyleTags = document.getElementsByTagName("style");', - 'for(var i = 0; i < existingStyleTags.length; i++) {', - Template.indent([ - 'var tag = existingStyleTags[i];', - 'var dataHref = tag.getAttribute("data-href");', - 'if(dataHref === href || dataHref === fullhref) return resolve();', - ]), - '}', 'var linkTag = document.createElement("link");', 'linkTag.rel = "stylesheet";', 'linkTag.type = "text/css";', @@ -359,6 +343,7 @@ class MiniCssExtractPlugin { 'var request = event && event.target && event.target.src || fullhref;', 'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");', 'err.request = request;', + 'delete installedCssChunks[chunkId]', 'reject(err);', ]), '};', From ea7bc2f0acab70fc37629b473132492c031b0d57 Mon Sep 17 00:00:00 2001 From: Christian Alten Date: Fri, 5 Oct 2018 12:15:05 -0500 Subject: [PATCH 2/4] test(manual): add async failure test --- test/manual/index.html | 5 +++++ test/manual/src/index.js | 8 ++++++-- test/manual/src/lazy-failure.css | 3 +++ test/manual/src/lazy-failure.js | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/manual/src/lazy-failure.css create mode 100644 test/manual/src/lazy-failure.js diff --git a/test/manual/index.html b/test/manual/index.html index e49d208a..5da5e5b1 100644 --- a/test/manual/index.html +++ b/test/manual/index.html @@ -42,6 +42,11 @@

Preloaded inlined CSS: Must be green.

displays an alert and should turn red.

+
+

Lazy CSS: Turn off the network and .

+

An error should have appeared.

+

Now if you turn the network back on and click it again, it should turn aqua.

+
diff --git a/test/manual/src/index.js b/test/manual/src/index.js index 3f4bd150..c6b9b72f 100644 --- a/test/manual/src/index.js +++ b/test/manual/src/index.js @@ -5,10 +5,12 @@ const handleError = (err) => { console.error(err); } -const makeButton = (className, fn) => { +const makeButton = (className, fn, shouldDisable = true) => { const button = document.querySelector(className); button.addEventListener("click", () => { - button.disabled = true; + if(shouldDisable) { + button.disabled = true; + } fn().then(() => { button.disabled = false; }).catch(handleError); @@ -20,3 +22,5 @@ makeButton(".lazy-button2", () => import('./lazy2.css')); makeButton(".preloaded-button1", () => import(/* webpackChunkName: "preloaded1" */ './preloaded1')); makeButton(".preloaded-button2", () => import(/* webpackChunkName: "preloaded2" */ './preloaded2')); + +makeButton(".lazy-failure-button", () => import('./lazy-failure.js'), false); diff --git a/test/manual/src/lazy-failure.css b/test/manual/src/lazy-failure.css new file mode 100644 index 00000000..479edbac --- /dev/null +++ b/test/manual/src/lazy-failure.css @@ -0,0 +1,3 @@ +.lazy-failure-css { + background: aqua; +} diff --git a/test/manual/src/lazy-failure.js b/test/manual/src/lazy-failure.js new file mode 100644 index 00000000..cf0f24b4 --- /dev/null +++ b/test/manual/src/lazy-failure.js @@ -0,0 +1 @@ +import './lazy-failure.css'; From 9d1fb1cbe75bca678aa7c4c7e77fe7d317cc8124 Mon Sep 17 00:00:00 2001 From: Christian Alten Date: Fri, 26 Oct 2018 14:15:23 -0500 Subject: [PATCH 3/4] test(manual): update placement of test ui --- test/manual/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/manual/index.html b/test/manual/index.html index 5da5e5b1..8b29a314 100644 --- a/test/manual/index.html +++ b/test/manual/index.html @@ -34,6 +34,11 @@

But turn orange, when . Additional clicks have no effect.

Refresh and press buttons in reverse order: This should turn green instead.

+
+

Lazy CSS: Turn off the network and .

+

An error should have appeared.

+

Now if you turn the network back on and click it again, it should turn aqua.

+

Preloaded CSS: Must be green.

displays an alert and should turn red.

@@ -42,11 +47,6 @@

Preloaded inlined CSS: Must be green.

displays an alert and should turn red.

-
-

Lazy CSS: Turn off the network and .

-

An error should have appeared.

-

Now if you turn the network back on and click it again, it should turn aqua.

-
From 0523dad4f838d6a659171073028a7ef72e501baf Mon Sep 17 00:00:00 2001 From: Christian Alten Date: Thu, 1 Nov 2018 14:48:53 -0500 Subject: [PATCH 4/4] fix(index): add code back and remove tag in failure --- src/index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/index.js b/src/index.js index f6905f75..60e909d2 100644 --- a/src/index.js +++ b/src/index.js @@ -334,6 +334,22 @@ class MiniCssExtractPlugin { Template.indent([ `var href = ${linkHrefPath};`, `var fullhref = ${mainTemplate.requireFn}.p + href;`, + 'var existingLinkTags = document.getElementsByTagName("link");', + 'for(var i = 0; i < existingLinkTags.length; i++) {', + Template.indent([ + 'var tag = existingLinkTags[i];', + 'var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href");', + 'if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return resolve();', + ]), + '}', + 'var existingStyleTags = document.getElementsByTagName("style");', + 'for(var i = 0; i < existingStyleTags.length; i++) {', + Template.indent([ + 'var tag = existingStyleTags[i];', + 'var dataHref = tag.getAttribute("data-href");', + 'if(dataHref === href || dataHref === fullhref) return resolve();', + ]), + '}', 'var linkTag = document.createElement("link");', 'linkTag.rel = "stylesheet";', 'linkTag.type = "text/css";', @@ -344,6 +360,7 @@ class MiniCssExtractPlugin { 'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");', 'err.request = request;', 'delete installedCssChunks[chunkId]', + 'linkTag.parentNode.removeChild(linkTag)', 'reject(err);', ]), '};',