Skip to content

Commit 0523dad

Browse files
committed
fix(index): add code back and remove tag in failure
1 parent 9d1fb1c commit 0523dad

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,22 @@ class MiniCssExtractPlugin {
334334
Template.indent([
335335
`var href = ${linkHrefPath};`,
336336
`var fullhref = ${mainTemplate.requireFn}.p + href;`,
337+
'var existingLinkTags = document.getElementsByTagName("link");',
338+
'for(var i = 0; i < existingLinkTags.length; i++) {',
339+
Template.indent([
340+
'var tag = existingLinkTags[i];',
341+
'var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href");',
342+
'if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return resolve();',
343+
]),
344+
'}',
345+
'var existingStyleTags = document.getElementsByTagName("style");',
346+
'for(var i = 0; i < existingStyleTags.length; i++) {',
347+
Template.indent([
348+
'var tag = existingStyleTags[i];',
349+
'var dataHref = tag.getAttribute("data-href");',
350+
'if(dataHref === href || dataHref === fullhref) return resolve();',
351+
]),
352+
'}',
337353
'var linkTag = document.createElement("link");',
338354
'linkTag.rel = "stylesheet";',
339355
'linkTag.type = "text/css";',
@@ -344,6 +360,7 @@ class MiniCssExtractPlugin {
344360
'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");',
345361
'err.request = request;',
346362
'delete installedCssChunks[chunkId]',
363+
'linkTag.parentNode.removeChild(linkTag)',
347364
'reject(err);',
348365
]),
349366
'};',

0 commit comments

Comments
 (0)