@module-federation/bridge-react 0.0.0-next-20240822063818 → 0.0.0-next-20240822101913
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 +9 -2
- package/dist/index.cjs.js +57 -53
- package/dist/index.d.ts +10 -8
- package/dist/index.es.js +57 -53
- package/package.json +2 -2
- package/src/provider.tsx +64 -54
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240822101913
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- 3082116: feat: support module isolated reported
|
|
8
|
+
- @module-federation/bridge-shared@0.0.0-next-20240822101913
|
|
9
|
+
|
|
10
|
+
## 0.5.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- @module-federation/bridge-shared@0.5.1
|
|
8
15
|
|
|
9
16
|
## 0.5.0
|
|
10
17
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -177,7 +177,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
177
177
|
}
|
|
178
178
|
);
|
|
179
179
|
};
|
|
180
|
-
RemoteApp2["__APP_VERSION__"] = "0.5.
|
|
180
|
+
RemoteApp2["__APP_VERSION__"] = "0.5.1";
|
|
181
181
|
return /* @__PURE__ */ React.createElement(RemoteApp2, null);
|
|
182
182
|
});
|
|
183
183
|
function withRouterData(WrappedComponent) {
|
|
@@ -327,6 +327,7 @@ if (process.env.NODE_ENV === "production") {
|
|
|
327
327
|
};
|
|
328
328
|
}
|
|
329
329
|
function createBridgeComponent(bridgeInfo) {
|
|
330
|
+
let provider;
|
|
330
331
|
return () => {
|
|
331
332
|
const rootMap = /* @__PURE__ */ new Map();
|
|
332
333
|
const RawComponent = (info) => {
|
|
@@ -341,62 +342,65 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
341
342
|
}
|
|
342
343
|
));
|
|
343
344
|
};
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
345
|
+
if (!provider) {
|
|
346
|
+
provider = {
|
|
347
|
+
async render(info) {
|
|
348
|
+
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
349
|
+
const {
|
|
350
|
+
moduleName,
|
|
351
|
+
dom,
|
|
352
|
+
basename,
|
|
353
|
+
memoryRoute,
|
|
354
|
+
fallback,
|
|
355
|
+
...propsInfo
|
|
356
|
+
} = info;
|
|
357
|
+
const rootComponentWithErrorBoundary = (
|
|
358
|
+
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
359
|
+
/* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
|
|
360
|
+
RawComponent,
|
|
361
|
+
{
|
|
362
|
+
appInfo: {
|
|
363
|
+
moduleName,
|
|
364
|
+
basename,
|
|
365
|
+
memoryRoute
|
|
366
|
+
},
|
|
367
|
+
propsInfo
|
|
368
|
+
}
|
|
369
|
+
))
|
|
370
|
+
);
|
|
371
|
+
if (context.atLeastReact18(React__namespace)) {
|
|
372
|
+
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
|
|
373
|
+
Promise.resolve(
|
|
374
|
+
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
375
|
+
).then((root) => rootMap.set(info.dom, root));
|
|
376
|
+
} else {
|
|
377
|
+
const root = client.createRoot(info.dom);
|
|
378
|
+
root.render(rootComponentWithErrorBoundary);
|
|
379
|
+
rootMap.set(info.dom, root);
|
|
366
380
|
}
|
|
367
|
-
))
|
|
368
|
-
);
|
|
369
|
-
if (context.atLeastReact18(React__namespace)) {
|
|
370
|
-
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
|
|
371
|
-
Promise.resolve(
|
|
372
|
-
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
373
|
-
).then((root) => rootMap.set(info.dom, root));
|
|
374
381
|
} else {
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
rootMap.set(info.dom, root);
|
|
382
|
+
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
383
|
+
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
378
384
|
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
385
|
+
},
|
|
386
|
+
async destroy(info) {
|
|
387
|
+
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
388
|
+
dom: info.dom
|
|
389
|
+
});
|
|
390
|
+
if (context.atLeastReact18(React__namespace)) {
|
|
391
|
+
const root = rootMap.get(info.dom);
|
|
392
|
+
root == null ? void 0 : root.unmount();
|
|
393
|
+
rootMap.delete(info.dom);
|
|
394
|
+
} else {
|
|
395
|
+
ReactDOM.unmountComponentAtNode(info.dom);
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
rawComponent: bridgeInfo.rootComponent,
|
|
399
|
+
__BRIDGE_FN__: (_args) => {
|
|
394
400
|
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
};
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
return provider;
|
|
400
404
|
};
|
|
401
405
|
}
|
|
402
406
|
exports.createBridgeComponent = createBridgeComponent;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,14 +5,7 @@ import { ErrorInfo } from 'react';
|
|
|
5
5
|
import { PropsWithChildren } from 'react';
|
|
6
6
|
import * as React_2 from 'react';
|
|
7
7
|
|
|
8
|
-
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () =>
|
|
9
|
-
render(info: RenderFnParams & any): Promise<void>;
|
|
10
|
-
destroy(info: {
|
|
11
|
-
dom: HTMLElement;
|
|
12
|
-
}): Promise<void>;
|
|
13
|
-
rawComponent: React_2.ComponentType<T>;
|
|
14
|
-
__BRIDGE_FN__: (_args: T) => void;
|
|
15
|
-
};
|
|
8
|
+
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => Provider<T>;
|
|
16
9
|
|
|
17
10
|
export declare function createRemoteComponent<T, E extends keyof T>(info: {
|
|
18
11
|
loader: () => Promise<T>;
|
|
@@ -45,6 +38,15 @@ declare type FallbackProps = {
|
|
|
45
38
|
resetErrorBoundary: (...args: any[]) => void;
|
|
46
39
|
};
|
|
47
40
|
|
|
41
|
+
declare type Provider<T> = {
|
|
42
|
+
render(info: any): Promise<void>;
|
|
43
|
+
destroy(info: {
|
|
44
|
+
dom: HTMLElement;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
rawComponent: React_2.ComponentType<T>;
|
|
47
|
+
__BRIDGE_FN__: (_args: T) => void;
|
|
48
|
+
};
|
|
49
|
+
|
|
48
50
|
declare type ProviderFnParams<T> = {
|
|
49
51
|
rootComponent: React_2.ComponentType<T>;
|
|
50
52
|
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
package/dist/index.es.js
CHANGED
|
@@ -158,7 +158,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
158
158
|
}
|
|
159
159
|
);
|
|
160
160
|
};
|
|
161
|
-
RemoteApp2["__APP_VERSION__"] = "0.5.
|
|
161
|
+
RemoteApp2["__APP_VERSION__"] = "0.5.1";
|
|
162
162
|
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
|
|
163
163
|
});
|
|
164
164
|
function withRouterData(WrappedComponent) {
|
|
@@ -308,6 +308,7 @@ if (process.env.NODE_ENV === "production") {
|
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
310
|
function createBridgeComponent(bridgeInfo) {
|
|
311
|
+
let provider;
|
|
311
312
|
return () => {
|
|
312
313
|
const rootMap = /* @__PURE__ */ new Map();
|
|
313
314
|
const RawComponent = (info) => {
|
|
@@ -322,62 +323,65 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
322
323
|
}
|
|
323
324
|
));
|
|
324
325
|
};
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
326
|
+
if (!provider) {
|
|
327
|
+
provider = {
|
|
328
|
+
async render(info) {
|
|
329
|
+
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
330
|
+
const {
|
|
331
|
+
moduleName,
|
|
332
|
+
dom,
|
|
333
|
+
basename,
|
|
334
|
+
memoryRoute,
|
|
335
|
+
fallback,
|
|
336
|
+
...propsInfo
|
|
337
|
+
} = info;
|
|
338
|
+
const rootComponentWithErrorBoundary = (
|
|
339
|
+
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
340
|
+
/* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
|
|
341
|
+
RawComponent,
|
|
342
|
+
{
|
|
343
|
+
appInfo: {
|
|
344
|
+
moduleName,
|
|
345
|
+
basename,
|
|
346
|
+
memoryRoute
|
|
347
|
+
},
|
|
348
|
+
propsInfo
|
|
349
|
+
}
|
|
350
|
+
))
|
|
351
|
+
);
|
|
352
|
+
if (atLeastReact18(React)) {
|
|
353
|
+
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
|
|
354
|
+
Promise.resolve(
|
|
355
|
+
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
356
|
+
).then((root) => rootMap.set(info.dom, root));
|
|
357
|
+
} else {
|
|
358
|
+
const root = client.createRoot(info.dom);
|
|
359
|
+
root.render(rootComponentWithErrorBoundary);
|
|
360
|
+
rootMap.set(info.dom, root);
|
|
347
361
|
}
|
|
348
|
-
))
|
|
349
|
-
);
|
|
350
|
-
if (atLeastReact18(React)) {
|
|
351
|
-
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
|
|
352
|
-
Promise.resolve(
|
|
353
|
-
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
354
|
-
).then((root) => rootMap.set(info.dom, root));
|
|
355
362
|
} else {
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
rootMap.set(info.dom, root);
|
|
363
|
+
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
364
|
+
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
359
365
|
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
366
|
+
},
|
|
367
|
+
async destroy(info) {
|
|
368
|
+
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
369
|
+
dom: info.dom
|
|
370
|
+
});
|
|
371
|
+
if (atLeastReact18(React)) {
|
|
372
|
+
const root = rootMap.get(info.dom);
|
|
373
|
+
root == null ? void 0 : root.unmount();
|
|
374
|
+
rootMap.delete(info.dom);
|
|
375
|
+
} else {
|
|
376
|
+
ReactDOM.unmountComponentAtNode(info.dom);
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
rawComponent: bridgeInfo.rootComponent,
|
|
380
|
+
__BRIDGE_FN__: (_args) => {
|
|
375
381
|
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
};
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
return provider;
|
|
381
385
|
};
|
|
382
386
|
}
|
|
383
387
|
export {
|
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-20240822101913",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@loadable/component": "^5.16.4",
|
|
37
37
|
"react-error-boundary": "^4.0.13",
|
|
38
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
38
|
+
"@module-federation/bridge-shared": "0.0.0-next-20240822101913"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=16.9.0",
|
package/src/provider.tsx
CHANGED
|
@@ -18,8 +18,15 @@ type ProviderFnParams<T> = {
|
|
|
18
18
|
id?: HTMLElement | string,
|
|
19
19
|
) => RootType | Promise<RootType>;
|
|
20
20
|
};
|
|
21
|
+
type Provider<T> = {
|
|
22
|
+
render(info: any): Promise<void>;
|
|
23
|
+
destroy(info: { dom: HTMLElement }): Promise<void>;
|
|
24
|
+
rawComponent: React.ComponentType<T>;
|
|
25
|
+
__BRIDGE_FN__: (_args: T) => void;
|
|
26
|
+
};
|
|
21
27
|
|
|
22
28
|
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
29
|
+
let provider: Provider<T>;
|
|
23
30
|
return () => {
|
|
24
31
|
const rootMap = new Map<any, RootType>();
|
|
25
32
|
const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
|
|
@@ -36,63 +43,66 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
36
43
|
);
|
|
37
44
|
};
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
if (!provider) {
|
|
47
|
+
provider = {
|
|
48
|
+
async render(info: RenderFnParams & any) {
|
|
49
|
+
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
50
|
+
const {
|
|
51
|
+
moduleName,
|
|
52
|
+
dom,
|
|
53
|
+
basename,
|
|
54
|
+
memoryRoute,
|
|
55
|
+
fallback,
|
|
56
|
+
...propsInfo
|
|
57
|
+
} = info;
|
|
58
|
+
const rootComponentWithErrorBoundary = (
|
|
59
|
+
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
60
|
+
<ErrorBoundary FallbackComponent={fallback}>
|
|
61
|
+
<RawComponent
|
|
62
|
+
appInfo={{
|
|
63
|
+
moduleName,
|
|
64
|
+
basename,
|
|
65
|
+
memoryRoute,
|
|
66
|
+
}}
|
|
67
|
+
propsInfo={propsInfo}
|
|
68
|
+
/>
|
|
69
|
+
</ErrorBoundary>
|
|
70
|
+
);
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
if (atLeastReact18(React)) {
|
|
73
|
+
if (bridgeInfo?.render) {
|
|
74
|
+
// in case bridgeInfo?.render is an async function, resolve this to promise
|
|
75
|
+
Promise.resolve(
|
|
76
|
+
bridgeInfo?.render(rootComponentWithErrorBoundary, dom),
|
|
77
|
+
).then((root: RootType) => rootMap.set(info.dom, root));
|
|
78
|
+
} else {
|
|
79
|
+
const root: RootType = ReactDOMClient.createRoot(info.dom);
|
|
80
|
+
root.render(rootComponentWithErrorBoundary);
|
|
81
|
+
rootMap.set(info.dom, root);
|
|
82
|
+
}
|
|
70
83
|
} else {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
84
|
+
// react 17 render
|
|
85
|
+
const renderFn = bridgeInfo?.render || ReactDOM.render;
|
|
86
|
+
renderFn?.(rootComponentWithErrorBoundary, info.dom);
|
|
74
87
|
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
rawComponent: bridgeInfo.rootComponent,
|
|
94
|
-
__BRIDGE_FN__: (_args: T) => {},
|
|
95
|
-
};
|
|
88
|
+
},
|
|
89
|
+
async destroy(info: { dom: HTMLElement }) {
|
|
90
|
+
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
91
|
+
dom: info.dom,
|
|
92
|
+
});
|
|
93
|
+
if (atLeastReact18(React)) {
|
|
94
|
+
const root = rootMap.get(info.dom);
|
|
95
|
+
(root as ReactDOMClient.Root)?.unmount();
|
|
96
|
+
rootMap.delete(info.dom);
|
|
97
|
+
} else {
|
|
98
|
+
ReactDOM.unmountComponentAtNode(info.dom);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
rawComponent: bridgeInfo.rootComponent,
|
|
102
|
+
__BRIDGE_FN__: (_args: T) => {},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return provider;
|
|
96
106
|
};
|
|
97
107
|
}
|
|
98
108
|
|