var extractCssOldTags = [];
var extractCssNewTags = [];
var extractCssTextKey = function (link) {
return Array.from(link.sheet.cssRules, function (r) { return r.cssText; }).join();
}
var extractCssApplyHandler = function (options) {
return {
dispose: function () {},
apply: function () {
for (var i = 0; i < extractCssNewTags.length; i++) extractCssNewTags[i].sheet.disabled = false;
for (var i = 0; i < extractCssOldTags.length; i++) {
var oldTag = extractCssOldTags[i];
if (oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);
}
extractCssOldTags.length = 0;
extractCssNewTags.length = 0;
}
}
}
<%- HMR_DOWNLOAD_UPDATE_HANDLERS %>.miniCss = function (chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList) {
applyHandlers.push(extractCssApplyHandler);
var seen = {};
chunkIds.forEach(function (chunkId) {
var href = <%- REQUIRE_SCOPE %>.miniCssF(chunkId);
if (!href) return;
var fullhref = <%- PUBLIC_PATH %> + href;
if (seen[fullhref]) return;
seen[fullhref] = true;
var oldTag = extractCssFindStylesheet(href, fullhref);
if (!oldTag) return;
promises.push(new Promise(function (resolve, reject) {
var tag = extractCssCreateStylesheet(
chunkId,
/**
If dynamically add link tag through dom API and there is already a loaded style link, browsers sometimes treats the new link tag as the same link, and won't fetch the new style.
Use query to avoid browser cache the link tag, force to re-fetch new style, this is the same strategy as updateCss API, this can happen during lazy compilation
*/
`${fullhref}?${Date.now()}`,
oldTag,
function () {
try {
if (extractCssTextKey(oldTag) === extractCssTextKey(tag)) {
if (tag.parentNode) tag.parentNode.removeChild(tag);
return resolve();
}
} catch (e) {}
tag.sheet.disabled = true;
extractCssOldTags.push(oldTag);
extractCssNewTags.push(tag);
resolve();
},
reject
);
}))
});
}