<%- var("cssOldTags") %> = [];
<%- var("cssNewTags") %> = [];
<%- var("cssApplyHandler") %> = <%- basicFunction("options") %> {
return {
apply: <%- basicFunction("") %> {
while (cssNewTags.length) {
var entry = cssNewTags.pop(), link = entry.link, oldTag = entry.oldTag;
// Read the latest state before removing the old link. Keep downloads enabled until apply.
if (oldTag && oldTag.hasAttribute("disabled")) link.setAttribute("disabled", "");
else link.sheet.disabled = !!(oldTag && oldTag.sheet && oldTag.sheet.disabled);
}
while (cssOldTags.length) {
var oldTag = cssOldTags.pop();
if (oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);
}
}
};
};
<%- var("cssOnlyInitialChunkIds") %> = <%- _css_only_initial_chunk_ids %>;
// A chunk is present on this page only when the active JavaScript
// chunk-loading runtime records it as fully loaded.
<%- var("cssChunkIsLoaded") %> = <%- basicFunction("chunkId") %> {
return typeof <%- _js_state_expression %> !== "undefined" && <%- _js_state_expression %> && <%- _js_state_expression %>[chunkId] === 0;
};
<%- HMR_DOWNLOAD_UPDATE_HANDLERS %>.css = <%- basicFunction("chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList, css") %> {
if (typeof document === 'undefined') return;
applyHandlers.push(cssApplyHandler);
// `css` is the hot-update manifest's css namespace (aligned with webpack):
// `css.c` lists the chunks whose CSS content actually changed and `css.r`
// the chunks whose CSS disappeared. Its absence means this update carries
// no CSS work at all — notably the runtime chunk is in `chunkIds` on every
// update (its full hash always changes) while its stylesheet rarely does.
var cssRemovedChunkIds = (css && css.r) || [];
var cssChunkIds = (css && css.c) || [];
var seen = {};
cssRemovedChunkIds.forEach(<%- basicFunction("chunkId") %> {
var filename = <%- GET_CHUNK_CSS_FILENAME %>(chunkId);
if (!filename) return;
var oldTag = cssLoadStylesheet(chunkId, <%- PUBLIC_PATH %> + filename);
if (oldTag) cssOldTags.push(oldTag);
});
cssChunkIds.forEach(<%- basicFunction("chunkId") %> {
var filename = <%- GET_CHUNK_CSS_FILENAME %>(chunkId);
if (!filename) return;
var url = <%- PUBLIC_PATH %> + filename;
if (seen[url]) {
return;
}
seen[url] = true;
var oldTag = cssLoadStylesheet(chunkId, url);
// The manifest lists every chunk of this runtime, including other entries'
// chunks this page never loaded. Without a tag, only a chunk whose JS ran
// here (an initial chunk gaining its first stylesheet, or a loaded async
// chunk whose stylesheet an earlier update removed) gets a new stylesheet.
if (!oldTag && (cssOnlyInitialChunkIds[chunkId] === 1 || !cssChunkIsLoaded(chunkId))) return;
promises.push(
new Promise(<%- basicFunction("resolve, reject") %> {
var link = cssLoadStylesheet(
chunkId,
url + (url.indexOf("?") < 0 ? "?" : "&") + "hmr=" + Date.now(),
<%- basicFunction("event") %> {
if (event.type !== "load") {
var error = new Error();
var errorType = event && event.type;
var realSrc = event && event.target && event.target.src;
error.message =
"Loading css hot update chunk " +
chunkId +
" failed.\n(" +
errorType +
": " +
realSrc +
")";
error.name = "ChunkLoadError";
error.type = errorType;
error.request = realSrc;
reject(error);
} else {
link.sheet.disabled = true;
if (oldTag) cssOldTags.push(oldTag);
cssNewTags.push({ link: link, oldTag: oldTag });
resolve();
}
},
oldTag
);
})
);
});
};