@rsbuild/plugin-assets-retry 1.0.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +47 -24
- package/dist/index.js +57 -35
- package/dist/runtime/asyncChunkRetry.d.ts +6 -3
- package/dist/runtime/asyncChunkRetry.js +209 -200
- package/dist/runtime/asyncChunkRetry.min.js +1 -1
- package/dist/runtime/initialChunkRetry.d.ts +1 -0
- package/dist/runtime/initialChunkRetry.js +233 -274
- package/dist/runtime/initialChunkRetry.min.js +1 -1
- package/package.json +6 -9
|
@@ -1,243 +1,252 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _ref, _RUNTIME_GLOBALS_GET;
|
|
4
1
|
// rsbuild/runtime/async-chunk-retry
|
|
5
|
-
|
|
6
|
-
// e.g: src_AsyncCompTest_tsx
|
|
7
|
-
// e.g: static/js/async/src_AsyncCompTest_tsx.js
|
|
8
|
-
// publicPath + ChunkFilename e.g: http://localhost:3000/static/js/async/src_AsyncCompTest_tsx.js
|
|
9
|
-
|
|
10
2
|
// init retryCollector and nextRetry function
|
|
11
3
|
var config = __RETRY_OPTIONS__;
|
|
12
4
|
var maxRetries = config.max || 3;
|
|
13
5
|
var retryCollector = {};
|
|
6
|
+
var retryCssCollector = {};
|
|
14
7
|
function findCurrentDomain(url) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
var domains = config.domain || [];
|
|
9
|
+
var domain = '';
|
|
10
|
+
for(var i = 0; i < domains.length; i++){
|
|
11
|
+
if (url.indexOf(domains[i]) !== -1) {
|
|
12
|
+
domain = domains[i];
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
22
15
|
}
|
|
23
|
-
|
|
24
|
-
return domain || window.origin;
|
|
16
|
+
return domain || window.origin;
|
|
25
17
|
}
|
|
26
18
|
function findNextDomain(url) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return domainList[(index + 1) % domainList.length] || url;
|
|
19
|
+
var domains = config.domain || [];
|
|
20
|
+
var currentDomain = findCurrentDomain(url);
|
|
21
|
+
var index = domains.indexOf(currentDomain);
|
|
22
|
+
return domains[(index + 1) % domains.length] || url;
|
|
32
23
|
}
|
|
33
24
|
var postfixRE = /[?#].*$/;
|
|
34
25
|
function cleanUrl(url) {
|
|
35
|
-
|
|
26
|
+
return url.replace(postfixRE, '');
|
|
36
27
|
}
|
|
37
28
|
function getQueryFromUrl(url) {
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
var parts = url.split('?')[1];
|
|
30
|
+
return parts ? "?".concat(parts.split('#')[0]) : '';
|
|
40
31
|
}
|
|
41
32
|
function getUrlRetryQuery(existRetryTimes, originalQuery) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
if (config.addQuery === true) {
|
|
34
|
+
return originalQuery !== '' ? "".concat(originalQuery, "&retry=").concat(existRetryTimes) : "?retry=".concat(existRetryTimes);
|
|
35
|
+
}
|
|
36
|
+
if (typeof config.addQuery === 'function') {
|
|
37
|
+
return config.addQuery({
|
|
38
|
+
times: existRetryTimes,
|
|
39
|
+
originalQuery: originalQuery
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return '';
|
|
52
43
|
}
|
|
53
44
|
function getNextRetryUrl(currRetryUrl, domain, nextDomain, existRetryTimes, originalQuery) {
|
|
54
|
-
|
|
45
|
+
return cleanUrl(currRetryUrl.replace(domain, nextDomain)) + getUrlRetryQuery(existRetryTimes + 1, originalQuery);
|
|
55
46
|
}
|
|
56
|
-
|
|
57
47
|
// shared between ensureChunk and loadScript
|
|
58
48
|
var globalCurrRetrying = {};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
// shared between ensureChunk and loadStyleSheet
|
|
50
|
+
var globalCurrRetryingCss = {};
|
|
51
|
+
function getCurrentRetry(chunkId, existRetryTimes, isCssAsyncChunk) {
|
|
52
|
+
var _retryCssCollector_chunkId, _retryCollector_chunkId;
|
|
53
|
+
return isCssAsyncChunk ? (_retryCssCollector_chunkId = retryCssCollector[chunkId]) === null || _retryCssCollector_chunkId === void 0 ? void 0 : _retryCssCollector_chunkId[existRetryTimes] : (_retryCollector_chunkId = retryCollector[chunkId]) === null || _retryCollector_chunkId === void 0 ? void 0 : _retryCollector_chunkId[existRetryTimes];
|
|
62
54
|
}
|
|
63
|
-
function initRetry(chunkId) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
var currRetry = getCurrentRetry(chunkId, existRetryTimes);
|
|
81
|
-
var nextRetry;
|
|
82
|
-
var nextExistRetryTimes = existRetryTimes + 1;
|
|
83
|
-
if (existRetryTimes === 0 || currRetry === undefined) {
|
|
84
|
-
nextRetry = initRetry(chunkId);
|
|
85
|
-
retryCollector[chunkId] = [];
|
|
86
|
-
} else {
|
|
87
|
-
var originalScriptFilename = currRetry.originalScriptFilename,
|
|
88
|
-
originalSrcUrl = currRetry.originalSrcUrl,
|
|
89
|
-
originalQuery = currRetry.originalQuery;
|
|
90
|
-
var nextDomain = findNextDomain(currRetry.nextDomain);
|
|
91
|
-
nextRetry = {
|
|
92
|
-
nextDomain: nextDomain,
|
|
93
|
-
nextRetryUrl: getNextRetryUrl(currRetry.nextRetryUrl, currRetry.nextDomain, nextDomain, existRetryTimes, originalQuery),
|
|
94
|
-
originalScriptFilename: originalScriptFilename,
|
|
95
|
-
originalSrcUrl: originalSrcUrl,
|
|
96
|
-
originalQuery: originalQuery
|
|
55
|
+
function initRetry(chunkId, isCssAsyncChunk) {
|
|
56
|
+
var _config_domain;
|
|
57
|
+
var originalScriptFilename = isCssAsyncChunk ? originalGetCssFilename(chunkId) : originalGetChunkScriptFilename(chunkId);
|
|
58
|
+
if (!originalScriptFilename) {
|
|
59
|
+
throw new Error('only support cssExtract');
|
|
60
|
+
}
|
|
61
|
+
var originalPublicPath = __RUNTIME_GLOBALS_PUBLIC_PATH__;
|
|
62
|
+
var originalSrcUrl = originalPublicPath.startsWith('/') ? window.origin + originalPublicPath + originalScriptFilename : originalPublicPath + originalScriptFilename;
|
|
63
|
+
var originalQuery = getQueryFromUrl(originalSrcUrl);
|
|
64
|
+
var existRetryTimes = 0;
|
|
65
|
+
var nextDomain = ((_config_domain = config.domain) === null || _config_domain === void 0 ? void 0 : _config_domain[0]) || window.origin;
|
|
66
|
+
return {
|
|
67
|
+
nextDomain: nextDomain,
|
|
68
|
+
nextRetryUrl: getNextRetryUrl(originalSrcUrl, nextDomain, nextDomain, existRetryTimes, originalQuery),
|
|
69
|
+
originalScriptFilename: originalScriptFilename,
|
|
70
|
+
originalSrcUrl: originalSrcUrl,
|
|
71
|
+
originalQuery: originalQuery
|
|
97
72
|
};
|
|
98
|
-
}
|
|
99
|
-
retryCollector[chunkId][nextExistRetryTimes] = nextRetry;
|
|
100
|
-
globalCurrRetrying[chunkId] = nextRetry;
|
|
101
|
-
return nextRetry;
|
|
102
73
|
}
|
|
103
|
-
|
|
74
|
+
function nextRetry(chunkId, existRetryTimes, isCssAsyncChunk) {
|
|
75
|
+
var currRetry = getCurrentRetry(chunkId, existRetryTimes, isCssAsyncChunk);
|
|
76
|
+
var nextRetry;
|
|
77
|
+
var nextExistRetryTimes = existRetryTimes + 1;
|
|
78
|
+
if (existRetryTimes === 0 || currRetry === undefined) {
|
|
79
|
+
nextRetry = initRetry(chunkId, isCssAsyncChunk);
|
|
80
|
+
if (isCssAsyncChunk) {
|
|
81
|
+
retryCssCollector[chunkId] = [];
|
|
82
|
+
} else {
|
|
83
|
+
retryCollector[chunkId] = [];
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
var originalScriptFilename = currRetry.originalScriptFilename, originalSrcUrl = currRetry.originalSrcUrl, originalQuery = currRetry.originalQuery;
|
|
87
|
+
var nextDomain = findNextDomain(currRetry.nextDomain);
|
|
88
|
+
nextRetry = {
|
|
89
|
+
nextDomain: nextDomain,
|
|
90
|
+
nextRetryUrl: getNextRetryUrl(currRetry.nextRetryUrl, currRetry.nextDomain, nextDomain, existRetryTimes, originalQuery),
|
|
91
|
+
originalScriptFilename: originalScriptFilename,
|
|
92
|
+
originalSrcUrl: originalSrcUrl,
|
|
93
|
+
originalQuery: originalQuery
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (isCssAsyncChunk) {
|
|
97
|
+
retryCssCollector[chunkId][nextExistRetryTimes] = nextRetry;
|
|
98
|
+
globalCurrRetryingCss[chunkId] = nextRetry;
|
|
99
|
+
} else {
|
|
100
|
+
retryCollector[chunkId][nextExistRetryTimes] = nextRetry;
|
|
101
|
+
globalCurrRetrying[chunkId] = nextRetry;
|
|
102
|
+
}
|
|
103
|
+
return nextRetry;
|
|
104
|
+
}
|
|
104
105
|
// rewrite webpack runtime with nextRetry()
|
|
105
106
|
var originalEnsureChunk = __RUNTIME_GLOBALS_ENSURE_CHUNK__;
|
|
106
107
|
var originalGetChunkScriptFilename = __RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__;
|
|
107
|
-
var originalGetCssFilename =
|
|
108
|
-
|
|
108
|
+
var originalGetCssFilename = __RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__ || __RUNTIME_GLOBALS_GET_CSS_FILENAME__ || function() {
|
|
109
|
+
return null;
|
|
109
110
|
};
|
|
110
111
|
var originalLoadScript = __RUNTIME_GLOBALS_LOAD_SCRIPT__;
|
|
111
112
|
var ERROR_PREFIX = '[@rsbuild/plugin-assets-retry] ';
|
|
112
|
-
|
|
113
113
|
// if users want to support es5, add Promise polyfill first https://github.com/webpack/webpack/issues/12877
|
|
114
|
-
function ensureChunk(chunkId
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
var originalScriptFilename = originalGetChunkScriptFilename(chunkId);
|
|
126
|
-
var originalCssFilename = originalGetCssFilename(chunkId);
|
|
127
|
-
|
|
128
|
-
// mark the async chunk name in the global variables and share it with initial chunk retry to avoid duplicate retrying
|
|
129
|
-
if (typeof window !== 'undefined') {
|
|
130
|
-
if (originalScriptFilename) {
|
|
131
|
-
window.__RB_ASYNC_CHUNKS__[originalScriptFilename] = true;
|
|
132
|
-
}
|
|
133
|
-
if (originalCssFilename) {
|
|
134
|
-
window.__RB_ASYNC_CHUNKS__[originalCssFilename] = true;
|
|
135
|
-
}
|
|
114
|
+
function ensureChunk(chunkId) {
|
|
115
|
+
// biome-ignore lint/style/noArguments: allowed
|
|
116
|
+
var args = Array.prototype.slice.call(arguments);
|
|
117
|
+
// Other webpack runtimes would add arguments for `__webpack_require__.e`,
|
|
118
|
+
// So we use `arguments[10]` to avoid conflicts with other runtimes
|
|
119
|
+
if (!args[10]) {
|
|
120
|
+
args[10] = {
|
|
121
|
+
count: 0,
|
|
122
|
+
cssFailedCount: 0
|
|
123
|
+
};
|
|
136
124
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// if __webpack_require__.e is polluted by other runtime codes, fallback to originalEnsureChunk
|
|
142
|
-
if (typeof (callingCounter === null || callingCounter === void 0 ? void 0 : callingCounter.count) !== 'number') {
|
|
143
|
-
return result;
|
|
144
|
-
}
|
|
145
|
-
callingCounter.count += 1;
|
|
146
|
-
return result.catch(function (error) {
|
|
147
|
-
var _error$message;
|
|
148
|
-
// the first calling is not retry
|
|
149
|
-
// if the failed request is 4 in network panel, callingCounter.count === 4, the first one is the normal request, and existRetryTimes is 3, retried 3 times
|
|
150
|
-
var existRetryTimes = callingCounter.count - 1;
|
|
151
|
-
var originalScriptFilename;
|
|
152
|
-
var nextRetryUrl;
|
|
153
|
-
var nextDomain;
|
|
125
|
+
var callingCounter = args[10];
|
|
126
|
+
var result = originalEnsureChunk.apply(null, args);
|
|
154
127
|
try {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
128
|
+
var originalScriptFilename = originalGetChunkScriptFilename(chunkId);
|
|
129
|
+
var originalCssFilename = originalGetCssFilename(chunkId);
|
|
130
|
+
// mark the async chunk name in the global variables and share it with initial chunk retry to avoid duplicate retrying
|
|
131
|
+
if (typeof window !== 'undefined') {
|
|
132
|
+
if (originalScriptFilename) {
|
|
133
|
+
window.__RB_ASYNC_CHUNKS__[originalScriptFilename] = true;
|
|
134
|
+
}
|
|
135
|
+
if (originalCssFilename) {
|
|
136
|
+
window.__RB_ASYNC_CHUNKS__[originalCssFilename] = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
159
139
|
} catch (e) {
|
|
160
|
-
|
|
161
|
-
throw error;
|
|
140
|
+
console.error(ERROR_PREFIX, 'get original script or CSS filename error', e);
|
|
162
141
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// 2. the code of loading CSS in webpack runtime is complex and it may be modified by cssExtractPlugin, increase the complexity of this plugin.
|
|
167
|
-
var isCssAsyncChunkLoadFailed = Boolean(error === null || error === void 0 || (_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.includes('CSS chunk'));
|
|
168
|
-
var createContext = function createContext(times) {
|
|
169
|
-
return {
|
|
170
|
-
times: times,
|
|
171
|
-
domain: nextDomain,
|
|
172
|
-
url: nextRetryUrl,
|
|
173
|
-
tagName: isCssAsyncChunkLoadFailed ? 'link' : 'script',
|
|
174
|
-
isAsyncChunk: true
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
var context = createContext(existRetryTimes);
|
|
178
|
-
if (existRetryTimes >= maxRetries) {
|
|
179
|
-
var _error$message2;
|
|
180
|
-
error.message = (_error$message2 = error.message) !== null && _error$message2 !== void 0 && _error$message2.includes('retries:') ? error.message : "Loading chunk ".concat(chunkId, " from \"").concat(originalScriptFilename, "\" failed after ").concat(maxRetries, " retries: \"").concat(error.message, "\"");
|
|
181
|
-
if (typeof config.onFail === 'function') {
|
|
182
|
-
config.onFail(context);
|
|
183
|
-
}
|
|
184
|
-
throw error;
|
|
142
|
+
// if __webpack_require__.e is polluted by other runtime codes, fallback to originalEnsureChunk
|
|
143
|
+
if (!callingCounter || typeof callingCounter.count !== 'number' || typeof callingCounter.cssFailedCount !== 'number') {
|
|
144
|
+
return result;
|
|
185
145
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
var
|
|
192
|
-
|
|
193
|
-
|
|
146
|
+
callingCounter.count += 1;
|
|
147
|
+
return result.catch(function(error) {
|
|
148
|
+
var _error_message;
|
|
149
|
+
// the first calling is not retry
|
|
150
|
+
// if the failed request is 4 in network panel, callingCounter.count === 4, the first one is the normal request, and existRetryTimes is 3, retried 3 times
|
|
151
|
+
var existRetryTimesAll = callingCounter.count - 1;
|
|
152
|
+
var cssExistRetryTimes = callingCounter.cssFailedCount;
|
|
153
|
+
var jsExistRetryTimes = existRetryTimesAll - cssExistRetryTimes;
|
|
154
|
+
var originalScriptFilename;
|
|
155
|
+
var nextRetryUrl;
|
|
156
|
+
var nextDomain;
|
|
157
|
+
var isCssAsyncChunkLoadFailed = Boolean(error === null || error === void 0 ? void 0 : (_error_message = error.message) === null || _error_message === void 0 ? void 0 : _error_message.includes('CSS chunk'));
|
|
158
|
+
if (isCssAsyncChunkLoadFailed) {
|
|
159
|
+
callingCounter.cssFailedCount += 1;
|
|
160
|
+
}
|
|
161
|
+
var existRetryTimes = isCssAsyncChunkLoadFailed ? cssExistRetryTimes : jsExistRetryTimes;
|
|
162
|
+
try {
|
|
163
|
+
var retryResult = nextRetry(chunkId, existRetryTimes, isCssAsyncChunkLoadFailed);
|
|
164
|
+
originalScriptFilename = retryResult.originalScriptFilename;
|
|
165
|
+
nextRetryUrl = retryResult.nextRetryUrl;
|
|
166
|
+
nextDomain = retryResult.nextDomain;
|
|
167
|
+
} catch (e) {
|
|
168
|
+
console.error(ERROR_PREFIX, 'failed to get nextRetryUrl', e);
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
var createContext = function(times) {
|
|
172
|
+
return {
|
|
173
|
+
times: times,
|
|
174
|
+
domain: nextDomain,
|
|
175
|
+
url: nextRetryUrl,
|
|
176
|
+
tagName: isCssAsyncChunkLoadFailed ? 'link' : 'script',
|
|
177
|
+
isAsyncChunk: true
|
|
178
|
+
};
|
|
194
179
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
180
|
+
var context = createContext(existRetryTimes);
|
|
181
|
+
if (existRetryTimes >= maxRetries) {
|
|
182
|
+
var _error_message1;
|
|
183
|
+
error.message = ((_error_message1 = error.message) === null || _error_message1 === void 0 ? void 0 : _error_message1.includes('retries:')) ? error.message : "Loading chunk ".concat(chunkId, ' from "').concat(originalScriptFilename, '" failed after ').concat(maxRetries, ' retries: "').concat(error.message, '"');
|
|
184
|
+
if (typeof config.onFail === 'function') {
|
|
185
|
+
config.onFail(context);
|
|
186
|
+
}
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
// Filter by config.test and config.domain
|
|
190
|
+
var tester = config.test;
|
|
191
|
+
if (tester) {
|
|
192
|
+
if (typeof tester === 'string') {
|
|
193
|
+
var regexp = new RegExp(tester);
|
|
194
|
+
tester = function(str) {
|
|
195
|
+
return regexp.test(str);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (typeof tester !== 'function' || !tester(nextRetryUrl)) {
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (config.domain && config.domain.indexOf(nextDomain) === -1) {
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
// Start retry
|
|
206
|
+
if (typeof config.onRetry === 'function') {
|
|
207
|
+
config.onRetry(context);
|
|
208
|
+
}
|
|
209
|
+
var nextPromise = ensureChunk.apply(ensureChunk, args);
|
|
210
|
+
return nextPromise.then(function(result) {
|
|
211
|
+
// when after retrying the third time
|
|
212
|
+
// ensureChunk(chunkId, { count: 3 }), at that time, existRetryTimes === 2
|
|
213
|
+
// at the end, callingCounter.count is 4
|
|
214
|
+
var isLastSuccessRetry = (callingCounter === null || callingCounter === void 0 ? void 0 : callingCounter.count) === existRetryTimesAll + 2;
|
|
215
|
+
if (typeof config.onSuccess === 'function' && isLastSuccessRetry) {
|
|
216
|
+
var context = createContext(existRetryTimes + 1);
|
|
217
|
+
config.onSuccess(context);
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
});
|
|
219
221
|
});
|
|
220
|
-
});
|
|
221
222
|
}
|
|
222
|
-
function loadScript(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
223
|
+
function loadScript() {
|
|
224
|
+
// biome-ignore lint/style/noArguments: allowed
|
|
225
|
+
var args = Array.prototype.slice.call(arguments);
|
|
226
|
+
var retry = globalCurrRetrying[args[3]];
|
|
227
|
+
if (retry) {
|
|
228
|
+
args[0] = retry.nextRetryUrl;
|
|
229
|
+
}
|
|
230
|
+
return originalLoadScript.apply(null, args);
|
|
231
|
+
}
|
|
232
|
+
function loadStyleSheet(href, chunkId) {
|
|
233
|
+
var retry = globalCurrRetryingCss[chunkId];
|
|
234
|
+
return(// biome-ignore lint/complexity/useOptionalChain: for less code
|
|
235
|
+
retry && retry.nextRetryUrl || __RUNTIME_GLOBALS_PUBLIC_PATH__ + href);
|
|
228
236
|
}
|
|
229
237
|
function registerAsyncChunkRetry() {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
// init global variables shared between initial-chunk-retry and async-chunk-retry
|
|
239
|
+
if (typeof window !== 'undefined' && !window.__RB_ASYNC_CHUNKS__) {
|
|
240
|
+
window.__RB_ASYNC_CHUNKS__ = {};
|
|
241
|
+
}
|
|
242
|
+
if (typeof __RUNTIME_GLOBALS_REQUIRE__ !== 'undefined') {
|
|
243
|
+
try {
|
|
244
|
+
__RUNTIME_GLOBALS_ENSURE_CHUNK__ = ensureChunk;
|
|
245
|
+
__RUNTIME_GLOBALS_LOAD_SCRIPT__ = loadScript;
|
|
246
|
+
__RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__ = loadStyleSheet;
|
|
247
|
+
} catch (e) {
|
|
248
|
+
console.error(ERROR_PREFIX, 'Register async chunk retry runtime failed', e);
|
|
249
|
+
}
|
|
240
250
|
}
|
|
241
|
-
}
|
|
242
251
|
}
|
|
243
|
-
registerAsyncChunkRetry();
|
|
252
|
+
registerAsyncChunkRetry();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var n=__RETRY_OPTIONS__,r=n.max||3,e={},i={},t=/[?#].*$/;function o(r,e,i,o,_){var a;return r.replace(e,i).replace(t,"")+(a=o+1,!0===n.addQuery?""!==_?"".concat(_,"&retry=").concat(a):"?retry=".concat(a):"function"==typeof n.addQuery?n.addQuery({times:a,originalQuery:_}):"")}var _={},a={},c=__RUNTIME_GLOBALS_ENSURE_CHUNK__,l=__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__,u=__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__||__RUNTIME_GLOBALS_GET_CSS_FILENAME__||function(){return null},d=__RUNTIME_GLOBALS_LOAD_SCRIPT__,s="[@rsbuild/plugin-assets-retry] ";function f(t){var d=Array.prototype.slice.call(arguments);d[10]||(d[10]={count:0,cssFailedCount:0});var S=d[10],y=c.apply(null,d);try{var R=l(t),p=u(t);"undefined"!=typeof window&&(R&&(window.__RB_ASYNC_CHUNKS__[R]=!0),p&&(window.__RB_ASYNC_CHUNKS__[p]=!0))}catch(n){console.error(s,"get original script or CSS filename error",n)}return S&&"number"==typeof S.count&&"number"==typeof S.cssFailedCount?(S.count+=1,y.catch(function(c){var y,R,p,v,E,U=S.count-1,L=S.cssFailedCount,g=!!(null==c?void 0:null===(y=c.message)||void 0===y?void 0:y.includes("CSS chunk"));g&&(S.cssFailedCount+=1);var N=g?L:U-L;try{var m=function(r,t,c){var d,s,f,S=c?null===(d=i[r])||void 0===d?void 0:d[t]:null===(s=e[r])||void 0===s?void 0:s[t],y=t+1;if(0===t||void 0===S)f=function(r,e){var i,t,_=e?u(r):l(r);if(!_)throw Error("only support cssExtract");var a=__RUNTIME_GLOBALS_PUBLIC_PATH__,c=a.startsWith("/")?window.origin+a+_:a+_,d=(i=c.split("?")[1])?"?".concat(i.split("#")[0]):"",s=(null===(t=n.domain)||void 0===t?void 0:t[0])||window.origin;return{nextDomain:s,nextRetryUrl:o(c,s,s,0,d),originalScriptFilename:_,originalSrcUrl:c,originalQuery:d}}(r,c),c?i[r]=[]:e[r]=[];else{var R,p,v,E,U=S.originalScriptFilename,L=S.originalSrcUrl,g=S.originalQuery,N=(R=S.nextDomain,p=n.domain||[],v=function(r){for(var e=n.domain||[],i="",t=0;t<e.length;t++)if(-1!==r.indexOf(e[t])){i=e[t];break}return i||window.origin}(R),E=p.indexOf(v),p[(E+1)%p.length]||R);f={nextDomain:N,nextRetryUrl:o(S.nextRetryUrl,S.nextDomain,N,t,g),originalScriptFilename:U,originalSrcUrl:L,originalQuery:g}}return c?(i[r][y]=f,a[r]=f):(e[r][y]=f,_[r]=f),f}(t,N,g);R=m.originalScriptFilename,p=m.nextRetryUrl,v=m.nextDomain}catch(n){throw console.error(s,"failed to get nextRetryUrl",n),c}var A=function(n){return{times:n,domain:v,url:p,tagName:g?"link":"script",isAsyncChunk:!0}},C=A(N);if(N>=r)throw c.message=(null===(E=c.message)||void 0===E?void 0:E.includes("retries:"))?c.message:"Loading chunk ".concat(t,' from "').concat(R,'" failed after ').concat(r,' retries: "').concat(c.message,'"'),"function"==typeof n.onFail&&n.onFail(C),c;var T=n.test;if(T){if("string"==typeof T){var w=new RegExp(T);T=function(n){return w.test(n)}}if("function"!=typeof T||!T(p))throw c}if(n.domain&&-1===n.domain.indexOf(v))throw c;return"function"==typeof n.onRetry&&n.onRetry(C),f.apply(f,d).then(function(r){var e=(null==S?void 0:S.count)===U+2;if("function"==typeof n.onSuccess&&e){var i=A(N+1);n.onSuccess(i)}return r})})):y}function S(){var n=Array.prototype.slice.call(arguments),r=_[n[3]];return r&&(n[0]=r.nextRetryUrl),d.apply(null,n)}function y(n,r){var e=a[r];return e&&e.nextRetryUrl||__RUNTIME_GLOBALS_PUBLIC_PATH__+n}!function(){if("undefined"==typeof window||window.__RB_ASYNC_CHUNKS__||(window.__RB_ASYNC_CHUNKS__={}),"undefined"!=typeof __RUNTIME_GLOBALS_REQUIRE__)try{__RUNTIME_GLOBALS_ENSURE_CHUNK__=f,__RUNTIME_GLOBALS_LOAD_SCRIPT__=S,__RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__=y}catch(n){console.error(s,"Register async chunk retry runtime failed",n)}}();
|