@module-federation/bridge-react 0.0.0-next-20240718040714 → 0.0.0-next-20240718063946
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 -2
- package/dist/index.cjs.js +6 -7
- package/dist/index.d.ts +5 -3
- package/dist/index.es.js +6 -7
- package/package.json +2 -2
- package/src/provider.tsx +11 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240718063946
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- chore: bump next
|
|
8
|
-
- @module-federation/bridge-shared@0.0.0-next-
|
|
8
|
+
- @module-federation/bridge-shared@0.0.0-next-20240718063946
|
|
9
9
|
|
|
10
10
|
## 0.2.6
|
|
11
11
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -312,13 +312,12 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
312
312
|
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename, ...restProps }));
|
|
313
313
|
};
|
|
314
314
|
return {
|
|
315
|
-
render(info) {
|
|
315
|
+
async render(info) {
|
|
316
316
|
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
317
317
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
318
318
|
if (context.atLeastReact18(React__namespace)) {
|
|
319
|
-
let root = null;
|
|
320
319
|
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
|
|
321
|
-
|
|
320
|
+
Promise.resolve(bridgeInfo == null ? void 0 : bridgeInfo.render(
|
|
322
321
|
/* @__PURE__ */ React__namespace.createElement(
|
|
323
322
|
RawComponent,
|
|
324
323
|
{
|
|
@@ -331,9 +330,9 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
331
330
|
}
|
|
332
331
|
),
|
|
333
332
|
info.dom
|
|
334
|
-
);
|
|
333
|
+
)).then((root) => rootMap.set(info.dom, root));
|
|
335
334
|
} else {
|
|
336
|
-
root = client.createRoot(info.dom);
|
|
335
|
+
const root = client.createRoot(info.dom);
|
|
337
336
|
root.render(
|
|
338
337
|
/* @__PURE__ */ React__namespace.createElement(
|
|
339
338
|
RawComponent,
|
|
@@ -347,8 +346,8 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
347
346
|
}
|
|
348
347
|
)
|
|
349
348
|
);
|
|
349
|
+
rootMap.set(info.dom, root);
|
|
350
350
|
}
|
|
351
|
-
rootMap.set(info.dom, root);
|
|
352
351
|
} else {
|
|
353
352
|
const renderFunc = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
354
353
|
renderFunc(
|
|
@@ -367,7 +366,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
367
366
|
);
|
|
368
367
|
}
|
|
369
368
|
},
|
|
370
|
-
destroy(info) {
|
|
369
|
+
async destroy(info) {
|
|
371
370
|
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
372
371
|
dom: info.dom
|
|
373
372
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ 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: RenderFnParams & any): void
|
|
9
|
+
render(info: RenderFnParams & any): Promise<void>;
|
|
10
10
|
destroy(info: {
|
|
11
11
|
dom: HTMLElement;
|
|
12
|
-
}): void
|
|
12
|
+
}): Promise<void>;
|
|
13
13
|
rawComponent: React_2.ComponentType<T>;
|
|
14
14
|
__BRIDGE_FN__: (_args: T) => void;
|
|
15
15
|
};
|
|
@@ -50,7 +50,7 @@ declare type FallbackProps = {
|
|
|
50
50
|
|
|
51
51
|
declare type ProviderFnParams<T> = {
|
|
52
52
|
rootComponent: React_2.ComponentType<T>;
|
|
53
|
-
render?: (App: React_2.ReactElement, id?: HTMLElement | string) =>
|
|
53
|
+
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export declare interface ProviderParams {
|
|
@@ -65,4 +65,6 @@ export declare interface RenderFnParams extends ProviderParams {
|
|
|
65
65
|
dom: HTMLElement;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
declare type RootType = HTMLElement | default_3.Root;
|
|
69
|
+
|
|
68
70
|
export { }
|
package/dist/index.es.js
CHANGED
|
@@ -293,13 +293,12 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
293
293
|
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename, ...restProps }));
|
|
294
294
|
};
|
|
295
295
|
return {
|
|
296
|
-
render(info) {
|
|
296
|
+
async render(info) {
|
|
297
297
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
298
298
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
299
299
|
if (atLeastReact18(React)) {
|
|
300
|
-
let root = null;
|
|
301
300
|
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
|
|
302
|
-
|
|
301
|
+
Promise.resolve(bridgeInfo == null ? void 0 : bridgeInfo.render(
|
|
303
302
|
/* @__PURE__ */ React.createElement(
|
|
304
303
|
RawComponent,
|
|
305
304
|
{
|
|
@@ -312,9 +311,9 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
312
311
|
}
|
|
313
312
|
),
|
|
314
313
|
info.dom
|
|
315
|
-
);
|
|
314
|
+
)).then((root) => rootMap.set(info.dom, root));
|
|
316
315
|
} else {
|
|
317
|
-
root = client.createRoot(info.dom);
|
|
316
|
+
const root = client.createRoot(info.dom);
|
|
318
317
|
root.render(
|
|
319
318
|
/* @__PURE__ */ React.createElement(
|
|
320
319
|
RawComponent,
|
|
@@ -328,8 +327,8 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
328
327
|
}
|
|
329
328
|
)
|
|
330
329
|
);
|
|
330
|
+
rootMap.set(info.dom, root);
|
|
331
331
|
}
|
|
332
|
-
rootMap.set(info.dom, root);
|
|
333
332
|
} else {
|
|
334
333
|
const renderFunc = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
335
334
|
renderFunc(
|
|
@@ -348,7 +347,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
348
347
|
);
|
|
349
348
|
}
|
|
350
349
|
},
|
|
351
|
-
destroy(info) {
|
|
350
|
+
async destroy(info) {
|
|
352
351
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
353
352
|
dom: info.dom
|
|
354
353
|
});
|
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-20240718063946",
|
|
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-20240718063946"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=16.9.0",
|
package/src/provider.tsx
CHANGED
|
@@ -9,15 +9,15 @@ import type {
|
|
|
9
9
|
} from '@module-federation/bridge-shared';
|
|
10
10
|
import { LoggerInstance, atLeastReact18 } from './utils';
|
|
11
11
|
|
|
12
|
+
type RootType = HTMLElement | ReactDOMClient.Root;
|
|
12
13
|
type ProviderFnParams<T> = {
|
|
13
14
|
rootComponent: React.ComponentType<T>;
|
|
14
|
-
render?: (App: React.ReactElement, id?: HTMLElement | string) =>
|
|
15
|
+
render?: (App: React.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
18
19
|
return () => {
|
|
19
|
-
const rootMap = new Map<any,
|
|
20
|
-
|
|
20
|
+
const rootMap = new Map<any, RootType>();
|
|
21
21
|
const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
|
|
22
22
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
23
23
|
const { name, memoryRoute, basename = '/' } = appInfo;
|
|
@@ -30,14 +30,13 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
return {
|
|
33
|
-
render(info: RenderFnParams & any) {
|
|
33
|
+
async render(info: RenderFnParams & any) {
|
|
34
34
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
35
35
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
36
36
|
if (atLeastReact18(React)) {
|
|
37
|
-
//
|
|
38
|
-
let root = null;
|
|
37
|
+
// render is provided by user
|
|
39
38
|
if (bridgeInfo?.render) {
|
|
40
|
-
|
|
39
|
+
Promise.resolve(bridgeInfo?.render(
|
|
41
40
|
<RawComponent
|
|
42
41
|
propsInfo={propsInfo}
|
|
43
42
|
appInfo={{
|
|
@@ -47,9 +46,9 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
47
46
|
}}
|
|
48
47
|
/>,
|
|
49
48
|
info.dom
|
|
50
|
-
);
|
|
49
|
+
)).then((root: RootType) => rootMap.set(info.dom, root));
|
|
51
50
|
} else {
|
|
52
|
-
root = ReactDOMClient.createRoot(info.dom);
|
|
51
|
+
const root: RootType = ReactDOMClient.createRoot(info.dom);
|
|
53
52
|
root.render(
|
|
54
53
|
<RawComponent
|
|
55
54
|
propsInfo={propsInfo}
|
|
@@ -60,8 +59,8 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
60
59
|
}}
|
|
61
60
|
/>,
|
|
62
61
|
);
|
|
62
|
+
rootMap.set(info.dom, root);
|
|
63
63
|
}
|
|
64
|
-
rootMap.set(info.dom, root);
|
|
65
64
|
} else {
|
|
66
65
|
const renderFunc = bridgeInfo?.render || ReactDOM.render;
|
|
67
66
|
renderFunc(
|
|
@@ -77,13 +76,13 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
77
76
|
);
|
|
78
77
|
}
|
|
79
78
|
},
|
|
80
|
-
destroy(info: { dom: HTMLElement }) {
|
|
79
|
+
async destroy(info: { dom: HTMLElement }) {
|
|
81
80
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
82
81
|
dom: info.dom,
|
|
83
82
|
});
|
|
84
83
|
if (atLeastReact18(React)) {
|
|
85
84
|
const root = rootMap.get(info.dom);
|
|
86
|
-
root?.unmount();
|
|
85
|
+
(root as ReactDOMClient.Root)?.unmount();
|
|
87
86
|
} else {
|
|
88
87
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
89
88
|
}
|
|
@@ -101,5 +100,3 @@ export function ShadowRoot(info: { children: () => JSX.Element }) {
|
|
|
101
100
|
|
|
102
101
|
return <div ref={domRef}>{root && <info.children />}</div>;
|
|
103
102
|
}
|
|
104
|
-
|
|
105
|
-
// function ShadowContent() {}
|