@module-federation/retry-plugin 0.0.0-perf-devtools-20260108034446 → 0.0.0-perf-website-code-usage-20260914033703
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 +50 -61
- package/dist/CHANGELOG.md +177 -3
- package/dist/README.md +50 -61
- package/dist/esm/index.js +288 -341
- package/dist/index.d.ts +25 -22
- package/dist/index.js +294 -371
- package/package.json +13 -3
- package/dist/index.d.mts +0 -110
- package/dist/package.json +0 -41
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ const mf = createInstance({
|
|
|
35
35
|
{
|
|
36
36
|
name: 'remote1',
|
|
37
37
|
entry: 'http://localhost:2001/mf-manifest.json',
|
|
38
|
-
}
|
|
38
|
+
},
|
|
39
39
|
],
|
|
40
40
|
plugins: [
|
|
41
41
|
RetryPlugin({
|
|
@@ -48,7 +48,7 @@ const mf = createInstance({
|
|
|
48
48
|
onSuccess: ({ url }) => console.log('Success!', url),
|
|
49
49
|
onError: ({ url }) => console.log('Failed!', url),
|
|
50
50
|
}),
|
|
51
|
-
]
|
|
51
|
+
],
|
|
52
52
|
});
|
|
53
53
|
```
|
|
54
54
|
|
|
@@ -66,9 +66,7 @@ export default {
|
|
|
66
66
|
remotes: {
|
|
67
67
|
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
|
|
68
68
|
},
|
|
69
|
-
runtimePlugins: [
|
|
70
|
-
path.join(__dirname, './src/runtime-plugin/retry.ts'),
|
|
71
|
-
],
|
|
69
|
+
runtimePlugins: [path.join(__dirname, './src/runtime-plugin/retry.ts')],
|
|
72
70
|
}),
|
|
73
71
|
],
|
|
74
72
|
};
|
|
@@ -78,43 +76,49 @@ export default {
|
|
|
78
76
|
// src/runtime-plugin/retry.ts
|
|
79
77
|
import { RetryPlugin } from '@module-federation/retry-plugin';
|
|
80
78
|
|
|
81
|
-
export default () =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
79
|
+
export default () =>
|
|
80
|
+
RetryPlugin({
|
|
81
|
+
retryTimes: 3,
|
|
82
|
+
retryDelay: 1000,
|
|
83
|
+
domains: ['https://cdn1.example.com', 'https://cdn2.example.com'],
|
|
84
|
+
manifestDomains: ['https://domain1.example.com', 'https://domain2.example.com'],
|
|
85
|
+
addQuery: ({ times, originalQuery }) => `${originalQuery}&retry=${times}`,
|
|
86
|
+
onRetry: ({ times, url }) => console.log('Retrying...', times, url),
|
|
87
|
+
onSuccess: ({ url }) => console.log('Success!', url),
|
|
88
|
+
onError: ({ url }) => console.log('Failed!', url),
|
|
89
|
+
});
|
|
91
90
|
```
|
|
92
91
|
|
|
93
92
|
## Configuration Options
|
|
94
93
|
|
|
95
94
|
### CommonRetryOptions
|
|
96
95
|
|
|
97
|
-
| Option
|
|
98
|
-
|
|
99
|
-
| `retryTimes`
|
|
100
|
-
| `retryDelay`
|
|
101
|
-
| `successTimes`
|
|
102
|
-
| `domains`
|
|
103
|
-
| `manifestDomains` | `string[]`
|
|
104
|
-
| `addQuery`
|
|
105
|
-
| `fetchOptions`
|
|
106
|
-
| `onRetry`
|
|
107
|
-
| `onSuccess`
|
|
108
|
-
| `onError`
|
|
96
|
+
| Option | Type | Default | Description |
|
|
97
|
+
| ----------------- | --------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------ |
|
|
98
|
+
| `retryTimes` | `number` | `3` | Number of retry attempts |
|
|
99
|
+
| `retryDelay` | `number \| (attempt: number) => number` | `1000` | Delay between retries in milliseconds, or a function returning delay per 1-indexed retry attempt |
|
|
100
|
+
| `successTimes` | `number` | `0` | Number of successful requests required |
|
|
101
|
+
| `domains` | `string[]` | `[]` | Alternative domains for script resources |
|
|
102
|
+
| `manifestDomains` | `string[]` | `[]` | Alternative domains for manifest files |
|
|
103
|
+
| `addQuery` | `boolean \| function` | See below | Add query parameters for cache busting |
|
|
104
|
+
| `fetchOptions` | `RequestInit` | `{}` | Additional fetch options |
|
|
105
|
+
| `onRetry` | `function` | `undefined` | Callback when retry occurs |
|
|
106
|
+
| `onSuccess` | `function` | `undefined` | Callback when request succeeds |
|
|
107
|
+
| `onError` | `function` | `undefined` | Callback when all retries fail |
|
|
109
108
|
|
|
110
109
|
### addQuery Function
|
|
111
110
|
|
|
111
|
+
When omitted, `addQuery` defaults to `true` only for `esm` and `module` remote
|
|
112
|
+
entry retries. This gives failed dynamic imports a new URL because browsers cache
|
|
113
|
+
their failures by URL. Manifest, fetch, and classic script retries still default
|
|
114
|
+
to no query parameter. Set `addQuery: false` to disable the ESM/module default.
|
|
115
|
+
|
|
112
116
|
```ts
|
|
113
117
|
addQuery: ({ times, originalQuery }) => {
|
|
114
118
|
// Add retry count and timestamp for cache busting
|
|
115
119
|
const separator = originalQuery ? '&' : '?';
|
|
116
120
|
return `${originalQuery}${separator}retry=${times}&t=${Date.now()}`;
|
|
117
|
-
}
|
|
121
|
+
};
|
|
118
122
|
```
|
|
119
123
|
|
|
120
124
|
### Callback Functions
|
|
@@ -143,16 +147,9 @@ onError: ({ domains, url, tagName }) => {
|
|
|
143
147
|
```ts
|
|
144
148
|
RetryPlugin({
|
|
145
149
|
retryTimes: 5,
|
|
146
|
-
retryDelay: (attempt) =>
|
|
147
|
-
domains: [
|
|
148
|
-
|
|
149
|
-
'https://cdn2.example.com',
|
|
150
|
-
'https://cdn3.example.com',
|
|
151
|
-
],
|
|
152
|
-
manifestDomains: [
|
|
153
|
-
'https://api1.example.com',
|
|
154
|
-
'https://api2.example.com',
|
|
155
|
-
],
|
|
150
|
+
retryDelay: (attempt) => 1000 * 2 ** (attempt - 1), // Exponential backoff: 1s, 2s, 4s, ...
|
|
151
|
+
domains: ['https://cdn1.example.com', 'https://cdn2.example.com', 'https://cdn3.example.com'],
|
|
152
|
+
manifestDomains: ['https://api1.example.com', 'https://api2.example.com'],
|
|
156
153
|
addQuery: ({ times, originalQuery }) => {
|
|
157
154
|
const params = new URLSearchParams(originalQuery);
|
|
158
155
|
params.set('retry', times.toString());
|
|
@@ -171,7 +168,7 @@ RetryPlugin({
|
|
|
171
168
|
console.error(`❌ Failed to load ${url} after all retries`);
|
|
172
169
|
console.error(`❌ Tried all domains: ${domains?.join(', ')}`);
|
|
173
170
|
},
|
|
174
|
-
})
|
|
171
|
+
});
|
|
175
172
|
```
|
|
176
173
|
|
|
177
174
|
### Error Handling with Fallback
|
|
@@ -184,7 +181,7 @@ RetryPlugin({
|
|
|
184
181
|
onError: ({ url, domains }) => {
|
|
185
182
|
// Log error for monitoring
|
|
186
183
|
console.error('Module loading failed:', { url, domains });
|
|
187
|
-
|
|
184
|
+
|
|
188
185
|
// Send error to monitoring service
|
|
189
186
|
if (window.gtag) {
|
|
190
187
|
window.gtag('event', 'module_load_error', {
|
|
@@ -193,7 +190,7 @@ RetryPlugin({
|
|
|
193
190
|
value: domains?.length || 0,
|
|
194
191
|
});
|
|
195
192
|
}
|
|
196
|
-
|
|
193
|
+
|
|
197
194
|
// Show user-friendly error message
|
|
198
195
|
const errorElement = document.createElement('div');
|
|
199
196
|
errorElement.className = 'module-load-error';
|
|
@@ -206,7 +203,7 @@ RetryPlugin({
|
|
|
206
203
|
`;
|
|
207
204
|
document.body.appendChild(errorElement);
|
|
208
205
|
},
|
|
209
|
-
})
|
|
206
|
+
});
|
|
210
207
|
```
|
|
211
208
|
|
|
212
209
|
### Production Configuration
|
|
@@ -215,15 +212,8 @@ RetryPlugin({
|
|
|
215
212
|
RetryPlugin({
|
|
216
213
|
retryTimes: 3,
|
|
217
214
|
retryDelay: 1000,
|
|
218
|
-
domains: [
|
|
219
|
-
|
|
220
|
-
'https://cdn2.prod.example.com',
|
|
221
|
-
'https://cdn3.prod.example.com',
|
|
222
|
-
],
|
|
223
|
-
manifestDomains: [
|
|
224
|
-
'https://api1.prod.example.com',
|
|
225
|
-
'https://api2.prod.example.com',
|
|
226
|
-
],
|
|
215
|
+
domains: ['https://cdn1.prod.example.com', 'https://cdn2.prod.example.com', 'https://cdn3.prod.example.com'],
|
|
216
|
+
manifestDomains: ['https://api1.prod.example.com', 'https://api2.prod.example.com'],
|
|
227
217
|
addQuery: ({ times, originalQuery }) => {
|
|
228
218
|
const params = new URLSearchParams(originalQuery);
|
|
229
219
|
params.set('retry', times.toString());
|
|
@@ -251,13 +241,10 @@ RetryPlugin({
|
|
|
251
241
|
onError: ({ url, domains }) => {
|
|
252
242
|
// Send error to monitoring service
|
|
253
243
|
if (window.errorReporting) {
|
|
254
|
-
window.errorReporting.captureException(
|
|
255
|
-
new Error(`Module loading failed: ${url}`),
|
|
256
|
-
{ extra: { domains, url } }
|
|
257
|
-
);
|
|
244
|
+
window.errorReporting.captureException(new Error(`Module loading failed: ${url}`), { extra: { domains, url } });
|
|
258
245
|
}
|
|
259
246
|
},
|
|
260
|
-
})
|
|
247
|
+
});
|
|
261
248
|
```
|
|
262
249
|
|
|
263
250
|
## How It Works
|
|
@@ -318,9 +305,11 @@ RetryPlugin({
|
|
|
318
305
|
},
|
|
319
306
|
script: {
|
|
320
307
|
url: 'http://localhost:2001/static/js/async/src_App_tsx.js',
|
|
321
|
-
customCreateScript: (url, attrs) => {
|
|
322
|
-
|
|
323
|
-
}
|
|
308
|
+
customCreateScript: (url, attrs) => {
|
|
309
|
+
/* ... */
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
});
|
|
324
313
|
|
|
325
314
|
// ✅ New way
|
|
326
315
|
RetryPlugin({
|
|
@@ -329,7 +318,7 @@ RetryPlugin({
|
|
|
329
318
|
domains: ['http://localhost:2001'],
|
|
330
319
|
manifestDomains: ['http://localhost:2001'],
|
|
331
320
|
addQuery: ({ times, originalQuery }) => `${originalQuery}&retry=${times}`,
|
|
332
|
-
})
|
|
321
|
+
});
|
|
333
322
|
```
|
|
334
323
|
|
|
335
324
|
## Contributing
|
|
@@ -344,4 +333,4 @@ Contributions are welcome! Please read our [contributing guidelines](https://git
|
|
|
344
333
|
|
|
345
334
|
- [Module Federation Documentation](https://module-federation.io/)
|
|
346
335
|
- [Module Federation Runtime](https://www.npmjs.com/package/@module-federation/runtime)
|
|
347
|
-
- [Module Federation Enhanced](https://www.npmjs.com/package/@module-federation/enhanced)
|
|
336
|
+
- [Module Federation Enhanced](https://www.npmjs.com/package/@module-federation/enhanced)
|
package/dist/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,185 @@
|
|
|
1
1
|
# @module-federation/retry-plugin
|
|
2
2
|
|
|
3
|
-
## 0.0.0-perf-
|
|
3
|
+
## 0.0.0-perf-website-code-usage-20260914033703
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- @module-federation/
|
|
7
|
+
- @module-federation/runtime@0.0.0-perf-website-code-usage-20260914033703
|
|
8
|
+
- @module-federation/sdk@0.0.0-perf-website-code-usage-20260914033703
|
|
9
|
+
|
|
10
|
+
## 2.9.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [df8b40f]
|
|
15
|
+
- Updated dependencies [df8b40f]
|
|
16
|
+
- @module-federation/runtime@2.9.0
|
|
17
|
+
- @module-federation/sdk@2.9.0
|
|
18
|
+
|
|
19
|
+
## 2.8.2
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- db13cf6: Fix retry-plugin recovery for ESM and module remote entry load failures, including default cache-busting retries.
|
|
24
|
+
- @module-federation/runtime@2.8.2
|
|
25
|
+
- @module-federation/sdk@2.8.2
|
|
26
|
+
|
|
27
|
+
## 2.8.1
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [d901e2c]
|
|
32
|
+
- @module-federation/sdk@2.8.1
|
|
33
|
+
- @module-federation/runtime@2.8.1
|
|
34
|
+
|
|
35
|
+
## 2.8.0
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Updated dependencies [ea490ae]
|
|
40
|
+
- @module-federation/sdk@2.8.0
|
|
41
|
+
- @module-federation/runtime@2.8.0
|
|
42
|
+
|
|
43
|
+
## 2.7.0
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- c103676: fix: externalize @module-federation/runtime and runtime-core from DTS bundle to prevent type incompatibility in consumers
|
|
48
|
+
- Updated dependencies [dcc640b]
|
|
49
|
+
- Updated dependencies [9958086]
|
|
50
|
+
- @module-federation/sdk@2.7.0
|
|
51
|
+
- @module-federation/runtime@2.7.0
|
|
52
|
+
|
|
53
|
+
## 2.6.0
|
|
54
|
+
|
|
55
|
+
### Minor Changes
|
|
56
|
+
|
|
57
|
+
- 64719e2: Support function-based `retryDelay` for per-attempt delay strategies such as exponential backoff.
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- @module-federation/sdk@2.6.0
|
|
62
|
+
|
|
63
|
+
## 2.5.1
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- Updated dependencies [b9b3b8c]
|
|
68
|
+
- @module-federation/sdk@2.5.1
|
|
69
|
+
|
|
70
|
+
## 2.5.0
|
|
71
|
+
|
|
72
|
+
### Patch Changes
|
|
73
|
+
|
|
74
|
+
- Updated dependencies [5d4095d]
|
|
75
|
+
- Updated dependencies [0716c11]
|
|
76
|
+
- @module-federation/sdk@2.5.0
|
|
77
|
+
|
|
78
|
+
## 2.4.0
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- Updated dependencies [5eba770]
|
|
83
|
+
- Updated dependencies [13b1e84]
|
|
84
|
+
- @module-federation/sdk@2.4.0
|
|
85
|
+
|
|
86
|
+
## 2.3.3
|
|
87
|
+
|
|
88
|
+
### Patch Changes
|
|
89
|
+
|
|
90
|
+
- @module-federation/sdk@2.3.3
|
|
91
|
+
|
|
92
|
+
## 2.3.2
|
|
93
|
+
|
|
94
|
+
### Patch Changes
|
|
95
|
+
|
|
96
|
+
- 0e7b1a1: Fix retryDelay not being applied on the first retry attempt in scriptRetry.
|
|
97
|
+
- @module-federation/sdk@2.3.2
|
|
98
|
+
|
|
99
|
+
## 2.3.1
|
|
100
|
+
|
|
101
|
+
### Patch Changes
|
|
102
|
+
|
|
103
|
+
- @module-federation/sdk@2.3.1
|
|
104
|
+
|
|
105
|
+
## 2.3.0
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- Updated dependencies [eb26065]
|
|
110
|
+
- Updated dependencies [8f2ec9b]
|
|
111
|
+
- @module-federation/sdk@2.3.0
|
|
112
|
+
|
|
113
|
+
## 2.2.3
|
|
114
|
+
|
|
115
|
+
### Patch Changes
|
|
116
|
+
|
|
117
|
+
- @module-federation/sdk@2.2.3
|
|
118
|
+
|
|
119
|
+
## 2.2.2
|
|
120
|
+
|
|
121
|
+
### Patch Changes
|
|
122
|
+
|
|
123
|
+
- @module-federation/sdk@2.2.2
|
|
124
|
+
|
|
125
|
+
## 2.2.1
|
|
126
|
+
|
|
127
|
+
### Patch Changes
|
|
128
|
+
|
|
129
|
+
- @module-federation/sdk@2.2.1
|
|
130
|
+
|
|
131
|
+
## 2.2.0
|
|
132
|
+
|
|
133
|
+
### Patch Changes
|
|
134
|
+
|
|
135
|
+
- Updated dependencies [c856ec1]
|
|
136
|
+
- Updated dependencies [12240bb]
|
|
137
|
+
- Updated dependencies [e5dd6ef]
|
|
138
|
+
- @module-federation/sdk@2.2.0
|
|
139
|
+
|
|
140
|
+
## 2.1.0
|
|
141
|
+
|
|
142
|
+
### Patch Changes
|
|
143
|
+
|
|
144
|
+
- 918294f: Add missing release coverage for packages moved to the new build implementation and standardized ESM/CJS artifact outputs. This ensures package versioning and publish automation include the remaining affected packages on this branch.
|
|
145
|
+
- Updated dependencies [918294f]
|
|
146
|
+
- @module-federation/sdk@2.1.0
|
|
147
|
+
|
|
148
|
+
## 2.0.1
|
|
149
|
+
|
|
150
|
+
### Patch Changes
|
|
151
|
+
|
|
152
|
+
- @module-federation/sdk@2.0.1
|
|
153
|
+
|
|
154
|
+
## 2.0.0
|
|
155
|
+
|
|
156
|
+
### Patch Changes
|
|
157
|
+
|
|
158
|
+
- @module-federation/sdk@2.0.0
|
|
159
|
+
|
|
160
|
+
## 0.24.1
|
|
161
|
+
|
|
162
|
+
### Patch Changes
|
|
163
|
+
|
|
164
|
+
- @module-federation/sdk@0.24.1
|
|
165
|
+
|
|
166
|
+
## 0.24.0
|
|
167
|
+
|
|
168
|
+
### Patch Changes
|
|
169
|
+
|
|
170
|
+
- @module-federation/sdk@0.24.0
|
|
171
|
+
|
|
172
|
+
## 0.23.0
|
|
173
|
+
|
|
174
|
+
### Patch Changes
|
|
175
|
+
|
|
176
|
+
- @module-federation/sdk@0.23.0
|
|
177
|
+
|
|
178
|
+
## 0.22.1
|
|
179
|
+
|
|
180
|
+
### Patch Changes
|
|
181
|
+
|
|
182
|
+
- @module-federation/sdk@0.22.1
|
|
8
183
|
|
|
9
184
|
## 0.22.0
|
|
10
185
|
|
|
@@ -123,7 +298,6 @@
|
|
|
123
298
|
### Patch Changes
|
|
124
299
|
|
|
125
300
|
- a7cf276: chore: upgrade NX to 21.2.3, Storybook to 9.0.9, and TypeScript to 5.8.3
|
|
126
|
-
|
|
127
301
|
- Upgraded NX from 21.0.3 to 21.2.3 with workspace configuration updates
|
|
128
302
|
- Migrated Storybook from 8.3.5 to 9.0.9 with updated configurations and automigrations
|
|
129
303
|
- Upgraded TypeScript from 5.7.3 to 5.8.3 with compatibility fixes
|
package/dist/README.md
CHANGED
|
@@ -35,7 +35,7 @@ const mf = createInstance({
|
|
|
35
35
|
{
|
|
36
36
|
name: 'remote1',
|
|
37
37
|
entry: 'http://localhost:2001/mf-manifest.json',
|
|
38
|
-
}
|
|
38
|
+
},
|
|
39
39
|
],
|
|
40
40
|
plugins: [
|
|
41
41
|
RetryPlugin({
|
|
@@ -48,7 +48,7 @@ const mf = createInstance({
|
|
|
48
48
|
onSuccess: ({ url }) => console.log('Success!', url),
|
|
49
49
|
onError: ({ url }) => console.log('Failed!', url),
|
|
50
50
|
}),
|
|
51
|
-
]
|
|
51
|
+
],
|
|
52
52
|
});
|
|
53
53
|
```
|
|
54
54
|
|
|
@@ -66,9 +66,7 @@ export default {
|
|
|
66
66
|
remotes: {
|
|
67
67
|
remote1: 'remote1@http://localhost:2001/mf-manifest.json',
|
|
68
68
|
},
|
|
69
|
-
runtimePlugins: [
|
|
70
|
-
path.join(__dirname, './src/runtime-plugin/retry.ts'),
|
|
71
|
-
],
|
|
69
|
+
runtimePlugins: [path.join(__dirname, './src/runtime-plugin/retry.ts')],
|
|
72
70
|
}),
|
|
73
71
|
],
|
|
74
72
|
};
|
|
@@ -78,43 +76,49 @@ export default {
|
|
|
78
76
|
// src/runtime-plugin/retry.ts
|
|
79
77
|
import { RetryPlugin } from '@module-federation/retry-plugin';
|
|
80
78
|
|
|
81
|
-
export default () =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
79
|
+
export default () =>
|
|
80
|
+
RetryPlugin({
|
|
81
|
+
retryTimes: 3,
|
|
82
|
+
retryDelay: 1000,
|
|
83
|
+
domains: ['https://cdn1.example.com', 'https://cdn2.example.com'],
|
|
84
|
+
manifestDomains: ['https://domain1.example.com', 'https://domain2.example.com'],
|
|
85
|
+
addQuery: ({ times, originalQuery }) => `${originalQuery}&retry=${times}`,
|
|
86
|
+
onRetry: ({ times, url }) => console.log('Retrying...', times, url),
|
|
87
|
+
onSuccess: ({ url }) => console.log('Success!', url),
|
|
88
|
+
onError: ({ url }) => console.log('Failed!', url),
|
|
89
|
+
});
|
|
91
90
|
```
|
|
92
91
|
|
|
93
92
|
## Configuration Options
|
|
94
93
|
|
|
95
94
|
### CommonRetryOptions
|
|
96
95
|
|
|
97
|
-
| Option
|
|
98
|
-
|
|
99
|
-
| `retryTimes`
|
|
100
|
-
| `retryDelay`
|
|
101
|
-
| `successTimes`
|
|
102
|
-
| `domains`
|
|
103
|
-
| `manifestDomains` | `string[]`
|
|
104
|
-
| `addQuery`
|
|
105
|
-
| `fetchOptions`
|
|
106
|
-
| `onRetry`
|
|
107
|
-
| `onSuccess`
|
|
108
|
-
| `onError`
|
|
96
|
+
| Option | Type | Default | Description |
|
|
97
|
+
| ----------------- | --------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------ |
|
|
98
|
+
| `retryTimes` | `number` | `3` | Number of retry attempts |
|
|
99
|
+
| `retryDelay` | `number \| (attempt: number) => number` | `1000` | Delay between retries in milliseconds, or a function returning delay per 1-indexed retry attempt |
|
|
100
|
+
| `successTimes` | `number` | `0` | Number of successful requests required |
|
|
101
|
+
| `domains` | `string[]` | `[]` | Alternative domains for script resources |
|
|
102
|
+
| `manifestDomains` | `string[]` | `[]` | Alternative domains for manifest files |
|
|
103
|
+
| `addQuery` | `boolean \| function` | See below | Add query parameters for cache busting |
|
|
104
|
+
| `fetchOptions` | `RequestInit` | `{}` | Additional fetch options |
|
|
105
|
+
| `onRetry` | `function` | `undefined` | Callback when retry occurs |
|
|
106
|
+
| `onSuccess` | `function` | `undefined` | Callback when request succeeds |
|
|
107
|
+
| `onError` | `function` | `undefined` | Callback when all retries fail |
|
|
109
108
|
|
|
110
109
|
### addQuery Function
|
|
111
110
|
|
|
111
|
+
When omitted, `addQuery` defaults to `true` only for `esm` and `module` remote
|
|
112
|
+
entry retries. This gives failed dynamic imports a new URL because browsers cache
|
|
113
|
+
their failures by URL. Manifest, fetch, and classic script retries still default
|
|
114
|
+
to no query parameter. Set `addQuery: false` to disable the ESM/module default.
|
|
115
|
+
|
|
112
116
|
```ts
|
|
113
117
|
addQuery: ({ times, originalQuery }) => {
|
|
114
118
|
// Add retry count and timestamp for cache busting
|
|
115
119
|
const separator = originalQuery ? '&' : '?';
|
|
116
120
|
return `${originalQuery}${separator}retry=${times}&t=${Date.now()}`;
|
|
117
|
-
}
|
|
121
|
+
};
|
|
118
122
|
```
|
|
119
123
|
|
|
120
124
|
### Callback Functions
|
|
@@ -143,16 +147,9 @@ onError: ({ domains, url, tagName }) => {
|
|
|
143
147
|
```ts
|
|
144
148
|
RetryPlugin({
|
|
145
149
|
retryTimes: 5,
|
|
146
|
-
retryDelay: (attempt) =>
|
|
147
|
-
domains: [
|
|
148
|
-
|
|
149
|
-
'https://cdn2.example.com',
|
|
150
|
-
'https://cdn3.example.com',
|
|
151
|
-
],
|
|
152
|
-
manifestDomains: [
|
|
153
|
-
'https://api1.example.com',
|
|
154
|
-
'https://api2.example.com',
|
|
155
|
-
],
|
|
150
|
+
retryDelay: (attempt) => 1000 * 2 ** (attempt - 1), // Exponential backoff: 1s, 2s, 4s, ...
|
|
151
|
+
domains: ['https://cdn1.example.com', 'https://cdn2.example.com', 'https://cdn3.example.com'],
|
|
152
|
+
manifestDomains: ['https://api1.example.com', 'https://api2.example.com'],
|
|
156
153
|
addQuery: ({ times, originalQuery }) => {
|
|
157
154
|
const params = new URLSearchParams(originalQuery);
|
|
158
155
|
params.set('retry', times.toString());
|
|
@@ -171,7 +168,7 @@ RetryPlugin({
|
|
|
171
168
|
console.error(`❌ Failed to load ${url} after all retries`);
|
|
172
169
|
console.error(`❌ Tried all domains: ${domains?.join(', ')}`);
|
|
173
170
|
},
|
|
174
|
-
})
|
|
171
|
+
});
|
|
175
172
|
```
|
|
176
173
|
|
|
177
174
|
### Error Handling with Fallback
|
|
@@ -184,7 +181,7 @@ RetryPlugin({
|
|
|
184
181
|
onError: ({ url, domains }) => {
|
|
185
182
|
// Log error for monitoring
|
|
186
183
|
console.error('Module loading failed:', { url, domains });
|
|
187
|
-
|
|
184
|
+
|
|
188
185
|
// Send error to monitoring service
|
|
189
186
|
if (window.gtag) {
|
|
190
187
|
window.gtag('event', 'module_load_error', {
|
|
@@ -193,7 +190,7 @@ RetryPlugin({
|
|
|
193
190
|
value: domains?.length || 0,
|
|
194
191
|
});
|
|
195
192
|
}
|
|
196
|
-
|
|
193
|
+
|
|
197
194
|
// Show user-friendly error message
|
|
198
195
|
const errorElement = document.createElement('div');
|
|
199
196
|
errorElement.className = 'module-load-error';
|
|
@@ -206,7 +203,7 @@ RetryPlugin({
|
|
|
206
203
|
`;
|
|
207
204
|
document.body.appendChild(errorElement);
|
|
208
205
|
},
|
|
209
|
-
})
|
|
206
|
+
});
|
|
210
207
|
```
|
|
211
208
|
|
|
212
209
|
### Production Configuration
|
|
@@ -215,15 +212,8 @@ RetryPlugin({
|
|
|
215
212
|
RetryPlugin({
|
|
216
213
|
retryTimes: 3,
|
|
217
214
|
retryDelay: 1000,
|
|
218
|
-
domains: [
|
|
219
|
-
|
|
220
|
-
'https://cdn2.prod.example.com',
|
|
221
|
-
'https://cdn3.prod.example.com',
|
|
222
|
-
],
|
|
223
|
-
manifestDomains: [
|
|
224
|
-
'https://api1.prod.example.com',
|
|
225
|
-
'https://api2.prod.example.com',
|
|
226
|
-
],
|
|
215
|
+
domains: ['https://cdn1.prod.example.com', 'https://cdn2.prod.example.com', 'https://cdn3.prod.example.com'],
|
|
216
|
+
manifestDomains: ['https://api1.prod.example.com', 'https://api2.prod.example.com'],
|
|
227
217
|
addQuery: ({ times, originalQuery }) => {
|
|
228
218
|
const params = new URLSearchParams(originalQuery);
|
|
229
219
|
params.set('retry', times.toString());
|
|
@@ -251,13 +241,10 @@ RetryPlugin({
|
|
|
251
241
|
onError: ({ url, domains }) => {
|
|
252
242
|
// Send error to monitoring service
|
|
253
243
|
if (window.errorReporting) {
|
|
254
|
-
window.errorReporting.captureException(
|
|
255
|
-
new Error(`Module loading failed: ${url}`),
|
|
256
|
-
{ extra: { domains, url } }
|
|
257
|
-
);
|
|
244
|
+
window.errorReporting.captureException(new Error(`Module loading failed: ${url}`), { extra: { domains, url } });
|
|
258
245
|
}
|
|
259
246
|
},
|
|
260
|
-
})
|
|
247
|
+
});
|
|
261
248
|
```
|
|
262
249
|
|
|
263
250
|
## How It Works
|
|
@@ -318,9 +305,11 @@ RetryPlugin({
|
|
|
318
305
|
},
|
|
319
306
|
script: {
|
|
320
307
|
url: 'http://localhost:2001/static/js/async/src_App_tsx.js',
|
|
321
|
-
customCreateScript: (url, attrs) => {
|
|
322
|
-
|
|
323
|
-
}
|
|
308
|
+
customCreateScript: (url, attrs) => {
|
|
309
|
+
/* ... */
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
});
|
|
324
313
|
|
|
325
314
|
// ✅ New way
|
|
326
315
|
RetryPlugin({
|
|
@@ -329,7 +318,7 @@ RetryPlugin({
|
|
|
329
318
|
domains: ['http://localhost:2001'],
|
|
330
319
|
manifestDomains: ['http://localhost:2001'],
|
|
331
320
|
addQuery: ({ times, originalQuery }) => `${originalQuery}&retry=${times}`,
|
|
332
|
-
})
|
|
321
|
+
});
|
|
333
322
|
```
|
|
334
323
|
|
|
335
324
|
## Contributing
|
|
@@ -344,4 +333,4 @@ Contributions are welcome! Please read our [contributing guidelines](https://git
|
|
|
344
333
|
|
|
345
334
|
- [Module Federation Documentation](https://module-federation.io/)
|
|
346
335
|
- [Module Federation Runtime](https://www.npmjs.com/package/@module-federation/runtime)
|
|
347
|
-
- [Module Federation Enhanced](https://www.npmjs.com/package/@module-federation/enhanced)
|
|
336
|
+
- [Module Federation Enhanced](https://www.npmjs.com/package/@module-federation/enhanced)
|