@module-federation/bridge-react 0.7.2 → 0.7.5
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 +27 -0
- package/dist/{context-BBLu8BlQ.cjs → context-BcJ-YlNr.cjs} +18 -0
- package/dist/{context-BcyT-d0V.js → context-CUbFnlO5.js} +18 -0
- package/dist/index.cjs.js +48 -7
- package/dist/index.d.ts +11 -4
- package/dist/index.es.js +48 -7
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +3 -2
- package/dist/router-v6.d.ts +1 -1
- package/dist/router-v6.es.js +7 -7
- package/dist/router.cjs.js +2 -2
- package/dist/router.es.js +2 -2
- package/package.json +4 -3
- package/src/create.tsx +2 -2
- package/src/provider.tsx +33 -6
- package/src/remote/index.tsx +42 -3
- package/src/router-v5.tsx +1 -2
- package/src/router-v6.tsx +2 -1
- package/src/router.tsx +1 -1
- package/src/utils.ts +21 -0
- package/vite.config.ts +10 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
+
## 0.7.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0309fb5: fix: wrap try catch with react-router-dom path resolve
|
|
8
|
+
- @module-federation/runtime@0.7.5
|
|
9
|
+
- @module-federation/sdk@0.7.5
|
|
10
|
+
- @module-federation/bridge-shared@0.7.5
|
|
11
|
+
|
|
12
|
+
## 0.7.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- ff8ce29: feat: feat: support lifecycyle hooks in module-deferation bridge
|
|
17
|
+
- Updated dependencies [ff8ce29]
|
|
18
|
+
- @module-federation/runtime@0.7.4
|
|
19
|
+
- @module-federation/sdk@0.7.4
|
|
20
|
+
- @module-federation/bridge-shared@0.7.4
|
|
21
|
+
|
|
22
|
+
## 0.7.3
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [4ab9295]
|
|
27
|
+
- @module-federation/sdk@0.7.3
|
|
28
|
+
- @module-federation/bridge-shared@0.7.3
|
|
29
|
+
|
|
3
30
|
## 0.7.2
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
|
@@ -329,8 +329,26 @@ 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.getRootDomDefaultClassName = getRootDomDefaultClassName;
|
|
336
354
|
exports.pathJoin = pathJoin;
|
|
@@ -328,10 +328,28 @@ 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
|
atLeastReact18 as a,
|
|
353
|
+
getRootDomDefaultClassName as g,
|
|
336
354
|
pathJoin as p
|
|
337
355
|
};
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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-BcJ-YlNr.cjs");
|
|
5
5
|
const ReactRouterDOM = require("react-router-dom");
|
|
6
|
+
const runtime = require("@module-federation/runtime");
|
|
6
7
|
const ReactDOM = require("react-dom");
|
|
7
8
|
function _interopNamespaceDefault(e2) {
|
|
8
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -137,11 +138,14 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
137
138
|
const rootRef = ref && "current" in ref ? ref : React.useRef(null);
|
|
138
139
|
const renderDom = React.useRef(null);
|
|
139
140
|
const providerInfoRef = React.useRef(null);
|
|
141
|
+
const hostInstance = runtime.getInstance();
|
|
142
|
+
context.LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
|
|
140
143
|
React.useEffect(() => {
|
|
141
144
|
const renderTimeout = setTimeout(() => {
|
|
145
|
+
var _a, _b, _c, _d, _e, _f;
|
|
142
146
|
const providerReturn = providerInfo();
|
|
143
147
|
providerInfoRef.current = providerReturn;
|
|
144
|
-
|
|
148
|
+
let renderProps = {
|
|
145
149
|
moduleName,
|
|
146
150
|
dom: rootRef.current,
|
|
147
151
|
basename,
|
|
@@ -154,34 +158,63 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
154
158
|
`createRemoteComponent LazyComponent render >>>`,
|
|
155
159
|
renderProps
|
|
156
160
|
);
|
|
161
|
+
context.LoggerInstance.log(
|
|
162
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
163
|
+
hostInstance
|
|
164
|
+
);
|
|
165
|
+
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(
|
|
166
|
+
renderProps
|
|
167
|
+
)) || {};
|
|
168
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
157
169
|
providerReturn.render(renderProps);
|
|
170
|
+
(_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
|
|
171
|
+
renderProps
|
|
172
|
+
);
|
|
158
173
|
});
|
|
159
174
|
return () => {
|
|
160
175
|
clearTimeout(renderTimeout);
|
|
161
176
|
setTimeout(() => {
|
|
162
|
-
var _a, _b;
|
|
177
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
163
178
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
164
179
|
context.LoggerInstance.log(
|
|
165
180
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
166
181
|
{ moduleName, basename, dom: renderDom.current }
|
|
167
182
|
);
|
|
168
|
-
(_b =
|
|
183
|
+
(_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
184
|
+
moduleName,
|
|
185
|
+
dom: renderDom.current,
|
|
186
|
+
basename,
|
|
187
|
+
memoryRoute,
|
|
188
|
+
fallback,
|
|
189
|
+
...resProps
|
|
190
|
+
});
|
|
191
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
192
|
+
moduleName,
|
|
169
193
|
dom: renderDom.current
|
|
170
194
|
});
|
|
195
|
+
(_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
196
|
+
moduleName,
|
|
197
|
+
dom: renderDom.current,
|
|
198
|
+
basename,
|
|
199
|
+
memoryRoute,
|
|
200
|
+
fallback,
|
|
201
|
+
...resProps
|
|
202
|
+
});
|
|
171
203
|
}
|
|
172
204
|
});
|
|
173
205
|
};
|
|
174
206
|
}, []);
|
|
207
|
+
const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
175
208
|
return /* @__PURE__ */ React.createElement(
|
|
176
209
|
"div",
|
|
177
210
|
{
|
|
178
|
-
className:
|
|
211
|
+
className: rootComponentClassName,
|
|
179
212
|
style: props == null ? void 0 : props.style,
|
|
180
213
|
ref: rootRef
|
|
181
214
|
}
|
|
182
215
|
);
|
|
183
216
|
};
|
|
184
|
-
RemoteApp2["__APP_VERSION__"] = "0.7.
|
|
217
|
+
RemoteApp2["__APP_VERSION__"] = "0.7.5";
|
|
185
218
|
return /* @__PURE__ */ React.createElement(RemoteApp2, null);
|
|
186
219
|
});
|
|
187
220
|
function withRouterData(WrappedComponent) {
|
|
@@ -333,6 +366,8 @@ if (process.env.NODE_ENV === "production") {
|
|
|
333
366
|
function createBridgeComponent(bridgeInfo) {
|
|
334
367
|
return () => {
|
|
335
368
|
const rootMap = /* @__PURE__ */ new Map();
|
|
369
|
+
const instance = runtime.getInstance();
|
|
370
|
+
context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
336
371
|
const RawComponent = (info) => {
|
|
337
372
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
338
373
|
const { moduleName, memoryRoute, basename = "/" } = appInfo;
|
|
@@ -347,6 +382,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
347
382
|
};
|
|
348
383
|
return {
|
|
349
384
|
async render(info) {
|
|
385
|
+
var _a, _b, _c, _d, _e, _f;
|
|
350
386
|
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
351
387
|
const {
|
|
352
388
|
moduleName,
|
|
@@ -356,6 +392,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
356
392
|
fallback,
|
|
357
393
|
...propsInfo
|
|
358
394
|
} = info;
|
|
395
|
+
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)) || {};
|
|
359
396
|
const rootComponentWithErrorBoundary = (
|
|
360
397
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
361
398
|
/* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
|
|
@@ -366,7 +403,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
366
403
|
basename,
|
|
367
404
|
memoryRoute
|
|
368
405
|
},
|
|
369
|
-
propsInfo
|
|
406
|
+
propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
|
|
370
407
|
}
|
|
371
408
|
))
|
|
372
409
|
);
|
|
@@ -384,11 +421,14 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
384
421
|
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
385
422
|
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
386
423
|
}
|
|
424
|
+
((_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)) || {};
|
|
387
425
|
},
|
|
388
426
|
async destroy(info) {
|
|
427
|
+
var _a, _b, _c, _d, _e, _f;
|
|
389
428
|
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
390
429
|
dom: info.dom
|
|
391
430
|
});
|
|
431
|
+
(_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);
|
|
392
432
|
if (context.atLeastReact18(React__namespace)) {
|
|
393
433
|
const root = rootMap.get(info.dom);
|
|
394
434
|
root == null ? void 0 : root.unmount();
|
|
@@ -396,6 +436,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
396
436
|
} else {
|
|
397
437
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
398
438
|
}
|
|
439
|
+
(_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);
|
|
399
440
|
},
|
|
400
441
|
rawComponent: bridgeInfo.rootComponent,
|
|
401
442
|
__BRIDGE_FN__: (_args) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,8 @@ import { PropsWithChildren } from 'react';
|
|
|
6
6
|
import * as React_2 from 'react';
|
|
7
7
|
|
|
8
8
|
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
|
|
9
|
-
render(info:
|
|
10
|
-
destroy(info:
|
|
11
|
-
dom: HTMLElement;
|
|
12
|
-
}): Promise<void>;
|
|
9
|
+
render(info: RenderParams): Promise<void>;
|
|
10
|
+
destroy(info: DestroyParams): Promise<void>;
|
|
13
11
|
rawComponent: React_2.ComponentType<T>;
|
|
14
12
|
__BRIDGE_FN__: (_args: T) => void;
|
|
15
13
|
};
|
|
@@ -21,6 +19,11 @@ export declare function createRemoteComponent<T, E extends keyof T>(info: {
|
|
|
21
19
|
export?: E;
|
|
22
20
|
}): 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
21
|
|
|
22
|
+
declare type DestroyParams = {
|
|
23
|
+
moduleName: string;
|
|
24
|
+
dom: HTMLElement;
|
|
25
|
+
};
|
|
26
|
+
|
|
24
27
|
declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {
|
|
25
28
|
fallback?: never;
|
|
26
29
|
FallbackComponent: ComponentType<FallbackProps>;
|
|
@@ -64,6 +67,10 @@ export declare interface RenderFnParams extends ProviderParams {
|
|
|
64
67
|
dom: HTMLElement;
|
|
65
68
|
}
|
|
66
69
|
|
|
70
|
+
declare type RenderParams = RenderFnParams & {
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
};
|
|
73
|
+
|
|
67
74
|
declare type RootType = HTMLElement | default_3.Root;
|
|
68
75
|
|
|
69
76
|
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, g as getRootDomDefaultClassName, p as pathJoin, a as atLeastReact18, R as RouterContext } from "./context-CUbFnlO5.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 = {
|
|
@@ -118,11 +119,14 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
118
119
|
const rootRef = ref && "current" in ref ? ref : useRef(null);
|
|
119
120
|
const renderDom = useRef(null);
|
|
120
121
|
const providerInfoRef = useRef(null);
|
|
122
|
+
const hostInstance = getInstance();
|
|
123
|
+
LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
|
|
121
124
|
useEffect(() => {
|
|
122
125
|
const renderTimeout = setTimeout(() => {
|
|
126
|
+
var _a, _b, _c, _d, _e, _f;
|
|
123
127
|
const providerReturn = providerInfo();
|
|
124
128
|
providerInfoRef.current = providerReturn;
|
|
125
|
-
|
|
129
|
+
let renderProps = {
|
|
126
130
|
moduleName,
|
|
127
131
|
dom: rootRef.current,
|
|
128
132
|
basename,
|
|
@@ -135,34 +139,63 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
135
139
|
`createRemoteComponent LazyComponent render >>>`,
|
|
136
140
|
renderProps
|
|
137
141
|
);
|
|
142
|
+
LoggerInstance.log(
|
|
143
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
144
|
+
hostInstance
|
|
145
|
+
);
|
|
146
|
+
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(
|
|
147
|
+
renderProps
|
|
148
|
+
)) || {};
|
|
149
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
138
150
|
providerReturn.render(renderProps);
|
|
151
|
+
(_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
|
|
152
|
+
renderProps
|
|
153
|
+
);
|
|
139
154
|
});
|
|
140
155
|
return () => {
|
|
141
156
|
clearTimeout(renderTimeout);
|
|
142
157
|
setTimeout(() => {
|
|
143
|
-
var _a, _b;
|
|
158
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
144
159
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
145
160
|
LoggerInstance.log(
|
|
146
161
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
147
162
|
{ moduleName, basename, dom: renderDom.current }
|
|
148
163
|
);
|
|
149
|
-
(_b =
|
|
164
|
+
(_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
165
|
+
moduleName,
|
|
166
|
+
dom: renderDom.current,
|
|
167
|
+
basename,
|
|
168
|
+
memoryRoute,
|
|
169
|
+
fallback,
|
|
170
|
+
...resProps
|
|
171
|
+
});
|
|
172
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
173
|
+
moduleName,
|
|
150
174
|
dom: renderDom.current
|
|
151
175
|
});
|
|
176
|
+
(_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
177
|
+
moduleName,
|
|
178
|
+
dom: renderDom.current,
|
|
179
|
+
basename,
|
|
180
|
+
memoryRoute,
|
|
181
|
+
fallback,
|
|
182
|
+
...resProps
|
|
183
|
+
});
|
|
152
184
|
}
|
|
153
185
|
});
|
|
154
186
|
};
|
|
155
187
|
}, []);
|
|
188
|
+
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
156
189
|
return /* @__PURE__ */ React__default.createElement(
|
|
157
190
|
"div",
|
|
158
191
|
{
|
|
159
|
-
className:
|
|
192
|
+
className: rootComponentClassName,
|
|
160
193
|
style: props == null ? void 0 : props.style,
|
|
161
194
|
ref: rootRef
|
|
162
195
|
}
|
|
163
196
|
);
|
|
164
197
|
};
|
|
165
|
-
RemoteApp2["__APP_VERSION__"] = "0.7.
|
|
198
|
+
RemoteApp2["__APP_VERSION__"] = "0.7.5";
|
|
166
199
|
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
|
|
167
200
|
});
|
|
168
201
|
function withRouterData(WrappedComponent) {
|
|
@@ -314,6 +347,8 @@ if (process.env.NODE_ENV === "production") {
|
|
|
314
347
|
function createBridgeComponent(bridgeInfo) {
|
|
315
348
|
return () => {
|
|
316
349
|
const rootMap = /* @__PURE__ */ new Map();
|
|
350
|
+
const instance = getInstance();
|
|
351
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
317
352
|
const RawComponent = (info) => {
|
|
318
353
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
319
354
|
const { moduleName, memoryRoute, basename = "/" } = appInfo;
|
|
@@ -328,6 +363,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
328
363
|
};
|
|
329
364
|
return {
|
|
330
365
|
async render(info) {
|
|
366
|
+
var _a, _b, _c, _d, _e, _f;
|
|
331
367
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
332
368
|
const {
|
|
333
369
|
moduleName,
|
|
@@ -337,6 +373,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
337
373
|
fallback,
|
|
338
374
|
...propsInfo
|
|
339
375
|
} = info;
|
|
376
|
+
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)) || {};
|
|
340
377
|
const rootComponentWithErrorBoundary = (
|
|
341
378
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
342
379
|
/* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
|
|
@@ -347,7 +384,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
347
384
|
basename,
|
|
348
385
|
memoryRoute
|
|
349
386
|
},
|
|
350
|
-
propsInfo
|
|
387
|
+
propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
|
|
351
388
|
}
|
|
352
389
|
))
|
|
353
390
|
);
|
|
@@ -365,11 +402,14 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
365
402
|
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
366
403
|
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
367
404
|
}
|
|
405
|
+
((_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)) || {};
|
|
368
406
|
},
|
|
369
407
|
async destroy(info) {
|
|
408
|
+
var _a, _b, _c, _d, _e, _f;
|
|
370
409
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
371
410
|
dom: info.dom
|
|
372
411
|
});
|
|
412
|
+
(_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);
|
|
373
413
|
if (atLeastReact18(React)) {
|
|
374
414
|
const root = rootMap.get(info.dom);
|
|
375
415
|
root == null ? void 0 : root.unmount();
|
|
@@ -377,6 +417,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
377
417
|
} else {
|
|
378
418
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
379
419
|
}
|
|
420
|
+
(_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);
|
|
380
421
|
},
|
|
381
422
|
rawComponent: bridgeInfo.rootComponent,
|
|
382
423
|
__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-BcJ-YlNr.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-CUbFnlO5.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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
|
+
const ReactRouterDom$1 = require("react-router-dom/dist/index.js");
|
|
5
|
+
const context = require("./context-BcJ-YlNr.cjs");
|
|
4
6
|
const ReactRouterDom = require("react-router-dom/dist/index.js");
|
|
5
|
-
const context = require("./context-BBLu8BlQ.cjs");
|
|
6
7
|
function _interopNamespaceDefault(e) {
|
|
7
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
9
|
if (e) {
|
|
@@ -19,7 +20,7 @@ function _interopNamespaceDefault(e) {
|
|
|
19
20
|
n.default = e;
|
|
20
21
|
return Object.freeze(n);
|
|
21
22
|
}
|
|
22
|
-
const ReactRouterDom__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDom);
|
|
23
|
+
const ReactRouterDom__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDom$1);
|
|
23
24
|
function WraperRouter(props) {
|
|
24
25
|
const { basename, ...propsRes } = props;
|
|
25
26
|
const routerContextProps = React.useContext(context.RouterContext) || {};
|
package/dist/router-v6.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export declare function BrowserRouter(props: Parameters<typeof ReactRouterDom.Br
|
|
|
6
6
|
export declare function RouterProvider(props: Parameters<typeof ReactRouterDom.RouterProvider>[0]): default_2.JSX.Element;
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
export * from "react-router-dom/
|
|
9
|
+
export * from "react-router-dom/";
|
|
10
10
|
|
|
11
11
|
export { }
|
package/dist/router-v6.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { useContext } from "react";
|
|
2
|
-
import * as ReactRouterDom from "react-router-dom/dist/index.js";
|
|
2
|
+
import * as ReactRouterDom$1 from "react-router-dom/dist/index.js";
|
|
3
|
+
import { R as RouterContext, L as LoggerInstance } from "./context-CUbFnlO5.js";
|
|
3
4
|
export * from "react-router-dom/dist/index.js";
|
|
4
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-BcyT-d0V.js";
|
|
5
5
|
function WraperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
|
7
7
|
const routerContextProps = useContext(RouterContext) || {};
|
|
@@ -12,7 +12,7 @@ function WraperRouter(props) {
|
|
|
12
12
|
});
|
|
13
13
|
if (routerContextProps == null ? void 0 : routerContextProps.memoryRoute) {
|
|
14
14
|
return /* @__PURE__ */ React__default.createElement(
|
|
15
|
-
ReactRouterDom.MemoryRouter,
|
|
15
|
+
ReactRouterDom$1.MemoryRouter,
|
|
16
16
|
{
|
|
17
17
|
...props,
|
|
18
18
|
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
@@ -20,7 +20,7 @@ function WraperRouter(props) {
|
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
return /* @__PURE__ */ React__default.createElement(
|
|
23
|
-
ReactRouterDom.BrowserRouter,
|
|
23
|
+
ReactRouterDom$1.BrowserRouter,
|
|
24
24
|
{
|
|
25
25
|
...propsRes,
|
|
26
26
|
basename: (routerContextProps == null ? void 0 : routerContextProps.basename) || basename
|
|
@@ -37,9 +37,9 @@ function WraperRouterProvider(props) {
|
|
|
37
37
|
WraperRouterProviderProps: props,
|
|
38
38
|
router
|
|
39
39
|
});
|
|
40
|
-
const RouterProvider = ReactRouterDom["RouterProvider"];
|
|
41
|
-
const createMemoryRouter = ReactRouterDom["createMemoryRouter"];
|
|
42
|
-
const createBrowserRouter = ReactRouterDom["createBrowserRouter"];
|
|
40
|
+
const RouterProvider = ReactRouterDom$1["RouterProvider"];
|
|
41
|
+
const createMemoryRouter = ReactRouterDom$1["createMemoryRouter"];
|
|
42
|
+
const createBrowserRouter = ReactRouterDom$1["createBrowserRouter"];
|
|
43
43
|
if (routerContextProps.memoryRoute) {
|
|
44
44
|
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
45
45
|
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
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-BcJ-YlNr.cjs");
|
|
6
6
|
function _interopNamespaceDefault(e) {
|
|
7
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
8
|
if (e) {
|
|
@@ -65,7 +65,7 @@ function WrapperRouterProvider(props) {
|
|
|
65
65
|
return /* @__PURE__ */ React.createElement(RouterProvider, { router: MemeoryRouterInstance });
|
|
66
66
|
} else {
|
|
67
67
|
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
68
|
-
basename: routerContextProps.basename,
|
|
68
|
+
basename: routerContextProps.basename || (router == null ? void 0 : router.basename),
|
|
69
69
|
future: router.future,
|
|
70
70
|
window: router.window
|
|
71
71
|
});
|
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-CUbFnlO5.js";
|
|
5
5
|
function WrapperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
|
7
7
|
const routerContextProps = useContext(RouterContext) || {};
|
|
@@ -47,7 +47,7 @@ function WrapperRouterProvider(props) {
|
|
|
47
47
|
return /* @__PURE__ */ React__default.createElement(RouterProvider, { router: MemeoryRouterInstance });
|
|
48
48
|
} else {
|
|
49
49
|
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
50
|
-
basename: routerContextProps.basename,
|
|
50
|
+
basename: routerContextProps.basename || (router == null ? void 0 : router.basename),
|
|
51
51
|
future: router.future,
|
|
52
52
|
window: router.window
|
|
53
53
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-react",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@loadable/component": "^5.16.4",
|
|
43
43
|
"react-error-boundary": "^4.0.13",
|
|
44
|
-
"@module-federation/bridge-shared": "0.7.
|
|
45
|
-
"@module-federation/sdk": "0.7.
|
|
44
|
+
"@module-federation/bridge-shared": "0.7.5",
|
|
45
|
+
"@module-federation/sdk": "0.7.5",
|
|
46
|
+
"@module-federation/runtime": "0.7.5"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
49
|
"react": ">=16.9.0",
|
package/src/create.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import type { ProviderParams } from '@module-federation/bridge-shared';
|
|
3
|
-
import { LoggerInstance } from './utils';
|
|
4
2
|
import {
|
|
5
3
|
ErrorBoundary,
|
|
6
4
|
ErrorBoundaryPropsWithComponent,
|
|
7
5
|
} from 'react-error-boundary';
|
|
6
|
+
import { LoggerInstance } from './utils';
|
|
8
7
|
import RemoteApp from './remote';
|
|
8
|
+
import type { ProviderParams } from '@module-federation/bridge-shared';
|
|
9
9
|
|
|
10
10
|
export interface RenderFnParams extends ProviderParams {
|
|
11
11
|
dom?: any;
|
package/src/provider.tsx
CHANGED
|
@@ -2,15 +2,24 @@ import { useLayoutEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import ReactDOM from 'react-dom';
|
|
4
4
|
import ReactDOMClient from 'react-dom/client';
|
|
5
|
-
import { RouterContext } from './context';
|
|
6
5
|
import type {
|
|
7
6
|
ProviderParams,
|
|
8
7
|
RenderFnParams,
|
|
9
8
|
} from '@module-federation/bridge-shared';
|
|
10
|
-
import { LoggerInstance, atLeastReact18 } from './utils';
|
|
11
9
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
10
|
+
import { RouterContext } from './context';
|
|
11
|
+
import { LoggerInstance, atLeastReact18 } from './utils';
|
|
12
|
+
import { getInstance } from '@module-federation/runtime';
|
|
12
13
|
|
|
14
|
+
type RenderParams = RenderFnParams & {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
type DestroyParams = {
|
|
18
|
+
moduleName: string;
|
|
19
|
+
dom: HTMLElement;
|
|
20
|
+
};
|
|
13
21
|
type RootType = HTMLElement | ReactDOMClient.Root;
|
|
22
|
+
|
|
14
23
|
type ProviderFnParams<T> = {
|
|
15
24
|
rootComponent: React.ComponentType<T>;
|
|
16
25
|
render?: (
|
|
@@ -22,6 +31,9 @@ type ProviderFnParams<T> = {
|
|
|
22
31
|
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
23
32
|
return () => {
|
|
24
33
|
const rootMap = new Map<any, RootType>();
|
|
34
|
+
const instance = getInstance();
|
|
35
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
36
|
+
|
|
25
37
|
const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
|
|
26
38
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
27
39
|
const { moduleName, memoryRoute, basename = '/' } = appInfo;
|
|
@@ -37,7 +49,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
37
49
|
};
|
|
38
50
|
|
|
39
51
|
return {
|
|
40
|
-
async render(info:
|
|
52
|
+
async render(info: RenderParams) {
|
|
41
53
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
42
54
|
const {
|
|
43
55
|
moduleName,
|
|
@@ -47,6 +59,10 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
47
59
|
fallback,
|
|
48
60
|
...propsInfo
|
|
49
61
|
} = info;
|
|
62
|
+
|
|
63
|
+
const beforeBridgeRenderRes =
|
|
64
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
|
|
65
|
+
|
|
50
66
|
const rootComponentWithErrorBoundary = (
|
|
51
67
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
52
68
|
<ErrorBoundary FallbackComponent={fallback}>
|
|
@@ -56,11 +72,13 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
56
72
|
basename,
|
|
57
73
|
memoryRoute,
|
|
58
74
|
}}
|
|
59
|
-
propsInfo={
|
|
75
|
+
propsInfo={
|
|
76
|
+
{ ...propsInfo, ...beforeBridgeRenderRes?.extraProps } as T
|
|
77
|
+
}
|
|
60
78
|
/>
|
|
61
79
|
</ErrorBoundary>
|
|
62
80
|
);
|
|
63
|
-
|
|
81
|
+
// call render function
|
|
64
82
|
if (atLeastReact18(React)) {
|
|
65
83
|
if (bridgeInfo?.render) {
|
|
66
84
|
// in case bridgeInfo?.render is an async function, resolve this to promise
|
|
@@ -77,11 +95,18 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
77
95
|
const renderFn = bridgeInfo?.render || ReactDOM.render;
|
|
78
96
|
renderFn?.(rootComponentWithErrorBoundary, info.dom);
|
|
79
97
|
}
|
|
98
|
+
|
|
99
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
|
|
80
100
|
},
|
|
81
|
-
|
|
101
|
+
|
|
102
|
+
async destroy(info: DestroyParams) {
|
|
82
103
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
83
104
|
dom: info.dom,
|
|
84
105
|
});
|
|
106
|
+
|
|
107
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit(info);
|
|
108
|
+
|
|
109
|
+
// call destroy function
|
|
85
110
|
if (atLeastReact18(React)) {
|
|
86
111
|
const root = rootMap.get(info.dom);
|
|
87
112
|
(root as ReactDOMClient.Root)?.unmount();
|
|
@@ -89,6 +114,8 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
89
114
|
} else {
|
|
90
115
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
91
116
|
}
|
|
117
|
+
|
|
118
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit(info);
|
|
92
119
|
},
|
|
93
120
|
rawComponent: bridgeInfo.rootComponent,
|
|
94
121
|
__BRIDGE_FN__: (_args: T) => {},
|
package/src/remote/index.tsx
CHANGED
|
@@ -7,9 +7,10 @@ import React, {
|
|
|
7
7
|
} from 'react';
|
|
8
8
|
import * as ReactRouterDOM from 'react-router-dom';
|
|
9
9
|
import type { ProviderParams } from '@module-federation/bridge-shared';
|
|
10
|
-
import { LoggerInstance, pathJoin } from '../utils';
|
|
11
10
|
import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
|
|
12
11
|
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
|
|
12
|
+
import { LoggerInstance, pathJoin, getRootDomDefaultClassName } from '../utils';
|
|
13
|
+
import { getInstance } from '@module-federation/runtime';
|
|
13
14
|
|
|
14
15
|
declare const __APP_VERSION__: string;
|
|
15
16
|
export interface RenderFnParams extends ProviderParams {
|
|
@@ -59,13 +60,15 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
59
60
|
|
|
60
61
|
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
61
62
|
const providerInfoRef = useRef<any>(null);
|
|
63
|
+
const hostInstance = getInstance();
|
|
64
|
+
LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
|
|
62
65
|
|
|
63
66
|
useEffect(() => {
|
|
64
67
|
const renderTimeout = setTimeout(() => {
|
|
65
68
|
const providerReturn = providerInfo();
|
|
66
69
|
providerInfoRef.current = providerReturn;
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
let renderProps = {
|
|
69
72
|
moduleName,
|
|
70
73
|
dom: rootRef.current,
|
|
71
74
|
basename,
|
|
@@ -78,7 +81,21 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
78
81
|
`createRemoteComponent LazyComponent render >>>`,
|
|
79
82
|
renderProps,
|
|
80
83
|
);
|
|
84
|
+
|
|
85
|
+
LoggerInstance.log(
|
|
86
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
87
|
+
hostInstance,
|
|
88
|
+
);
|
|
89
|
+
const beforeBridgeRenderRes =
|
|
90
|
+
hostInstance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
|
|
91
|
+
renderProps,
|
|
92
|
+
) || {};
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
81
95
|
providerReturn.render(renderProps);
|
|
96
|
+
hostInstance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(
|
|
97
|
+
renderProps,
|
|
98
|
+
);
|
|
82
99
|
});
|
|
83
100
|
|
|
84
101
|
return () => {
|
|
@@ -89,17 +106,39 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
89
106
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
90
107
|
{ moduleName, basename, dom: renderDom.current },
|
|
91
108
|
);
|
|
109
|
+
|
|
110
|
+
hostInstance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
|
|
111
|
+
moduleName,
|
|
112
|
+
dom: renderDom.current,
|
|
113
|
+
basename,
|
|
114
|
+
memoryRoute,
|
|
115
|
+
fallback,
|
|
116
|
+
...resProps,
|
|
117
|
+
});
|
|
118
|
+
|
|
92
119
|
providerInfoRef.current?.destroy({
|
|
120
|
+
moduleName,
|
|
121
|
+
dom: renderDom.current,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
hostInstance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
|
|
125
|
+
moduleName,
|
|
93
126
|
dom: renderDom.current,
|
|
127
|
+
basename,
|
|
128
|
+
memoryRoute,
|
|
129
|
+
fallback,
|
|
130
|
+
...resProps,
|
|
94
131
|
});
|
|
95
132
|
}
|
|
96
133
|
});
|
|
97
134
|
};
|
|
98
135
|
}, []);
|
|
99
136
|
|
|
137
|
+
// bridge-remote-root
|
|
138
|
+
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props?.className}`;
|
|
100
139
|
return (
|
|
101
140
|
<div
|
|
102
|
-
className={
|
|
141
|
+
className={rootComponentClassName}
|
|
103
142
|
style={props?.style}
|
|
104
143
|
ref={rootRef}
|
|
105
144
|
></div>
|
package/src/router-v5.tsx
CHANGED
|
@@ -2,7 +2,6 @@ import React, { useContext } from 'react';
|
|
|
2
2
|
// The upper alias react-router-dom$ into this file avoids the loop
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
import * as ReactRouterDom from 'react-router-dom/index.js';
|
|
5
|
-
|
|
6
5
|
import { RouterContext } from './context';
|
|
7
6
|
import { LoggerInstance } from './utils';
|
|
8
7
|
|
|
@@ -37,7 +36,7 @@ function WraperRouter(
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
// @ts-ignore
|
|
40
|
-
//
|
|
39
|
+
// because export directly from react-router-dom/index.js will cause build falied.
|
|
41
40
|
// it will be replace by react-router-dom/index.js in building phase
|
|
42
41
|
export * from 'react-router-dom/';
|
|
43
42
|
|
package/src/router-v6.tsx
CHANGED
|
@@ -69,6 +69,7 @@ function WraperRouterProvider(
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
export * from 'react-router-dom/dist/index.js';
|
|
72
|
+
// export * from 'react-router-dom/dist/index.js';
|
|
73
|
+
export * from 'react-router-dom/';
|
|
73
74
|
export { WraperRouter as BrowserRouter };
|
|
74
75
|
export { WraperRouterProvider as RouterProvider };
|
package/src/router.tsx
CHANGED
|
@@ -59,7 +59,7 @@ function WrapperRouterProvider(
|
|
|
59
59
|
return <RouterProvider router={MemeoryRouterInstance} />;
|
|
60
60
|
} else {
|
|
61
61
|
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
62
|
-
basename: routerContextProps.basename,
|
|
62
|
+
basename: routerContextProps.basename || router?.basename,
|
|
63
63
|
future: router.future,
|
|
64
64
|
window: router.window,
|
|
65
65
|
});
|
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
|
+
};
|
package/vite.config.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineConfig } from 'vite';
|
|
2
|
-
import vue from '@vitejs/plugin-vue';
|
|
2
|
+
// import vue from '@vitejs/plugin-vue';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import dts from 'vite-plugin-dts';
|
|
5
|
-
import react from '@vitejs/plugin-react';
|
|
5
|
+
// import react from '@vitejs/plugin-react';
|
|
6
6
|
import packageJson from './package.json';
|
|
7
7
|
|
|
8
8
|
const perDepsKeys = Object.keys(packageJson.peerDependencies);
|
|
@@ -36,6 +36,7 @@ export default defineConfig({
|
|
|
36
36
|
'react-router-dom/',
|
|
37
37
|
'react-router-dom/index.js',
|
|
38
38
|
'react-router-dom/dist/index.js',
|
|
39
|
+
'@module-federation/runtime',
|
|
39
40
|
],
|
|
40
41
|
plugins: [
|
|
41
42
|
{
|
|
@@ -43,13 +44,13 @@ export default defineConfig({
|
|
|
43
44
|
generateBundle(options, bundle) {
|
|
44
45
|
for (const fileName in bundle) {
|
|
45
46
|
const chunk = bundle[fileName];
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
if (fileName.includes('router-v6') && chunk.type === 'chunk') {
|
|
48
|
+
chunk.code = chunk.code.replace(
|
|
49
|
+
// Match 'react-router-dom/' followed by single quotes, double quotes, or backticks, replacing only 'react-router-dom/' to react-router-v6 dist file structure
|
|
50
|
+
/react-router-dom\/(?=[\'\"\`])/g,
|
|
51
|
+
'react-router-dom/dist/index.js',
|
|
52
|
+
);
|
|
53
|
+
}
|
|
53
54
|
|
|
54
55
|
if (fileName.includes('router-v5') && chunk.type === 'chunk') {
|
|
55
56
|
chunk.code = chunk.code.replace(
|