@module-federation/bridge-react 0.0.0-next-20240923073245 → 0.0.0-next-20240924022552
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 -5
- package/dist/index.cjs.js +14 -1045
- package/dist/index.d.ts +4 -12
- package/dist/index.es.js +14 -1045
- package/package.json +3 -4
- package/src/create.tsx +2 -2
- package/src/provider.tsx +5 -34
- package/src/remote/index.tsx +1 -20
- package/src/lifecycle.ts +0 -29
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-20240924022552",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -35,13 +35,12 @@
|
|
|
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-20240924022552"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=16.9.0",
|
|
42
42
|
"react-dom": ">=16.9.0",
|
|
43
|
-
"react-router-dom": ">=4"
|
|
44
|
-
"@module-federation/runtime": "0.0.0-next-20240923073245"
|
|
43
|
+
"react-router-dom": ">=4"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
46
|
"@testing-library/react": "15.0.7",
|
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';
|
|
2
4
|
import {
|
|
3
5
|
ErrorBoundary,
|
|
4
6
|
ErrorBoundaryPropsWithComponent,
|
|
5
7
|
} from 'react-error-boundary';
|
|
6
|
-
import { LoggerInstance } from './utils';
|
|
7
8
|
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,31 +2,23 @@ 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';
|
|
5
6
|
import type {
|
|
6
7
|
ProviderParams,
|
|
7
8
|
RenderFnParams,
|
|
8
9
|
} from '@module-federation/bridge-shared';
|
|
9
|
-
import { ErrorBoundary } from 'react-error-boundary';
|
|
10
|
-
import { RouterContext } from './context';
|
|
11
10
|
import { LoggerInstance, atLeastReact18 } from './utils';
|
|
11
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
12
12
|
|
|
13
|
-
type RenderParams = RenderFnParams & any;
|
|
14
|
-
type DestroyParams = {
|
|
15
|
-
dom: HTMLElement;
|
|
16
|
-
};
|
|
17
13
|
type RootType = HTMLElement | ReactDOMClient.Root;
|
|
18
|
-
|
|
19
14
|
type ProviderFnParams<T> = {
|
|
20
15
|
rootComponent: React.ComponentType<T>;
|
|
21
16
|
render?: (
|
|
22
17
|
App: React.ReactElement,
|
|
23
18
|
id?: HTMLElement | string,
|
|
24
19
|
) => RootType | Promise<RootType>;
|
|
25
|
-
hooks?: {
|
|
26
|
-
beforeBridgeRender?: (params: RenderFnParams) => void;
|
|
27
|
-
beforeBridgeDestroy?: (params: DestroyParams) => void;
|
|
28
|
-
};
|
|
29
20
|
};
|
|
21
|
+
|
|
30
22
|
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
31
23
|
return () => {
|
|
32
24
|
const rootMap = new Map<any, RootType>();
|
|
@@ -45,7 +37,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
45
37
|
};
|
|
46
38
|
|
|
47
39
|
return {
|
|
48
|
-
async render(info:
|
|
40
|
+
async render(info: RenderFnParams & any) {
|
|
49
41
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
50
42
|
const {
|
|
51
43
|
moduleName,
|
|
@@ -69,16 +61,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
69
61
|
</ErrorBoundary>
|
|
70
62
|
);
|
|
71
63
|
|
|
72
|
-
// call beforeBridgeRender hook
|
|
73
|
-
if (
|
|
74
|
-
bridgeInfo?.hooks &&
|
|
75
|
-
bridgeInfo?.hooks.beforeBridgeRender &&
|
|
76
|
-
typeof bridgeInfo?.hooks.beforeBridgeRender === 'function'
|
|
77
|
-
) {
|
|
78
|
-
bridgeInfo.hooks.beforeBridgeRender(info);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// call render function
|
|
82
64
|
if (atLeastReact18(React)) {
|
|
83
65
|
if (bridgeInfo?.render) {
|
|
84
66
|
// in case bridgeInfo?.render is an async function, resolve this to promise
|
|
@@ -96,21 +78,10 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
96
78
|
renderFn?.(rootComponentWithErrorBoundary, info.dom);
|
|
97
79
|
}
|
|
98
80
|
},
|
|
99
|
-
async destroy(info:
|
|
81
|
+
async destroy(info: { dom: HTMLElement }) {
|
|
100
82
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
101
83
|
dom: info.dom,
|
|
102
84
|
});
|
|
103
|
-
|
|
104
|
-
// call beforeBridgeDestroy hook
|
|
105
|
-
if (
|
|
106
|
-
bridgeInfo?.hooks &&
|
|
107
|
-
bridgeInfo?.hooks.beforeBridgeDestroy &&
|
|
108
|
-
typeof bridgeInfo?.hooks.beforeBridgeDestroy === 'function'
|
|
109
|
-
) {
|
|
110
|
-
bridgeInfo.hooks.beforeBridgeDestroy(info);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// call destroy function
|
|
114
85
|
if (atLeastReact18(React)) {
|
|
115
86
|
const root = rootMap.get(info.dom);
|
|
116
87
|
(root as ReactDOMClient.Root)?.unmount();
|
package/src/remote/index.tsx
CHANGED
|
@@ -7,10 +7,9 @@ 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';
|
|
10
11
|
import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
|
|
11
12
|
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
|
|
12
|
-
import { registerBridgeLifeCycle } from '../lifecycle';
|
|
13
|
-
import { LoggerInstance, pathJoin } from '../utils';
|
|
14
13
|
|
|
15
14
|
declare const __APP_VERSION__: string;
|
|
16
15
|
export interface RenderFnParams extends ProviderParams {
|
|
@@ -40,7 +39,6 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
40
39
|
props: RemoteAppParams & RenderFnParams,
|
|
41
40
|
ref,
|
|
42
41
|
) {
|
|
43
|
-
const bridgeHook = registerBridgeLifeCycle();
|
|
44
42
|
const RemoteApp = () => {
|
|
45
43
|
LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
46
44
|
const {
|
|
@@ -80,13 +78,6 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
80
78
|
`createRemoteComponent LazyComponent render >>>`,
|
|
81
79
|
renderProps,
|
|
82
80
|
);
|
|
83
|
-
|
|
84
|
-
if (bridgeHook && bridgeHook?.lifecycle?.beforeBridgeRender) {
|
|
85
|
-
bridgeHook?.lifecycle?.beforeBridgeRender.emit({
|
|
86
|
-
...renderProps,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
81
|
providerReturn.render(renderProps);
|
|
91
82
|
});
|
|
92
83
|
|
|
@@ -98,16 +89,6 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
98
89
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
99
90
|
{ moduleName, basename, dom: renderDom.current },
|
|
100
91
|
);
|
|
101
|
-
if (bridgeHook && bridgeHook?.lifecycle?.beforeBridgeDestroy) {
|
|
102
|
-
bridgeHook?.lifecycle?.beforeBridgeDestroy.emit({
|
|
103
|
-
moduleName,
|
|
104
|
-
dom: renderDom.current,
|
|
105
|
-
basename,
|
|
106
|
-
memoryRoute,
|
|
107
|
-
fallback,
|
|
108
|
-
...resProps,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
92
|
providerInfoRef.current?.destroy({
|
|
112
93
|
dom: renderDom.current,
|
|
113
94
|
});
|
package/src/lifecycle.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getInstance } from '@module-federation/runtime';
|
|
2
|
-
import helper from '@module-federation/runtime/helpers';
|
|
3
|
-
|
|
4
|
-
function registerBridgeLifeCycle() {
|
|
5
|
-
const { registerPlugins, pluginHelper } = helper.global;
|
|
6
|
-
const host = getInstance();
|
|
7
|
-
const pluginSystem = new pluginHelper.PluginSystem({
|
|
8
|
-
beforeBridgeRender: new pluginHelper.SyncHook<
|
|
9
|
-
[Record<string, any>],
|
|
10
|
-
void
|
|
11
|
-
>(),
|
|
12
|
-
beforeBridgeDestroy: new pluginHelper.SyncHook<
|
|
13
|
-
[Record<string, any>],
|
|
14
|
-
void
|
|
15
|
-
>(),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
if (host) {
|
|
19
|
-
registerPlugins<typeof pluginSystem.lifecycle, typeof pluginSystem>(
|
|
20
|
-
host?.options?.plugins,
|
|
21
|
-
[pluginSystem],
|
|
22
|
-
);
|
|
23
|
-
return pluginSystem;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { registerBridgeLifeCycle };
|