@module-federation/bridge-react 0.15.0 → 0.17.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 (76) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/__tests__/bridge.spec.tsx +7 -7
  3. package/__tests__/createLazyComponent.spec.tsx +210 -0
  4. package/__tests__/prefetch.spec.ts +153 -0
  5. package/__tests__/setupTests.ts +3 -0
  6. package/dist/{bridge-base-P6pEjY1q.js → bridge-base-BoshEggF.mjs} +1 -1
  7. package/dist/{bridge-base-BBH982Tz.cjs → bridge-base-UGCwcMnG.js} +1 -1
  8. package/dist/data-fetch-server-middleware.cjs.js +163 -0
  9. package/dist/data-fetch-server-middleware.d.ts +15 -0
  10. package/dist/data-fetch-server-middleware.es.js +164 -0
  11. package/dist/data-fetch-utils.cjs.js +24 -0
  12. package/dist/data-fetch-utils.d.ts +81 -0
  13. package/dist/data-fetch-utils.es.js +26 -0
  14. package/dist/index-C0fDZB5b.js +45 -0
  15. package/dist/index-CqxytsLY.mjs +46 -0
  16. package/dist/index.cjs.js +35 -9
  17. package/dist/index.d.ts +140 -0
  18. package/dist/index.es.js +38 -12
  19. package/dist/index.esm-BCeUd-x9.mjs +418 -0
  20. package/dist/index.esm-j_1sIRzg.js +417 -0
  21. package/dist/lazy-load-component-plugin-C1tVve-W.js +521 -0
  22. package/dist/lazy-load-component-plugin-PERjiaFJ.mjs +522 -0
  23. package/dist/lazy-load-component-plugin.cjs.js +6 -0
  24. package/dist/lazy-load-component-plugin.d.ts +16 -0
  25. package/dist/lazy-load-component-plugin.es.js +6 -0
  26. package/dist/lazy-utils.cjs.js +24 -0
  27. package/dist/lazy-utils.d.ts +149 -0
  28. package/dist/lazy-utils.es.js +24 -0
  29. package/dist/plugin.d.ts +13 -4
  30. package/dist/prefetch-CZvoIftg.js +1334 -0
  31. package/dist/prefetch-Dux8GUpr.mjs +1335 -0
  32. package/dist/router-v5.cjs.js +1 -1
  33. package/dist/router-v5.d.ts +9 -0
  34. package/dist/router-v5.es.js +1 -1
  35. package/dist/router-v6.cjs.js +1 -1
  36. package/dist/router-v6.d.ts +9 -0
  37. package/dist/router-v6.es.js +1 -1
  38. package/dist/router.cjs.js +1 -1
  39. package/dist/router.d.ts +9 -0
  40. package/dist/router.es.js +1 -1
  41. package/dist/utils-Cy-amYU5.mjs +2016 -0
  42. package/dist/utils-iEVlDmyk.js +2015 -0
  43. package/dist/v18.cjs.js +1 -1
  44. package/dist/v18.d.ts +9 -0
  45. package/dist/v18.es.js +1 -1
  46. package/dist/v19.cjs.js +1 -1
  47. package/dist/v19.d.ts +9 -0
  48. package/dist/v19.es.js +1 -1
  49. package/package.json +47 -5
  50. package/src/index.ts +32 -1
  51. package/src/lazy/AwaitDataFetch.tsx +215 -0
  52. package/src/lazy/constant.ts +30 -0
  53. package/src/lazy/createLazyComponent.tsx +411 -0
  54. package/src/lazy/data-fetch/cache.ts +291 -0
  55. package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
  56. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
  57. package/src/lazy/data-fetch/index.ts +16 -0
  58. package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
  59. package/src/lazy/data-fetch/prefetch.ts +106 -0
  60. package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
  61. package/src/lazy/index.ts +35 -0
  62. package/src/lazy/logger.ts +6 -0
  63. package/src/lazy/types.ts +75 -0
  64. package/src/lazy/utils.ts +372 -0
  65. package/src/lazy/wrapNoSSR.tsx +10 -0
  66. package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
  67. package/src/plugins/lazy-load-component-plugin.ts +57 -0
  68. package/src/provider/plugin.ts +4 -4
  69. package/src/remote/component.tsx +3 -3
  70. package/src/remote/create.tsx +17 -4
  71. package/tsconfig.json +1 -1
  72. package/vite.config.ts +13 -0
  73. package/vitest.config.ts +6 -1
  74. package/dist/index-Cv3p6r66.cjs +0 -235
  75. package/dist/index-D4yt7Udv.js +0 -236
  76. package/src/.eslintrc.js +0 -9
@@ -0,0 +1,522 @@
1
+ import { i as injectDataFetch, p as prefetch } from "./prefetch-Dux8GUpr.mjs";
2
+ import { i as initDataFetchMap, j as isDataLoaderExpose, k as getDataFetchInfo, m as getDataFetchMapKey, l as logger, n as getDataFetchItem, o as DATA_FETCH_CLIENT_SUFFIX, p as MF_DATA_FETCH_TYPE, q as isServerEnv, t as isCSROnly, a as loadDataFetchModule, M as MF_DATA_FETCH_STATUS, g as getDataFetchMap, u as getDataFetchIdWithErrorMsgs, v as DATA_FETCH_ERROR_PREFIX, E as ERROR_TYPE, w as wrapDataFetchId, L as LOAD_REMOTE_ERROR_PREFIX, x as DATA_FETCH_FUNCTION, y as getLoadedRemoteInfos, f as fetchData$1, z as setDataFetchItemLoadedStatus, F as FS_HREF } from "./utils-Cy-amYU5.mjs";
3
+ import React__default, { useRef, useState, Suspense, useEffect } from "react";
4
+ const autoFetchData = () => {
5
+ initDataFetchMap();
6
+ injectDataFetch();
7
+ return {
8
+ name: "auto-fetch-data-plugin",
9
+ afterLoadSnapshot(args) {
10
+ const { id, moduleInfo, remoteSnapshot, host } = args;
11
+ if (typeof id === "string" && isDataLoaderExpose(id)) {
12
+ return args;
13
+ }
14
+ if (!remoteSnapshot || !id || !("modules" in remoteSnapshot)) {
15
+ return args;
16
+ }
17
+ const { name, alias } = moduleInfo;
18
+ const dataFetchInfo = getDataFetchInfo({
19
+ name,
20
+ alias,
21
+ id,
22
+ remoteSnapshot
23
+ });
24
+ if (!dataFetchInfo) {
25
+ return args;
26
+ }
27
+ const { dataFetchId, dataFetchName } = dataFetchInfo;
28
+ const dataFetchMapKey = getDataFetchMapKey(dataFetchInfo, {
29
+ name: host.name,
30
+ version: host.options.version
31
+ });
32
+ logger.debug(
33
+ "======= auto fetch plugin dataFetchMapKey: ",
34
+ dataFetchMapKey
35
+ );
36
+ if (!dataFetchMapKey) {
37
+ return args;
38
+ }
39
+ const dataFetchItem = getDataFetchItem(dataFetchMapKey);
40
+ if (dataFetchItem) {
41
+ return args;
42
+ }
43
+ const dataFetchMap = getDataFetchMap();
44
+ const hasSSRAsset = Boolean(remoteSnapshot.ssrRemoteEntry);
45
+ const hasDataFetchClient = Boolean(
46
+ remoteSnapshot.modules.find(
47
+ (module) => module.moduleName === `${dataFetchName}${DATA_FETCH_CLIENT_SUFFIX}`
48
+ )
49
+ );
50
+ const downgradeType = hasDataFetchClient ? MF_DATA_FETCH_TYPE.FETCH_CLIENT : hasSSRAsset ? MF_DATA_FETCH_TYPE.FETCH_SERVER : MF_DATA_FETCH_TYPE.FETCH_CLIENT;
51
+ let finalDataFetchId = dataFetchId;
52
+ if (!isServerEnv()) {
53
+ finalDataFetchId = downgradeType === MF_DATA_FETCH_TYPE.FETCH_CLIENT ? hasDataFetchClient ? `${dataFetchId}${DATA_FETCH_CLIENT_SUFFIX}` : dataFetchId : dataFetchId;
54
+ }
55
+ const getDataFetchGetter = () => loadDataFetchModule(host, finalDataFetchId);
56
+ const dataFetchFnItem = [
57
+ getDataFetchGetter,
58
+ downgradeType
59
+ ];
60
+ if (typeof window === "undefined" || isCSROnly()) {
61
+ dataFetchFnItem.push(getDataFetchGetter());
62
+ }
63
+ dataFetchMap[dataFetchMapKey] = [
64
+ dataFetchFnItem,
65
+ void 0,
66
+ MF_DATA_FETCH_STATUS.AWAIT
67
+ ];
68
+ return args;
69
+ }
70
+ };
71
+ };
72
+ function isPromise(obj) {
73
+ return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
74
+ }
75
+ const AWAIT_ERROR_PREFIX = "<Await /> caught the following error during render: ";
76
+ const transformError = (err) => {
77
+ const errMsg = err instanceof Error ? err.message : err;
78
+ const originalMsg = errMsg.replace(AWAIT_ERROR_PREFIX, "");
79
+ const dataFetchMapKey = getDataFetchIdWithErrorMsgs(originalMsg);
80
+ if (originalMsg.indexOf(DATA_FETCH_ERROR_PREFIX) === 0) {
81
+ return {
82
+ error: new Error(
83
+ originalMsg.replace(DATA_FETCH_ERROR_PREFIX, "").replace(wrapDataFetchId(dataFetchMapKey), "")
84
+ ),
85
+ errorType: ERROR_TYPE.DATA_FETCH,
86
+ dataFetchMapKey
87
+ };
88
+ }
89
+ if (originalMsg.indexOf(LOAD_REMOTE_ERROR_PREFIX) === 0) {
90
+ return {
91
+ error: new Error(
92
+ originalMsg.replace(LOAD_REMOTE_ERROR_PREFIX, "").replace(wrapDataFetchId(dataFetchMapKey), "")
93
+ ),
94
+ errorType: ERROR_TYPE.LOAD_REMOTE,
95
+ dataFetchMapKey
96
+ };
97
+ }
98
+ return {
99
+ error: new Error(originalMsg.replace(wrapDataFetchId(dataFetchMapKey), "")),
100
+ errorType: ERROR_TYPE.UNKNOWN,
101
+ dataFetchMapKey
102
+ };
103
+ };
104
+ const DefaultLoading = /* @__PURE__ */ React__default.createElement(React__default.Fragment, null);
105
+ const DefaultErrorElement = (_data) => /* @__PURE__ */ React__default.createElement("div", null, "Error");
106
+ function AwaitDataFetch({
107
+ resolve,
108
+ loading = DefaultLoading,
109
+ errorElement = DefaultErrorElement,
110
+ children,
111
+ params,
112
+ delayLoading
113
+ }) {
114
+ const dataRef = useRef();
115
+ const data = dataRef.current || resolve;
116
+ const getData = isPromise(data) ? fetchData(data, dataRef) : () => data;
117
+ return /* @__PURE__ */ React__default.createElement(
118
+ AwaitSuspense,
119
+ {
120
+ params,
121
+ loading,
122
+ errorElement,
123
+ delayLoading,
124
+ resolve: getData
125
+ },
126
+ children
127
+ );
128
+ }
129
+ const DelayedLoading = ({
130
+ delayLoading,
131
+ children
132
+ }) => {
133
+ const [show, setShow] = useState(false);
134
+ const timerSet = useRef(false);
135
+ if (!delayLoading) {
136
+ return children;
137
+ }
138
+ if (typeof window !== "undefined" && !show && !timerSet.current) {
139
+ timerSet.current = true;
140
+ setTimeout(() => {
141
+ setShow(true);
142
+ }, delayLoading);
143
+ }
144
+ return show ? children : null;
145
+ };
146
+ function AwaitSuspense({
147
+ resolve,
148
+ children,
149
+ loading = DefaultLoading,
150
+ errorElement = DefaultErrorElement,
151
+ delayLoading
152
+ }) {
153
+ return /* @__PURE__ */ React__default.createElement(
154
+ Suspense,
155
+ {
156
+ fallback: /* @__PURE__ */ React__default.createElement(DelayedLoading, { delayLoading }, loading)
157
+ },
158
+ /* @__PURE__ */ React__default.createElement(ResolveAwait, { resolve, errorElement }, children)
159
+ );
160
+ }
161
+ function ResolveAwait({
162
+ children,
163
+ resolve,
164
+ errorElement,
165
+ params
166
+ }) {
167
+ const data = resolve();
168
+ logger.debug("resolve data: ", data);
169
+ if (typeof data === "string" && data.indexOf(AWAIT_ERROR_PREFIX) === 0) {
170
+ const transformedError = transformError(data);
171
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, typeof errorElement === "function" ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, globalThis.FEDERATION_SSR && /* @__PURE__ */ React__default.createElement(
172
+ "script",
173
+ {
174
+ suppressHydrationWarning: true,
175
+ dangerouslySetInnerHTML: {
176
+ __html: String.raw`
177
+ globalThis['${DATA_FETCH_FUNCTION}'] = globalThis['${DATA_FETCH_FUNCTION}'] || []
178
+ globalThis['${DATA_FETCH_FUNCTION}'].push([${transformedError.dataFetchMapKey ? `'${transformedError.dataFetchMapKey}'` : ""},${params ? JSON.stringify(params) : null},true]);`
179
+ }
180
+ }
181
+ ), errorElement(transformedError)) : errorElement);
182
+ }
183
+ const toRender = typeof children === "function" ? children(data) : children;
184
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, toRender);
185
+ }
186
+ const fetchData = (promise, ref) => {
187
+ let data;
188
+ let status = "pending";
189
+ const suspender = promise.then((res) => {
190
+ status = "success";
191
+ data = res;
192
+ ref.current = res;
193
+ }).catch((e) => {
194
+ status = "success";
195
+ console.warn(e);
196
+ data = AWAIT_ERROR_PREFIX + e;
197
+ });
198
+ return () => {
199
+ if (status === "pending") {
200
+ throw suspender;
201
+ }
202
+ return data;
203
+ };
204
+ };
205
+ function getTargetModuleInfo(id, instance) {
206
+ if (!instance) {
207
+ return;
208
+ }
209
+ const loadedRemoteInfo = getLoadedRemoteInfos(id, instance);
210
+ if (!loadedRemoteInfo) {
211
+ return;
212
+ }
213
+ const { snapshot } = loadedRemoteInfo;
214
+ if (!snapshot) {
215
+ return;
216
+ }
217
+ const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
218
+ if (!publicPath) {
219
+ return;
220
+ }
221
+ const modules = "modules" in snapshot ? snapshot.modules : [];
222
+ const targetModule = modules.find(
223
+ (m) => m.modulePath === loadedRemoteInfo.expose
224
+ );
225
+ if (!targetModule) {
226
+ return;
227
+ }
228
+ const remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
229
+ if (!remoteEntry) {
230
+ return;
231
+ }
232
+ return {
233
+ module: targetModule,
234
+ publicPath,
235
+ remoteEntry
236
+ };
237
+ }
238
+ function collectSSRAssets(options) {
239
+ const {
240
+ id,
241
+ injectLink = true,
242
+ injectScript = false
243
+ } = typeof options === "string" ? { id: options } : options;
244
+ const links = [];
245
+ const scripts = [];
246
+ const instance = options.instance;
247
+ if (!instance || !injectLink && !injectScript) {
248
+ return [...scripts, ...links];
249
+ }
250
+ const moduleAndPublicPath = getTargetModuleInfo(id, instance);
251
+ if (!moduleAndPublicPath) {
252
+ return [...scripts, ...links];
253
+ }
254
+ const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
255
+ if (injectLink) {
256
+ [...targetModule.assets.css.sync, ...targetModule.assets.css.async].sort().forEach((file, index) => {
257
+ links.push(
258
+ /* @__PURE__ */ React__default.createElement(
259
+ "link",
260
+ {
261
+ key: `${file.split(".")[0]}_${index}`,
262
+ href: `${publicPath}${file}`,
263
+ rel: "stylesheet",
264
+ type: "text/css"
265
+ }
266
+ )
267
+ );
268
+ });
269
+ }
270
+ if (injectScript) {
271
+ scripts.push(
272
+ /* @__PURE__ */ React__default.createElement(
273
+ "script",
274
+ {
275
+ async: true,
276
+ key: remoteEntry.split(".")[0],
277
+ src: `${publicPath}${remoteEntry}`,
278
+ crossOrigin: "anonymous"
279
+ }
280
+ )
281
+ );
282
+ [...targetModule.assets.js.sync].sort().forEach((file, index) => {
283
+ scripts.push(
284
+ /* @__PURE__ */ React__default.createElement(
285
+ "script",
286
+ {
287
+ key: `${file.split(".")[0]}_${index}`,
288
+ async: true,
289
+ src: `${publicPath}${file}`,
290
+ crossOrigin: "anonymous"
291
+ }
292
+ )
293
+ );
294
+ });
295
+ }
296
+ return [...scripts, ...links];
297
+ }
298
+ function getServerNeedRemoteInfo(loadedRemoteInfo, id, noSSR) {
299
+ var _a;
300
+ if (noSSR || typeof window !== "undefined" && window.location.href !== window[FS_HREF]) {
301
+ if (!(loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.version)) {
302
+ throw new Error(`${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} version is empty`);
303
+ }
304
+ const { snapshot } = loadedRemoteInfo;
305
+ if (!snapshot) {
306
+ throw new Error(`${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} snapshot is empty`);
307
+ }
308
+ const dataFetchItem = getDataFetchItem(id);
309
+ const isFetchServer = ((_a = dataFetchItem == null ? void 0 : dataFetchItem[0]) == null ? void 0 : _a[1]) === MF_DATA_FETCH_TYPE.FETCH_SERVER;
310
+ if (isFetchServer && (!("ssrPublicPath" in snapshot) || !snapshot.ssrPublicPath)) {
311
+ throw new Error(
312
+ `ssrPublicPath is required while fetching ${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} data in SSR project!`
313
+ );
314
+ }
315
+ if (isFetchServer && (!("ssrRemoteEntry" in snapshot) || !snapshot.ssrRemoteEntry)) {
316
+ throw new Error(
317
+ `ssrRemoteEntry is required while loading ${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} data loader in SSR project!`
318
+ );
319
+ }
320
+ return {
321
+ name: loadedRemoteInfo.name,
322
+ version: loadedRemoteInfo.version,
323
+ ssrPublicPath: "ssrPublicPath" in snapshot ? snapshot.ssrPublicPath || "" : "",
324
+ ssrRemoteEntry: "ssrRemoteEntry" in snapshot ? snapshot.ssrRemoteEntry || "" : "",
325
+ globalName: loadedRemoteInfo.entryGlobalName
326
+ };
327
+ }
328
+ return void 0;
329
+ }
330
+ function createLazyComponent(options) {
331
+ const { instance, injectScript, injectLink } = options;
332
+ if (!instance) {
333
+ throw new Error("instance is required for createLazyComponent!");
334
+ }
335
+ const exportName = (options == null ? void 0 : options.export) || "default";
336
+ const callLoader = async () => {
337
+ logger.debug("callLoader start", Date.now());
338
+ const m = await options.loader();
339
+ logger.debug("callLoader end", Date.now());
340
+ if (!m) {
341
+ throw new Error("load remote failed");
342
+ }
343
+ return m;
344
+ };
345
+ const getData = async (noSSR) => {
346
+ let loadedRemoteInfo;
347
+ let moduleId;
348
+ try {
349
+ const m = await callLoader();
350
+ moduleId = m && m[Symbol.for("mf_module_id")];
351
+ if (!moduleId) {
352
+ throw new Error("moduleId is empty");
353
+ }
354
+ loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
355
+ if (!loadedRemoteInfo) {
356
+ throw new Error(`can not find loaded remote('${moduleId}') info!`);
357
+ }
358
+ } catch (e) {
359
+ const errMsg = `${LOAD_REMOTE_ERROR_PREFIX}${e}`;
360
+ logger.debug(e);
361
+ throw new Error(errMsg);
362
+ }
363
+ let dataFetchMapKey;
364
+ try {
365
+ dataFetchMapKey = getDataFetchMapKey(
366
+ getDataFetchInfo({
367
+ name: loadedRemoteInfo.name,
368
+ alias: loadedRemoteInfo.alias,
369
+ id: moduleId,
370
+ remoteSnapshot: loadedRemoteInfo.snapshot
371
+ }),
372
+ { name: instance.name, version: instance.options.version }
373
+ );
374
+ logger.debug("getData dataFetchMapKey: ", dataFetchMapKey);
375
+ if (!dataFetchMapKey) {
376
+ return;
377
+ }
378
+ const data = await fetchData$1(
379
+ dataFetchMapKey,
380
+ {
381
+ ...options.dataFetchParams,
382
+ isDowngrade: false
383
+ },
384
+ getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR)
385
+ );
386
+ setDataFetchItemLoadedStatus(dataFetchMapKey);
387
+ logger.debug("get data res: \n", data);
388
+ return data;
389
+ } catch (err) {
390
+ const errMsg = `${DATA_FETCH_ERROR_PREFIX}${wrapDataFetchId(dataFetchMapKey)}${err}`;
391
+ logger.debug(errMsg);
392
+ throw new Error(errMsg);
393
+ }
394
+ };
395
+ const LazyComponent = React__default.lazy(async () => {
396
+ const m = await callLoader();
397
+ const moduleId = m && m[Symbol.for("mf_module_id")];
398
+ const loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
399
+ loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.snapshot;
400
+ const dataFetchMapKey = loadedRemoteInfo ? getDataFetchMapKey(
401
+ getDataFetchInfo({
402
+ name: loadedRemoteInfo.name,
403
+ alias: loadedRemoteInfo.alias,
404
+ id: moduleId,
405
+ remoteSnapshot: loadedRemoteInfo.snapshot
406
+ }),
407
+ { name: instance.name, version: instance == null ? void 0 : instance.options.version }
408
+ ) : void 0;
409
+ logger.debug("LazyComponent dataFetchMapKey: ", dataFetchMapKey);
410
+ const assets = collectSSRAssets({
411
+ id: moduleId,
412
+ instance,
413
+ injectLink,
414
+ injectScript
415
+ });
416
+ const Com = m[exportName];
417
+ if (exportName in m && typeof Com === "function") {
418
+ return {
419
+ default: (props) => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, globalThis.FEDERATION_SSR && dataFetchMapKey && /* @__PURE__ */ React__default.createElement(
420
+ "script",
421
+ {
422
+ suppressHydrationWarning: true,
423
+ dangerouslySetInnerHTML: {
424
+ __html: String.raw`
425
+ globalThis['${DATA_FETCH_FUNCTION}'] = globalThis['${DATA_FETCH_FUNCTION}'] || [];
426
+ globalThis['${DATA_FETCH_FUNCTION}'].push(['${dataFetchMapKey}',${JSON.stringify(props.mfData)}]);
427
+ `
428
+ }
429
+ }
430
+ ), globalThis.FEDERATION_SSR && assets, /* @__PURE__ */ React__default.createElement(Com, { ...props }))
431
+ };
432
+ } else {
433
+ throw Error(
434
+ `Make sure that ${moduleId} has the correct export when export is ${String(
435
+ exportName
436
+ )}`
437
+ );
438
+ }
439
+ });
440
+ return (props) => {
441
+ const { key, ...args } = props;
442
+ if (!options.noSSR) {
443
+ return /* @__PURE__ */ React__default.createElement(
444
+ AwaitDataFetch,
445
+ {
446
+ resolve: getData(options.noSSR),
447
+ loading: options.loading,
448
+ delayLoading: options.delayLoading,
449
+ errorElement: options.fallback
450
+ },
451
+ (data) => /* @__PURE__ */ React__default.createElement(LazyComponent, { ...args, mfData: data })
452
+ );
453
+ } else {
454
+ const [data, setData] = useState(null);
455
+ const [loading, setLoading] = useState(true);
456
+ const [error, setError] = useState(null);
457
+ useEffect(() => {
458
+ let isMounted = true;
459
+ const fetchDataAsync = async () => {
460
+ try {
461
+ setLoading(true);
462
+ const result = await getData(options.noSSR);
463
+ if (isMounted) {
464
+ setData(result);
465
+ }
466
+ } catch (e) {
467
+ if (isMounted) {
468
+ setError(transformError(e));
469
+ }
470
+ } finally {
471
+ if (isMounted) {
472
+ setLoading(false);
473
+ }
474
+ }
475
+ };
476
+ fetchDataAsync();
477
+ return () => {
478
+ isMounted = false;
479
+ };
480
+ }, []);
481
+ if (loading) {
482
+ return /* @__PURE__ */ React__default.createElement(DelayedLoading, { delayLoading: options.delayLoading }, options.loading);
483
+ }
484
+ if (error) {
485
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, typeof options.fallback === "function" ? options.fallback(error) : options.fallback);
486
+ }
487
+ return /* @__PURE__ */ React__default.createElement(LazyComponent, { ...args, mfData: data });
488
+ }
489
+ };
490
+ }
491
+ function lazyLoadComponentPlugin() {
492
+ return {
493
+ name: "lazy-load-component-plugin",
494
+ apply(instance) {
495
+ instance.registerPlugins([autoFetchData()]);
496
+ instance.createLazyComponent = (options) => {
497
+ return createLazyComponent({
498
+ instance,
499
+ ...options
500
+ });
501
+ };
502
+ instance.prefetch = (options) => {
503
+ return prefetch({
504
+ instance,
505
+ ...options
506
+ });
507
+ };
508
+ instance.collectSSRAssets = (options) => {
509
+ return collectSSRAssets({
510
+ instance,
511
+ ...options
512
+ });
513
+ };
514
+ }
515
+ };
516
+ }
517
+ export {
518
+ collectSSRAssets as a,
519
+ autoFetchData as b,
520
+ createLazyComponent as c,
521
+ lazyLoadComponentPlugin as l
522
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-C1tVve-W.js");
4
+ require("./prefetch-CZvoIftg.js");
5
+ exports.default = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
6
+ exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
@@ -0,0 +1,16 @@
1
+ import { FederationRuntimePlugin } from '@module-federation/runtime';
2
+
3
+ declare function lazyLoadComponentPlugin(): FederationRuntimePlugin;
4
+ export default lazyLoadComponentPlugin;
5
+ export { lazyLoadComponentPlugin }
6
+
7
+ export { }
8
+
9
+
10
+ declare module '@module-federation/runtime-core' {
11
+ interface ModuleFederation {
12
+ createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
13
+ prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
14
+ collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
15
+ }
16
+ }
@@ -0,0 +1,6 @@
1
+ import { l, l as l2 } from "./lazy-load-component-plugin-PERjiaFJ.mjs";
2
+ import "./prefetch-Dux8GUpr.mjs";
3
+ export {
4
+ l as default,
5
+ l2 as lazyLoadComponentPlugin
6
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("./index.esm-j_1sIRzg.js");
4
+ const lazyUtils = require("./utils-iEVlDmyk.js");
5
+ exports.callAllDowngrade = lazyUtils.callAllDowngrade;
6
+ exports.callDowngrade = lazyUtils.callDowngrade;
7
+ exports.fetchData = lazyUtils.fetchData;
8
+ exports.flushDataFetch = lazyUtils.flushDataFetch;
9
+ exports.getDataFetchCache = lazyUtils.getDataFetchCache;
10
+ exports.getDataFetchIdWithErrorMsgs = lazyUtils.getDataFetchIdWithErrorMsgs;
11
+ exports.getDataFetchInfo = lazyUtils.getDataFetchInfo;
12
+ exports.getDataFetchItem = lazyUtils.getDataFetchItem;
13
+ exports.getDataFetchMap = lazyUtils.getDataFetchMap;
14
+ exports.getDataFetchMapKey = lazyUtils.getDataFetchMapKey;
15
+ exports.getDowngradeTag = lazyUtils.getDowngradeTag;
16
+ exports.getLoadedRemoteInfos = lazyUtils.getLoadedRemoteInfos;
17
+ exports.initDataFetchMap = lazyUtils.initDataFetchMap;
18
+ exports.isCSROnly = lazyUtils.isCSROnly;
19
+ exports.isDataLoaderExpose = lazyUtils.isDataLoaderExpose;
20
+ exports.isServerEnv = lazyUtils.isServerEnv;
21
+ exports.loadDataFetchModule = lazyUtils.loadDataFetchModule;
22
+ exports.setDataFetchItemLoadedStatus = lazyUtils.setDataFetchItemLoadedStatus;
23
+ exports.setSSREnv = lazyUtils.setSSREnv;
24
+ exports.wrapDataFetchId = lazyUtils.wrapDataFetchId;