@module-federation/bridge-react 0.0.0-next-20250708033956 → 0.0.0-next-20250708104625
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/CHANGELOG.md +3 -3
- package/dist/data-fetch-server-middleware.d.ts +9 -0
- package/dist/data-fetch-server-middleware.es.js +1 -1
- package/dist/data-fetch-utils.cjs.js +4 -1253
- package/dist/data-fetch-utils.d.ts +10 -1
- package/dist/data-fetch-utils.es.js +11 -1260
- package/dist/index.cjs.js +7 -433
- package/dist/index.d.ts +11 -11
- package/dist/index.es.js +20 -447
- package/dist/lazy-load-component-plugin-CttAWi8N.js +500 -0
- package/dist/lazy-load-component-plugin-hOC-Yus_.mjs +501 -0
- package/dist/lazy-load-component-plugin.cjs.js +6 -0
- package/dist/lazy-load-component-plugin.d.ts +16 -0
- package/dist/lazy-load-component-plugin.es.js +6 -0
- package/dist/lazy-utils.d.ts +9 -0
- package/dist/lazy-utils.es.js +19 -19
- package/dist/plugin.d.ts +9 -0
- package/dist/prefetch-Cx6MrkdU.mjs +1330 -0
- package/dist/prefetch-cGDaDkgV.js +1329 -0
- package/dist/router-v5.d.ts +9 -0
- package/dist/router-v6.d.ts +9 -0
- package/dist/router.d.ts +9 -0
- package/dist/{utils-Bk8hGjjF.mjs → utils-BTYYwZcb.mjs} +31 -31
- package/dist/v18.d.ts +9 -0
- package/dist/v19.d.ts +9 -0
- package/package.json +11 -11
- package/src/index.ts +3 -1
- package/src/lazy/createLazyComponent.tsx +88 -74
- package/src/lazy/data-fetch/index.ts +1 -0
- package/src/lazy/data-fetch/prefetch.ts +1 -1
- package/src/lazy/data-fetch/runtime-plugin.ts +80 -81
- package/src/lazy/index.ts +6 -2
- package/src/plugins/lazy-load-component-plugin.ts +72 -0
- package/vite.config.ts +2 -2
- package/dist/data-fetch-runtime-plugin.cjs.js +0 -73
- package/dist/data-fetch-runtime-plugin.d.ts +0 -6
- package/dist/data-fetch-runtime-plugin.es.js +0 -74
- package/dist/inject-data-fetch-CAvi-gSf.js +0 -79
- package/dist/inject-data-fetch-errCdqBS.mjs +0 -80
- package/src/.eslintrc.js +0 -9
package/dist/index.cjs.js
CHANGED
|
@@ -6,9 +6,10 @@ const React = require("react");
|
|
|
6
6
|
const index = require("./index-C0fDZB5b.js");
|
|
7
7
|
const ReactRouterDOM = require("react-router-dom");
|
|
8
8
|
const plugin = require("./plugin.cjs.js");
|
|
9
|
-
const
|
|
9
|
+
const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-CttAWi8N.js");
|
|
10
10
|
const lazyUtils = require("./utils-iEVlDmyk.js");
|
|
11
11
|
const dataFetchUtils = require("./data-fetch-utils.cjs.js");
|
|
12
|
+
const prefetch = require("./prefetch-cGDaDkgV.js");
|
|
12
13
|
function _interopNamespaceDefault(e2) {
|
|
13
14
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
14
15
|
if (e2) {
|
|
@@ -270,434 +271,10 @@ function createRemoteComponent(info) {
|
|
|
270
271
|
);
|
|
271
272
|
return createRemoteAppComponent(info);
|
|
272
273
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const transformError = (err) => {
|
|
278
|
-
const errMsg = err instanceof Error ? err.message : err;
|
|
279
|
-
const originalMsg = errMsg.replace(AWAIT_ERROR_PREFIX, "");
|
|
280
|
-
const dataFetchMapKey = lazyUtils.getDataFetchIdWithErrorMsgs(originalMsg);
|
|
281
|
-
if (originalMsg.indexOf(lazyUtils.DATA_FETCH_ERROR_PREFIX) === 0) {
|
|
282
|
-
return {
|
|
283
|
-
error: new Error(
|
|
284
|
-
originalMsg.replace(lazyUtils.DATA_FETCH_ERROR_PREFIX, "").replace(lazyUtils.wrapDataFetchId(dataFetchMapKey), "")
|
|
285
|
-
),
|
|
286
|
-
errorType: lazyUtils.ERROR_TYPE.DATA_FETCH,
|
|
287
|
-
dataFetchMapKey
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
if (originalMsg.indexOf(lazyUtils.LOAD_REMOTE_ERROR_PREFIX) === 0) {
|
|
291
|
-
return {
|
|
292
|
-
error: new Error(
|
|
293
|
-
originalMsg.replace(lazyUtils.LOAD_REMOTE_ERROR_PREFIX, "").replace(lazyUtils.wrapDataFetchId(dataFetchMapKey), "")
|
|
294
|
-
),
|
|
295
|
-
errorType: lazyUtils.ERROR_TYPE.LOAD_REMOTE,
|
|
296
|
-
dataFetchMapKey
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
return {
|
|
300
|
-
error: new Error(originalMsg.replace(lazyUtils.wrapDataFetchId(dataFetchMapKey), "")),
|
|
301
|
-
errorType: lazyUtils.ERROR_TYPE.UNKNOWN,
|
|
302
|
-
dataFetchMapKey
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
|
-
const DefaultLoading = /* @__PURE__ */ React.createElement(React.Fragment, null);
|
|
306
|
-
const DefaultErrorElement = (_data) => /* @__PURE__ */ React.createElement("div", null, "Error");
|
|
307
|
-
function AwaitDataFetch({
|
|
308
|
-
resolve,
|
|
309
|
-
loading = DefaultLoading,
|
|
310
|
-
errorElement = DefaultErrorElement,
|
|
311
|
-
children,
|
|
312
|
-
params,
|
|
313
|
-
delayLoading
|
|
314
|
-
}) {
|
|
315
|
-
const dataRef = React.useRef();
|
|
316
|
-
const data = dataRef.current || resolve;
|
|
317
|
-
const getData = isPromise(data) ? fetchData(data, dataRef) : () => data;
|
|
318
|
-
return /* @__PURE__ */ React.createElement(
|
|
319
|
-
AwaitSuspense,
|
|
320
|
-
{
|
|
321
|
-
params,
|
|
322
|
-
loading,
|
|
323
|
-
errorElement,
|
|
324
|
-
delayLoading,
|
|
325
|
-
resolve: getData
|
|
326
|
-
},
|
|
327
|
-
children
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
const DelayedLoading = ({
|
|
331
|
-
delayLoading,
|
|
332
|
-
children
|
|
333
|
-
}) => {
|
|
334
|
-
const [show, setShow] = React.useState(false);
|
|
335
|
-
const timerSet = React.useRef(false);
|
|
336
|
-
if (!delayLoading) {
|
|
337
|
-
return children;
|
|
338
|
-
}
|
|
339
|
-
if (typeof window !== "undefined" && !show && !timerSet.current) {
|
|
340
|
-
timerSet.current = true;
|
|
341
|
-
setTimeout(() => {
|
|
342
|
-
setShow(true);
|
|
343
|
-
}, delayLoading);
|
|
344
|
-
}
|
|
345
|
-
return show ? children : null;
|
|
346
|
-
};
|
|
347
|
-
function AwaitSuspense({
|
|
348
|
-
resolve,
|
|
349
|
-
children,
|
|
350
|
-
loading = DefaultLoading,
|
|
351
|
-
errorElement = DefaultErrorElement,
|
|
352
|
-
delayLoading
|
|
353
|
-
}) {
|
|
354
|
-
return /* @__PURE__ */ React.createElement(
|
|
355
|
-
React.Suspense,
|
|
356
|
-
{
|
|
357
|
-
fallback: /* @__PURE__ */ React.createElement(DelayedLoading, { delayLoading }, loading)
|
|
358
|
-
},
|
|
359
|
-
/* @__PURE__ */ React.createElement(ResolveAwait, { resolve, errorElement }, children)
|
|
360
|
-
);
|
|
361
|
-
}
|
|
362
|
-
function ResolveAwait({
|
|
363
|
-
children,
|
|
364
|
-
resolve,
|
|
365
|
-
errorElement,
|
|
366
|
-
params
|
|
367
|
-
}) {
|
|
368
|
-
const data = resolve();
|
|
369
|
-
lazyUtils.logger.debug("resolve data: ", data);
|
|
370
|
-
if (typeof data === "string" && data.indexOf(AWAIT_ERROR_PREFIX) === 0) {
|
|
371
|
-
const transformedError = transformError(data);
|
|
372
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, typeof errorElement === "function" ? /* @__PURE__ */ React.createElement(React.Fragment, null, globalThis.FEDERATION_SSR && /* @__PURE__ */ React.createElement(
|
|
373
|
-
"script",
|
|
374
|
-
{
|
|
375
|
-
suppressHydrationWarning: true,
|
|
376
|
-
dangerouslySetInnerHTML: {
|
|
377
|
-
__html: String.raw`
|
|
378
|
-
globalThis['${lazyUtils.DATA_FETCH_FUNCTION}'] = globalThis['${lazyUtils.DATA_FETCH_FUNCTION}'] || []
|
|
379
|
-
globalThis['${lazyUtils.DATA_FETCH_FUNCTION}'].push([${transformedError.dataFetchMapKey ? `'${transformedError.dataFetchMapKey}'` : ""},${params ? JSON.stringify(params) : null},true]);`
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
), errorElement(transformedError)) : errorElement);
|
|
383
|
-
}
|
|
384
|
-
const toRender = typeof children === "function" ? children(data) : children;
|
|
385
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, toRender);
|
|
386
|
-
}
|
|
387
|
-
const fetchData = (promise, ref) => {
|
|
388
|
-
let data;
|
|
389
|
-
let status = "pending";
|
|
390
|
-
const suspender = promise.then((res) => {
|
|
391
|
-
status = "success";
|
|
392
|
-
data = res;
|
|
393
|
-
ref.current = res;
|
|
394
|
-
}).catch((e2) => {
|
|
395
|
-
status = "success";
|
|
396
|
-
console.warn(e2);
|
|
397
|
-
data = AWAIT_ERROR_PREFIX + e2;
|
|
398
|
-
});
|
|
399
|
-
return () => {
|
|
400
|
-
if (status === "pending") {
|
|
401
|
-
throw suspender;
|
|
402
|
-
}
|
|
403
|
-
return data;
|
|
404
|
-
};
|
|
405
|
-
};
|
|
406
|
-
function getTargetModuleInfo(id, instance) {
|
|
407
|
-
if (!instance) {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
const loadedRemoteInfo = lazyUtils.getLoadedRemoteInfos(id, instance);
|
|
411
|
-
if (!loadedRemoteInfo) {
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
const snapshot = loadedRemoteInfo.snapshot;
|
|
415
|
-
if (!snapshot) {
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
|
|
419
|
-
if (!publicPath) {
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
const modules = "modules" in snapshot ? snapshot.modules : [];
|
|
423
|
-
const targetModule = modules.find(
|
|
424
|
-
(m) => m.modulePath === loadedRemoteInfo.expose
|
|
425
|
-
);
|
|
426
|
-
if (!targetModule) {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
const remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
|
|
430
|
-
if (!remoteEntry) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
return {
|
|
434
|
-
module: targetModule,
|
|
435
|
-
publicPath,
|
|
436
|
-
remoteEntry
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
function collectSSRAssets(options) {
|
|
440
|
-
const {
|
|
441
|
-
id,
|
|
442
|
-
injectLink = true,
|
|
443
|
-
injectScript = false
|
|
444
|
-
} = typeof options === "string" ? { id: options } : options;
|
|
445
|
-
const links = [];
|
|
446
|
-
const scripts = [];
|
|
447
|
-
const instance = options.instance;
|
|
448
|
-
if (!instance || !injectLink && !injectScript) {
|
|
449
|
-
return [...scripts, ...links];
|
|
450
|
-
}
|
|
451
|
-
const moduleAndPublicPath = getTargetModuleInfo(id, instance);
|
|
452
|
-
if (!moduleAndPublicPath) {
|
|
453
|
-
return [...scripts, ...links];
|
|
454
|
-
}
|
|
455
|
-
const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
|
|
456
|
-
if (injectLink) {
|
|
457
|
-
[...targetModule.assets.css.sync, ...targetModule.assets.css.async].sort().forEach((file, index2) => {
|
|
458
|
-
links.push(
|
|
459
|
-
/* @__PURE__ */ React.createElement(
|
|
460
|
-
"link",
|
|
461
|
-
{
|
|
462
|
-
key: `${file.split(".")[0]}_${index2}`,
|
|
463
|
-
href: `${publicPath}${file}`,
|
|
464
|
-
rel: "stylesheet",
|
|
465
|
-
type: "text/css"
|
|
466
|
-
}
|
|
467
|
-
)
|
|
468
|
-
);
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
if (injectScript) {
|
|
472
|
-
scripts.push(
|
|
473
|
-
/* @__PURE__ */ React.createElement(
|
|
474
|
-
"script",
|
|
475
|
-
{
|
|
476
|
-
async: true,
|
|
477
|
-
key: remoteEntry.split(".")[0],
|
|
478
|
-
src: `${publicPath}${remoteEntry}`,
|
|
479
|
-
crossOrigin: "anonymous"
|
|
480
|
-
}
|
|
481
|
-
)
|
|
482
|
-
);
|
|
483
|
-
[...targetModule.assets.js.sync].sort().forEach((file, index2) => {
|
|
484
|
-
scripts.push(
|
|
485
|
-
/* @__PURE__ */ React.createElement(
|
|
486
|
-
"script",
|
|
487
|
-
{
|
|
488
|
-
key: `${file.split(".")[0]}_${index2}`,
|
|
489
|
-
async: true,
|
|
490
|
-
src: `${publicPath}${file}`,
|
|
491
|
-
crossOrigin: "anonymous"
|
|
492
|
-
}
|
|
493
|
-
)
|
|
494
|
-
);
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
return [...scripts, ...links];
|
|
498
|
-
}
|
|
499
|
-
function getServerNeedRemoteInfo(loadedRemoteInfo, id, noSSR) {
|
|
500
|
-
var _a;
|
|
501
|
-
if (noSSR || typeof window !== "undefined" && window.location.href !== window[lazyUtils.FS_HREF]) {
|
|
502
|
-
if (!(loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.version)) {
|
|
503
|
-
throw new Error(`${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} version is empty`);
|
|
504
|
-
}
|
|
505
|
-
const { snapshot } = loadedRemoteInfo;
|
|
506
|
-
if (!snapshot) {
|
|
507
|
-
throw new Error(`${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} snapshot is empty`);
|
|
508
|
-
}
|
|
509
|
-
const dataFetchItem = lazyUtils.getDataFetchItem(id);
|
|
510
|
-
const isFetchServer = ((_a = dataFetchItem == null ? void 0 : dataFetchItem[0]) == null ? void 0 : _a[1]) === lazyUtils.MF_DATA_FETCH_TYPE.FETCH_SERVER;
|
|
511
|
-
if (isFetchServer && (!("ssrPublicPath" in snapshot) || !snapshot.ssrPublicPath)) {
|
|
512
|
-
throw new Error(
|
|
513
|
-
`ssrPublicPath is required while fetching ${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} data in SSR project!`
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
if (isFetchServer && (!("ssrRemoteEntry" in snapshot) || !snapshot.ssrRemoteEntry)) {
|
|
517
|
-
throw new Error(
|
|
518
|
-
`ssrRemoteEntry is required while loading ${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} data loader in SSR project!`
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
return {
|
|
522
|
-
name: loadedRemoteInfo.name,
|
|
523
|
-
version: loadedRemoteInfo.version,
|
|
524
|
-
ssrPublicPath: "ssrPublicPath" in snapshot ? snapshot.ssrPublicPath || "" : "",
|
|
525
|
-
ssrRemoteEntry: "ssrRemoteEntry" in snapshot ? snapshot.ssrRemoteEntry || "" : "",
|
|
526
|
-
globalName: loadedRemoteInfo.entryGlobalName
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
return void 0;
|
|
530
|
-
}
|
|
531
|
-
function createLazyComponent(options) {
|
|
532
|
-
const { instance, cacheData } = options;
|
|
533
|
-
if (!instance) {
|
|
534
|
-
throw new Error("instance is required for createLazyComponent!");
|
|
535
|
-
}
|
|
536
|
-
let dataCache = null;
|
|
537
|
-
const exportName = (options == null ? void 0 : options.export) || "default";
|
|
538
|
-
const callLoader = async () => {
|
|
539
|
-
lazyUtils.logger.debug("callLoader start", Date.now());
|
|
540
|
-
const m = await options.loader();
|
|
541
|
-
lazyUtils.logger.debug("callLoader end", Date.now());
|
|
542
|
-
if (!m) {
|
|
543
|
-
throw new Error("load remote failed");
|
|
544
|
-
}
|
|
545
|
-
return m;
|
|
546
|
-
};
|
|
547
|
-
const getData = async (noSSR) => {
|
|
548
|
-
let loadedRemoteInfo;
|
|
549
|
-
let moduleId;
|
|
550
|
-
try {
|
|
551
|
-
const m = await callLoader();
|
|
552
|
-
moduleId = m && m[Symbol.for("mf_module_id")];
|
|
553
|
-
if (!moduleId) {
|
|
554
|
-
throw new Error("moduleId is empty");
|
|
555
|
-
}
|
|
556
|
-
loadedRemoteInfo = lazyUtils.getLoadedRemoteInfos(moduleId, instance);
|
|
557
|
-
if (!loadedRemoteInfo) {
|
|
558
|
-
throw new Error(`can not find loaded remote('${moduleId}') info!`);
|
|
559
|
-
}
|
|
560
|
-
} catch (e2) {
|
|
561
|
-
const errMsg = `${lazyUtils.LOAD_REMOTE_ERROR_PREFIX}${e2}`;
|
|
562
|
-
lazyUtils.logger.debug(e2);
|
|
563
|
-
throw new Error(errMsg);
|
|
564
|
-
}
|
|
565
|
-
let dataFetchMapKey;
|
|
566
|
-
try {
|
|
567
|
-
dataFetchMapKey = lazyUtils.getDataFetchMapKey(
|
|
568
|
-
lazyUtils.getDataFetchInfo({
|
|
569
|
-
name: loadedRemoteInfo.name,
|
|
570
|
-
alias: loadedRemoteInfo.alias,
|
|
571
|
-
id: moduleId,
|
|
572
|
-
remoteSnapshot: loadedRemoteInfo.snapshot
|
|
573
|
-
}),
|
|
574
|
-
{ name: instance.name, version: instance.options.version }
|
|
575
|
-
);
|
|
576
|
-
lazyUtils.logger.debug("getData dataFetchMapKey: ", dataFetchMapKey);
|
|
577
|
-
if (!dataFetchMapKey) {
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
const data = await lazyUtils.fetchData(
|
|
581
|
-
dataFetchMapKey,
|
|
582
|
-
{
|
|
583
|
-
...options.dataFetchParams,
|
|
584
|
-
isDowngrade: false
|
|
585
|
-
},
|
|
586
|
-
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR)
|
|
587
|
-
);
|
|
588
|
-
lazyUtils.setDataFetchItemLoadedStatus(dataFetchMapKey);
|
|
589
|
-
lazyUtils.logger.debug("get data res: \n", data);
|
|
590
|
-
dataCache = data;
|
|
591
|
-
return data;
|
|
592
|
-
} catch (err) {
|
|
593
|
-
const errMsg = `${lazyUtils.DATA_FETCH_ERROR_PREFIX}${lazyUtils.wrapDataFetchId(dataFetchMapKey)}${err}`;
|
|
594
|
-
lazyUtils.logger.debug(errMsg);
|
|
595
|
-
throw new Error(errMsg);
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
const LazyComponent = React.lazy(async () => {
|
|
599
|
-
const m = await callLoader();
|
|
600
|
-
const moduleId = m && m[Symbol.for("mf_module_id")];
|
|
601
|
-
const loadedRemoteInfo = lazyUtils.getLoadedRemoteInfos(moduleId, instance);
|
|
602
|
-
loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.snapshot;
|
|
603
|
-
const dataFetchMapKey = loadedRemoteInfo ? lazyUtils.getDataFetchMapKey(
|
|
604
|
-
lazyUtils.getDataFetchInfo({
|
|
605
|
-
name: loadedRemoteInfo.name,
|
|
606
|
-
alias: loadedRemoteInfo.alias,
|
|
607
|
-
id: moduleId,
|
|
608
|
-
remoteSnapshot: loadedRemoteInfo.snapshot
|
|
609
|
-
}),
|
|
610
|
-
{ name: instance.name, version: instance == null ? void 0 : instance.options.version }
|
|
611
|
-
) : void 0;
|
|
612
|
-
lazyUtils.logger.debug("LazyComponent dataFetchMapKey: ", dataFetchMapKey);
|
|
613
|
-
const assets = collectSSRAssets({
|
|
614
|
-
id: moduleId,
|
|
615
|
-
instance
|
|
616
|
-
});
|
|
617
|
-
const Com = m[exportName];
|
|
618
|
-
if (exportName in m && typeof Com === "function") {
|
|
619
|
-
return {
|
|
620
|
-
default: (props) => /* @__PURE__ */ React.createElement(React.Fragment, null, globalThis.FEDERATION_SSR && dataFetchMapKey && /* @__PURE__ */ React.createElement(
|
|
621
|
-
"script",
|
|
622
|
-
{
|
|
623
|
-
suppressHydrationWarning: true,
|
|
624
|
-
dangerouslySetInnerHTML: {
|
|
625
|
-
__html: String.raw`
|
|
626
|
-
globalThis['${lazyUtils.DATA_FETCH_FUNCTION}'] = globalThis['${lazyUtils.DATA_FETCH_FUNCTION}'] || [];
|
|
627
|
-
globalThis['${lazyUtils.DATA_FETCH_FUNCTION}'].push(['${dataFetchMapKey}',${JSON.stringify(props.mfData)}]);
|
|
628
|
-
`
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
), globalThis.FEDERATION_SSR && assets, /* @__PURE__ */ React.createElement(Com, { ...props }))
|
|
632
|
-
};
|
|
633
|
-
} else {
|
|
634
|
-
throw Error(
|
|
635
|
-
`Make sure that ${moduleId} has the correct export when export is ${String(
|
|
636
|
-
exportName
|
|
637
|
-
)}`
|
|
638
|
-
);
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
return (props) => {
|
|
642
|
-
const { key, ...args } = props;
|
|
643
|
-
if (cacheData && dataCache) {
|
|
644
|
-
return /* @__PURE__ */ React.createElement(LazyComponent, { ...args, mfData: dataCache });
|
|
645
|
-
}
|
|
646
|
-
if (!options.noSSR) {
|
|
647
|
-
return /* @__PURE__ */ React.createElement(
|
|
648
|
-
AwaitDataFetch,
|
|
649
|
-
{
|
|
650
|
-
resolve: getData(options.noSSR),
|
|
651
|
-
loading: options.loading,
|
|
652
|
-
delayLoading: options.delayLoading,
|
|
653
|
-
errorElement: options.fallback
|
|
654
|
-
},
|
|
655
|
-
(data) => /* @__PURE__ */ React.createElement(LazyComponent, { ...args, mfData: data })
|
|
656
|
-
);
|
|
657
|
-
} else {
|
|
658
|
-
const [data, setData] = React.useState(null);
|
|
659
|
-
const [loading, setLoading] = React.useState(true);
|
|
660
|
-
const [error, setError] = React.useState(null);
|
|
661
|
-
React.useEffect(() => {
|
|
662
|
-
let isMounted = true;
|
|
663
|
-
const fetchDataAsync = async () => {
|
|
664
|
-
try {
|
|
665
|
-
setLoading(true);
|
|
666
|
-
const result = await getData(options.noSSR);
|
|
667
|
-
if (isMounted) {
|
|
668
|
-
setData(result);
|
|
669
|
-
}
|
|
670
|
-
} catch (e2) {
|
|
671
|
-
if (isMounted) {
|
|
672
|
-
setError(transformError(e2));
|
|
673
|
-
}
|
|
674
|
-
} finally {
|
|
675
|
-
if (isMounted) {
|
|
676
|
-
setLoading(false);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
fetchDataAsync();
|
|
681
|
-
return () => {
|
|
682
|
-
isMounted = false;
|
|
683
|
-
};
|
|
684
|
-
}, []);
|
|
685
|
-
if (loading) {
|
|
686
|
-
return /* @__PURE__ */ React.createElement(DelayedLoading, { delayLoading: options.delayLoading }, options.loading);
|
|
687
|
-
}
|
|
688
|
-
if (error) {
|
|
689
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, typeof options.fallback === "function" ? options.fallback(error) : options.fallback);
|
|
690
|
-
}
|
|
691
|
-
return /* @__PURE__ */ React.createElement(LazyComponent, { ...args, mfData: data });
|
|
692
|
-
}
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
function wrapNoSSR(createLazyComponentFn) {
|
|
696
|
-
return (options) => {
|
|
697
|
-
return createLazyComponentFn({ ...options, noSSR: true });
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
exports.autoFetchDataPlugin = dataFetchRuntimePlugin;
|
|
274
|
+
exports.autoFetchDataPlugin = lazyLoadComponentPlugin.autoFetchData;
|
|
275
|
+
exports.collectSSRAssets = lazyLoadComponentPlugin.collectSSRAssets;
|
|
276
|
+
exports.createLazyComponent = lazyLoadComponentPlugin.createLazyComponent;
|
|
277
|
+
exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
|
|
701
278
|
exports.CacheSize = lazyUtils.CacheSize;
|
|
702
279
|
exports.CacheTime = lazyUtils.CacheTime;
|
|
703
280
|
exports.ERROR_TYPE = lazyUtils.ERROR_TYPE;
|
|
@@ -708,10 +285,7 @@ exports.generateKey = lazyUtils.generateKey;
|
|
|
708
285
|
exports.revalidateTag = lazyUtils.revalidateTag;
|
|
709
286
|
exports.setSSREnv = lazyUtils.setSSREnv;
|
|
710
287
|
exports.callDataFetch = dataFetchUtils.callDataFetch;
|
|
711
|
-
exports.prefetch =
|
|
712
|
-
exports.collectSSRAssets = collectSSRAssets;
|
|
288
|
+
exports.prefetch = prefetch.prefetch;
|
|
713
289
|
exports.createBridgeComponent = createBridgeComponent;
|
|
714
|
-
exports.createLazyComponent = createLazyComponent;
|
|
715
290
|
exports.createRemoteAppComponent = createRemoteAppComponent;
|
|
716
291
|
exports.createRemoteComponent = createRemoteComponent;
|
|
717
|
-
exports.wrapNoSSR = wrapNoSSR;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { default as default_2 } from 'react';
|
|
2
2
|
import { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
3
3
|
import { getInstance } from '@module-federation/runtime';
|
|
4
|
-
import { JSX as JSX_2 } from 'react';
|
|
5
|
-
import { Key } from 'react';
|
|
6
4
|
import * as React_2 from 'react';
|
|
7
5
|
import { ReactNode } from 'react';
|
|
8
6
|
|
|
@@ -84,7 +82,6 @@ export declare type CreateLazyComponentOptions<T, E extends keyof T> = {
|
|
|
84
82
|
fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
|
|
85
83
|
export?: E;
|
|
86
84
|
dataFetchParams?: DataFetchParams;
|
|
87
|
-
noSSR?: boolean;
|
|
88
85
|
cacheData?: boolean;
|
|
89
86
|
};
|
|
90
87
|
|
|
@@ -138,6 +135,8 @@ declare type ErrorInfo = {
|
|
|
138
135
|
|
|
139
136
|
export declare function generateKey(dataFetchOptions: DataFetchParams): string;
|
|
140
137
|
|
|
138
|
+
export declare function lazyLoadComponentPlugin(): FederationRuntimePlugin;
|
|
139
|
+
|
|
141
140
|
declare type LazyRemoteComponentInfo<T, E extends keyof T> = RemoteComponentParams<T>;
|
|
142
141
|
|
|
143
142
|
export declare type NoSSRRemoteInfo = {
|
|
@@ -266,12 +265,13 @@ export declare function setSSREnv({ fetchServerQuery, }: {
|
|
|
266
265
|
fetchServerQuery?: Record<string, unknown>;
|
|
267
266
|
}): void;
|
|
268
267
|
|
|
269
|
-
export declare function wrapNoSSR<T, E extends keyof T>(createLazyComponentFn: typeof createLazyComponent<T, E>): (options: Omit<CreateLazyComponentOptions<T, E>, "noSSR">) => (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? {
|
|
270
|
-
key?: Key | null;
|
|
271
|
-
} : Parameters<T[E]>[0] & {
|
|
272
|
-
key?: Key | null;
|
|
273
|
-
} : {
|
|
274
|
-
key?: Key | null;
|
|
275
|
-
}) => JSX_2.Element;
|
|
276
|
-
|
|
277
268
|
export { }
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
declare module '@module-federation/runtime' {
|
|
272
|
+
interface FederationHost {
|
|
273
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
274
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
275
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
276
|
+
}
|
|
277
|
+
}
|