-
-
Notifications
You must be signed in to change notification settings - Fork 826
Expand file tree
/
Copy pathcss_loading.ejs
More file actions
72 lines (70 loc) · 3.21 KB
/
Copy pathcss_loading.ejs
File metadata and controls
72 lines (70 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
if (typeof document === "undefined") return;
// Scopes the chunk-identity attribute used to find a currently installed stylesheet
// (see extractCssFindStylesheet) to this compilation, so two independently compiled
// apps sharing a chunk id on the same page can't steal or remove each other's
// stylesheet. Matches the same output.uniqueName-based identity scheme chunk/module
// script loading already uses (see load_script.ejs).
var extractCssUniquePrefix = <%- _unique_name_prefix %>;
var extractCssCreateStylesheet = function (
chunkId, fullhref, oldTag, resolve, reject, fetchPriority
) {
<%- _create_link %>
var onLinkComplete = function (event) {
// avoid mem leaks.
linkTag.onerror = linkTag.onload = null;
if (event.type === 'load') {
resolve();
} else {
var errorType = event && (event.type === 'load' ? 'missing' : event.type);
var realHref = event && event.target && event.target.href || fullhref;
var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + realHref + ")");
err.code = "CSS_CHUNK_LOAD_FAILED";
err.type = errorType;
err.request = realHref;
if (linkTag.parentNode) linkTag.parentNode.removeChild(linkTag)
reject(err);
}
}
linkTag.onerror = linkTag.onload = onLinkComplete;
<%- _insert %>
return linkTag;
}
var extractCssFindStylesheet = function (href, fullhref, chunkId) {
var existingLinkTags = document.getElementsByTagName("link");
for (var i = 0; i < existingLinkTags.length; i++) {
var tag = existingLinkTags[i];
// When a chunkId is given (HMR replacement lookup), prefer matching the tag that
// was created for that chunk: the href it was created with may since have changed
// (e.g. a hashed filename), so it can no longer be found by comparing hrefs.
if (chunkId !== undefined && tag.getAttribute("data-webpack-chunk") === extractCssUniquePrefix + String(chunkId)) {
return tag;
}
var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href");
if (dataHref) {
dataHref = dataHref.split('?')[0]
}
if (tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return tag;
}
var existingStyleTags = document.getElementsByTagName("style");
for (var i = 0; i < existingStyleTags.length; i++) {
var tag = existingStyleTags[i];
var dataHref = tag.getAttribute("data-href");
if (dataHref === href || dataHref === fullhref) return tag;
}
}
var extractCssLoadStylesheet = function (chunkId, fetchPriority) {
return new Promise(function (resolve, reject) {
/**
A chunk that hasn't been loaded yet (e.g. a lazy route not imported so far) has
no tag for the HMR handler to update, so it instead just retains the fresh
filename it learned about (see HMR_MINI_CSS_FILENAMES in the with-hmr runtime).
Consult that retained mapping here too, or loading the chunk for the first time
after its CSS changed would still request the stale, pre-edit filename.
*/
var miniCssFilenames = <%- weak(HMR_MINI_CSS_FILENAMES) %>;
var href = (miniCssFilenames && miniCssFilenames[chunkId]) || <%- REQUIRE_SCOPE %>.miniCssF(chunkId);
var fullhref = <%- PUBLIC_PATH %> + href;
if (extractCssFindStylesheet(href, fullhref)) return resolve();
extractCssCreateStylesheet(chunkId, fullhref, null, resolve, reject, fetchPriority);
})
}