@module-federation/bridge-react 2.6.0 → 2.8.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.
Files changed (90) hide show
  1. package/dist/base.cjs.js +4 -4
  2. package/dist/base.d.ts +8 -311
  3. package/dist/base.es.js +5 -5
  4. package/dist/{bridge-base-CIOXqUYV.mjs → bridge-base-BaKy6CY_.mjs} +25 -92
  5. package/dist/{bridge-base-HLp3d7aF.js → bridge-base-Ch33UJuN.js} +25 -91
  6. package/dist/{createHelpers-DNBacpxb.js → createHelpers-19BP0xtB.js} +2 -3
  7. package/dist/{createHelpers-BY5Uj9_Z.mjs → createHelpers-BSHeKyd-.mjs} +2 -3
  8. package/dist/data-fetch-server-middleware.cjs.js +1 -1
  9. package/dist/data-fetch-server-middleware.d.ts +1 -15
  10. package/dist/data-fetch-server-middleware.es.js +1 -1
  11. package/dist/data-fetch-utils.cjs.js +2 -2
  12. package/dist/data-fetch-utils.d.ts +1 -81
  13. package/dist/data-fetch-utils.es.js +4 -4
  14. package/dist/data-fetch.cjs.js +3 -3
  15. package/dist/data-fetch.d.ts +4 -140
  16. package/dist/data-fetch.es.js +3 -3
  17. package/dist/error-boundary.d.ts +17 -0
  18. package/dist/error-boundary.spec.d.ts +1 -0
  19. package/dist/index.cjs.js +4 -4
  20. package/dist/index.d.ts +12 -299
  21. package/dist/index.es.js +5 -5
  22. package/dist/lazy/AwaitDataFetch.d.ts +24 -0
  23. package/dist/lazy/constant.d.ts +26 -0
  24. package/dist/lazy/createLazyComponent.d.ts +28 -0
  25. package/dist/lazy/data-fetch/cache.d.ts +34 -0
  26. package/dist/lazy/data-fetch/cache.spec.d.ts +1 -0
  27. package/dist/lazy/data-fetch/call-data-fetch.d.ts +1 -0
  28. package/dist/lazy/data-fetch/data-fetch-server-middleware.d.ts +3 -0
  29. package/dist/lazy/data-fetch/index.d.ts +6 -0
  30. package/dist/lazy/data-fetch/inject-data-fetch.d.ts +4 -0
  31. package/dist/lazy/data-fetch/prefetch.d.ts +9 -0
  32. package/dist/lazy/data-fetch/runtime-plugin.d.ts +3 -0
  33. package/dist/lazy/index.d.ts +9 -0
  34. package/dist/lazy/logger.d.ts +2 -0
  35. package/dist/lazy/types.d.ts +60 -0
  36. package/dist/lazy/utils.d.ts +48 -0
  37. package/dist/lazy/wrapNoSSR.d.ts +9 -0
  38. package/dist/{lazy-load-component-plugin-BYI941I2.mjs → lazy-load-component-plugin-DEu-DfZt.mjs} +2 -2
  39. package/dist/{lazy-load-component-plugin-DG4e3Tib.js → lazy-load-component-plugin-FKp6nQa-.js} +2 -2
  40. package/dist/lazy-load-component-plugin.cjs.js +2 -2
  41. package/dist/lazy-load-component-plugin.d.ts +2 -16
  42. package/dist/lazy-load-component-plugin.es.js +2 -2
  43. package/dist/lazy-utils.cjs.js +1 -1
  44. package/dist/lazy-utils.d.ts +1 -149
  45. package/dist/lazy-utils.es.js +2 -2
  46. package/dist/plugin.d.ts +2 -22
  47. package/dist/plugins/lazy-load-component-plugin.d.ts +12 -0
  48. package/dist/plugins/lazy-load-component-plugin.spec.d.ts +1 -0
  49. package/dist/{prefetch-DzO9_QQ-.mjs → prefetch-CTZuFBqh.mjs} +387 -16
  50. package/dist/{prefetch-CG2l-06N.js → prefetch-D66kL1aM.js} +387 -16
  51. package/dist/provider/context.d.ts +3 -0
  52. package/dist/provider/plugin.d.ts +7 -0
  53. package/dist/provider/versions/bridge-base.d.ts +5 -0
  54. package/dist/provider/versions/legacy.d.ts +26 -0
  55. package/dist/provider/versions/v18.d.ts +19 -0
  56. package/dist/provider/versions/v19.d.ts +21 -0
  57. package/dist/remote/RemoteAppWrapper.d.ts +7 -0
  58. package/dist/remote/base-component/component.d.ts +2 -0
  59. package/dist/remote/base-component/create.d.ts +9 -0
  60. package/dist/remote/base-component/index.d.ts +5 -0
  61. package/dist/remote/createHelpers.d.ts +17 -0
  62. package/dist/remote/router-component/component.d.ts +8 -0
  63. package/dist/remote/router-component/create.d.ts +9 -0
  64. package/dist/remote/router-component/index.d.ts +5 -0
  65. package/dist/router/default.d.ts +7 -0
  66. package/dist/router/v5.d.ts +4 -0
  67. package/dist/router/v6.d.ts +7 -0
  68. package/dist/router/v7.d.ts +6 -0
  69. package/dist/router-v5.d.ts +1 -17
  70. package/dist/router-v6.d.ts +1 -20
  71. package/dist/router-v7.d.ts +1 -19
  72. package/dist/router.d.ts +1 -20
  73. package/dist/shared/size-limited-cache.d.ts +29 -0
  74. package/dist/shared/size-limited-cache.spec.d.ts +1 -0
  75. package/dist/size-limited-cache.cjs.js +82 -0
  76. package/dist/size-limited-cache.d.ts +1 -0
  77. package/dist/size-limited-cache.es.js +82 -0
  78. package/dist/types.d.ts +137 -0
  79. package/dist/utils/index.d.ts +4 -0
  80. package/dist/utils-5dGErM3C.js +588 -0
  81. package/dist/utils-BBP3hEeV.mjs +589 -0
  82. package/dist/v18.cjs.js +1 -1
  83. package/dist/v18.d.ts +3 -114
  84. package/dist/v18.es.js +1 -1
  85. package/dist/v19.cjs.js +1 -1
  86. package/dist/v19.d.ts +3 -115
  87. package/dist/v19.es.js +1 -1
  88. package/package.json +20 -13
  89. package/dist/utils-CFTy4LVE.js +0 -2029
  90. package/dist/utils-DGS4pYp8.mjs +0 -2030
@@ -0,0 +1,589 @@
1
+ import { S as SEPARATOR, c as createLogger, i as isBrowserEnvValue } from "./logger-DwWkXsWl.mjs";
2
+ import { SizeLimitedCache } from "./size-limited-cache.es.js";
3
+ const LOG_CATEGORY = "[ Federation Runtime ]";
4
+ const composeKeyWithSeparator = function(...args) {
5
+ if (!args.length) return "";
6
+ return args.reduce((sum, cur) => {
7
+ if (!cur) return sum;
8
+ if (!sum) return cur;
9
+ return `${sum}${SEPARATOR}${cur}`;
10
+ }, "");
11
+ };
12
+ const warn = (msg) => {
13
+ console.warn(`${LOG_CATEGORY}: ${msg}`);
14
+ };
15
+ function safeToString(info) {
16
+ try {
17
+ return JSON.stringify(info, null, 2);
18
+ } catch (e) {
19
+ return "";
20
+ }
21
+ }
22
+ const PLUGIN_IDENTIFIER = "[ Module Federation React ]";
23
+ const DOWNGRADE_KEY = "_mfSSRDowngrade";
24
+ const DATA_FETCH_FUNCTION = "_mfDataFetch";
25
+ const FS_HREF = "_mfFSHref";
26
+ const ERROR_TYPE = {
27
+ DATA_FETCH: 1,
28
+ LOAD_REMOTE: 2,
29
+ UNKNOWN: 3
30
+ };
31
+ const WRAP_DATA_FETCH_ID_IDENTIFIER = "wrap_dfip_identifier";
32
+ var MF_DATA_FETCH_TYPE = /* @__PURE__ */ ((MF_DATA_FETCH_TYPE2) => {
33
+ MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_SERVER"] = 1] = "FETCH_SERVER";
34
+ MF_DATA_FETCH_TYPE2[MF_DATA_FETCH_TYPE2["FETCH_CLIENT"] = 2] = "FETCH_CLIENT";
35
+ return MF_DATA_FETCH_TYPE2;
36
+ })(MF_DATA_FETCH_TYPE || {});
37
+ var MF_DATA_FETCH_STATUS = /* @__PURE__ */ ((MF_DATA_FETCH_STATUS2) => {
38
+ MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADED"] = 1] = "LOADED";
39
+ MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["LOADING"] = 2] = "LOADING";
40
+ MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["AWAIT"] = 0] = "AWAIT";
41
+ MF_DATA_FETCH_STATUS2[MF_DATA_FETCH_STATUS2["ERROR"] = 3] = "ERROR";
42
+ return MF_DATA_FETCH_STATUS2;
43
+ })(MF_DATA_FETCH_STATUS || {});
44
+ const DATA_FETCH_IDENTIFIER = "data";
45
+ const DATA_FETCH_CLIENT_SUFFIX = ".client";
46
+ const DATA_FETCH_QUERY = "x-mf-data-fetch";
47
+ const DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
48
+ const LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
49
+ const logger = createLogger(PLUGIN_IDENTIFIER);
50
+ const CacheSize = {
51
+ KB: 1024,
52
+ MB: 1024 * 1024,
53
+ GB: 1024 * 1024 * 1024
54
+ };
55
+ const CacheTime = {
56
+ SECOND: 1e3,
57
+ MINUTE: 60 * 1e3,
58
+ HOUR: 60 * 60 * 1e3,
59
+ DAY: 24 * 60 * 60 * 1e3,
60
+ WEEK: 7 * 24 * 60 * 60 * 1e3,
61
+ MONTH: 30 * 24 * 60 * 60 * 1e3
62
+ };
63
+ function getTagKeyMap() {
64
+ const dataFetchCache = getDataFetchCache();
65
+ if (!dataFetchCache || !dataFetchCache.tagKeyMap) {
66
+ const tagKeyMap = /* @__PURE__ */ new Map();
67
+ globalThis.__MF_DATA_FETCH_CACHE__ || (globalThis.__MF_DATA_FETCH_CACHE__ = {});
68
+ globalThis.__MF_DATA_FETCH_CACHE__.tagKeyMap = tagKeyMap;
69
+ return tagKeyMap;
70
+ }
71
+ return dataFetchCache.tagKeyMap;
72
+ }
73
+ function addTagKeyRelation(tag, key) {
74
+ const tagKeyMap = getTagKeyMap();
75
+ let keys = tagKeyMap.get(tag);
76
+ if (!keys) {
77
+ keys = /* @__PURE__ */ new Set();
78
+ tagKeyMap.set(tag, keys);
79
+ }
80
+ keys.add(key);
81
+ }
82
+ function getCacheConfig() {
83
+ const dataFetchCache = getDataFetchCache();
84
+ if (!dataFetchCache || !dataFetchCache.cacheConfig) {
85
+ const cacheConfig = {
86
+ maxSize: CacheSize.GB
87
+ };
88
+ globalThis.__MF_DATA_FETCH_CACHE__ || (globalThis.__MF_DATA_FETCH_CACHE__ = {});
89
+ globalThis.__MF_DATA_FETCH_CACHE__.cacheConfig = cacheConfig;
90
+ return cacheConfig;
91
+ }
92
+ return dataFetchCache.cacheConfig;
93
+ }
94
+ function configureCache(config) {
95
+ const cacheConfig = getCacheConfig();
96
+ Object.assign(cacheConfig, config);
97
+ }
98
+ function getSizeLimitedCache() {
99
+ const dataFetchCache = getDataFetchCache();
100
+ const cacheConfig = getCacheConfig();
101
+ if (!dataFetchCache || !dataFetchCache.cacheStore) {
102
+ const cacheStore = new SizeLimitedCache({
103
+ maxSize: cacheConfig.maxSize ?? CacheSize.GB,
104
+ sizeCalculation: (value) => {
105
+ if (!value.size) {
106
+ return 1;
107
+ }
108
+ let size = 0;
109
+ for (const [k, item] of value.entries()) {
110
+ size += k.length * 2;
111
+ size += estimateObjectSize(item.data);
112
+ size += 8;
113
+ }
114
+ return size;
115
+ }
116
+ });
117
+ globalThis.__MF_DATA_FETCH_CACHE__ || (globalThis.__MF_DATA_FETCH_CACHE__ = {});
118
+ globalThis.__MF_DATA_FETCH_CACHE__.cacheStore = cacheStore;
119
+ return cacheStore;
120
+ }
121
+ return dataFetchCache.cacheStore;
122
+ }
123
+ function estimateObjectSize(data) {
124
+ const type = typeof data;
125
+ if (type === "number") return 8;
126
+ if (type === "boolean") return 4;
127
+ if (type === "string") return Math.max(data.length * 2, 1);
128
+ if (data === null || data === void 0) return 1;
129
+ if (ArrayBuffer.isView(data)) {
130
+ return Math.max(data.byteLength, 1);
131
+ }
132
+ if (Array.isArray(data)) {
133
+ return Math.max(
134
+ data.reduce((acc, item) => acc + estimateObjectSize(item), 0),
135
+ 1
136
+ );
137
+ }
138
+ if (data instanceof Map || data instanceof Set) {
139
+ return 1024;
140
+ }
141
+ if (data instanceof Date) {
142
+ return 8;
143
+ }
144
+ if (type === "object") {
145
+ return Math.max(
146
+ Object.entries(data).reduce(
147
+ (acc, [key, value]) => acc + key.length * 2 + estimateObjectSize(value),
148
+ 0
149
+ ),
150
+ 1
151
+ );
152
+ }
153
+ return 1;
154
+ }
155
+ function generateKey(dataFetchOptions) {
156
+ return JSON.stringify(dataFetchOptions, (_, value) => {
157
+ if (value && typeof value === "object" && !Array.isArray(value)) {
158
+ return Object.keys(value).sort().reduce((result, key) => {
159
+ result[key] = value[key];
160
+ return result;
161
+ }, {});
162
+ }
163
+ return value;
164
+ });
165
+ }
166
+ function cache(fn, options) {
167
+ const {
168
+ tag = "default",
169
+ maxAge = CacheTime.MINUTE * 5,
170
+ revalidate = 0,
171
+ onCache,
172
+ getKey
173
+ } = options || {};
174
+ const tags = Array.isArray(tag) ? tag : [tag];
175
+ return async (dataFetchOptions) => {
176
+ if (dataFetchOptions.isDowngrade || !dataFetchOptions._id) {
177
+ return fn(dataFetchOptions);
178
+ }
179
+ const store = getSizeLimitedCache();
180
+ const now = Date.now();
181
+ const storeKey = dataFetchOptions._id;
182
+ const cacheKey = getKey ? getKey(dataFetchOptions) : generateKey(dataFetchOptions);
183
+ tags.forEach((t) => addTagKeyRelation(t, cacheKey));
184
+ let cacheStore = store.get(cacheKey);
185
+ if (!cacheStore) {
186
+ cacheStore = /* @__PURE__ */ new Map();
187
+ }
188
+ const cached = cacheStore.get(storeKey);
189
+ if (cached) {
190
+ const age = now - cached.timestamp;
191
+ if (age < maxAge) {
192
+ if (onCache) {
193
+ const useCache = onCache({
194
+ status: "hit",
195
+ key: cacheKey,
196
+ params: dataFetchOptions,
197
+ result: cached.data
198
+ });
199
+ if (!useCache) {
200
+ return fn(dataFetchOptions);
201
+ }
202
+ }
203
+ return cached.data;
204
+ }
205
+ if (revalidate > 0 && age < maxAge + revalidate) {
206
+ if (onCache) {
207
+ onCache({
208
+ status: "stale",
209
+ key: cacheKey,
210
+ params: dataFetchOptions,
211
+ result: cached.data
212
+ });
213
+ }
214
+ if (!cached.isRevalidating) {
215
+ cached.isRevalidating = true;
216
+ Promise.resolve().then(async () => {
217
+ try {
218
+ const newData = await fn(dataFetchOptions);
219
+ cacheStore.set(storeKey, {
220
+ data: newData,
221
+ timestamp: Date.now(),
222
+ isRevalidating: false
223
+ });
224
+ store.set(cacheKey, cacheStore);
225
+ } catch (error) {
226
+ cached.isRevalidating = false;
227
+ console.error("Background revalidation failed:", error);
228
+ }
229
+ });
230
+ }
231
+ return cached.data;
232
+ }
233
+ }
234
+ const data = await fn(dataFetchOptions);
235
+ cacheStore.set(storeKey, {
236
+ data,
237
+ timestamp: now,
238
+ isRevalidating: false
239
+ });
240
+ store.set(cacheKey, cacheStore);
241
+ if (onCache) {
242
+ onCache({
243
+ status: "miss",
244
+ key: cacheKey,
245
+ params: dataFetchOptions,
246
+ result: data
247
+ });
248
+ }
249
+ return data;
250
+ };
251
+ }
252
+ function revalidateTag(tag) {
253
+ const tagKeyMap = getTagKeyMap();
254
+ const keys = tagKeyMap.get(tag);
255
+ const cacheStore = getSizeLimitedCache();
256
+ if (keys) {
257
+ keys.forEach((key) => {
258
+ cacheStore == null ? void 0 : cacheStore.delete(key);
259
+ });
260
+ }
261
+ }
262
+ function clearStore() {
263
+ var _a;
264
+ const cacheStore = getSizeLimitedCache();
265
+ const tagKeyMap = getTagKeyMap();
266
+ cacheStore == null ? void 0 : cacheStore.clear();
267
+ (_a = globalThis.__MF_DATA_FETCH_CACHE__) == null ? true : delete _a.cacheStore;
268
+ tagKeyMap.clear();
269
+ }
270
+ const getDataFetchInfo = ({
271
+ name,
272
+ alias,
273
+ id,
274
+ remoteSnapshot
275
+ }) => {
276
+ if (!remoteSnapshot) {
277
+ return;
278
+ }
279
+ if (!("modules" in remoteSnapshot)) {
280
+ return;
281
+ }
282
+ const regex = new RegExp(`^${name}(/[^/].*|)$`);
283
+ const nameOrAlias = regex.test(id) ? name : alias || name;
284
+ const expose = id.replace(nameOrAlias, "");
285
+ let dataFetchName = "";
286
+ let dataFetchId = "";
287
+ let dataFetchKey = "";
288
+ if (expose.startsWith("/")) {
289
+ dataFetchName = `${expose.slice(1)}.${DATA_FETCH_IDENTIFIER}`;
290
+ dataFetchId = `${id}.${DATA_FETCH_IDENTIFIER}`;
291
+ dataFetchKey = `${name}${expose}.${DATA_FETCH_IDENTIFIER}`;
292
+ } else if (expose === "") {
293
+ dataFetchName = DATA_FETCH_IDENTIFIER;
294
+ dataFetchId = `${id}/${DATA_FETCH_IDENTIFIER}`;
295
+ dataFetchKey = `${name}/${DATA_FETCH_IDENTIFIER}`;
296
+ } else {
297
+ return;
298
+ }
299
+ if (!dataFetchName || !dataFetchId || !dataFetchKey) {
300
+ return;
301
+ }
302
+ if (!remoteSnapshot.modules.find(
303
+ (module) => module.moduleName === dataFetchName
304
+ )) {
305
+ return;
306
+ }
307
+ return {
308
+ dataFetchName,
309
+ dataFetchId,
310
+ dataFetchKey
311
+ };
312
+ };
313
+ function initDataFetchMap() {
314
+ globalThis.__MF_DATA_FETCH_MAP__ || (globalThis.__MF_DATA_FETCH_MAP__ = {});
315
+ }
316
+ function getDataFetchItem(id) {
317
+ var _a;
318
+ return (_a = globalThis.__MF_DATA_FETCH_MAP__) == null ? void 0 : _a[id];
319
+ }
320
+ function getDataFetchMap() {
321
+ return globalThis.__MF_DATA_FETCH_MAP__;
322
+ }
323
+ function getDataFetchCache() {
324
+ return globalThis.__MF_DATA_FETCH_CACHE__;
325
+ }
326
+ const flushDataFetch = () => {
327
+ globalThis.__MF_DATA_FETCH_MAP__ = {};
328
+ globalThis[DOWNGRADE_KEY] = void 0;
329
+ clearStore();
330
+ };
331
+ function setDataFetchItemLoadedStatus(id) {
332
+ const dataFetchItem = getDataFetchItem(id);
333
+ if (!dataFetchItem) {
334
+ return;
335
+ }
336
+ dataFetchItem[2] = MF_DATA_FETCH_STATUS.LOADED;
337
+ }
338
+ const wrapDataFetchId = (id) => {
339
+ return `${WRAP_DATA_FETCH_ID_IDENTIFIER}${id}${WRAP_DATA_FETCH_ID_IDENTIFIER}`;
340
+ };
341
+ const getDataFetchIdWithErrorMsgs = (errMsgs) => {
342
+ const firstIdentifierIndex = errMsgs.indexOf(WRAP_DATA_FETCH_ID_IDENTIFIER);
343
+ if (firstIdentifierIndex === -1) {
344
+ return void 0;
345
+ }
346
+ const secondIdentifierIndex = errMsgs.indexOf(
347
+ WRAP_DATA_FETCH_ID_IDENTIFIER,
348
+ firstIdentifierIndex + WRAP_DATA_FETCH_ID_IDENTIFIER.length
349
+ );
350
+ if (secondIdentifierIndex === -1) {
351
+ return void 0;
352
+ }
353
+ return errMsgs.substring(
354
+ firstIdentifierIndex + WRAP_DATA_FETCH_ID_IDENTIFIER.length,
355
+ secondIdentifierIndex
356
+ );
357
+ };
358
+ async function fetchData(id, params, remoteInfo) {
359
+ var _a;
360
+ const callFetchData = async () => {
361
+ const item = getDataFetchItem(id);
362
+ if (!item) {
363
+ return;
364
+ }
365
+ const [fetchDataFnArr, ..._rest] = item;
366
+ const fetchDataFn = await fetchDataFnArr[2];
367
+ if (!fetchDataFn) {
368
+ return;
369
+ }
370
+ return fetchDataFn({
371
+ ...params,
372
+ _id: id
373
+ });
374
+ };
375
+ if (isBrowserEnvValue) {
376
+ const dataFetchItem = getDataFetchItem(id);
377
+ if (!dataFetchItem) {
378
+ throw new Error(`dataFetchItem not found, id: ${id}`);
379
+ }
380
+ if ((_a = dataFetchItem[1]) == null ? void 0 : _a[0]) {
381
+ return dataFetchItem[1][0];
382
+ }
383
+ if (isCSROnly()) {
384
+ logger.debug("==========csr only!");
385
+ return callFetchData();
386
+ }
387
+ if (remoteInfo) {
388
+ return callDowngrade(id, params, remoteInfo);
389
+ }
390
+ const mfDowngrade = getDowngradeTag();
391
+ if (mfDowngrade && (typeof mfDowngrade === "boolean" || mfDowngrade.includes(id))) {
392
+ return callDowngrade(id, { ...params, isDowngrade: true });
393
+ }
394
+ let res;
395
+ let rej;
396
+ const p = new Promise((resolve, reject) => {
397
+ res = resolve;
398
+ rej = reject;
399
+ });
400
+ dataFetchItem[1] = [p, res, rej];
401
+ dataFetchItem[2] = MF_DATA_FETCH_STATUS.AWAIT;
402
+ return dataFetchItem[1][0];
403
+ }
404
+ return callFetchData();
405
+ }
406
+ function getDataFetchMapKey(dataFetchInfo, hostInfo) {
407
+ if (!dataFetchInfo || !hostInfo) {
408
+ return;
409
+ }
410
+ const { dataFetchKey } = dataFetchInfo;
411
+ return composeKeyWithSeparator(dataFetchKey, hostInfo.name, hostInfo.version);
412
+ }
413
+ async function loadDataFetchModule(instance, id) {
414
+ return instance.loadRemote(id).then((m) => {
415
+ if (m && typeof m === "object" && "fetchData" in m && typeof m.fetchData === "function") {
416
+ return m.fetchData;
417
+ }
418
+ throw new Error(
419
+ `fetchData not found in remote ${id}, ${JSON.stringify(m)}`
420
+ );
421
+ });
422
+ }
423
+ function isDataLoaderExpose(exposeKey) {
424
+ return exposeKey.endsWith(DATA_FETCH_IDENTIFIER) || exposeKey.endsWith(DATA_FETCH_CLIENT_SUFFIX);
425
+ }
426
+ function getDowngradeTag() {
427
+ return globalThis[DOWNGRADE_KEY];
428
+ }
429
+ function callAllDowngrade() {
430
+ const dataFetchMap = getDataFetchMap();
431
+ if (!dataFetchMap) {
432
+ return;
433
+ }
434
+ Object.keys(dataFetchMap).forEach((key) => {
435
+ callDowngrade(key);
436
+ });
437
+ }
438
+ async function callDowngrade(id, params, remoteInfo) {
439
+ const dataFetchMap = getDataFetchMap();
440
+ if (!dataFetchMap) {
441
+ return;
442
+ }
443
+ const mfDataFetch = dataFetchMap[id];
444
+ if ((mfDataFetch == null ? void 0 : mfDataFetch[2]) === MF_DATA_FETCH_STATUS.AWAIT) {
445
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADING;
446
+ let promise;
447
+ let res;
448
+ let rej;
449
+ if (mfDataFetch[1]) {
450
+ promise = mfDataFetch[1][0];
451
+ res = mfDataFetch[1][1];
452
+ rej = mfDataFetch[1][2];
453
+ } else {
454
+ promise = new Promise((resolve, reject) => {
455
+ res = resolve;
456
+ rej = reject;
457
+ });
458
+ mfDataFetch[1] = [promise, res, rej];
459
+ }
460
+ const dataFetchType = mfDataFetch[0][1];
461
+ if (dataFetchType === MF_DATA_FETCH_TYPE.FETCH_CLIENT) {
462
+ try {
463
+ mfDataFetch[0][0]().then(async (getDataFetchFn) => {
464
+ return getDataFetchFn({
465
+ ...params,
466
+ isDowngrade: true,
467
+ _id: id
468
+ }).then((data) => {
469
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADED;
470
+ res && res(data);
471
+ });
472
+ });
473
+ } catch (e) {
474
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.ERROR;
475
+ rej && rej(e);
476
+ }
477
+ } else if (dataFetchType === MF_DATA_FETCH_TYPE.FETCH_SERVER) {
478
+ try {
479
+ const currentUrl = new URL(window.location.href);
480
+ currentUrl.searchParams.set(DATA_FETCH_QUERY, encodeURIComponent(id));
481
+ if (params) {
482
+ currentUrl.searchParams.set(
483
+ "params",
484
+ encodeURIComponent(JSON.stringify(params))
485
+ );
486
+ }
487
+ if (remoteInfo) {
488
+ currentUrl.searchParams.set(
489
+ "remoteInfo",
490
+ encodeURIComponent(JSON.stringify(remoteInfo))
491
+ );
492
+ }
493
+ const fetchServerQuery = globalThis.FEDERATION_SERVER_QUERY;
494
+ if (fetchServerQuery && typeof fetchServerQuery === "object") {
495
+ Object.keys(fetchServerQuery).forEach((key) => {
496
+ currentUrl.searchParams.set(
497
+ key,
498
+ JSON.stringify(fetchServerQuery[key])
499
+ );
500
+ });
501
+ }
502
+ const fetchUrl = currentUrl.toString();
503
+ const data = await fetch(fetchUrl).then((res2) => res2.json());
504
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.LOADED;
505
+ res && res(data);
506
+ } catch (e) {
507
+ mfDataFetch[2] = MF_DATA_FETCH_STATUS.ERROR;
508
+ rej && rej(e);
509
+ }
510
+ }
511
+ return promise;
512
+ }
513
+ }
514
+ function isCSROnly() {
515
+ return window._SSR_DATA === void 0;
516
+ }
517
+ function isServerEnv() {
518
+ return typeof window === "undefined";
519
+ }
520
+ function setSSREnv({
521
+ fetchServerQuery
522
+ }) {
523
+ globalThis.FEDERATION_SSR = true;
524
+ globalThis.FEDERATION_SERVER_QUERY = fetchServerQuery;
525
+ }
526
+ function getLoadedRemoteInfos(id, instance) {
527
+ if (!instance) {
528
+ return;
529
+ }
530
+ const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
531
+ if (!name) {
532
+ return;
533
+ }
534
+ const module = instance.moduleCache.get(name);
535
+ if (!module) {
536
+ return;
537
+ }
538
+ const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(
539
+ module.remoteInfo
540
+ );
541
+ return {
542
+ ...module.remoteInfo,
543
+ snapshot: remoteSnapshot,
544
+ expose
545
+ };
546
+ }
547
+ export {
548
+ setDataFetchItemLoadedStatus as A,
549
+ warn as B,
550
+ CacheSize as C,
551
+ DATA_FETCH_QUERY as D,
552
+ ERROR_TYPE as E,
553
+ FS_HREF as F,
554
+ DOWNGRADE_KEY as G,
555
+ callAllDowngrade as H,
556
+ callDowngrade as I,
557
+ getDowngradeTag as J,
558
+ composeKeyWithSeparator as K,
559
+ LOAD_REMOTE_ERROR_PREFIX as L,
560
+ MF_DATA_FETCH_STATUS as M,
561
+ safeToString as N,
562
+ getDataFetchCache as O,
563
+ CacheTime as a,
564
+ clearStore as b,
565
+ cache as c,
566
+ configureCache as d,
567
+ getDataFetchMap as e,
568
+ flushDataFetch as f,
569
+ generateKey as g,
570
+ fetchData as h,
571
+ initDataFetchMap as i,
572
+ loadDataFetchModule as j,
573
+ isDataLoaderExpose as k,
574
+ logger as l,
575
+ getDataFetchInfo as m,
576
+ getDataFetchMapKey as n,
577
+ getDataFetchItem as o,
578
+ DATA_FETCH_CLIENT_SUFFIX as p,
579
+ MF_DATA_FETCH_TYPE as q,
580
+ revalidateTag as r,
581
+ setSSREnv as s,
582
+ isCSROnly as t,
583
+ isServerEnv as u,
584
+ getDataFetchIdWithErrorMsgs as v,
585
+ DATA_FETCH_ERROR_PREFIX as w,
586
+ wrapDataFetchId as x,
587
+ DATA_FETCH_FUNCTION as y,
588
+ getLoadedRemoteInfos as z
589
+ };
package/dist/v18.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const client = require("react-dom/client");
4
- const bridgeBase = require("./bridge-base-HLp3d7aF.js");
4
+ const bridgeBase = require("./bridge-base-Ch33UJuN.js");
5
5
  function createReact18Root(container, options) {
6
6
  return client.createRoot(container, options);
7
7
  }
package/dist/v18.d.ts CHANGED
@@ -1,114 +1,3 @@
1
- import { default as default_2 } from 'react';
2
- import * as React_2 from 'react';
3
-
4
- export declare function createBridgeComponent<T = any>(bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>): () => {
5
- render(info: RenderParams): Promise<void>;
6
- destroy(info: DestroyParams): void;
7
- };
8
-
9
- export declare interface CreateRootOptions {
10
- identifierPrefix?: string;
11
- onRecoverableError?: (error: unknown, errorInfo: unknown) => void;
12
- }
13
-
14
- /**
15
- * Options for creating a React root
16
- */
17
- declare interface CreateRootOptions_2 {
18
- identifierPrefix?: string;
19
- onRecoverableError?: (error: unknown) => void;
20
- transitionCallbacks?: unknown;
21
- }
22
-
23
- /**
24
- * Parameters for the destroy function
25
- */
26
- export declare interface DestroyParams {
27
- moduleName: string;
28
- dom: HTMLElement;
29
- }
30
-
31
- /**
32
- * Parameters for the provider function
33
- */
34
- export declare interface ProviderFnParams<T> {
35
- rootComponent: React_2.ComponentType<T>;
36
- render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
37
- createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions_2) => Root_2;
38
- /**
39
- * Default options to pass to createRoot for React 18 and 19
40
- * These options will be used when creating a root unless overridden by rootOptions in render params
41
- * @example
42
- * {
43
- * identifierPrefix: 'app-',
44
- * onRecoverableError: (err) => console.error(err)
45
- * }
46
- */
47
- defaultRootOptions?: CreateRootOptions_2;
48
- }
49
-
50
- /**
51
- * Parameters for the provider function
52
- */
53
- export declare interface ProviderParams {
54
- moduleName?: string;
55
- basename?: string;
56
- memoryRoute?: {
57
- entryPath: string;
58
- initialState?: Record<string, unknown>;
59
- };
60
- style?: React_2.CSSProperties;
61
- className?: string;
62
- }
63
-
64
- /**
65
- * Parameters for the render function
66
- */
67
- export declare interface RenderParams {
68
- moduleName?: string;
69
- basename?: string;
70
- memoryRoute?: {
71
- entryPath: string;
72
- initialState?: Record<string, unknown>;
73
- };
74
- dom: HTMLElement;
75
- /**
76
- * Options to pass to createRoot for React 18 and 19
77
- * @example
78
- * {
79
- * identifierPrefix: 'app-',
80
- * onRecoverableError: (err) => console.error(err)
81
- * }
82
- */
83
- rootOptions?: CreateRootOptions_2;
84
- [key: string]: unknown;
85
- }
86
-
87
- export declare interface Root {
88
- render(children: default_2.ReactNode): void;
89
- unmount(): void;
90
- }
91
-
92
- /**
93
- * Interface for a React root object
94
- */
95
- declare interface Root_2 {
96
- render(children: React_2.ReactNode): void;
97
- unmount(): void;
98
- }
99
-
100
- /**
101
- * Type for a root element, which can be either an HTMLElement or a React root
102
- */
103
- export declare type RootType = HTMLElement | Root_2;
104
-
105
- export { }
106
-
107
-
108
- declare module '@module-federation/runtime-core' {
109
- interface ModuleFederation {
110
- createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
111
- prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
112
- collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
113
- }
114
- }
1
+ export { createBridgeComponent } from './provider/versions/v18';
2
+ export type { CreateRootOptions, Root } from './provider/versions/v18';
3
+ export type { ProviderParams, ProviderFnParams, RootType, DestroyParams, RenderParams, } from './types';