@module-federation/bridge-react 0.0.0-next-20250708121428 → 0.0.0-next-20250708134245
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.es.js +1 -1
- package/dist/data-fetch-utils.es.js +4 -4
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +3 -3
- package/dist/{lazy-load-component-plugin-DgYHamxE.js → lazy-load-component-plugin-Bobxn-VP.js} +51 -18
- package/dist/{lazy-load-component-plugin-BbqmMGKu.mjs → lazy-load-component-plugin-Dvi5dnb7.mjs} +54 -21
- package/dist/lazy-load-component-plugin.cjs.js +1 -1
- package/dist/lazy-load-component-plugin.es.js +2 -2
- package/dist/lazy-utils.es.js +3 -3
- package/dist/{prefetch-CXJhiNUD.mjs → prefetch-Dq-ZhN17.mjs} +1 -1
- package/dist/{utils-BTYYwZcb.mjs → utils-Cy-amYU5.mjs} +4 -4
- package/package.json +5 -5
- package/src/lazy/createLazyComponent.tsx +66 -70
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20250708134245
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
### Patch Changes
|
|
10
10
|
|
|
11
11
|
- eb0d1dc: feat(bridge-react): export createLazyCompoent api
|
|
12
|
-
- @module-federation/sdk@0.0.0-next-
|
|
13
|
-
- @module-federation/bridge-shared@0.0.0-next-
|
|
12
|
+
- @module-federation/sdk@0.0.0-next-20250708134245
|
|
13
|
+
- @module-federation/bridge-shared@0.0.0-next-20250708134245
|
|
14
14
|
|
|
15
15
|
## 0.16.0
|
|
16
16
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as DATA_FETCH_QUERY, l as logger, g as getDataFetchMap, i as initDataFetchMap, M as MF_DATA_FETCH_STATUS, f as fetchData, a as loadDataFetchModule } from "./utils-
|
|
1
|
+
import { D as DATA_FETCH_QUERY, l as logger, g as getDataFetchMap, i as initDataFetchMap, M as MF_DATA_FETCH_STATUS, f as fetchData, a as loadDataFetchModule } from "./utils-Cy-amYU5.mjs";
|
|
2
2
|
import { M as MANIFEST_EXT, S as SEPARATOR } from "./index.esm-BCeUd-x9.mjs";
|
|
3
3
|
function wrapSetTimeout(targetPromise, delay = 2e4, id) {
|
|
4
4
|
if (targetPromise && typeof targetPromise.then === "function") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { C, b, e, h, c, d, r } from "./utils-
|
|
3
|
-
import { d as dataFetchFunction } from "./prefetch-
|
|
4
|
-
import { i, p } from "./prefetch-
|
|
1
|
+
import { x as DATA_FETCH_FUNCTION } from "./utils-Cy-amYU5.mjs";
|
|
2
|
+
import { C, b, e, h, c, d, r } from "./utils-Cy-amYU5.mjs";
|
|
3
|
+
import { d as dataFetchFunction } from "./prefetch-Dq-ZhN17.mjs";
|
|
4
|
+
import { i, p } from "./prefetch-Dq-ZhN17.mjs";
|
|
5
5
|
async function callDataFetch() {
|
|
6
6
|
const dataFetch = globalThis[DATA_FETCH_FUNCTION];
|
|
7
7
|
if (dataFetch) {
|
package/dist/index.cjs.js
CHANGED
|
@@ -6,7 +6,7 @@ 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 lazyLoadComponentPlugin = require("./lazy-load-component-plugin-
|
|
9
|
+
const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-Bobxn-VP.js");
|
|
10
10
|
const lazyUtils = require("./utils-iEVlDmyk.js");
|
|
11
11
|
const dataFetchUtils = require("./data-fetch-utils.cjs.js");
|
|
12
12
|
const prefetch = require("./prefetch-BWabXlKU.js");
|
package/dist/index.d.ts
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -4,10 +4,10 @@ import React__default, { forwardRef, useRef, useState, useEffect, useContext } f
|
|
|
4
4
|
import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin } from "./index-CqxytsLY.mjs";
|
|
5
5
|
import * as ReactRouterDOM from "react-router-dom";
|
|
6
6
|
import { federationRuntime } from "./plugin.es.js";
|
|
7
|
-
import { b, a, c, l } from "./lazy-load-component-plugin-
|
|
8
|
-
import { C, b as b2, E, e, h, c as c2, d, r, s } from "./utils-
|
|
7
|
+
import { b, a, c, l } from "./lazy-load-component-plugin-Dvi5dnb7.mjs";
|
|
8
|
+
import { C, b as b2, E, e, h, c as c2, d, r, s } from "./utils-Cy-amYU5.mjs";
|
|
9
9
|
import { callDataFetch } from "./data-fetch-utils.es.js";
|
|
10
|
-
import { p } from "./prefetch-
|
|
10
|
+
import { p } from "./prefetch-Dq-ZhN17.mjs";
|
|
11
11
|
function createReact16Or17Root(container) {
|
|
12
12
|
return {
|
|
13
13
|
render(children) {
|
package/dist/{lazy-load-component-plugin-DgYHamxE.js → lazy-load-component-plugin-Bobxn-VP.js}
RENAMED
|
@@ -296,12 +296,9 @@ function collectSSRAssets(options) {
|
|
|
296
296
|
}
|
|
297
297
|
return [...scripts, ...links];
|
|
298
298
|
}
|
|
299
|
-
function getServerNeedRemoteInfo(loadedRemoteInfo, id) {
|
|
299
|
+
function getServerNeedRemoteInfo(loadedRemoteInfo, id, noSSR) {
|
|
300
300
|
var _a;
|
|
301
|
-
if (
|
|
302
|
-
// noSSR ||
|
|
303
|
-
typeof window !== "undefined" && window.location.href !== window[lazyUtils.FS_HREF]
|
|
304
|
-
) {
|
|
301
|
+
if (noSSR || typeof window !== "undefined" && window.location.href !== window[lazyUtils.FS_HREF]) {
|
|
305
302
|
if (!(loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.version)) {
|
|
306
303
|
throw new Error(`${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} version is empty`);
|
|
307
304
|
}
|
|
@@ -347,7 +344,7 @@ function createLazyComponent(options) {
|
|
|
347
344
|
}
|
|
348
345
|
return m;
|
|
349
346
|
};
|
|
350
|
-
const getData = async () => {
|
|
347
|
+
const getData = async (noSSR) => {
|
|
351
348
|
let loadedRemoteInfo;
|
|
352
349
|
let moduleId;
|
|
353
350
|
try {
|
|
@@ -386,8 +383,7 @@ function createLazyComponent(options) {
|
|
|
386
383
|
...options.dataFetchParams,
|
|
387
384
|
isDowngrade: false
|
|
388
385
|
},
|
|
389
|
-
|
|
390
|
-
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey)
|
|
386
|
+
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR)
|
|
391
387
|
);
|
|
392
388
|
lazyUtils.setDataFetchItemLoadedStatus(dataFetchMapKey);
|
|
393
389
|
lazyUtils.logger.debug("get data res: \n", data);
|
|
@@ -447,16 +443,53 @@ function createLazyComponent(options) {
|
|
|
447
443
|
if (cacheData && dataCache) {
|
|
448
444
|
return /* @__PURE__ */ React.createElement(LazyComponent, { ...args, mfData: dataCache });
|
|
449
445
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
446
|
+
if (!options.noSSR) {
|
|
447
|
+
return /* @__PURE__ */ React.createElement(
|
|
448
|
+
AwaitDataFetch,
|
|
449
|
+
{
|
|
450
|
+
resolve: getData(options.noSSR),
|
|
451
|
+
loading: options.loading,
|
|
452
|
+
delayLoading: options.delayLoading,
|
|
453
|
+
errorElement: options.fallback
|
|
454
|
+
},
|
|
455
|
+
(data) => /* @__PURE__ */ React.createElement(LazyComponent, { ...args, mfData: data })
|
|
456
|
+
);
|
|
457
|
+
} else {
|
|
458
|
+
const [data, setData] = React.useState(null);
|
|
459
|
+
const [loading, setLoading] = React.useState(true);
|
|
460
|
+
const [error, setError] = React.useState(null);
|
|
461
|
+
React.useEffect(() => {
|
|
462
|
+
let isMounted = true;
|
|
463
|
+
const fetchDataAsync = async () => {
|
|
464
|
+
try {
|
|
465
|
+
setLoading(true);
|
|
466
|
+
const result = await getData(options.noSSR);
|
|
467
|
+
if (isMounted) {
|
|
468
|
+
setData(result);
|
|
469
|
+
}
|
|
470
|
+
} catch (e) {
|
|
471
|
+
if (isMounted) {
|
|
472
|
+
setError(transformError(e));
|
|
473
|
+
}
|
|
474
|
+
} finally {
|
|
475
|
+
if (isMounted) {
|
|
476
|
+
setLoading(false);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
fetchDataAsync();
|
|
481
|
+
return () => {
|
|
482
|
+
isMounted = false;
|
|
483
|
+
};
|
|
484
|
+
}, []);
|
|
485
|
+
if (loading) {
|
|
486
|
+
return /* @__PURE__ */ React.createElement(DelayedLoading, { delayLoading: options.delayLoading }, options.loading);
|
|
487
|
+
}
|
|
488
|
+
if (error) {
|
|
489
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, typeof options.fallback === "function" ? options.fallback(error) : options.fallback);
|
|
490
|
+
}
|
|
491
|
+
return /* @__PURE__ */ React.createElement(LazyComponent, { ...args, mfData: data });
|
|
492
|
+
}
|
|
460
493
|
};
|
|
461
494
|
}
|
|
462
495
|
function lazyLoadComponentPlugin() {
|
package/dist/{lazy-load-component-plugin-BbqmMGKu.mjs → lazy-load-component-plugin-Dvi5dnb7.mjs}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as injectDataFetch, p as prefetch } from "./prefetch-
|
|
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
|
|
3
|
-
import React__default, { useRef, Suspense,
|
|
1
|
+
import { i as injectDataFetch, p as prefetch } from "./prefetch-Dq-ZhN17.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
4
|
const autoFetchData = () => {
|
|
5
5
|
initDataFetchMap();
|
|
6
6
|
injectDataFetch();
|
|
@@ -295,12 +295,9 @@ function collectSSRAssets(options) {
|
|
|
295
295
|
}
|
|
296
296
|
return [...scripts, ...links];
|
|
297
297
|
}
|
|
298
|
-
function getServerNeedRemoteInfo(loadedRemoteInfo, id) {
|
|
298
|
+
function getServerNeedRemoteInfo(loadedRemoteInfo, id, noSSR) {
|
|
299
299
|
var _a;
|
|
300
|
-
if (
|
|
301
|
-
// noSSR ||
|
|
302
|
-
typeof window !== "undefined" && window.location.href !== window[FS_HREF]
|
|
303
|
-
) {
|
|
300
|
+
if (noSSR || typeof window !== "undefined" && window.location.href !== window[FS_HREF]) {
|
|
304
301
|
if (!(loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.version)) {
|
|
305
302
|
throw new Error(`${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} version is empty`);
|
|
306
303
|
}
|
|
@@ -346,7 +343,7 @@ function createLazyComponent(options) {
|
|
|
346
343
|
}
|
|
347
344
|
return m;
|
|
348
345
|
};
|
|
349
|
-
const getData = async () => {
|
|
346
|
+
const getData = async (noSSR) => {
|
|
350
347
|
let loadedRemoteInfo;
|
|
351
348
|
let moduleId;
|
|
352
349
|
try {
|
|
@@ -385,8 +382,7 @@ function createLazyComponent(options) {
|
|
|
385
382
|
...options.dataFetchParams,
|
|
386
383
|
isDowngrade: false
|
|
387
384
|
},
|
|
388
|
-
|
|
389
|
-
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey)
|
|
385
|
+
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR)
|
|
390
386
|
);
|
|
391
387
|
setDataFetchItemLoadedStatus(dataFetchMapKey);
|
|
392
388
|
logger.debug("get data res: \n", data);
|
|
@@ -446,16 +442,53 @@ function createLazyComponent(options) {
|
|
|
446
442
|
if (cacheData && dataCache) {
|
|
447
443
|
return /* @__PURE__ */ React__default.createElement(LazyComponent, { ...args, mfData: dataCache });
|
|
448
444
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
445
|
+
if (!options.noSSR) {
|
|
446
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
447
|
+
AwaitDataFetch,
|
|
448
|
+
{
|
|
449
|
+
resolve: getData(options.noSSR),
|
|
450
|
+
loading: options.loading,
|
|
451
|
+
delayLoading: options.delayLoading,
|
|
452
|
+
errorElement: options.fallback
|
|
453
|
+
},
|
|
454
|
+
(data) => /* @__PURE__ */ React__default.createElement(LazyComponent, { ...args, mfData: data })
|
|
455
|
+
);
|
|
456
|
+
} else {
|
|
457
|
+
const [data, setData] = useState(null);
|
|
458
|
+
const [loading, setLoading] = useState(true);
|
|
459
|
+
const [error, setError] = useState(null);
|
|
460
|
+
useEffect(() => {
|
|
461
|
+
let isMounted = true;
|
|
462
|
+
const fetchDataAsync = async () => {
|
|
463
|
+
try {
|
|
464
|
+
setLoading(true);
|
|
465
|
+
const result = await getData(options.noSSR);
|
|
466
|
+
if (isMounted) {
|
|
467
|
+
setData(result);
|
|
468
|
+
}
|
|
469
|
+
} catch (e) {
|
|
470
|
+
if (isMounted) {
|
|
471
|
+
setError(transformError(e));
|
|
472
|
+
}
|
|
473
|
+
} finally {
|
|
474
|
+
if (isMounted) {
|
|
475
|
+
setLoading(false);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
fetchDataAsync();
|
|
480
|
+
return () => {
|
|
481
|
+
isMounted = false;
|
|
482
|
+
};
|
|
483
|
+
}, []);
|
|
484
|
+
if (loading) {
|
|
485
|
+
return /* @__PURE__ */ React__default.createElement(DelayedLoading, { delayLoading: options.delayLoading }, options.loading);
|
|
486
|
+
}
|
|
487
|
+
if (error) {
|
|
488
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, typeof options.fallback === "function" ? options.fallback(error) : options.fallback);
|
|
489
|
+
}
|
|
490
|
+
return /* @__PURE__ */ React__default.createElement(LazyComponent, { ...args, mfData: data });
|
|
491
|
+
}
|
|
459
492
|
};
|
|
460
493
|
}
|
|
461
494
|
function lazyLoadComponentPlugin() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-
|
|
3
|
+
const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-Bobxn-VP.js");
|
|
4
4
|
require("./prefetch-BWabXlKU.js");
|
|
5
5
|
exports.default = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
|
|
6
6
|
exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l, l as l2 } from "./lazy-load-component-plugin-
|
|
2
|
-
import "./prefetch-
|
|
1
|
+
import { l, l as l2 } from "./lazy-load-component-plugin-Dvi5dnb7.mjs";
|
|
2
|
+
import "./prefetch-Dq-ZhN17.mjs";
|
|
3
3
|
export {
|
|
4
4
|
l as default,
|
|
5
5
|
l2 as lazyLoadComponentPlugin
|
package/dist/lazy-utils.es.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import "./index.esm-BCeUd-x9.mjs";
|
|
2
|
-
import { G, H, f, J, I,
|
|
2
|
+
import { G, H, f, J, I, u, k, n, g, m, B, y, i, t, j, q, a, z, s, w } from "./utils-Cy-amYU5.mjs";
|
|
3
3
|
export {
|
|
4
4
|
G as callAllDowngrade,
|
|
5
5
|
H as callDowngrade,
|
|
6
6
|
f as fetchData,
|
|
7
7
|
J as flushDataFetch,
|
|
8
8
|
I as getDataFetchCache,
|
|
9
|
-
|
|
9
|
+
u as getDataFetchIdWithErrorMsgs,
|
|
10
10
|
k as getDataFetchInfo,
|
|
11
11
|
n as getDataFetchItem,
|
|
12
12
|
g as getDataFetchMap,
|
|
@@ -20,5 +20,5 @@ export {
|
|
|
20
20
|
a as loadDataFetchModule,
|
|
21
21
|
z as setDataFetchItemLoadedStatus,
|
|
22
22
|
s as setSSREnv,
|
|
23
|
-
|
|
23
|
+
w as wrapDataFetchId
|
|
24
24
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { x as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger$1, g as getDataFetchMap, i as initDataFetchMap, n as getDataFetchItem, M as MF_DATA_FETCH_STATUS, p as MF_DATA_FETCH_TYPE, A as DOWNGRADE_KEY, B as getDowngradeTag, G as callAllDowngrade, H as callDowngrade, k as getDataFetchInfo, m as getDataFetchMapKey } from "./utils-Cy-amYU5.mjs";
|
|
2
2
|
import { b as isDebugMode, d as createLink, e as createScript, i as isBrowserEnv, c as createLogger, a as composeKeyWithSeparator, l as loadScriptNode, f as loadScript } from "./index.esm-BCeUd-x9.mjs";
|
|
3
3
|
const dataFetchFunction = async function(options) {
|
|
4
4
|
var _a, _b;
|
|
@@ -2007,10 +2007,10 @@ export {
|
|
|
2007
2007
|
revalidateTag as r,
|
|
2008
2008
|
setSSREnv as s,
|
|
2009
2009
|
isCSROnly as t,
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2010
|
+
getDataFetchIdWithErrorMsgs as u,
|
|
2011
|
+
DATA_FETCH_ERROR_PREFIX as v,
|
|
2012
|
+
wrapDataFetchId as w,
|
|
2013
|
+
DATA_FETCH_FUNCTION as x,
|
|
2014
2014
|
getLoadedRemoteInfos as y,
|
|
2015
2015
|
setDataFetchItemLoadedStatus as z
|
|
2016
2016
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250708134245",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -94,8 +94,8 @@
|
|
|
94
94
|
"dependencies": {
|
|
95
95
|
"react-error-boundary": "^4.1.2",
|
|
96
96
|
"lru-cache": "^10.4.3",
|
|
97
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
98
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
97
|
+
"@module-federation/bridge-shared": "0.0.0-next-20250708134245",
|
|
98
|
+
"@module-federation/sdk": "0.0.0-next-20250708134245"
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|
|
101
101
|
"react": ">=16.9.0",
|
|
@@ -117,8 +117,8 @@
|
|
|
117
117
|
"vite": "^5.4.18",
|
|
118
118
|
"vite-plugin-dts": "^4.3.0",
|
|
119
119
|
"hono": "3.12.12",
|
|
120
|
-
"@module-federation/runtime": "0.0.0-next-
|
|
121
|
-
"@module-federation/runtime-core": "0.0.0-next-
|
|
120
|
+
"@module-federation/runtime": "0.0.0-next-20250708134245",
|
|
121
|
+
"@module-federation/runtime-core": "0.0.0-next-20250708134245"
|
|
122
122
|
},
|
|
123
123
|
"scripts": {
|
|
124
124
|
"dev": "vite",
|
|
@@ -42,7 +42,7 @@ export type CreateLazyComponentOptions<T, E extends keyof T> = {
|
|
|
42
42
|
fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
|
|
43
43
|
export?: E;
|
|
44
44
|
dataFetchParams?: DataFetchParams;
|
|
45
|
-
|
|
45
|
+
noSSR?: boolean;
|
|
46
46
|
cacheData?: boolean;
|
|
47
47
|
};
|
|
48
48
|
|
|
@@ -157,12 +157,11 @@ export function collectSSRAssets(options: IProps) {
|
|
|
157
157
|
function getServerNeedRemoteInfo(
|
|
158
158
|
loadedRemoteInfo: ReturnType<typeof getLoadedRemoteInfos>,
|
|
159
159
|
id: string,
|
|
160
|
-
|
|
160
|
+
noSSR?: boolean,
|
|
161
161
|
): NoSSRRemoteInfo | undefined {
|
|
162
162
|
if (
|
|
163
|
-
|
|
164
|
-
typeof window !== 'undefined' &&
|
|
165
|
-
window.location.href !== window[FS_HREF]
|
|
163
|
+
noSSR ||
|
|
164
|
+
(typeof window !== 'undefined' && window.location.href !== window[FS_HREF])
|
|
166
165
|
) {
|
|
167
166
|
if (!loadedRemoteInfo?.version) {
|
|
168
167
|
throw new Error(`${loadedRemoteInfo?.name} version is empty`);
|
|
@@ -233,8 +232,7 @@ export function createLazyComponent<T, E extends keyof T>(
|
|
|
233
232
|
return m;
|
|
234
233
|
};
|
|
235
234
|
|
|
236
|
-
|
|
237
|
-
const getData = async () => {
|
|
235
|
+
const getData = async (noSSR?: boolean) => {
|
|
238
236
|
let loadedRemoteInfo: ReturnType<typeof getLoadedRemoteInfos>;
|
|
239
237
|
let moduleId: string;
|
|
240
238
|
try {
|
|
@@ -273,8 +271,7 @@ export function createLazyComponent<T, E extends keyof T>(
|
|
|
273
271
|
...options.dataFetchParams,
|
|
274
272
|
isDowngrade: false,
|
|
275
273
|
},
|
|
276
|
-
|
|
277
|
-
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey),
|
|
274
|
+
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR),
|
|
278
275
|
);
|
|
279
276
|
setDataFetchItemLoadedStatus(dataFetchMapKey);
|
|
280
277
|
logger.debug('get data res: \n', data);
|
|
@@ -347,72 +344,71 @@ export function createLazyComponent<T, E extends keyof T>(
|
|
|
347
344
|
// @ts-expect-error ignore
|
|
348
345
|
return <LazyComponent {...args} mfData={dataCache} />;
|
|
349
346
|
}
|
|
350
|
-
return (
|
|
351
|
-
<AwaitDataFetch
|
|
352
|
-
// resolve={getData(options.noSSR)}
|
|
353
|
-
resolve={getData()}
|
|
354
|
-
loading={options.loading}
|
|
355
|
-
delayLoading={options.delayLoading}
|
|
356
|
-
errorElement={options.fallback}
|
|
357
|
-
>
|
|
358
|
-
{/* @ts-expect-error ignore */}
|
|
359
|
-
{(data) => <LazyComponent {...args} mfData={data} />}
|
|
360
|
-
</AwaitDataFetch>
|
|
361
|
-
);
|
|
362
|
-
// if (!options.noSSR) {
|
|
363
347
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
348
|
+
if (!options.noSSR) {
|
|
349
|
+
return (
|
|
350
|
+
<AwaitDataFetch
|
|
351
|
+
resolve={getData(options.noSSR)}
|
|
352
|
+
loading={options.loading}
|
|
353
|
+
delayLoading={options.delayLoading}
|
|
354
|
+
errorElement={options.fallback}
|
|
355
|
+
>
|
|
356
|
+
{/* @ts-expect-error ignore */}
|
|
357
|
+
{(data) => <LazyComponent {...args} mfData={data} />}
|
|
358
|
+
</AwaitDataFetch>
|
|
359
|
+
);
|
|
360
|
+
} else {
|
|
361
|
+
// Client-side rendering logic
|
|
362
|
+
const [data, setData] = useState<unknown>(null);
|
|
363
|
+
const [loading, setLoading] = useState<boolean>(true);
|
|
364
|
+
const [error, setError] = useState<ErrorInfo | null>(null);
|
|
369
365
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
366
|
+
useEffect(() => {
|
|
367
|
+
let isMounted = true;
|
|
368
|
+
const fetchDataAsync = async () => {
|
|
369
|
+
try {
|
|
370
|
+
setLoading(true);
|
|
371
|
+
const result = await getData(options.noSSR);
|
|
372
|
+
if (isMounted) {
|
|
373
|
+
setData(result);
|
|
374
|
+
}
|
|
375
|
+
} catch (e) {
|
|
376
|
+
if (isMounted) {
|
|
377
|
+
setError(transformError(e as Error));
|
|
378
|
+
}
|
|
379
|
+
} finally {
|
|
380
|
+
if (isMounted) {
|
|
381
|
+
setLoading(false);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
389
385
|
|
|
390
|
-
|
|
386
|
+
fetchDataAsync();
|
|
391
387
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
388
|
+
return () => {
|
|
389
|
+
isMounted = false;
|
|
390
|
+
};
|
|
391
|
+
}, []);
|
|
396
392
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
393
|
+
if (loading) {
|
|
394
|
+
return (
|
|
395
|
+
<DelayedLoading delayLoading={options.delayLoading}>
|
|
396
|
+
{options.loading}
|
|
397
|
+
</DelayedLoading>
|
|
398
|
+
);
|
|
399
|
+
}
|
|
404
400
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
401
|
+
if (error) {
|
|
402
|
+
return (
|
|
403
|
+
<>
|
|
404
|
+
{typeof options.fallback === 'function'
|
|
405
|
+
? options.fallback(error)
|
|
406
|
+
: options.fallback}
|
|
407
|
+
</>
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
// @ts-expect-error ignore
|
|
411
|
+
return <LazyComponent {...args} mfData={data} />;
|
|
412
|
+
}
|
|
417
413
|
};
|
|
418
414
|
}
|