@module-federation/bridge-react 0.0.0-next-20241101074502 → 0.0.0-next-20241101093646
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 +5 -24
- package/dist/context--mtFt3tp.cjs +73 -0
- package/dist/context-Bw2PEwa6.js +74 -0
- package/dist/index.cjs.js +65 -19
- package/dist/index.d.ts +19 -5
- package/dist/index.es.js +59 -13
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +2 -2
- package/dist/router.es.js +2 -2
- package/package.json +4 -4
- package/src/create.tsx +2 -2
- package/src/lifecycle.ts +28 -0
- package/src/provider.tsx +61 -8
- package/src/remote/index.tsx +58 -3
- package/src/router-v5.tsx +0 -1
- package/src/router.tsx +1 -1
- package/src/utils.ts +2 -4
- package/dist/context-9t7opEwi.js +0 -329
- package/dist/context-BVnJi3LE.cjs +0 -328
package/CHANGELOG.md
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20241101093646
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- ad605d2: chore: unified logger
|
|
15
|
-
- Updated dependencies [ad605d2]
|
|
16
|
-
- @module-federation/bridge-shared@0.6.14
|
|
17
|
-
- @module-federation/sdk@0.6.14
|
|
18
|
-
|
|
19
|
-
## 0.6.13
|
|
20
|
-
|
|
21
|
-
### Patch Changes
|
|
22
|
-
|
|
23
|
-
- @module-federation/bridge-shared@0.6.13
|
|
24
|
-
|
|
25
|
-
## 0.6.12
|
|
26
|
-
|
|
27
|
-
### Patch Changes
|
|
28
|
-
|
|
29
|
-
- @module-federation/bridge-shared@0.6.12
|
|
7
|
+
- 3082116: feat: support module isolated reported
|
|
8
|
+
- Updated dependencies [3082116]
|
|
9
|
+
- @module-federation/runtime@0.0.0-next-20241101093646
|
|
10
|
+
- @module-federation/bridge-shared@0.0.0-next-20241101093646
|
|
30
11
|
|
|
31
12
|
## 0.6.11
|
|
32
13
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const React = require("react");
|
|
3
|
+
var a = Object.defineProperty;
|
|
4
|
+
var c = (s, e, t) => e in s ? a(s, e, { enumerable: true, configurable: true, writable: true, value: t }) : s[e] = t;
|
|
5
|
+
var i = (s, e, t) => (c(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
6
|
+
class g {
|
|
7
|
+
constructor(e) {
|
|
8
|
+
i(this, "name");
|
|
9
|
+
i(this, "isDebugEnabled");
|
|
10
|
+
i(this, "color");
|
|
11
|
+
this.name = e, this.isDebugEnabled = false, this.color = this.stringToColor(e), typeof window < "u" && typeof localStorage < "u" && (this.isDebugEnabled = localStorage.getItem("debug") === "true"), typeof process < "u" && process.env && (this.isDebugEnabled = process.env.DEBUG === "true");
|
|
12
|
+
}
|
|
13
|
+
log(...e) {
|
|
14
|
+
var t, n;
|
|
15
|
+
if (this.isDebugEnabled) {
|
|
16
|
+
const o = `color: ${this.color}; font-weight: bold`, l = `%c[${this.name}]`, r = ((n = (t = new Error().stack) == null ? void 0 : t.split(`
|
|
17
|
+
`)[2]) == null ? void 0 : n.trim()) || "Stack information not available";
|
|
18
|
+
typeof console < "u" && console.debug && console.debug(l, o, ...e, `
|
|
19
|
+
(${r})`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
stringToColor(e) {
|
|
23
|
+
let t = 0;
|
|
24
|
+
for (let o = 0; o < e.length; o++)
|
|
25
|
+
t = e.charCodeAt(o) + ((t << 5) - t);
|
|
26
|
+
let n = "#";
|
|
27
|
+
for (let o = 0; o < 3; o++) {
|
|
28
|
+
const l = t >> o * 8 & 255;
|
|
29
|
+
n += ("00" + l.toString(16)).substr(-2);
|
|
30
|
+
}
|
|
31
|
+
return n;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function f() {
|
|
35
|
+
const s = new PopStateEvent("popstate", { state: window.history.state });
|
|
36
|
+
window.dispatchEvent(s);
|
|
37
|
+
}
|
|
38
|
+
const LoggerInstance = new g("bridge-react");
|
|
39
|
+
function atLeastReact18(React2) {
|
|
40
|
+
if (React2 && typeof React2.version === "string" && React2.version.indexOf(".") >= 0) {
|
|
41
|
+
const majorVersionString = React2.version.split(".")[0];
|
|
42
|
+
try {
|
|
43
|
+
return Number(majorVersionString) >= 18;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function pathJoin(...args) {
|
|
52
|
+
const res = args.reduce((res2, path) => {
|
|
53
|
+
let nPath = path;
|
|
54
|
+
if (!nPath || typeof nPath !== "string") {
|
|
55
|
+
return res2;
|
|
56
|
+
}
|
|
57
|
+
if (nPath[0] !== "/") {
|
|
58
|
+
nPath = `/${nPath}`;
|
|
59
|
+
}
|
|
60
|
+
const lastIndex = nPath.length - 1;
|
|
61
|
+
if (nPath[lastIndex] === "/") {
|
|
62
|
+
nPath = nPath.substring(0, lastIndex);
|
|
63
|
+
}
|
|
64
|
+
return res2 + nPath;
|
|
65
|
+
}, "");
|
|
66
|
+
return res || "/";
|
|
67
|
+
}
|
|
68
|
+
const RouterContext = React.createContext(null);
|
|
69
|
+
exports.LoggerInstance = LoggerInstance;
|
|
70
|
+
exports.RouterContext = RouterContext;
|
|
71
|
+
exports.atLeastReact18 = atLeastReact18;
|
|
72
|
+
exports.f = f;
|
|
73
|
+
exports.pathJoin = pathJoin;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
var a = Object.defineProperty;
|
|
3
|
+
var c = (s, e, t) => e in s ? a(s, e, { enumerable: true, configurable: true, writable: true, value: t }) : s[e] = t;
|
|
4
|
+
var i = (s, e, t) => (c(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
5
|
+
class g {
|
|
6
|
+
constructor(e) {
|
|
7
|
+
i(this, "name");
|
|
8
|
+
i(this, "isDebugEnabled");
|
|
9
|
+
i(this, "color");
|
|
10
|
+
this.name = e, this.isDebugEnabled = false, this.color = this.stringToColor(e), typeof window < "u" && typeof localStorage < "u" && (this.isDebugEnabled = localStorage.getItem("debug") === "true"), typeof process < "u" && process.env && (this.isDebugEnabled = process.env.DEBUG === "true");
|
|
11
|
+
}
|
|
12
|
+
log(...e) {
|
|
13
|
+
var t, n;
|
|
14
|
+
if (this.isDebugEnabled) {
|
|
15
|
+
const o = `color: ${this.color}; font-weight: bold`, l = `%c[${this.name}]`, r = ((n = (t = new Error().stack) == null ? void 0 : t.split(`
|
|
16
|
+
`)[2]) == null ? void 0 : n.trim()) || "Stack information not available";
|
|
17
|
+
typeof console < "u" && console.debug && console.debug(l, o, ...e, `
|
|
18
|
+
(${r})`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
stringToColor(e) {
|
|
22
|
+
let t = 0;
|
|
23
|
+
for (let o = 0; o < e.length; o++)
|
|
24
|
+
t = e.charCodeAt(o) + ((t << 5) - t);
|
|
25
|
+
let n = "#";
|
|
26
|
+
for (let o = 0; o < 3; o++) {
|
|
27
|
+
const l = t >> o * 8 & 255;
|
|
28
|
+
n += ("00" + l.toString(16)).substr(-2);
|
|
29
|
+
}
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function f() {
|
|
34
|
+
const s = new PopStateEvent("popstate", { state: window.history.state });
|
|
35
|
+
window.dispatchEvent(s);
|
|
36
|
+
}
|
|
37
|
+
const LoggerInstance = new g("bridge-react");
|
|
38
|
+
function atLeastReact18(React2) {
|
|
39
|
+
if (React2 && typeof React2.version === "string" && React2.version.indexOf(".") >= 0) {
|
|
40
|
+
const majorVersionString = React2.version.split(".")[0];
|
|
41
|
+
try {
|
|
42
|
+
return Number(majorVersionString) >= 18;
|
|
43
|
+
} catch (err) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function pathJoin(...args) {
|
|
51
|
+
const res = args.reduce((res2, path) => {
|
|
52
|
+
let nPath = path;
|
|
53
|
+
if (!nPath || typeof nPath !== "string") {
|
|
54
|
+
return res2;
|
|
55
|
+
}
|
|
56
|
+
if (nPath[0] !== "/") {
|
|
57
|
+
nPath = `/${nPath}`;
|
|
58
|
+
}
|
|
59
|
+
const lastIndex = nPath.length - 1;
|
|
60
|
+
if (nPath[lastIndex] === "/") {
|
|
61
|
+
nPath = nPath.substring(0, lastIndex);
|
|
62
|
+
}
|
|
63
|
+
return res2 + nPath;
|
|
64
|
+
}, "");
|
|
65
|
+
return res || "/";
|
|
66
|
+
}
|
|
67
|
+
const RouterContext = React__default.createContext(null);
|
|
68
|
+
export {
|
|
69
|
+
LoggerInstance as L,
|
|
70
|
+
RouterContext as R,
|
|
71
|
+
atLeastReact18 as a,
|
|
72
|
+
f,
|
|
73
|
+
pathJoin as p
|
|
74
|
+
};
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
|
-
const context = require("./context
|
|
4
|
+
const context = require("./context--mtFt3tp.cjs");
|
|
5
5
|
const ReactRouterDOM = require("react-router-dom");
|
|
6
|
+
const runtime = require("@module-federation/runtime");
|
|
6
7
|
const ReactDOM = require("react-dom");
|
|
7
|
-
function _interopNamespaceDefault(
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
8
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
|
-
if (
|
|
10
|
-
for (const k in
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
11
12
|
if (k !== "default") {
|
|
12
|
-
const d = Object.getOwnPropertyDescriptor(
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
14
|
Object.defineProperty(n, k, d.get ? d : {
|
|
14
15
|
enumerable: true,
|
|
15
|
-
get: () =>
|
|
16
|
+
get: () => e[k]
|
|
16
17
|
});
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
n.default =
|
|
21
|
+
n.default = e;
|
|
21
22
|
return Object.freeze(n);
|
|
22
23
|
}
|
|
23
24
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
@@ -117,11 +118,20 @@ function hasArrayChanged() {
|
|
|
117
118
|
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
118
119
|
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
const getModuleName = (id) => {
|
|
122
|
+
const idArray = id.split("/");
|
|
123
|
+
if (idArray.length < 2) {
|
|
124
|
+
return id;
|
|
125
|
+
}
|
|
126
|
+
return idArray[0] + "/" + idArray[1];
|
|
127
|
+
};
|
|
128
|
+
const getRootDomDefaultClassName = (moduleName) => {
|
|
129
|
+
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
130
|
+
return `bridge-root-component-${name}`;
|
|
131
|
+
};
|
|
124
132
|
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
133
|
+
const host = runtime.getInstance();
|
|
134
|
+
context.LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
|
|
125
135
|
const RemoteApp2 = () => {
|
|
126
136
|
context.LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
127
137
|
const {
|
|
@@ -139,9 +149,10 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
139
149
|
const providerInfoRef = React.useRef(null);
|
|
140
150
|
React.useEffect(() => {
|
|
141
151
|
const renderTimeout = setTimeout(() => {
|
|
152
|
+
var _a, _b, _c, _d;
|
|
142
153
|
const providerReturn = providerInfo();
|
|
143
154
|
providerInfoRef.current = providerReturn;
|
|
144
|
-
|
|
155
|
+
let renderProps = {
|
|
145
156
|
moduleName,
|
|
146
157
|
dom: rootRef.current,
|
|
147
158
|
basename,
|
|
@@ -154,34 +165,55 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
154
165
|
`createRemoteComponent LazyComponent render >>>`,
|
|
155
166
|
renderProps
|
|
156
167
|
);
|
|
168
|
+
if ((host == null ? void 0 : host.bridgeHook) && ((_b = (_a = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender)) {
|
|
169
|
+
const beforeBridgeRenderRes = (_d = (_c = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _c.lifecycle) == null ? void 0 : _d.beforeBridgeRender.emit({
|
|
170
|
+
...renderProps
|
|
171
|
+
});
|
|
172
|
+
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
|
|
173
|
+
renderProps = {
|
|
174
|
+
...renderProps,
|
|
175
|
+
...extraProps
|
|
176
|
+
};
|
|
177
|
+
}
|
|
157
178
|
providerReturn.render(renderProps);
|
|
158
179
|
});
|
|
159
180
|
return () => {
|
|
160
181
|
clearTimeout(renderTimeout);
|
|
161
182
|
setTimeout(() => {
|
|
162
|
-
var _a, _b;
|
|
183
|
+
var _a, _b, _c, _d, _e, _f;
|
|
163
184
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
164
185
|
context.LoggerInstance.log(
|
|
165
186
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
166
187
|
{ moduleName, basename, dom: renderDom.current }
|
|
167
188
|
);
|
|
168
|
-
(_b =
|
|
189
|
+
if ((host == null ? void 0 : host.bridgeHook) && ((_c = (_b = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.afterBridgeDestroy)) {
|
|
190
|
+
(_e = (_d = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy.emit({
|
|
191
|
+
moduleName,
|
|
192
|
+
dom: renderDom.current,
|
|
193
|
+
basename,
|
|
194
|
+
memoryRoute,
|
|
195
|
+
fallback,
|
|
196
|
+
...resProps
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
(_f = providerInfoRef.current) == null ? void 0 : _f.destroy({
|
|
169
200
|
dom: renderDom.current
|
|
170
201
|
});
|
|
171
202
|
}
|
|
172
203
|
});
|
|
173
204
|
};
|
|
174
205
|
}, []);
|
|
206
|
+
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
175
207
|
return /* @__PURE__ */ React.createElement(
|
|
176
208
|
"div",
|
|
177
209
|
{
|
|
178
|
-
className:
|
|
210
|
+
className: rootComponentClassName,
|
|
179
211
|
style: props == null ? void 0 : props.style,
|
|
180
212
|
ref: rootRef
|
|
181
213
|
}
|
|
182
214
|
);
|
|
183
215
|
};
|
|
184
|
-
RemoteApp2["__APP_VERSION__"] = "0.6.
|
|
216
|
+
RemoteApp2["__APP_VERSION__"] = "0.6.11";
|
|
185
217
|
return /* @__PURE__ */ React.createElement(RemoteApp2, null);
|
|
186
218
|
});
|
|
187
219
|
function withRouterData(WrappedComponent) {
|
|
@@ -238,7 +270,7 @@ function withRouterData(WrappedComponent) {
|
|
|
238
270
|
name: props.name,
|
|
239
271
|
pathname: location.pathname
|
|
240
272
|
});
|
|
241
|
-
|
|
273
|
+
context.f();
|
|
242
274
|
}
|
|
243
275
|
setPathname(location.pathname);
|
|
244
276
|
}, [location]);
|
|
@@ -331,7 +363,7 @@ if (process.env.NODE_ENV === "production") {
|
|
|
331
363
|
};
|
|
332
364
|
}
|
|
333
365
|
function createBridgeComponent(bridgeInfo) {
|
|
334
|
-
return () => {
|
|
366
|
+
return (params) => {
|
|
335
367
|
const rootMap = /* @__PURE__ */ new Map();
|
|
336
368
|
const RawComponent = (info) => {
|
|
337
369
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
@@ -347,6 +379,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
347
379
|
};
|
|
348
380
|
return {
|
|
349
381
|
async render(info) {
|
|
382
|
+
var _a, _b;
|
|
350
383
|
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
351
384
|
const {
|
|
352
385
|
moduleName,
|
|
@@ -356,6 +389,9 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
356
389
|
fallback,
|
|
357
390
|
...propsInfo
|
|
358
391
|
} = info;
|
|
392
|
+
const beforeBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeRender) || ((_a = params == null ? void 0 : params.hooks) == null ? void 0 : _a.beforeBridgeRender);
|
|
393
|
+
const beforeBridgeRenderRes = beforeBridgeRender && beforeBridgeRender(info);
|
|
394
|
+
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
|
|
359
395
|
const rootComponentWithErrorBoundary = (
|
|
360
396
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
361
397
|
/* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
|
|
@@ -366,7 +402,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
366
402
|
basename,
|
|
367
403
|
memoryRoute
|
|
368
404
|
},
|
|
369
|
-
propsInfo
|
|
405
|
+
propsInfo: { ...propsInfo, ...extraProps }
|
|
370
406
|
}
|
|
371
407
|
))
|
|
372
408
|
);
|
|
@@ -384,11 +420,19 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
384
420
|
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
385
421
|
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
386
422
|
}
|
|
423
|
+
const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_b = params == null ? void 0 : params.hooks) == null ? void 0 : _b.afterBridgeRender);
|
|
424
|
+
afterBridgeRender && afterBridgeRender(info);
|
|
387
425
|
},
|
|
388
426
|
async destroy(info) {
|
|
427
|
+
var _a, _b;
|
|
389
428
|
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
390
429
|
dom: info.dom
|
|
391
430
|
});
|
|
431
|
+
if ((bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) && typeof (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) === "function") {
|
|
432
|
+
bridgeInfo.hooks.beforeBridgeDestroy(info);
|
|
433
|
+
}
|
|
434
|
+
const beforeBridgeDestroy = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) || ((_a = params == null ? void 0 : params.hooks) == null ? void 0 : _a.beforeBridgeDestroy);
|
|
435
|
+
beforeBridgeDestroy && beforeBridgeDestroy(info);
|
|
392
436
|
if (context.atLeastReact18(React__namespace)) {
|
|
393
437
|
const root = rootMap.get(info.dom);
|
|
394
438
|
root == null ? void 0 : root.unmount();
|
|
@@ -396,6 +440,8 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
396
440
|
} else {
|
|
397
441
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
398
442
|
}
|
|
443
|
+
const afterBridgeDestroy = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_b = params == null ? void 0 : params.hooks) == null ? void 0 : _b.afterBridgeDestroy);
|
|
444
|
+
afterBridgeDestroy && afterBridgeDestroy(info);
|
|
399
445
|
},
|
|
400
446
|
rawComponent: bridgeInfo.rootComponent,
|
|
401
447
|
__BRIDGE_FN__: (_args) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,18 @@ import { ErrorInfo } from 'react';
|
|
|
5
5
|
import { PropsWithChildren } from 'react';
|
|
6
6
|
import * as React_2 from 'react';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
declare type BridgeHooks = {
|
|
9
|
+
beforeBridgeRender?: (params: RenderFnParams) => any;
|
|
10
|
+
afterBridgeRender?: (params: RenderFnParams) => any;
|
|
11
|
+
beforeBridgeDestroy?: (params: DestroyParams) => any;
|
|
12
|
+
afterBridgeDestroy?: (params: DestroyParams) => any;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): (params: {
|
|
16
|
+
hooks?: BridgeHooks;
|
|
17
|
+
}) => {
|
|
18
|
+
render(info: RenderParams): Promise<void>;
|
|
19
|
+
destroy(info: DestroyParams): Promise<void>;
|
|
13
20
|
rawComponent: React_2.ComponentType<T>;
|
|
14
21
|
__BRIDGE_FN__: (_args: T) => void;
|
|
15
22
|
};
|
|
@@ -21,6 +28,10 @@ export declare function createRemoteComponent<T, E extends keyof T>(info: {
|
|
|
21
28
|
export?: E;
|
|
22
29
|
}): default_2.ForwardRefExoticComponent<default_2.PropsWithoutRef<ProviderParams & ("__BRIDGE_FN__" extends keyof (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never) ? (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"] extends (...args: any) => any ? Parameters<(T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"]>[0] : {} : {})> & default_2.RefAttributes<HTMLDivElement>>;
|
|
23
30
|
|
|
31
|
+
declare type DestroyParams = {
|
|
32
|
+
dom: HTMLElement;
|
|
33
|
+
};
|
|
34
|
+
|
|
24
35
|
declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {
|
|
25
36
|
fallback?: never;
|
|
26
37
|
FallbackComponent: ComponentType<FallbackProps>;
|
|
@@ -48,6 +59,7 @@ declare type FallbackProps = {
|
|
|
48
59
|
declare type ProviderFnParams<T> = {
|
|
49
60
|
rootComponent: React_2.ComponentType<T>;
|
|
50
61
|
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
62
|
+
hooks?: BridgeHooks;
|
|
51
63
|
};
|
|
52
64
|
|
|
53
65
|
export declare interface ProviderParams {
|
|
@@ -64,6 +76,8 @@ export declare interface RenderFnParams extends ProviderParams {
|
|
|
64
76
|
dom: HTMLElement;
|
|
65
77
|
}
|
|
66
78
|
|
|
79
|
+
declare type RenderParams = RenderFnParams & any;
|
|
80
|
+
|
|
67
81
|
declare type RootType = HTMLElement | default_3.Root;
|
|
68
82
|
|
|
69
83
|
export { }
|
package/dist/index.es.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import React__default, { createContext, Component, createElement, isValidElement, forwardRef, useRef, useEffect, useContext, useState } from "react";
|
|
3
|
-
import { L as LoggerInstance, p as pathJoin, a as atLeastReact18, R as RouterContext } from "./context-
|
|
3
|
+
import { L as LoggerInstance, p as pathJoin, f, a as atLeastReact18, R as RouterContext } from "./context-Bw2PEwa6.js";
|
|
4
4
|
import * as ReactRouterDOM from "react-router-dom";
|
|
5
|
+
import { getInstance } from "@module-federation/runtime";
|
|
5
6
|
import ReactDOM from "react-dom";
|
|
6
7
|
const ErrorBoundaryContext = createContext(null);
|
|
7
8
|
const initialState = {
|
|
@@ -98,11 +99,20 @@ function hasArrayChanged() {
|
|
|
98
99
|
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
99
100
|
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
const getModuleName = (id) => {
|
|
103
|
+
const idArray = id.split("/");
|
|
104
|
+
if (idArray.length < 2) {
|
|
105
|
+
return id;
|
|
106
|
+
}
|
|
107
|
+
return idArray[0] + "/" + idArray[1];
|
|
108
|
+
};
|
|
109
|
+
const getRootDomDefaultClassName = (moduleName) => {
|
|
110
|
+
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
111
|
+
return `bridge-root-component-${name}`;
|
|
112
|
+
};
|
|
105
113
|
const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
114
|
+
const host = getInstance();
|
|
115
|
+
LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
|
|
106
116
|
const RemoteApp2 = () => {
|
|
107
117
|
LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
108
118
|
const {
|
|
@@ -120,9 +130,10 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
120
130
|
const providerInfoRef = useRef(null);
|
|
121
131
|
useEffect(() => {
|
|
122
132
|
const renderTimeout = setTimeout(() => {
|
|
133
|
+
var _a, _b, _c, _d;
|
|
123
134
|
const providerReturn = providerInfo();
|
|
124
135
|
providerInfoRef.current = providerReturn;
|
|
125
|
-
|
|
136
|
+
let renderProps = {
|
|
126
137
|
moduleName,
|
|
127
138
|
dom: rootRef.current,
|
|
128
139
|
basename,
|
|
@@ -135,34 +146,55 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
135
146
|
`createRemoteComponent LazyComponent render >>>`,
|
|
136
147
|
renderProps
|
|
137
148
|
);
|
|
149
|
+
if ((host == null ? void 0 : host.bridgeHook) && ((_b = (_a = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender)) {
|
|
150
|
+
const beforeBridgeRenderRes = (_d = (_c = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _c.lifecycle) == null ? void 0 : _d.beforeBridgeRender.emit({
|
|
151
|
+
...renderProps
|
|
152
|
+
});
|
|
153
|
+
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
|
|
154
|
+
renderProps = {
|
|
155
|
+
...renderProps,
|
|
156
|
+
...extraProps
|
|
157
|
+
};
|
|
158
|
+
}
|
|
138
159
|
providerReturn.render(renderProps);
|
|
139
160
|
});
|
|
140
161
|
return () => {
|
|
141
162
|
clearTimeout(renderTimeout);
|
|
142
163
|
setTimeout(() => {
|
|
143
|
-
var _a, _b;
|
|
164
|
+
var _a, _b, _c, _d, _e, _f;
|
|
144
165
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
145
166
|
LoggerInstance.log(
|
|
146
167
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
147
168
|
{ moduleName, basename, dom: renderDom.current }
|
|
148
169
|
);
|
|
149
|
-
(_b =
|
|
170
|
+
if ((host == null ? void 0 : host.bridgeHook) && ((_c = (_b = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.afterBridgeDestroy)) {
|
|
171
|
+
(_e = (_d = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy.emit({
|
|
172
|
+
moduleName,
|
|
173
|
+
dom: renderDom.current,
|
|
174
|
+
basename,
|
|
175
|
+
memoryRoute,
|
|
176
|
+
fallback,
|
|
177
|
+
...resProps
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
(_f = providerInfoRef.current) == null ? void 0 : _f.destroy({
|
|
150
181
|
dom: renderDom.current
|
|
151
182
|
});
|
|
152
183
|
}
|
|
153
184
|
});
|
|
154
185
|
};
|
|
155
186
|
}, []);
|
|
187
|
+
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
156
188
|
return /* @__PURE__ */ React__default.createElement(
|
|
157
189
|
"div",
|
|
158
190
|
{
|
|
159
|
-
className:
|
|
191
|
+
className: rootComponentClassName,
|
|
160
192
|
style: props == null ? void 0 : props.style,
|
|
161
193
|
ref: rootRef
|
|
162
194
|
}
|
|
163
195
|
);
|
|
164
196
|
};
|
|
165
|
-
RemoteApp2["__APP_VERSION__"] = "0.6.
|
|
197
|
+
RemoteApp2["__APP_VERSION__"] = "0.6.11";
|
|
166
198
|
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
|
|
167
199
|
});
|
|
168
200
|
function withRouterData(WrappedComponent) {
|
|
@@ -219,7 +251,7 @@ function withRouterData(WrappedComponent) {
|
|
|
219
251
|
name: props.name,
|
|
220
252
|
pathname: location.pathname
|
|
221
253
|
});
|
|
222
|
-
|
|
254
|
+
f();
|
|
223
255
|
}
|
|
224
256
|
setPathname(location.pathname);
|
|
225
257
|
}, [location]);
|
|
@@ -312,7 +344,7 @@ if (process.env.NODE_ENV === "production") {
|
|
|
312
344
|
};
|
|
313
345
|
}
|
|
314
346
|
function createBridgeComponent(bridgeInfo) {
|
|
315
|
-
return () => {
|
|
347
|
+
return (params) => {
|
|
316
348
|
const rootMap = /* @__PURE__ */ new Map();
|
|
317
349
|
const RawComponent = (info) => {
|
|
318
350
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
@@ -328,6 +360,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
328
360
|
};
|
|
329
361
|
return {
|
|
330
362
|
async render(info) {
|
|
363
|
+
var _a, _b;
|
|
331
364
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
332
365
|
const {
|
|
333
366
|
moduleName,
|
|
@@ -337,6 +370,9 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
337
370
|
fallback,
|
|
338
371
|
...propsInfo
|
|
339
372
|
} = info;
|
|
373
|
+
const beforeBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeRender) || ((_a = params == null ? void 0 : params.hooks) == null ? void 0 : _a.beforeBridgeRender);
|
|
374
|
+
const beforeBridgeRenderRes = beforeBridgeRender && beforeBridgeRender(info);
|
|
375
|
+
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
|
|
340
376
|
const rootComponentWithErrorBoundary = (
|
|
341
377
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
342
378
|
/* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
|
|
@@ -347,7 +383,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
347
383
|
basename,
|
|
348
384
|
memoryRoute
|
|
349
385
|
},
|
|
350
|
-
propsInfo
|
|
386
|
+
propsInfo: { ...propsInfo, ...extraProps }
|
|
351
387
|
}
|
|
352
388
|
))
|
|
353
389
|
);
|
|
@@ -365,11 +401,19 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
365
401
|
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
366
402
|
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
367
403
|
}
|
|
404
|
+
const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_b = params == null ? void 0 : params.hooks) == null ? void 0 : _b.afterBridgeRender);
|
|
405
|
+
afterBridgeRender && afterBridgeRender(info);
|
|
368
406
|
},
|
|
369
407
|
async destroy(info) {
|
|
408
|
+
var _a, _b;
|
|
370
409
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
371
410
|
dom: info.dom
|
|
372
411
|
});
|
|
412
|
+
if ((bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) && typeof (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) === "function") {
|
|
413
|
+
bridgeInfo.hooks.beforeBridgeDestroy(info);
|
|
414
|
+
}
|
|
415
|
+
const beforeBridgeDestroy = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) || ((_a = params == null ? void 0 : params.hooks) == null ? void 0 : _a.beforeBridgeDestroy);
|
|
416
|
+
beforeBridgeDestroy && beforeBridgeDestroy(info);
|
|
373
417
|
if (atLeastReact18(React)) {
|
|
374
418
|
const root = rootMap.get(info.dom);
|
|
375
419
|
root == null ? void 0 : root.unmount();
|
|
@@ -377,6 +421,8 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
377
421
|
} else {
|
|
378
422
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
379
423
|
}
|
|
424
|
+
const afterBridgeDestroy = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_b = params == null ? void 0 : params.hooks) == null ? void 0 : _b.afterBridgeDestroy);
|
|
425
|
+
afterBridgeDestroy && afterBridgeDestroy(info);
|
|
380
426
|
},
|
|
381
427
|
rawComponent: bridgeInfo.rootComponent,
|
|
382
428
|
__BRIDGE_FN__: (_args) => {
|
package/dist/router-v5.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const ReactRouterDom$1 = require("react-router-dom/index.js");
|
|
5
|
-
const context = require("./context
|
|
5
|
+
const context = require("./context--mtFt3tp.cjs");
|
|
6
6
|
const ReactRouterDom = require("react-router-dom/index.js");
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
package/dist/router-v5.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default, { useContext } from "react";
|
|
2
2
|
import * as ReactRouterDom$1 from "react-router-dom/index.js";
|
|
3
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-
|
|
3
|
+
import { R as RouterContext, L as LoggerInstance } from "./context-Bw2PEwa6.js";
|
|
4
4
|
export * from "react-router-dom/index.js";
|
|
5
5
|
function WraperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
package/dist/router-v6.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const ReactRouterDom = require("react-router-dom/dist/index.js");
|
|
5
|
-
const context = require("./context
|
|
5
|
+
const context = require("./context--mtFt3tp.cjs");
|
|
6
6
|
function _interopNamespaceDefault(e) {
|
|
7
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
8
|
if (e) {
|
package/dist/router-v6.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { useContext } from "react";
|
|
2
2
|
import * as ReactRouterDom from "react-router-dom/dist/index.js";
|
|
3
3
|
export * from "react-router-dom/dist/index.js";
|
|
4
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-
|
|
4
|
+
import { R as RouterContext, L as LoggerInstance } from "./context-Bw2PEwa6.js";
|
|
5
5
|
function WraperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
|
7
7
|
const routerContextProps = useContext(RouterContext) || {};
|