@module-federation/bridge-react 0.21.5 → 0.22.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.
- package/CHANGELOG.md +14 -0
- package/dist/base.cjs.js +29 -0
- package/dist/base.d.ts +311 -0
- package/dist/base.es.js +30 -0
- package/dist/createHelpers-B_L612IN.js +190 -0
- package/dist/createHelpers-Ui5pt7je.mjs +191 -0
- package/dist/data-fetch-server-middleware.es.js +1 -1
- package/dist/data-fetch-utils.cjs.js +1 -1
- package/dist/data-fetch-utils.es.js +8 -8
- package/dist/index.cjs.js +10 -178
- package/dist/index.d.ts +5 -3
- package/dist/index.es.js +19 -186
- package/dist/{lazy-load-component-plugin-BbiXdUFQ.mjs → lazy-load-component-plugin-BkcO9pUC.mjs} +2 -2
- package/dist/{lazy-load-component-plugin-2wIGAon4.js → lazy-load-component-plugin-Bt990iJq.js} +1 -1
- package/dist/lazy-load-component-plugin.cjs.js +2 -2
- package/dist/lazy-load-component-plugin.es.js +2 -2
- package/dist/lazy-utils.es.js +3 -3
- package/dist/{prefetch-CBwY1k41.js → prefetch-D-d4LlJ3.js} +1 -1
- package/dist/{prefetch-yYPFtZpU.mjs → prefetch-DAwiqbcO.mjs} +2 -2
- package/dist/{utils-Bx_8GGd-.mjs → utils-dUgb9Jkm.mjs} +6 -6
- package/package.json +13 -5
- package/src/base.ts +50 -0
- package/src/index.ts +2 -2
- package/src/remote/RemoteAppWrapper.tsx +108 -0
- package/src/remote/base-component/component.tsx +2 -0
- package/src/remote/base-component/create.tsx +23 -0
- package/src/remote/base-component/index.tsx +10 -0
- package/src/remote/createHelpers.tsx +130 -0
- package/src/remote/{component.tsx → router-component/component.tsx} +3 -110
- package/src/remote/router-component/create.tsx +23 -0
- package/src/remote/router-component/index.tsx +10 -0
- package/vite.config.ts +1 -0
- package/src/remote/create.tsx +0 -106
package/dist/index.es.js
CHANGED
|
@@ -1,120 +1,16 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import React__default, { forwardRef, useContext, useState, useEffect
|
|
1
|
+
import { R as RemoteAppWrapper, c as createDeprecatedRemoteComponentFactory, a as createRemoteAppComponentFactory } from "./createHelpers-Ui5pt7je.mjs";
|
|
2
|
+
import { b } from "./createHelpers-Ui5pt7je.mjs";
|
|
3
|
+
import { b as b2, a, c, l } from "./lazy-load-component-plugin-BkcO9pUC.mjs";
|
|
4
|
+
import React__default, { forwardRef, useContext, useState, useEffect } from "react";
|
|
5
5
|
import * as ReactRouterDOM from "react-router-dom";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { C, b as b2, E, e, h, c as c2, d, r, s } from "./utils-Bx_8GGd-.mjs";
|
|
6
|
+
import { p as pathJoin, L as LoggerInstance } from "./index-DyQNwY2M.mjs";
|
|
7
|
+
import { C, a as a2, E, b as b3, d, c as c2, g, r, s } from "./utils-dUgb9Jkm.mjs";
|
|
9
8
|
import { callDataFetch } from "./data-fetch-utils.es.js";
|
|
10
|
-
import { p } from "./prefetch-
|
|
11
|
-
function
|
|
12
|
-
return {
|
|
13
|
-
render(children) {
|
|
14
|
-
const reactVersion = ReactDOM.version || "";
|
|
15
|
-
const isReact18 = reactVersion.startsWith("18");
|
|
16
|
-
const isReact19 = reactVersion.startsWith("19");
|
|
17
|
-
if (isReact19) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
`React 19 detected in legacy mode. This is not supported. Please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v19'`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
if (isReact18) {
|
|
23
|
-
LoggerInstance.warn(
|
|
24
|
-
`[Bridge-React] React 18 detected in legacy mode. For better compatibility, please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v18'`
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
ReactDOM.render(children, container);
|
|
28
|
-
},
|
|
29
|
-
unmount() {
|
|
30
|
-
ReactDOM.unmountComponentAtNode(container);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function createBridgeComponent(bridgeInfo) {
|
|
35
|
-
const fullBridgeInfo = {
|
|
36
|
-
createRoot: createReact16Or17Root,
|
|
37
|
-
...bridgeInfo
|
|
38
|
-
};
|
|
39
|
-
return createBaseBridgeComponent(fullBridgeInfo);
|
|
40
|
-
}
|
|
41
|
-
function e2() {
|
|
9
|
+
import { p } from "./prefetch-DAwiqbcO.mjs";
|
|
10
|
+
function e() {
|
|
42
11
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
43
12
|
window.dispatchEvent(t);
|
|
44
13
|
}
|
|
45
|
-
const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
46
|
-
const {
|
|
47
|
-
moduleName,
|
|
48
|
-
memoryRoute,
|
|
49
|
-
basename,
|
|
50
|
-
providerInfo,
|
|
51
|
-
className,
|
|
52
|
-
style,
|
|
53
|
-
fallback,
|
|
54
|
-
loading,
|
|
55
|
-
...resProps
|
|
56
|
-
} = props;
|
|
57
|
-
const instance = federationRuntime.instance;
|
|
58
|
-
const rootRef = ref && "current" in ref ? ref : useRef(null);
|
|
59
|
-
const renderDom = useRef(null);
|
|
60
|
-
const providerInfoRef = useRef(null);
|
|
61
|
-
const [initialized, setInitialized] = useState(false);
|
|
62
|
-
LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
if (initialized) return;
|
|
65
|
-
const providerReturn = providerInfo();
|
|
66
|
-
providerInfoRef.current = providerReturn;
|
|
67
|
-
setInitialized(true);
|
|
68
|
-
return () => {
|
|
69
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
70
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
71
|
-
LoggerInstance.debug(
|
|
72
|
-
`createRemoteAppComponent LazyComponent destroy >>>`,
|
|
73
|
-
{ moduleName, basename, dom: renderDom.current }
|
|
74
|
-
);
|
|
75
|
-
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
76
|
-
moduleName,
|
|
77
|
-
dom: renderDom.current,
|
|
78
|
-
basename,
|
|
79
|
-
memoryRoute,
|
|
80
|
-
fallback,
|
|
81
|
-
...resProps
|
|
82
|
-
});
|
|
83
|
-
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
84
|
-
moduleName,
|
|
85
|
-
dom: renderDom.current
|
|
86
|
-
});
|
|
87
|
-
(_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
88
|
-
moduleName,
|
|
89
|
-
dom: renderDom.current,
|
|
90
|
-
basename,
|
|
91
|
-
memoryRoute,
|
|
92
|
-
fallback,
|
|
93
|
-
...resProps
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}, [moduleName]);
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
var _a, _b, _c, _d, _e, _f;
|
|
100
|
-
if (!initialized || !providerInfoRef.current) return;
|
|
101
|
-
let renderProps = {
|
|
102
|
-
moduleName,
|
|
103
|
-
dom: rootRef.current,
|
|
104
|
-
basename,
|
|
105
|
-
memoryRoute,
|
|
106
|
-
fallback,
|
|
107
|
-
...resProps
|
|
108
|
-
};
|
|
109
|
-
renderDom.current = rootRef.current;
|
|
110
|
-
const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
|
|
111
|
-
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
112
|
-
providerInfoRef.current.render(renderProps);
|
|
113
|
-
(_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
|
|
114
|
-
}, [initialized, ...Object.values(props)]);
|
|
115
|
-
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${className || ""}`;
|
|
116
|
-
return /* @__PURE__ */ React__default.createElement("div", { className: rootComponentClassName, style, ref: rootRef }, loading);
|
|
117
|
-
});
|
|
118
14
|
function withRouterData(WrappedComponent) {
|
|
119
15
|
const Component = forwardRef(function(props, ref) {
|
|
120
16
|
var _a;
|
|
@@ -175,7 +71,7 @@ function withRouterData(WrappedComponent) {
|
|
|
175
71
|
pathname: location.pathname
|
|
176
72
|
}
|
|
177
73
|
);
|
|
178
|
-
|
|
74
|
+
e();
|
|
179
75
|
}
|
|
180
76
|
setPathname(location.pathname);
|
|
181
77
|
}, [location]);
|
|
@@ -187,88 +83,25 @@ function withRouterData(WrappedComponent) {
|
|
|
187
83
|
});
|
|
188
84
|
}
|
|
189
85
|
const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
lazyComponent: info.loader,
|
|
195
|
-
exportName
|
|
196
|
-
});
|
|
197
|
-
try {
|
|
198
|
-
const m = await info.loader();
|
|
199
|
-
const moduleName = m && m[Symbol.for("mf_module_id")];
|
|
200
|
-
LoggerInstance.debug(
|
|
201
|
-
`createRemoteAppComponent LazyComponent loadRemote info >>>`,
|
|
202
|
-
{ name: moduleName, module: m, exportName }
|
|
203
|
-
);
|
|
204
|
-
const exportFn = m[exportName];
|
|
205
|
-
if (exportName in m && typeof exportFn === "function") {
|
|
206
|
-
const RemoteAppComponent = forwardRef((props, ref) => {
|
|
207
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
208
|
-
RemoteApp,
|
|
209
|
-
{
|
|
210
|
-
moduleName,
|
|
211
|
-
providerInfo: exportFn,
|
|
212
|
-
exportName: info.export || "default",
|
|
213
|
-
fallback: info.fallback,
|
|
214
|
-
loading: info.loading,
|
|
215
|
-
ref,
|
|
216
|
-
...props
|
|
217
|
-
}
|
|
218
|
-
);
|
|
219
|
-
});
|
|
220
|
-
return {
|
|
221
|
-
default: RemoteAppComponent
|
|
222
|
-
};
|
|
223
|
-
} else {
|
|
224
|
-
LoggerInstance.debug(
|
|
225
|
-
`createRemoteAppComponent LazyComponent module not found >>>`,
|
|
226
|
-
{ name: moduleName, module: m, exportName }
|
|
227
|
-
);
|
|
228
|
-
throw Error(
|
|
229
|
-
`Make sure that ${moduleName} has the correct export when export is ${String(
|
|
230
|
-
exportName
|
|
231
|
-
)}`
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
} catch (error) {
|
|
235
|
-
throw error;
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
function createRemoteAppComponent(info) {
|
|
240
|
-
const LazyComponent = createLazyRemoteComponent(info);
|
|
241
|
-
return forwardRef((props, ref) => {
|
|
242
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
243
|
-
ErrorBoundary,
|
|
244
|
-
{
|
|
245
|
-
FallbackComponent: info.fallback
|
|
246
|
-
},
|
|
247
|
-
/* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props, ref }))
|
|
248
|
-
);
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
function createRemoteComponent(info) {
|
|
252
|
-
LoggerInstance.warn(
|
|
253
|
-
`createRemoteComponent is deprecated, please use createRemoteAppComponent instead!`
|
|
254
|
-
);
|
|
255
|
-
return createRemoteAppComponent(info);
|
|
256
|
-
}
|
|
86
|
+
const createRemoteAppComponent = createRemoteAppComponentFactory(RemoteApp);
|
|
87
|
+
const createRemoteComponent = createDeprecatedRemoteComponentFactory(
|
|
88
|
+
createRemoteAppComponent
|
|
89
|
+
);
|
|
257
90
|
export {
|
|
258
91
|
C as CacheSize,
|
|
259
|
-
|
|
92
|
+
a2 as CacheTime,
|
|
260
93
|
E as ERROR_TYPE,
|
|
261
|
-
|
|
262
|
-
|
|
94
|
+
b2 as autoFetchDataPlugin,
|
|
95
|
+
b3 as cache,
|
|
263
96
|
callDataFetch,
|
|
264
|
-
|
|
97
|
+
d as clearStore,
|
|
265
98
|
a as collectSSRAssets,
|
|
266
99
|
c2 as configureCache,
|
|
267
|
-
createBridgeComponent,
|
|
100
|
+
b as createBridgeComponent,
|
|
268
101
|
c as createLazyComponent,
|
|
269
102
|
createRemoteAppComponent,
|
|
270
103
|
createRemoteComponent,
|
|
271
|
-
|
|
104
|
+
g as generateKey,
|
|
272
105
|
l as lazyLoadComponentPlugin,
|
|
273
106
|
p as prefetch,
|
|
274
107
|
r as revalidateTag,
|
package/dist/{lazy-load-component-plugin-BbiXdUFQ.mjs → lazy-load-component-plugin-BkcO9pUC.mjs}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
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 isCSROnly,
|
|
1
|
+
import { i as injectDataFetch, p as prefetch } from "./prefetch-DAwiqbcO.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 isCSROnly, h as loadDataFetchModule, M as MF_DATA_FETCH_STATUS, e as getDataFetchMap, t as isServerEnv, 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-dUgb9Jkm.mjs";
|
|
3
3
|
import React__default, { useRef, useState, Suspense, useEffect } from "react";
|
|
4
4
|
const autoFetchData = () => {
|
|
5
5
|
initDataFetchMap();
|
|
@@ -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-
|
|
4
|
-
require("./prefetch-
|
|
3
|
+
const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-Bt990iJq.js");
|
|
4
|
+
require("./prefetch-D-d4LlJ3.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-BkcO9pUC.mjs";
|
|
2
|
+
import "./prefetch-DAwiqbcO.mjs";
|
|
3
3
|
export {
|
|
4
4
|
l as default,
|
|
5
5
|
l2 as lazyLoadComponentPlugin
|
package/dist/lazy-utils.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./index.esm-CPwSeCvw.mjs";
|
|
2
|
-
import { G, H, f, J, I, u, k, n,
|
|
2
|
+
import { G, H, f, J, I, u, k, n, e, m, B, y, i, q, j, t, h, z, s, w } from "./utils-dUgb9Jkm.mjs";
|
|
3
3
|
export {
|
|
4
4
|
G as callAllDowngrade,
|
|
5
5
|
H as callDowngrade,
|
|
@@ -9,7 +9,7 @@ export {
|
|
|
9
9
|
u as getDataFetchIdWithErrorMsgs,
|
|
10
10
|
k as getDataFetchInfo,
|
|
11
11
|
n as getDataFetchItem,
|
|
12
|
-
|
|
12
|
+
e as getDataFetchMap,
|
|
13
13
|
m as getDataFetchMapKey,
|
|
14
14
|
B as getDowngradeTag,
|
|
15
15
|
y as getLoadedRemoteInfos,
|
|
@@ -17,7 +17,7 @@ export {
|
|
|
17
17
|
q as isCSROnly,
|
|
18
18
|
j as isDataLoaderExpose,
|
|
19
19
|
t as isServerEnv,
|
|
20
|
-
|
|
20
|
+
h as loadDataFetchModule,
|
|
21
21
|
z as setDataFetchItemLoadedStatus,
|
|
22
22
|
s as setSSREnv,
|
|
23
23
|
w as wrapDataFetchId
|
|
@@ -211,7 +211,7 @@ function getGlobalFederationConstructor() {
|
|
|
211
211
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = index_esm.isDebugMode()) {
|
|
212
212
|
if (isDebug) {
|
|
213
213
|
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
214
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.
|
|
214
|
+
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.22.0";
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
function getInfoWithoutType(target, key) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { x as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger$1,
|
|
1
|
+
import { x as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger$1, e 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-dUgb9Jkm.mjs";
|
|
2
2
|
import { i as isDebugMode, a as createLink, b as createScript, d as isBrowserEnv, c as createLogger, e as composeKeyWithSeparator, l as loadScriptNode, f as loadScript } from "./index.esm-CPwSeCvw.mjs";
|
|
3
3
|
const dataFetchFunction = async function(options) {
|
|
4
4
|
var _a, _b;
|
|
@@ -210,7 +210,7 @@ function getGlobalFederationConstructor() {
|
|
|
210
210
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
211
211
|
if (isDebug) {
|
|
212
212
|
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
213
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.
|
|
213
|
+
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.22.0";
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
function getInfoWithoutType(target, key) {
|
|
@@ -1987,14 +1987,14 @@ export {
|
|
|
1987
1987
|
flushDataFetch as J,
|
|
1988
1988
|
LOAD_REMOTE_ERROR_PREFIX as L,
|
|
1989
1989
|
MF_DATA_FETCH_STATUS as M,
|
|
1990
|
-
|
|
1991
|
-
|
|
1990
|
+
CacheTime as a,
|
|
1991
|
+
cache as b,
|
|
1992
1992
|
configureCache as c,
|
|
1993
|
-
|
|
1994
|
-
|
|
1993
|
+
clearStore as d,
|
|
1994
|
+
getDataFetchMap as e,
|
|
1995
1995
|
fetchData as f,
|
|
1996
|
-
|
|
1997
|
-
|
|
1996
|
+
generateKey as g,
|
|
1997
|
+
loadDataFetchModule as h,
|
|
1998
1998
|
initDataFetchMap as i,
|
|
1999
1999
|
isDataLoaderExpose as j,
|
|
2000
2000
|
getDataFetchInfo as k,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"import": "./dist/index.es.js",
|
|
22
22
|
"require": "./dist/index.cjs.js"
|
|
23
23
|
},
|
|
24
|
+
"./base": {
|
|
25
|
+
"types": "./dist/base.d.ts",
|
|
26
|
+
"import": "./dist/base.es.js",
|
|
27
|
+
"require": "./dist/base.cjs.js"
|
|
28
|
+
},
|
|
24
29
|
"./v18": {
|
|
25
30
|
"types": "./dist/v18.d.ts",
|
|
26
31
|
"import": "./dist/v18.es.js",
|
|
@@ -83,6 +88,9 @@
|
|
|
83
88
|
".": [
|
|
84
89
|
"./dist/index.d.ts"
|
|
85
90
|
],
|
|
91
|
+
"base": [
|
|
92
|
+
"./dist/base.d.ts"
|
|
93
|
+
],
|
|
86
94
|
"v18": [
|
|
87
95
|
"./dist/v18.d.ts"
|
|
88
96
|
],
|
|
@@ -121,8 +129,8 @@
|
|
|
121
129
|
"dependencies": {
|
|
122
130
|
"react-error-boundary": "^4.1.2",
|
|
123
131
|
"lru-cache": "^10.4.3",
|
|
124
|
-
"@module-federation/bridge-shared": "0.
|
|
125
|
-
"@module-federation/sdk": "0.
|
|
132
|
+
"@module-federation/bridge-shared": "0.22.0",
|
|
133
|
+
"@module-federation/sdk": "0.22.0"
|
|
126
134
|
},
|
|
127
135
|
"peerDependencies": {
|
|
128
136
|
"react": ">=16.9.0",
|
|
@@ -154,8 +162,8 @@
|
|
|
154
162
|
"vite": "^5.4.21",
|
|
155
163
|
"vite-plugin-dts": "^4.3.0",
|
|
156
164
|
"hono": "4.10.3",
|
|
157
|
-
"@module-federation/runtime": "0.
|
|
158
|
-
"@module-federation/runtime-core": "0.
|
|
165
|
+
"@module-federation/runtime": "0.22.0",
|
|
166
|
+
"@module-federation/runtime-core": "0.22.0"
|
|
159
167
|
},
|
|
160
168
|
"scripts": {
|
|
161
169
|
"dev": "vite",
|
package/src/base.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export { createBridgeComponent } from './provider/versions/legacy';
|
|
2
|
+
|
|
3
|
+
// Export router-free versions of remote component creators
|
|
4
|
+
export {
|
|
5
|
+
createRemoteComponent,
|
|
6
|
+
createRemoteAppComponent,
|
|
7
|
+
} from './remote/base-component';
|
|
8
|
+
export type { LazyRemoteComponentInfo } from './remote/base-component';
|
|
9
|
+
|
|
10
|
+
// Export all lazy loading and data fetching utilities (no router dependencies)
|
|
11
|
+
export {
|
|
12
|
+
ERROR_TYPE,
|
|
13
|
+
createLazyComponent,
|
|
14
|
+
collectSSRAssets,
|
|
15
|
+
callDataFetch,
|
|
16
|
+
setSSREnv,
|
|
17
|
+
autoFetchDataPlugin,
|
|
18
|
+
CacheSize,
|
|
19
|
+
CacheTime,
|
|
20
|
+
configureCache,
|
|
21
|
+
generateKey,
|
|
22
|
+
cache,
|
|
23
|
+
revalidateTag,
|
|
24
|
+
clearStore,
|
|
25
|
+
prefetch,
|
|
26
|
+
} from './lazy';
|
|
27
|
+
|
|
28
|
+
export { lazyLoadComponentPlugin } from './plugins/lazy-load-component-plugin';
|
|
29
|
+
|
|
30
|
+
// Export all types
|
|
31
|
+
export type { CreateRootOptions, Root } from './provider/versions/legacy';
|
|
32
|
+
export type {
|
|
33
|
+
ProviderParams,
|
|
34
|
+
ProviderFnParams,
|
|
35
|
+
RootType,
|
|
36
|
+
DestroyParams,
|
|
37
|
+
RenderParams,
|
|
38
|
+
RemoteComponentParams,
|
|
39
|
+
RenderFnParams,
|
|
40
|
+
RemoteComponentProps,
|
|
41
|
+
RemoteModule,
|
|
42
|
+
} from './types';
|
|
43
|
+
export type {
|
|
44
|
+
DataFetchParams,
|
|
45
|
+
NoSSRRemoteInfo,
|
|
46
|
+
CollectSSRAssetsOptions,
|
|
47
|
+
CreateLazyComponentOptions,
|
|
48
|
+
CacheStatus,
|
|
49
|
+
CacheStatsInfo,
|
|
50
|
+
} from './lazy';
|
package/src/index.ts
CHANGED
|
@@ -6,8 +6,8 @@ export { createBridgeComponent } from './provider/versions/legacy';
|
|
|
6
6
|
export {
|
|
7
7
|
createRemoteComponent,
|
|
8
8
|
createRemoteAppComponent,
|
|
9
|
-
} from './remote/
|
|
10
|
-
export type { LazyRemoteComponentInfo } from './remote/
|
|
9
|
+
} from './remote/router-component';
|
|
10
|
+
export type { LazyRemoteComponentInfo } from './remote/router-component';
|
|
11
11
|
export {
|
|
12
12
|
ERROR_TYPE,
|
|
13
13
|
createLazyComponent,
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared RemoteAppWrapper component used by both base and router versions
|
|
3
|
+
* This component handles the lifecycle of remote Module Federation apps
|
|
4
|
+
*/
|
|
5
|
+
import React, { useEffect, useRef, useState, forwardRef } from 'react';
|
|
6
|
+
import { LoggerInstance, getRootDomDefaultClassName } from '../utils';
|
|
7
|
+
import { federationRuntime } from '../provider/plugin';
|
|
8
|
+
import { RemoteComponentProps, RemoteAppParams } from '../types';
|
|
9
|
+
|
|
10
|
+
export const RemoteAppWrapper = forwardRef(function (
|
|
11
|
+
props: RemoteAppParams & RemoteComponentProps,
|
|
12
|
+
ref,
|
|
13
|
+
) {
|
|
14
|
+
const {
|
|
15
|
+
moduleName,
|
|
16
|
+
memoryRoute,
|
|
17
|
+
basename,
|
|
18
|
+
providerInfo,
|
|
19
|
+
className,
|
|
20
|
+
style,
|
|
21
|
+
fallback,
|
|
22
|
+
loading,
|
|
23
|
+
...resProps
|
|
24
|
+
} = props;
|
|
25
|
+
|
|
26
|
+
const instance = federationRuntime.instance;
|
|
27
|
+
const rootRef: React.MutableRefObject<HTMLDivElement | null> =
|
|
28
|
+
ref && 'current' in ref
|
|
29
|
+
? (ref as React.MutableRefObject<HTMLDivElement | null>)
|
|
30
|
+
: useRef(null);
|
|
31
|
+
|
|
32
|
+
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
33
|
+
const providerInfoRef = useRef<any>(null);
|
|
34
|
+
const [initialized, setInitialized] = useState(false);
|
|
35
|
+
|
|
36
|
+
LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
37
|
+
|
|
38
|
+
// 初始化远程组件
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (initialized) return;
|
|
41
|
+
const providerReturn = providerInfo();
|
|
42
|
+
providerInfoRef.current = providerReturn;
|
|
43
|
+
setInitialized(true);
|
|
44
|
+
|
|
45
|
+
return () => {
|
|
46
|
+
if (providerInfoRef.current?.destroy) {
|
|
47
|
+
LoggerInstance.debug(
|
|
48
|
+
`createRemoteAppComponent LazyComponent destroy >>>`,
|
|
49
|
+
{ moduleName, basename, dom: renderDom.current },
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
|
|
53
|
+
moduleName,
|
|
54
|
+
dom: renderDom.current,
|
|
55
|
+
basename,
|
|
56
|
+
memoryRoute,
|
|
57
|
+
fallback,
|
|
58
|
+
...resProps,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
providerInfoRef.current?.destroy({
|
|
62
|
+
moduleName,
|
|
63
|
+
dom: renderDom.current,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
|
|
67
|
+
moduleName,
|
|
68
|
+
dom: renderDom.current,
|
|
69
|
+
basename,
|
|
70
|
+
memoryRoute,
|
|
71
|
+
fallback,
|
|
72
|
+
...resProps,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}, [moduleName]);
|
|
77
|
+
|
|
78
|
+
// trigger render after props updated
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!initialized || !providerInfoRef.current) return;
|
|
81
|
+
|
|
82
|
+
let renderProps = {
|
|
83
|
+
moduleName,
|
|
84
|
+
dom: rootRef.current,
|
|
85
|
+
basename,
|
|
86
|
+
memoryRoute,
|
|
87
|
+
fallback,
|
|
88
|
+
...resProps,
|
|
89
|
+
};
|
|
90
|
+
renderDom.current = rootRef.current;
|
|
91
|
+
|
|
92
|
+
const beforeBridgeRenderRes =
|
|
93
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(renderProps) ||
|
|
94
|
+
{};
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
97
|
+
providerInfoRef.current.render(renderProps);
|
|
98
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(renderProps);
|
|
99
|
+
}, [initialized, ...Object.values(props)]);
|
|
100
|
+
|
|
101
|
+
// bridge-remote-root
|
|
102
|
+
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${className || ''}`;
|
|
103
|
+
return (
|
|
104
|
+
<div className={rootComponentClassName} style={style} ref={rootRef}>
|
|
105
|
+
{loading}
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import RemoteApp from './component';
|
|
2
|
+
import {
|
|
3
|
+
createLazyRemoteComponentFactory,
|
|
4
|
+
createRemoteAppComponentFactory,
|
|
5
|
+
createDeprecatedRemoteComponentFactory,
|
|
6
|
+
type LazyRemoteComponentInfo,
|
|
7
|
+
} from '../createHelpers';
|
|
8
|
+
|
|
9
|
+
export type { LazyRemoteComponentInfo };
|
|
10
|
+
|
|
11
|
+
const createLazyRemoteComponent = createLazyRemoteComponentFactory(RemoteApp);
|
|
12
|
+
|
|
13
|
+
export const createRemoteAppComponent =
|
|
14
|
+
createRemoteAppComponentFactory(RemoteApp);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated createRemoteComponent is deprecated, please use createRemoteAppComponent instead!
|
|
18
|
+
*/
|
|
19
|
+
export const createRemoteComponent = createDeprecatedRemoteComponentFactory(
|
|
20
|
+
createRemoteAppComponent,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export { createLazyRemoteComponent };
|