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