@module-federation/bridge-react 0.0.0-next-20241107072243 → 0.0.0-next-20241111073908
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -6
- 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 +66 -53
- package/dist/index.d.ts +1 -3
- package/dist/index.es.js +65 -52
- 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 +6 -6
- package/src/provider.tsx +22 -27
- package/src/remote/index.tsx +58 -55
- package/src/utils.ts +21 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20241111073908
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- 3082116: feat: feat: support lifecycyle hooks in module-deferation bridge
|
|
8
|
-
- Updated dependencies [8712967]
|
|
9
8
|
- Updated dependencies [6db4c5f]
|
|
10
|
-
-
|
|
11
|
-
- @module-federation/
|
|
12
|
-
- @module-federation/sdk@0.0.0-next-20241107072243
|
|
13
|
-
- @module-federation/bridge-shared@0.0.0-next-20241107072243
|
|
9
|
+
- @module-federation/sdk@0.0.0-next-20241111073908
|
|
10
|
+
- @module-federation/bridge-shared@0.0.0-next-20241111073908
|
|
14
11
|
|
|
15
12
|
## 0.7.0
|
|
16
13
|
|
|
@@ -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,9 +1,8 @@
|
|
|
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
|
-
const runtime = require("@module-federation/runtime");
|
|
7
6
|
const ReactDOM = require("react-dom");
|
|
8
7
|
function _interopNamespaceDefault(e2) {
|
|
9
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -122,23 +121,21 @@ function e() {
|
|
|
122
121
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
123
122
|
window.dispatchEvent(t);
|
|
124
123
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
124
|
+
const getHostInstance = (moduleName) => {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
let hostInstance = void 0;
|
|
127
|
+
const currentName = context.getModuleName(moduleName);
|
|
128
|
+
const remoteInstance = (_b = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.__INSTANCES__) == null ? void 0 : _b.find(
|
|
129
|
+
(v) => v.name === currentName
|
|
130
|
+
);
|
|
131
|
+
if (remoteInstance && (remoteInstance == null ? void 0 : remoteInstance.hostName)) {
|
|
132
|
+
hostInstance = window.__VMOK__.__INSTANCES__.find(
|
|
133
|
+
(instance) => instance.name === (remoteInstance == null ? void 0 : remoteInstance.hostName)
|
|
134
|
+
);
|
|
135
135
|
}
|
|
136
|
-
|
|
137
|
-
return `bridge-root-component-${name}`;
|
|
136
|
+
return hostInstance;
|
|
138
137
|
};
|
|
139
138
|
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
140
|
-
const host = runtime.getInstance();
|
|
141
|
-
context.LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
|
|
142
139
|
const RemoteApp2 = () => {
|
|
143
140
|
context.LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
144
141
|
const {
|
|
@@ -154,9 +151,11 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
154
151
|
const rootRef = ref && "current" in ref ? ref : React.useRef(null);
|
|
155
152
|
const renderDom = React.useRef(null);
|
|
156
153
|
const providerInfoRef = React.useRef(null);
|
|
154
|
+
const hostInstance = getHostInstance(moduleName);
|
|
155
|
+
context.LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
|
|
157
156
|
React.useEffect(() => {
|
|
158
157
|
const renderTimeout = setTimeout(() => {
|
|
159
|
-
var _a, _b, _c, _d;
|
|
158
|
+
var _a, _b, _c, _d, _e, _f;
|
|
160
159
|
const providerReturn = providerInfo();
|
|
161
160
|
providerInfoRef.current = providerReturn;
|
|
162
161
|
let renderProps = {
|
|
@@ -172,46 +171,53 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
172
171
|
`createRemoteComponent LazyComponent render >>>`,
|
|
173
172
|
renderProps
|
|
174
173
|
);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
renderProps
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
};
|
|
184
|
-
}
|
|
174
|
+
context.LoggerInstance.log(
|
|
175
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
176
|
+
hostInstance
|
|
177
|
+
);
|
|
178
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(
|
|
179
|
+
renderProps
|
|
180
|
+
)) || {};
|
|
181
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
185
182
|
providerReturn.render(renderProps);
|
|
183
|
+
(_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
|
|
184
|
+
renderProps
|
|
185
|
+
);
|
|
186
186
|
});
|
|
187
187
|
return () => {
|
|
188
188
|
clearTimeout(renderTimeout);
|
|
189
189
|
setTimeout(() => {
|
|
190
|
-
var _a, _b, _c, _d, _e, _f;
|
|
190
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
191
191
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
192
192
|
context.LoggerInstance.log(
|
|
193
193
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
194
194
|
{ moduleName, basename, dom: renderDom.current }
|
|
195
195
|
);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
(_f = providerInfoRef.current) == null ? void 0 : _f.destroy({
|
|
196
|
+
(_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
197
|
+
moduleName,
|
|
198
|
+
dom: renderDom.current,
|
|
199
|
+
basename,
|
|
200
|
+
memoryRoute,
|
|
201
|
+
fallback,
|
|
202
|
+
...resProps
|
|
203
|
+
});
|
|
204
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
207
205
|
moduleName,
|
|
208
206
|
dom: renderDom.current
|
|
209
207
|
});
|
|
208
|
+
(_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
209
|
+
moduleName,
|
|
210
|
+
dom: renderDom.current,
|
|
211
|
+
basename,
|
|
212
|
+
memoryRoute,
|
|
213
|
+
fallback,
|
|
214
|
+
...resProps
|
|
215
|
+
});
|
|
210
216
|
}
|
|
211
217
|
});
|
|
212
218
|
};
|
|
213
219
|
}, []);
|
|
214
|
-
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
220
|
+
const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
215
221
|
return /* @__PURE__ */ React.createElement(
|
|
216
222
|
"div",
|
|
217
223
|
{
|
|
@@ -371,7 +377,7 @@ if (process.env.NODE_ENV === "production") {
|
|
|
371
377
|
};
|
|
372
378
|
}
|
|
373
379
|
function createBridgeComponent(bridgeInfo) {
|
|
374
|
-
return (
|
|
380
|
+
return () => {
|
|
375
381
|
const rootMap = /* @__PURE__ */ new Map();
|
|
376
382
|
const RawComponent = (info) => {
|
|
377
383
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
@@ -385,9 +391,17 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
385
391
|
}
|
|
386
392
|
));
|
|
387
393
|
};
|
|
394
|
+
const getModuleInstance = (moduleName) => {
|
|
395
|
+
var _a, _b;
|
|
396
|
+
const moduleNameWithoutExpose = context.getModuleName(moduleName);
|
|
397
|
+
const instance = (_b = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.__INSTANCES__) == null ? void 0 : _b.find(
|
|
398
|
+
(v) => v.name === moduleNameWithoutExpose
|
|
399
|
+
);
|
|
400
|
+
return instance;
|
|
401
|
+
};
|
|
388
402
|
return {
|
|
389
403
|
async render(info) {
|
|
390
|
-
var _a, _b;
|
|
404
|
+
var _a, _b, _c, _d, _e, _f;
|
|
391
405
|
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
392
406
|
const {
|
|
393
407
|
moduleName,
|
|
@@ -397,9 +411,9 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
397
411
|
fallback,
|
|
398
412
|
...propsInfo
|
|
399
413
|
} = info;
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
const
|
|
414
|
+
const instance = getModuleInstance(moduleName);
|
|
415
|
+
context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
416
|
+
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
417
|
const rootComponentWithErrorBoundary = (
|
|
404
418
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
405
419
|
/* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
|
|
@@ -410,7 +424,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
410
424
|
basename,
|
|
411
425
|
memoryRoute
|
|
412
426
|
},
|
|
413
|
-
propsInfo: { ...propsInfo, ...extraProps }
|
|
427
|
+
propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
|
|
414
428
|
}
|
|
415
429
|
))
|
|
416
430
|
);
|
|
@@ -428,16 +442,16 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
428
442
|
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
429
443
|
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
430
444
|
}
|
|
431
|
-
|
|
432
|
-
afterBridgeRender && afterBridgeRender(info);
|
|
445
|
+
((_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(info)) || {};
|
|
433
446
|
},
|
|
434
447
|
async destroy(info) {
|
|
435
|
-
var _a, _b;
|
|
448
|
+
var _a, _b, _c, _d, _e, _f;
|
|
436
449
|
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
437
450
|
dom: info.dom
|
|
438
451
|
});
|
|
439
|
-
const
|
|
440
|
-
|
|
452
|
+
const instance = getModuleInstance(info.moduleName);
|
|
453
|
+
context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
454
|
+
(_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
455
|
if (context.atLeastReact18(React__namespace)) {
|
|
442
456
|
const root = rootMap.get(info.dom);
|
|
443
457
|
root == null ? void 0 : root.unmount();
|
|
@@ -445,8 +459,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
445
459
|
} else {
|
|
446
460
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
447
461
|
}
|
|
448
|
-
|
|
449
|
-
afterBridgeDestroy && afterBridgeDestroy(info);
|
|
462
|
+
(_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
463
|
},
|
|
451
464
|
rawComponent: bridgeInfo.rootComponent,
|
|
452
465
|
__BRIDGE_FN__: (_args) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +12,7 @@ declare type BridgeHooks = {
|
|
|
12
12
|
afterBridgeDestroy?: (params: DestroyParams) => void | Record<string, any>;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): (
|
|
16
|
-
hooks?: BridgeHooks;
|
|
17
|
-
}) => {
|
|
15
|
+
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
|
|
18
16
|
render(info: RenderParams): Promise<void>;
|
|
19
17
|
destroy(info: DestroyParams): Promise<void>;
|
|
20
18
|
rawComponent: React_2.ComponentType<T>;
|
package/dist/index.es.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
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
|
-
import { getInstance } from "@module-federation/runtime";
|
|
6
5
|
import ReactDOM from "react-dom";
|
|
7
6
|
const ErrorBoundaryContext = createContext(null);
|
|
8
7
|
const initialState = {
|
|
@@ -103,23 +102,21 @@ function e() {
|
|
|
103
102
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
104
103
|
window.dispatchEvent(t);
|
|
105
104
|
}
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
105
|
+
const getHostInstance = (moduleName) => {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
let hostInstance = void 0;
|
|
108
|
+
const currentName = getModuleName(moduleName);
|
|
109
|
+
const remoteInstance = (_b = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.__INSTANCES__) == null ? void 0 : _b.find(
|
|
110
|
+
(v) => v.name === currentName
|
|
111
|
+
);
|
|
112
|
+
if (remoteInstance && (remoteInstance == null ? void 0 : remoteInstance.hostName)) {
|
|
113
|
+
hostInstance = window.__VMOK__.__INSTANCES__.find(
|
|
114
|
+
(instance) => instance.name === (remoteInstance == null ? void 0 : remoteInstance.hostName)
|
|
115
|
+
);
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
return `bridge-root-component-${name}`;
|
|
117
|
+
return hostInstance;
|
|
119
118
|
};
|
|
120
119
|
const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
121
|
-
const host = getInstance();
|
|
122
|
-
LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
|
|
123
120
|
const RemoteApp2 = () => {
|
|
124
121
|
LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
125
122
|
const {
|
|
@@ -135,9 +132,11 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
135
132
|
const rootRef = ref && "current" in ref ? ref : useRef(null);
|
|
136
133
|
const renderDom = useRef(null);
|
|
137
134
|
const providerInfoRef = useRef(null);
|
|
135
|
+
const hostInstance = getHostInstance(moduleName);
|
|
136
|
+
LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
|
|
138
137
|
useEffect(() => {
|
|
139
138
|
const renderTimeout = setTimeout(() => {
|
|
140
|
-
var _a, _b, _c, _d;
|
|
139
|
+
var _a, _b, _c, _d, _e, _f;
|
|
141
140
|
const providerReturn = providerInfo();
|
|
142
141
|
providerInfoRef.current = providerReturn;
|
|
143
142
|
let renderProps = {
|
|
@@ -153,41 +152,48 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
153
152
|
`createRemoteComponent LazyComponent render >>>`,
|
|
154
153
|
renderProps
|
|
155
154
|
);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
renderProps
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
165
|
-
}
|
|
155
|
+
LoggerInstance.log(
|
|
156
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
157
|
+
hostInstance
|
|
158
|
+
);
|
|
159
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(
|
|
160
|
+
renderProps
|
|
161
|
+
)) || {};
|
|
162
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
166
163
|
providerReturn.render(renderProps);
|
|
164
|
+
(_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
|
|
165
|
+
renderProps
|
|
166
|
+
);
|
|
167
167
|
});
|
|
168
168
|
return () => {
|
|
169
169
|
clearTimeout(renderTimeout);
|
|
170
170
|
setTimeout(() => {
|
|
171
|
-
var _a, _b, _c, _d, _e, _f;
|
|
171
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
172
172
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
173
173
|
LoggerInstance.log(
|
|
174
174
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
175
175
|
{ moduleName, basename, dom: renderDom.current }
|
|
176
176
|
);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
(_f = providerInfoRef.current) == null ? void 0 : _f.destroy({
|
|
177
|
+
(_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
178
|
+
moduleName,
|
|
179
|
+
dom: renderDom.current,
|
|
180
|
+
basename,
|
|
181
|
+
memoryRoute,
|
|
182
|
+
fallback,
|
|
183
|
+
...resProps
|
|
184
|
+
});
|
|
185
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
188
186
|
moduleName,
|
|
189
187
|
dom: renderDom.current
|
|
190
188
|
});
|
|
189
|
+
(_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
190
|
+
moduleName,
|
|
191
|
+
dom: renderDom.current,
|
|
192
|
+
basename,
|
|
193
|
+
memoryRoute,
|
|
194
|
+
fallback,
|
|
195
|
+
...resProps
|
|
196
|
+
});
|
|
191
197
|
}
|
|
192
198
|
});
|
|
193
199
|
};
|
|
@@ -352,7 +358,7 @@ if (process.env.NODE_ENV === "production") {
|
|
|
352
358
|
};
|
|
353
359
|
}
|
|
354
360
|
function createBridgeComponent(bridgeInfo) {
|
|
355
|
-
return (
|
|
361
|
+
return () => {
|
|
356
362
|
const rootMap = /* @__PURE__ */ new Map();
|
|
357
363
|
const RawComponent = (info) => {
|
|
358
364
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
@@ -366,9 +372,17 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
366
372
|
}
|
|
367
373
|
));
|
|
368
374
|
};
|
|
375
|
+
const getModuleInstance = (moduleName) => {
|
|
376
|
+
var _a, _b;
|
|
377
|
+
const moduleNameWithoutExpose = getModuleName(moduleName);
|
|
378
|
+
const instance = (_b = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.__INSTANCES__) == null ? void 0 : _b.find(
|
|
379
|
+
(v) => v.name === moduleNameWithoutExpose
|
|
380
|
+
);
|
|
381
|
+
return instance;
|
|
382
|
+
};
|
|
369
383
|
return {
|
|
370
384
|
async render(info) {
|
|
371
|
-
var _a, _b;
|
|
385
|
+
var _a, _b, _c, _d, _e, _f;
|
|
372
386
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
373
387
|
const {
|
|
374
388
|
moduleName,
|
|
@@ -378,9 +392,9 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
378
392
|
fallback,
|
|
379
393
|
...propsInfo
|
|
380
394
|
} = info;
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
const
|
|
395
|
+
const instance = getModuleInstance(moduleName);
|
|
396
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
397
|
+
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
398
|
const rootComponentWithErrorBoundary = (
|
|
385
399
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
386
400
|
/* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
|
|
@@ -391,7 +405,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
391
405
|
basename,
|
|
392
406
|
memoryRoute
|
|
393
407
|
},
|
|
394
|
-
propsInfo: { ...propsInfo, ...extraProps }
|
|
408
|
+
propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
|
|
395
409
|
}
|
|
396
410
|
))
|
|
397
411
|
);
|
|
@@ -409,16 +423,16 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
409
423
|
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
410
424
|
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
411
425
|
}
|
|
412
|
-
|
|
413
|
-
afterBridgeRender && afterBridgeRender(info);
|
|
426
|
+
((_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(info)) || {};
|
|
414
427
|
},
|
|
415
428
|
async destroy(info) {
|
|
416
|
-
var _a, _b;
|
|
429
|
+
var _a, _b, _c, _d, _e, _f;
|
|
417
430
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
418
431
|
dom: info.dom
|
|
419
432
|
});
|
|
420
|
-
const
|
|
421
|
-
|
|
433
|
+
const instance = getModuleInstance(info.moduleName);
|
|
434
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
435
|
+
(_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
436
|
if (atLeastReact18(React)) {
|
|
423
437
|
const root = rootMap.get(info.dom);
|
|
424
438
|
root == null ? void 0 : root.unmount();
|
|
@@ -426,8 +440,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
426
440
|
} else {
|
|
427
441
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
428
442
|
}
|
|
429
|
-
|
|
430
|
-
afterBridgeDestroy && afterBridgeDestroy(info);
|
|
443
|
+
(_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
444
|
},
|
|
432
445
|
rawComponent: bridgeInfo.rootComponent,
|
|
433
446
|
__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-20241111073908",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -41,14 +41,13 @@
|
|
|
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-20241111073908",
|
|
45
|
+
"@module-federation/sdk": "0.0.0-next-20241111073908"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": ">=16.9.0",
|
|
49
49
|
"react-dom": ">=16.9.0",
|
|
50
|
-
"react-router-dom": ">=4"
|
|
51
|
-
"@module-federation/runtime": "0.0.0-next-20241107072243"
|
|
50
|
+
"react-router-dom": ">=4"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
53
|
"@testing-library/react": "15.0.7",
|
|
@@ -63,7 +62,8 @@
|
|
|
63
62
|
"react-router-dom": "6.22.3",
|
|
64
63
|
"typescript": "^5.2.2",
|
|
65
64
|
"vite": "^5.2.14",
|
|
66
|
-
"vite-plugin-dts": "^3.9.1"
|
|
65
|
+
"vite-plugin-dts": "^3.9.1",
|
|
66
|
+
"@module-federation/runtime": "0.0.0-next-20241111073908"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"dev": "vite",
|
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 = {
|
|
@@ -32,8 +32,9 @@ type ProviderFnParams<T> = {
|
|
|
32
32
|
) => RootType | Promise<RootType>;
|
|
33
33
|
hooks?: BridgeHooks;
|
|
34
34
|
};
|
|
35
|
+
|
|
35
36
|
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
36
|
-
return (
|
|
37
|
+
return () => {
|
|
37
38
|
const rootMap = new Map<any, RootType>();
|
|
38
39
|
const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
|
|
39
40
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
@@ -49,6 +50,14 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
49
50
|
);
|
|
50
51
|
};
|
|
51
52
|
|
|
53
|
+
const getModuleInstance = (moduleName: string) => {
|
|
54
|
+
const moduleNameWithoutExpose = getModuleName(moduleName);
|
|
55
|
+
const instance = window?.__FEDERATION__?.__INSTANCES__?.find(
|
|
56
|
+
(v) => v.name === moduleNameWithoutExpose,
|
|
57
|
+
);
|
|
58
|
+
return instance;
|
|
59
|
+
};
|
|
60
|
+
|
|
52
61
|
return {
|
|
53
62
|
async render(info: RenderParams) {
|
|
54
63
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
@@ -61,19 +70,11 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
61
70
|
...propsInfo
|
|
62
71
|
} = info;
|
|
63
72
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
params?.hooks?.beforeBridgeRender;
|
|
73
|
+
const instance = getModuleInstance(moduleName);
|
|
74
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
67
75
|
|
|
68
|
-
// you can return a props object through beforeBridgeRender to pass additional props parameters
|
|
69
76
|
const beforeBridgeRenderRes =
|
|
70
|
-
beforeBridgeRender
|
|
71
|
-
const extraProps =
|
|
72
|
-
beforeBridgeRenderRes &&
|
|
73
|
-
typeof beforeBridgeRenderRes === 'object' &&
|
|
74
|
-
beforeBridgeRenderRes?.extraProps
|
|
75
|
-
? beforeBridgeRenderRes?.extraProps
|
|
76
|
-
: {};
|
|
77
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
|
|
77
78
|
|
|
78
79
|
const rootComponentWithErrorBoundary = (
|
|
79
80
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
@@ -84,7 +85,9 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
84
85
|
basename,
|
|
85
86
|
memoryRoute,
|
|
86
87
|
}}
|
|
87
|
-
propsInfo={
|
|
88
|
+
propsInfo={
|
|
89
|
+
{ ...propsInfo, ...beforeBridgeRenderRes?.extraProps } as T
|
|
90
|
+
}
|
|
88
91
|
/>
|
|
89
92
|
</ErrorBoundary>
|
|
90
93
|
);
|
|
@@ -106,21 +109,16 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
106
109
|
renderFn?.(rootComponentWithErrorBoundary, info.dom);
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
(bridgeInfo?.hooks && bridgeInfo?.hooks.afterBridgeDestroy) ||
|
|
111
|
-
params?.hooks?.afterBridgeRender;
|
|
112
|
-
afterBridgeRender && afterBridgeRender(info);
|
|
112
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
|
|
113
113
|
},
|
|
114
114
|
|
|
115
115
|
async destroy(info: DestroyParams) {
|
|
116
116
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
117
117
|
dom: info.dom,
|
|
118
118
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
params?.hooks?.beforeBridgeDestroy;
|
|
123
|
-
beforeBridgeDestroy && beforeBridgeDestroy(info);
|
|
119
|
+
const instance = getModuleInstance(info.moduleName);
|
|
120
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
121
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit(info);
|
|
124
122
|
|
|
125
123
|
// call destroy function
|
|
126
124
|
if (atLeastReact18(React)) {
|
|
@@ -131,10 +129,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
131
129
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
132
130
|
}
|
|
133
131
|
|
|
134
|
-
|
|
135
|
-
(bridgeInfo?.hooks && bridgeInfo?.hooks.afterBridgeDestroy) ||
|
|
136
|
-
params?.hooks?.afterBridgeDestroy;
|
|
137
|
-
afterBridgeDestroy && afterBridgeDestroy(info);
|
|
132
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit(info);
|
|
138
133
|
},
|
|
139
134
|
rawComponent: bridgeInfo.rootComponent,
|
|
140
135
|
__BRIDGE_FN__: (_args: T) => {},
|
package/src/remote/index.tsx
CHANGED
|
@@ -9,26 +9,13 @@ 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 {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
};
|
|
12
|
+
import {
|
|
13
|
+
LoggerInstance,
|
|
14
|
+
pathJoin,
|
|
15
|
+
getModuleName,
|
|
16
|
+
getRootDomDefaultClassName,
|
|
17
|
+
} from '../utils';
|
|
18
|
+
import { FederationHost } from '@module-federation/runtime';
|
|
32
19
|
|
|
33
20
|
declare const __APP_VERSION__: string;
|
|
34
21
|
export interface RenderFnParams extends ProviderParams {
|
|
@@ -54,12 +41,27 @@ interface RemoteAppParams {
|
|
|
54
41
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
55
42
|
}
|
|
56
43
|
|
|
44
|
+
const getHostInstance = (moduleName: string) => {
|
|
45
|
+
let hostInstance: FederationHost | undefined = undefined;
|
|
46
|
+
const currentName = getModuleName(moduleName);
|
|
47
|
+
const remoteInstance = window?.__FEDERATION__?.__INSTANCES__?.find(
|
|
48
|
+
(v) => v.name === currentName,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
if (remoteInstance && remoteInstance?.hostName) {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
hostInstance = window.__VMOK__.__INSTANCES__.find(
|
|
55
|
+
(instance) => instance.name === remoteInstance?.hostName,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return hostInstance;
|
|
59
|
+
};
|
|
60
|
+
|
|
57
61
|
const RemoteAppWrapper = forwardRef(function (
|
|
58
62
|
props: RemoteAppParams & RenderFnParams,
|
|
59
63
|
ref,
|
|
60
64
|
) {
|
|
61
|
-
const host = getInstance();
|
|
62
|
-
LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
|
|
63
65
|
const RemoteApp = () => {
|
|
64
66
|
LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
65
67
|
const {
|
|
@@ -80,6 +82,8 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
80
82
|
|
|
81
83
|
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
82
84
|
const providerInfoRef = useRef<any>(null);
|
|
85
|
+
const hostInstance = getHostInstance(moduleName);
|
|
86
|
+
LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
|
|
83
87
|
|
|
84
88
|
useEffect(() => {
|
|
85
89
|
const renderTimeout = setTimeout(() => {
|
|
@@ -100,27 +104,20 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
100
104
|
renderProps,
|
|
101
105
|
);
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
typeof beforeBridgeRenderRes === 'object' &&
|
|
114
|
-
beforeBridgeRenderRes?.extraProps
|
|
115
|
-
? beforeBridgeRenderRes?.extraProps
|
|
116
|
-
: {};
|
|
117
|
-
|
|
118
|
-
renderProps = {
|
|
119
|
-
...renderProps,
|
|
120
|
-
...extraProps,
|
|
121
|
-
} as any;
|
|
122
|
-
}
|
|
107
|
+
LoggerInstance.log(
|
|
108
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
109
|
+
hostInstance,
|
|
110
|
+
);
|
|
111
|
+
const beforeBridgeRenderRes =
|
|
112
|
+
hostInstance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
|
|
113
|
+
renderProps,
|
|
114
|
+
) || {};
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
123
117
|
providerReturn.render(renderProps);
|
|
118
|
+
hostInstance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(
|
|
119
|
+
renderProps,
|
|
120
|
+
);
|
|
124
121
|
});
|
|
125
122
|
|
|
126
123
|
return () => {
|
|
@@ -131,23 +128,29 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
131
128
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
132
129
|
{ moduleName, basename, dom: renderDom.current },
|
|
133
130
|
);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
...resProps,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
131
|
+
|
|
132
|
+
hostInstance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
|
|
133
|
+
moduleName,
|
|
134
|
+
dom: renderDom.current,
|
|
135
|
+
basename,
|
|
136
|
+
memoryRoute,
|
|
137
|
+
fallback,
|
|
138
|
+
...resProps,
|
|
139
|
+
});
|
|
140
|
+
|
|
147
141
|
providerInfoRef.current?.destroy({
|
|
148
142
|
moduleName,
|
|
149
143
|
dom: renderDom.current,
|
|
150
144
|
});
|
|
145
|
+
|
|
146
|
+
hostInstance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
|
|
147
|
+
moduleName,
|
|
148
|
+
dom: renderDom.current,
|
|
149
|
+
basename,
|
|
150
|
+
memoryRoute,
|
|
151
|
+
fallback,
|
|
152
|
+
...resProps,
|
|
153
|
+
});
|
|
151
154
|
}
|
|
152
155
|
});
|
|
153
156
|
};
|
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
|
+
};
|