@module-federation/bridge-react 0.0.0-next-20241107072243 → 0.0.0-next-20241108091829
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 +4 -4
- package/dist/{context-BcyT-d0V.js → context-Dh6IUBWT.js} +20 -1
- package/dist/{context-BBLu8BlQ.cjs → context-DmzxwI_7.cjs} +19 -0
- package/dist/index.cjs.js +45 -50
- package/dist/index.es.js +44 -49
- 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 +1 -1
- package/dist/router.es.js +1 -1
- package/package.json +4 -4
- package/src/provider.tsx +21 -22
- package/src/remote/index.tsx +24 -52
- package/src/utils.ts +21 -0
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-20241108091829
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
- Updated dependencies [8712967]
|
|
9
9
|
- Updated dependencies [6db4c5f]
|
|
10
10
|
- Updated dependencies [3082116]
|
|
11
|
-
- @module-federation/runtime@0.0.0-next-
|
|
12
|
-
- @module-federation/sdk@0.0.0-next-
|
|
13
|
-
- @module-federation/bridge-shared@0.0.0-next-
|
|
11
|
+
- @module-federation/runtime@0.0.0-next-20241108091829
|
|
12
|
+
- @module-federation/sdk@0.0.0-next-20241108091829
|
|
13
|
+
- @module-federation/bridge-shared@0.0.0-next-20241108091829
|
|
14
14
|
|
|
15
15
|
## 0.7.0
|
|
16
16
|
|
|
@@ -328,10 +328,29 @@ function pathJoin(...args) {
|
|
|
328
328
|
}, "");
|
|
329
329
|
return res || "/";
|
|
330
330
|
}
|
|
331
|
+
const getModuleName = (id) => {
|
|
332
|
+
if (!id) {
|
|
333
|
+
return id;
|
|
334
|
+
}
|
|
335
|
+
const idArray = id.split("/");
|
|
336
|
+
if (idArray.length < 2) {
|
|
337
|
+
return id;
|
|
338
|
+
}
|
|
339
|
+
return idArray[0] + "/" + idArray[1];
|
|
340
|
+
};
|
|
341
|
+
const getRootDomDefaultClassName = (moduleName) => {
|
|
342
|
+
if (!moduleName) {
|
|
343
|
+
return "";
|
|
344
|
+
}
|
|
345
|
+
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
346
|
+
return `bridge-root-component-${name}`;
|
|
347
|
+
};
|
|
331
348
|
const RouterContext = React__default.createContext(null);
|
|
332
349
|
export {
|
|
333
350
|
LoggerInstance as L,
|
|
334
351
|
RouterContext as R,
|
|
335
|
-
|
|
352
|
+
getModuleName as a,
|
|
353
|
+
atLeastReact18 as b,
|
|
354
|
+
getRootDomDefaultClassName as g,
|
|
336
355
|
pathJoin as p
|
|
337
356
|
};
|
|
@@ -329,8 +329,27 @@ function pathJoin(...args) {
|
|
|
329
329
|
}, "");
|
|
330
330
|
return res || "/";
|
|
331
331
|
}
|
|
332
|
+
const getModuleName = (id) => {
|
|
333
|
+
if (!id) {
|
|
334
|
+
return id;
|
|
335
|
+
}
|
|
336
|
+
const idArray = id.split("/");
|
|
337
|
+
if (idArray.length < 2) {
|
|
338
|
+
return id;
|
|
339
|
+
}
|
|
340
|
+
return idArray[0] + "/" + idArray[1];
|
|
341
|
+
};
|
|
342
|
+
const getRootDomDefaultClassName = (moduleName) => {
|
|
343
|
+
if (!moduleName) {
|
|
344
|
+
return "";
|
|
345
|
+
}
|
|
346
|
+
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
347
|
+
return `bridge-root-component-${name}`;
|
|
348
|
+
};
|
|
332
349
|
const RouterContext = React.createContext(null);
|
|
333
350
|
exports.LoggerInstance = LoggerInstance;
|
|
334
351
|
exports.RouterContext = RouterContext;
|
|
335
352
|
exports.atLeastReact18 = atLeastReact18;
|
|
353
|
+
exports.getModuleName = getModuleName;
|
|
354
|
+
exports.getRootDomDefaultClassName = getRootDomDefaultClassName;
|
|
336
355
|
exports.pathJoin = pathJoin;
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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-DmzxwI_7.cjs");
|
|
5
5
|
const ReactRouterDOM = require("react-router-dom");
|
|
6
6
|
const runtime = require("@module-federation/runtime");
|
|
7
7
|
const ReactDOM = require("react-dom");
|
|
@@ -122,20 +122,6 @@ function e() {
|
|
|
122
122
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
123
123
|
window.dispatchEvent(t);
|
|
124
124
|
}
|
|
125
|
-
const getModuleName = (id) => {
|
|
126
|
-
const idArray = id.split("/");
|
|
127
|
-
if (idArray.length < 2) {
|
|
128
|
-
return id;
|
|
129
|
-
}
|
|
130
|
-
return idArray[0] + "/" + idArray[1];
|
|
131
|
-
};
|
|
132
|
-
const getRootDomDefaultClassName = (moduleName) => {
|
|
133
|
-
if (!moduleName) {
|
|
134
|
-
return "";
|
|
135
|
-
}
|
|
136
|
-
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
137
|
-
return `bridge-root-component-${name}`;
|
|
138
|
-
};
|
|
139
125
|
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
140
126
|
const host = runtime.getInstance();
|
|
141
127
|
context.LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
|
|
@@ -156,7 +142,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
156
142
|
const providerInfoRef = React.useRef(null);
|
|
157
143
|
React.useEffect(() => {
|
|
158
144
|
const renderTimeout = setTimeout(() => {
|
|
159
|
-
var _a, _b, _c, _d;
|
|
145
|
+
var _a, _b, _c, _d, _e, _f;
|
|
160
146
|
const providerReturn = providerInfo();
|
|
161
147
|
providerInfoRef.current = providerReturn;
|
|
162
148
|
let renderProps = {
|
|
@@ -172,46 +158,45 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
172
158
|
`createRemoteComponent LazyComponent render >>>`,
|
|
173
159
|
renderProps
|
|
174
160
|
);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
...renderProps
|
|
178
|
-
});
|
|
179
|
-
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
|
|
180
|
-
renderProps = {
|
|
181
|
-
...renderProps,
|
|
182
|
-
...extraProps
|
|
183
|
-
};
|
|
184
|
-
}
|
|
161
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
|
|
162
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
185
163
|
providerReturn.render(renderProps);
|
|
164
|
+
(_f = (_e = (_d = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
|
|
186
165
|
});
|
|
187
166
|
return () => {
|
|
188
167
|
clearTimeout(renderTimeout);
|
|
189
168
|
setTimeout(() => {
|
|
190
|
-
var _a, _b, _c, _d, _e, _f;
|
|
169
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
191
170
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
192
171
|
context.LoggerInstance.log(
|
|
193
172
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
194
173
|
{ moduleName, basename, dom: renderDom.current }
|
|
195
174
|
);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
(_f = providerInfoRef.current) == null ? void 0 : _f.destroy({
|
|
175
|
+
(_d = (_c = (_b = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
176
|
+
moduleName,
|
|
177
|
+
dom: renderDom.current,
|
|
178
|
+
basename,
|
|
179
|
+
memoryRoute,
|
|
180
|
+
fallback,
|
|
181
|
+
...resProps
|
|
182
|
+
});
|
|
183
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
207
184
|
moduleName,
|
|
208
185
|
dom: renderDom.current
|
|
209
186
|
});
|
|
187
|
+
(_h = (_g = (_f = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
188
|
+
moduleName,
|
|
189
|
+
dom: renderDom.current,
|
|
190
|
+
basename,
|
|
191
|
+
memoryRoute,
|
|
192
|
+
fallback,
|
|
193
|
+
...resProps
|
|
194
|
+
});
|
|
210
195
|
}
|
|
211
196
|
});
|
|
212
197
|
};
|
|
213
198
|
}, []);
|
|
214
|
-
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
199
|
+
const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
215
200
|
return /* @__PURE__ */ React.createElement(
|
|
216
201
|
"div",
|
|
217
202
|
{
|
|
@@ -387,7 +372,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
387
372
|
};
|
|
388
373
|
return {
|
|
389
374
|
async render(info) {
|
|
390
|
-
var _a, _b;
|
|
375
|
+
var _a, _b, _c, _d;
|
|
391
376
|
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
392
377
|
const {
|
|
393
378
|
moduleName,
|
|
@@ -397,9 +382,12 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
397
382
|
fallback,
|
|
398
383
|
...propsInfo
|
|
399
384
|
} = info;
|
|
400
|
-
const
|
|
401
|
-
const
|
|
402
|
-
|
|
385
|
+
const moduleNameWithoutExpose = context.getModuleName(moduleName);
|
|
386
|
+
const instance = __FEDERATION__.__INSTANCES__.find(
|
|
387
|
+
(v) => v.name === moduleNameWithoutExpose
|
|
388
|
+
);
|
|
389
|
+
context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
390
|
+
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(info)) || {};
|
|
403
391
|
const rootComponentWithErrorBoundary = (
|
|
404
392
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
405
393
|
/* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
|
|
@@ -410,7 +398,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
410
398
|
basename,
|
|
411
399
|
memoryRoute
|
|
412
400
|
},
|
|
413
|
-
propsInfo: { ...propsInfo, ...extraProps }
|
|
401
|
+
propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
|
|
414
402
|
}
|
|
415
403
|
))
|
|
416
404
|
);
|
|
@@ -428,16 +416,24 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
428
416
|
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
429
417
|
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
430
418
|
}
|
|
431
|
-
const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((
|
|
419
|
+
const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_d = params == null ? void 0 : params.hooks) == null ? void 0 : _d.afterBridgeRender);
|
|
432
420
|
afterBridgeRender && afterBridgeRender(info);
|
|
433
421
|
},
|
|
434
422
|
async destroy(info) {
|
|
435
|
-
var _a, _b;
|
|
423
|
+
var _a, _b, _c, _d, _e, _f;
|
|
436
424
|
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
437
425
|
dom: info.dom
|
|
438
426
|
});
|
|
439
|
-
const
|
|
440
|
-
|
|
427
|
+
const moduleNameWithoutExpose = context.getModuleName(info.moduleName);
|
|
428
|
+
context.LoggerInstance.log(
|
|
429
|
+
`createBridgeComponent remote module without expose name >>>`,
|
|
430
|
+
moduleNameWithoutExpose
|
|
431
|
+
);
|
|
432
|
+
const instance = __FEDERATION__.__INSTANCES__.find(
|
|
433
|
+
(v) => v.name === moduleNameWithoutExpose
|
|
434
|
+
);
|
|
435
|
+
context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
436
|
+
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeDestroy) == null ? void 0 : _c.emit(info);
|
|
441
437
|
if (context.atLeastReact18(React__namespace)) {
|
|
442
438
|
const root = rootMap.get(info.dom);
|
|
443
439
|
root == null ? void 0 : root.unmount();
|
|
@@ -445,8 +441,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
445
441
|
} else {
|
|
446
442
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
447
443
|
}
|
|
448
|
-
|
|
449
|
-
afterBridgeDestroy && afterBridgeDestroy(info);
|
|
444
|
+
(_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy) == null ? void 0 : _f.emit(info);
|
|
450
445
|
},
|
|
451
446
|
rawComponent: bridgeInfo.rootComponent,
|
|
452
447
|
__BRIDGE_FN__: (_args) => {
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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, g as getRootDomDefaultClassName, p as pathJoin, a as getModuleName, b as atLeastReact18, R as RouterContext } from "./context-Dh6IUBWT.js";
|
|
4
4
|
import * as ReactRouterDOM from "react-router-dom";
|
|
5
5
|
import { getInstance } from "@module-federation/runtime";
|
|
6
6
|
import ReactDOM from "react-dom";
|
|
@@ -103,20 +103,6 @@ function e() {
|
|
|
103
103
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
104
104
|
window.dispatchEvent(t);
|
|
105
105
|
}
|
|
106
|
-
const getModuleName = (id) => {
|
|
107
|
-
const idArray = id.split("/");
|
|
108
|
-
if (idArray.length < 2) {
|
|
109
|
-
return id;
|
|
110
|
-
}
|
|
111
|
-
return idArray[0] + "/" + idArray[1];
|
|
112
|
-
};
|
|
113
|
-
const getRootDomDefaultClassName = (moduleName) => {
|
|
114
|
-
if (!moduleName) {
|
|
115
|
-
return "";
|
|
116
|
-
}
|
|
117
|
-
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
118
|
-
return `bridge-root-component-${name}`;
|
|
119
|
-
};
|
|
120
106
|
const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
121
107
|
const host = getInstance();
|
|
122
108
|
LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
|
|
@@ -137,7 +123,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
137
123
|
const providerInfoRef = useRef(null);
|
|
138
124
|
useEffect(() => {
|
|
139
125
|
const renderTimeout = setTimeout(() => {
|
|
140
|
-
var _a, _b, _c, _d;
|
|
126
|
+
var _a, _b, _c, _d, _e, _f;
|
|
141
127
|
const providerReturn = providerInfo();
|
|
142
128
|
providerInfoRef.current = providerReturn;
|
|
143
129
|
let renderProps = {
|
|
@@ -153,41 +139,40 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
153
139
|
`createRemoteComponent LazyComponent render >>>`,
|
|
154
140
|
renderProps
|
|
155
141
|
);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
...renderProps
|
|
159
|
-
});
|
|
160
|
-
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
|
|
161
|
-
renderProps = {
|
|
162
|
-
...renderProps,
|
|
163
|
-
...extraProps
|
|
164
|
-
};
|
|
165
|
-
}
|
|
142
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
|
|
143
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
166
144
|
providerReturn.render(renderProps);
|
|
145
|
+
(_f = (_e = (_d = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
|
|
167
146
|
});
|
|
168
147
|
return () => {
|
|
169
148
|
clearTimeout(renderTimeout);
|
|
170
149
|
setTimeout(() => {
|
|
171
|
-
var _a, _b, _c, _d, _e, _f;
|
|
150
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
172
151
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
173
152
|
LoggerInstance.log(
|
|
174
153
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
175
154
|
{ moduleName, basename, dom: renderDom.current }
|
|
176
155
|
);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
(_f = providerInfoRef.current) == null ? void 0 : _f.destroy({
|
|
156
|
+
(_d = (_c = (_b = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
157
|
+
moduleName,
|
|
158
|
+
dom: renderDom.current,
|
|
159
|
+
basename,
|
|
160
|
+
memoryRoute,
|
|
161
|
+
fallback,
|
|
162
|
+
...resProps
|
|
163
|
+
});
|
|
164
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
188
165
|
moduleName,
|
|
189
166
|
dom: renderDom.current
|
|
190
167
|
});
|
|
168
|
+
(_h = (_g = (_f = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
169
|
+
moduleName,
|
|
170
|
+
dom: renderDom.current,
|
|
171
|
+
basename,
|
|
172
|
+
memoryRoute,
|
|
173
|
+
fallback,
|
|
174
|
+
...resProps
|
|
175
|
+
});
|
|
191
176
|
}
|
|
192
177
|
});
|
|
193
178
|
};
|
|
@@ -368,7 +353,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
368
353
|
};
|
|
369
354
|
return {
|
|
370
355
|
async render(info) {
|
|
371
|
-
var _a, _b;
|
|
356
|
+
var _a, _b, _c, _d;
|
|
372
357
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
373
358
|
const {
|
|
374
359
|
moduleName,
|
|
@@ -378,9 +363,12 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
378
363
|
fallback,
|
|
379
364
|
...propsInfo
|
|
380
365
|
} = info;
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
|
|
366
|
+
const moduleNameWithoutExpose = getModuleName(moduleName);
|
|
367
|
+
const instance = __FEDERATION__.__INSTANCES__.find(
|
|
368
|
+
(v) => v.name === moduleNameWithoutExpose
|
|
369
|
+
);
|
|
370
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
371
|
+
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(info)) || {};
|
|
384
372
|
const rootComponentWithErrorBoundary = (
|
|
385
373
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
386
374
|
/* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
|
|
@@ -391,7 +379,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
391
379
|
basename,
|
|
392
380
|
memoryRoute
|
|
393
381
|
},
|
|
394
|
-
propsInfo: { ...propsInfo, ...extraProps }
|
|
382
|
+
propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
|
|
395
383
|
}
|
|
396
384
|
))
|
|
397
385
|
);
|
|
@@ -409,16 +397,24 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
409
397
|
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
410
398
|
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
411
399
|
}
|
|
412
|
-
const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((
|
|
400
|
+
const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_d = params == null ? void 0 : params.hooks) == null ? void 0 : _d.afterBridgeRender);
|
|
413
401
|
afterBridgeRender && afterBridgeRender(info);
|
|
414
402
|
},
|
|
415
403
|
async destroy(info) {
|
|
416
|
-
var _a, _b;
|
|
404
|
+
var _a, _b, _c, _d, _e, _f;
|
|
417
405
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
418
406
|
dom: info.dom
|
|
419
407
|
});
|
|
420
|
-
const
|
|
421
|
-
|
|
408
|
+
const moduleNameWithoutExpose = getModuleName(info.moduleName);
|
|
409
|
+
LoggerInstance.log(
|
|
410
|
+
`createBridgeComponent remote module without expose name >>>`,
|
|
411
|
+
moduleNameWithoutExpose
|
|
412
|
+
);
|
|
413
|
+
const instance = __FEDERATION__.__INSTANCES__.find(
|
|
414
|
+
(v) => v.name === moduleNameWithoutExpose
|
|
415
|
+
);
|
|
416
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
417
|
+
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeDestroy) == null ? void 0 : _c.emit(info);
|
|
422
418
|
if (atLeastReact18(React)) {
|
|
423
419
|
const root = rootMap.get(info.dom);
|
|
424
420
|
root == null ? void 0 : root.unmount();
|
|
@@ -426,8 +422,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
426
422
|
} else {
|
|
427
423
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
428
424
|
}
|
|
429
|
-
|
|
430
|
-
afterBridgeDestroy && afterBridgeDestroy(info);
|
|
425
|
+
(_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy) == null ? void 0 : _f.emit(info);
|
|
431
426
|
},
|
|
432
427
|
rawComponent: bridgeInfo.rootComponent,
|
|
433
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-DmzxwI_7.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-Dh6IUBWT.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-DmzxwI_7.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-Dh6IUBWT.js";
|
|
5
5
|
function WraperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
|
7
7
|
const routerContextProps = useContext(RouterContext) || {};
|
package/dist/router.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/");
|
|
5
|
-
const context = require("./context-
|
|
5
|
+
const context = require("./context-DmzxwI_7.cjs");
|
|
6
6
|
function _interopNamespaceDefault(e) {
|
|
7
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
8
|
if (e) {
|
package/dist/router.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { useContext } from "react";
|
|
2
2
|
import * as ReactRouterDom from "react-router-dom/";
|
|
3
3
|
export * from "react-router-dom/";
|
|
4
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-
|
|
4
|
+
import { R as RouterContext, L as LoggerInstance } from "./context-Dh6IUBWT.js";
|
|
5
5
|
function WrapperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
|
7
7
|
const routerContextProps = useContext(RouterContext) || {};
|
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-20241108091829",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@loadable/component": "^5.16.4",
|
|
43
43
|
"react-error-boundary": "^4.0.13",
|
|
44
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
45
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
44
|
+
"@module-federation/bridge-shared": "0.0.0-next-20241108091829",
|
|
45
|
+
"@module-federation/sdk": "0.0.0-next-20241108091829"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": ">=16.9.0",
|
|
49
49
|
"react-dom": ">=16.9.0",
|
|
50
50
|
"react-router-dom": ">=4",
|
|
51
|
-
"@module-federation/runtime": "0.0.0-next-
|
|
51
|
+
"@module-federation/runtime": "0.0.0-next-20241108091829"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@testing-library/react": "15.0.7",
|
package/src/provider.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
} from '@module-federation/bridge-shared';
|
|
9
9
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
10
10
|
import { RouterContext } from './context';
|
|
11
|
-
import { LoggerInstance, atLeastReact18 } from './utils';
|
|
11
|
+
import { LoggerInstance, atLeastReact18, getModuleName } from './utils';
|
|
12
12
|
|
|
13
13
|
type RenderParams = RenderFnParams & any;
|
|
14
14
|
type DestroyParams = {
|
|
@@ -61,19 +61,14 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
61
61
|
...propsInfo
|
|
62
62
|
} = info;
|
|
63
63
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const moduleNameWithoutExpose = getModuleName(moduleName);
|
|
65
|
+
const instance = __FEDERATION__.__INSTANCES__.find(
|
|
66
|
+
(v) => v.name === moduleNameWithoutExpose,
|
|
67
|
+
);
|
|
68
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
67
69
|
|
|
68
|
-
// you can return a props object through beforeBridgeRender to pass additional props parameters
|
|
69
70
|
const beforeBridgeRenderRes =
|
|
70
|
-
beforeBridgeRender
|
|
71
|
-
const extraProps =
|
|
72
|
-
beforeBridgeRenderRes &&
|
|
73
|
-
typeof beforeBridgeRenderRes === 'object' &&
|
|
74
|
-
beforeBridgeRenderRes?.extraProps
|
|
75
|
-
? beforeBridgeRenderRes?.extraProps
|
|
76
|
-
: {};
|
|
71
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
|
|
77
72
|
|
|
78
73
|
const rootComponentWithErrorBoundary = (
|
|
79
74
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
@@ -84,7 +79,9 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
84
79
|
basename,
|
|
85
80
|
memoryRoute,
|
|
86
81
|
}}
|
|
87
|
-
propsInfo={
|
|
82
|
+
propsInfo={
|
|
83
|
+
{ ...propsInfo, ...beforeBridgeRenderRes?.extraProps } as T
|
|
84
|
+
}
|
|
88
85
|
/>
|
|
89
86
|
</ErrorBoundary>
|
|
90
87
|
);
|
|
@@ -116,12 +113,17 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
116
113
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
117
114
|
dom: info.dom,
|
|
118
115
|
});
|
|
116
|
+
const moduleNameWithoutExpose = getModuleName(info.moduleName);
|
|
117
|
+
LoggerInstance.log(
|
|
118
|
+
`createBridgeComponent remote module without expose name >>>`,
|
|
119
|
+
moduleNameWithoutExpose,
|
|
120
|
+
);
|
|
121
|
+
const instance = __FEDERATION__.__INSTANCES__.find(
|
|
122
|
+
(v) => v.name === moduleNameWithoutExpose,
|
|
123
|
+
);
|
|
124
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
119
125
|
|
|
120
|
-
|
|
121
|
-
(bridgeInfo?.hooks && bridgeInfo?.hooks.beforeBridgeDestroy) ||
|
|
122
|
-
params?.hooks?.beforeBridgeDestroy;
|
|
123
|
-
beforeBridgeDestroy && beforeBridgeDestroy(info);
|
|
124
|
-
|
|
126
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit(info);
|
|
125
127
|
// call destroy function
|
|
126
128
|
if (atLeastReact18(React)) {
|
|
127
129
|
const root = rootMap.get(info.dom);
|
|
@@ -131,10 +133,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
131
133
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
132
134
|
}
|
|
133
135
|
|
|
134
|
-
|
|
135
|
-
(bridgeInfo?.hooks && bridgeInfo?.hooks.afterBridgeDestroy) ||
|
|
136
|
-
params?.hooks?.afterBridgeDestroy;
|
|
137
|
-
afterBridgeDestroy && afterBridgeDestroy(info);
|
|
136
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit(info);
|
|
138
137
|
},
|
|
139
138
|
rawComponent: bridgeInfo.rootComponent,
|
|
140
139
|
__BRIDGE_FN__: (_args: T) => {},
|
package/src/remote/index.tsx
CHANGED
|
@@ -9,27 +9,9 @@ import * as ReactRouterDOM from 'react-router-dom';
|
|
|
9
9
|
import type { ProviderParams } from '@module-federation/bridge-shared';
|
|
10
10
|
import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
|
|
11
11
|
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
|
|
12
|
-
import { LoggerInstance, pathJoin } from '../utils';
|
|
12
|
+
import { LoggerInstance, pathJoin, getRootDomDefaultClassName } from '../utils';
|
|
13
13
|
import { getInstance } from '@module-federation/runtime';
|
|
14
14
|
|
|
15
|
-
export const getModuleName = (id: string) => {
|
|
16
|
-
// separate module name without detailed module path
|
|
17
|
-
// @vmok-e2e/edenx-demo-app2/button -> @vmok-e2e/edenx-demo-app2
|
|
18
|
-
const idArray = id.split('/');
|
|
19
|
-
if (idArray.length < 2) {
|
|
20
|
-
return id;
|
|
21
|
-
}
|
|
22
|
-
return idArray[0] + '/' + idArray[1];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const getRootDomDefaultClassName = (moduleName: string) => {
|
|
26
|
-
if (!moduleName) {
|
|
27
|
-
return '';
|
|
28
|
-
}
|
|
29
|
-
const name = getModuleName(moduleName).replace(/\@/, '').replace(/\//, '-');
|
|
30
|
-
return `bridge-root-component-${name}`;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
15
|
declare const __APP_VERSION__: string;
|
|
34
16
|
export interface RenderFnParams extends ProviderParams {
|
|
35
17
|
dom?: any;
|
|
@@ -100,27 +82,13 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
100
82
|
renderProps,
|
|
101
83
|
);
|
|
102
84
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
host?.bridgeHook?.lifecycle?.beforeBridgeRender
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
host?.bridgeHook?.lifecycle?.beforeBridgeRender.emit({
|
|
109
|
-
...renderProps,
|
|
110
|
-
});
|
|
111
|
-
const extraProps =
|
|
112
|
-
beforeBridgeRenderRes &&
|
|
113
|
-
typeof beforeBridgeRenderRes === 'object' &&
|
|
114
|
-
beforeBridgeRenderRes?.extraProps
|
|
115
|
-
? beforeBridgeRenderRes?.extraProps
|
|
116
|
-
: {};
|
|
117
|
-
|
|
118
|
-
renderProps = {
|
|
119
|
-
...renderProps,
|
|
120
|
-
...extraProps,
|
|
121
|
-
} as any;
|
|
122
|
-
}
|
|
85
|
+
// TODO: 寻找当前 remote 实例上的 hostName, 找到 host instance
|
|
86
|
+
const beforeBridgeRenderRes =
|
|
87
|
+
host?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(renderProps) ||
|
|
88
|
+
{};
|
|
89
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
123
90
|
providerReturn.render(renderProps);
|
|
91
|
+
host?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(renderProps);
|
|
124
92
|
});
|
|
125
93
|
|
|
126
94
|
return () => {
|
|
@@ -131,23 +99,27 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
131
99
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
132
100
|
{ moduleName, basename, dom: renderDom.current },
|
|
133
101
|
);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
memoryRoute,
|
|
143
|
-
fallback,
|
|
144
|
-
...resProps,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
102
|
+
host?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
|
|
103
|
+
moduleName,
|
|
104
|
+
dom: renderDom.current,
|
|
105
|
+
basename,
|
|
106
|
+
memoryRoute,
|
|
107
|
+
fallback,
|
|
108
|
+
...resProps,
|
|
109
|
+
});
|
|
147
110
|
providerInfoRef.current?.destroy({
|
|
148
111
|
moduleName,
|
|
149
112
|
dom: renderDom.current,
|
|
150
113
|
});
|
|
114
|
+
|
|
115
|
+
host?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
|
|
116
|
+
moduleName,
|
|
117
|
+
dom: renderDom.current,
|
|
118
|
+
basename,
|
|
119
|
+
memoryRoute,
|
|
120
|
+
fallback,
|
|
121
|
+
...resProps,
|
|
122
|
+
});
|
|
151
123
|
}
|
|
152
124
|
});
|
|
153
125
|
};
|
package/src/utils.ts
CHANGED
|
@@ -41,3 +41,24 @@ export function pathJoin(...args: string[]) {
|
|
|
41
41
|
}, '');
|
|
42
42
|
return res || '/';
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
export const getModuleName = (id: string) => {
|
|
46
|
+
if (!id) {
|
|
47
|
+
return id;
|
|
48
|
+
}
|
|
49
|
+
// separate module name without detailed module path
|
|
50
|
+
// @vmok-e2e/edenx-demo-app2/button -> @vmok-e2e/edenx-demo-app2
|
|
51
|
+
const idArray = id.split('/');
|
|
52
|
+
if (idArray.length < 2) {
|
|
53
|
+
return id;
|
|
54
|
+
}
|
|
55
|
+
return idArray[0] + '/' + idArray[1];
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const getRootDomDefaultClassName = (moduleName: string) => {
|
|
59
|
+
if (!moduleName) {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
const name = getModuleName(moduleName).replace(/\@/, '').replace(/\//, '-');
|
|
63
|
+
return `bridge-root-component-${name}`;
|
|
64
|
+
};
|