@module-federation/bridge-react 0.0.0-next-20241115100504 → 0.0.0-next-20241117185051
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 +4 -4
- package/dist/{plugin-CfJaHqe4.cjs → index.cjs.js} +14 -39
- package/dist/index.d.ts +6 -14
- package/dist/index.es.js +429 -4
- package/package.json +10 -15
- package/src/create.tsx +8 -12
- package/src/index.ts +0 -2
- package/src/provider.tsx +6 -10
- package/src/remote/index.tsx +10 -9
- package/vite.config.ts +2 -3
- package/dist/index..js +0 -6
- package/dist/plugin-qjDRExZS.js +0 -457
- package/dist/plugin..js +0 -3
- package/dist/plugin.d.ts +0 -6
- package/dist/plugin.es.js +0 -4
- package/src/plugin.ts +0 -31
- /package/dist/{router-v5..js → router-v5.cjs.js} +0 -0
- /package/dist/{router-v6..js → router-v6.cjs.js} +0 -0
- /package/dist/{router..js → router.cjs.js} +0 -0
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-20241117185051",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -12,42 +12,38 @@
|
|
|
12
12
|
"directory": "packages/bridge-react"
|
|
13
13
|
},
|
|
14
14
|
"type": "module",
|
|
15
|
-
"main": "./dist/index.js",
|
|
15
|
+
"main": "./dist/index.cjs.js",
|
|
16
16
|
"module": "./dist/index.es.js",
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
21
|
"import": "./dist/index.es.js",
|
|
22
|
-
"require": "./dist/index.js"
|
|
23
|
-
},
|
|
24
|
-
"./plugin": {
|
|
25
|
-
"types": "./dist/plugin.d.ts",
|
|
26
|
-
"import": "./dist/plugin.es.js",
|
|
27
|
-
"require": "./dist/plugin.js"
|
|
22
|
+
"require": "./dist/index.cjs.js"
|
|
28
23
|
},
|
|
29
24
|
"./router": {
|
|
30
25
|
"types": "./dist/router.d.ts",
|
|
31
26
|
"import": "./dist/router.es.js",
|
|
32
|
-
"require": "./dist/router.js"
|
|
27
|
+
"require": "./dist/router.cjs.js"
|
|
33
28
|
},
|
|
34
29
|
"./router-v5": {
|
|
35
30
|
"types": "./dist/router-v5.d.ts",
|
|
36
31
|
"import": "./dist/router-v5.es.js",
|
|
37
|
-
"require": "./dist/router-v5.js"
|
|
32
|
+
"require": "./dist/router-v5.cjs.js"
|
|
38
33
|
},
|
|
39
34
|
"./router-v6": {
|
|
40
35
|
"types": "./dist/router-v6.d.ts",
|
|
41
36
|
"import": "./dist/router-v6.es.js",
|
|
42
|
-
"require": "./dist/router-v6.js"
|
|
37
|
+
"require": "./dist/router-v6.cjs.js"
|
|
43
38
|
},
|
|
44
39
|
"./*": "./*"
|
|
45
40
|
},
|
|
46
41
|
"dependencies": {
|
|
47
42
|
"@loadable/component": "^5.16.4",
|
|
48
43
|
"react-error-boundary": "^4.0.13",
|
|
49
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
50
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
44
|
+
"@module-federation/bridge-shared": "0.0.0-next-20241117185051",
|
|
45
|
+
"@module-federation/sdk": "0.0.0-next-20241117185051",
|
|
46
|
+
"@module-federation/runtime": "0.0.0-next-20241117185051"
|
|
51
47
|
},
|
|
52
48
|
"peerDependencies": {
|
|
53
49
|
"react": ">=16.9.0",
|
|
@@ -67,8 +63,7 @@
|
|
|
67
63
|
"react-router-dom": "6.22.3",
|
|
68
64
|
"typescript": "^5.2.2",
|
|
69
65
|
"vite": "^5.2.14",
|
|
70
|
-
"vite-plugin-dts": "^3.9.1"
|
|
71
|
-
"@module-federation/enhanced": "0.0.0-next-20241115100504"
|
|
66
|
+
"vite-plugin-dts": "^3.9.1"
|
|
72
67
|
},
|
|
73
68
|
"scripts": {
|
|
74
69
|
"dev": "vite",
|
package/src/create.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import type { FederationHost } from '@module-federation/enhanced/runtime';
|
|
3
2
|
import {
|
|
4
3
|
ErrorBoundary,
|
|
5
4
|
ErrorBoundaryPropsWithComponent,
|
|
@@ -19,17 +18,12 @@ interface RemoteModule {
|
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
function createLazyRemoteComponent<T, E extends keyof T>(info: {
|
|
23
22
|
loader: () => Promise<T>;
|
|
24
23
|
loading: React.ReactNode;
|
|
25
24
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
26
25
|
export?: E;
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function createLazyRemoteComponent<T, E extends keyof T>(
|
|
31
|
-
info: LazyRemoteComponentInfo<T, E>,
|
|
32
|
-
) {
|
|
26
|
+
}) {
|
|
33
27
|
const exportName = info?.export || 'default';
|
|
34
28
|
return React.lazy(async () => {
|
|
35
29
|
LoggerInstance.log(`createRemoteComponent LazyComponent create >>>`, {
|
|
@@ -64,7 +58,6 @@ function createLazyRemoteComponent<T, E extends keyof T>(
|
|
|
64
58
|
exportName={info.export || 'default'}
|
|
65
59
|
fallback={info.fallback}
|
|
66
60
|
ref={ref}
|
|
67
|
-
instance={info.instance}
|
|
68
61
|
{...props}
|
|
69
62
|
/>
|
|
70
63
|
);
|
|
@@ -90,9 +83,12 @@ function createLazyRemoteComponent<T, E extends keyof T>(
|
|
|
90
83
|
});
|
|
91
84
|
}
|
|
92
85
|
|
|
93
|
-
export function createRemoteComponent<T, E extends keyof T>(
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
export function createRemoteComponent<T, E extends keyof T>(info: {
|
|
87
|
+
loader: () => Promise<T>;
|
|
88
|
+
loading: React.ReactNode;
|
|
89
|
+
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
90
|
+
export?: E;
|
|
91
|
+
}) {
|
|
96
92
|
type ExportType = T[E] extends (...args: any) => any
|
|
97
93
|
? ReturnType<T[E]>
|
|
98
94
|
: never;
|
package/src/index.ts
CHANGED
package/src/provider.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
10
10
|
import { RouterContext } from './context';
|
|
11
11
|
import { LoggerInstance, atLeastReact18 } from './utils';
|
|
12
|
-
import
|
|
12
|
+
import { getInstance } from '@module-federation/runtime';
|
|
13
13
|
|
|
14
14
|
type RenderParams = RenderFnParams & {
|
|
15
15
|
[key: string]: unknown;
|
|
@@ -26,17 +26,13 @@ type ProviderFnParams<T> = {
|
|
|
26
26
|
App: React.ReactElement,
|
|
27
27
|
id?: HTMLElement | string,
|
|
28
28
|
) => RootType | Promise<RootType>;
|
|
29
|
-
instance?: FederationHost;
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
33
32
|
return () => {
|
|
34
33
|
const rootMap = new Map<any, RootType>();
|
|
35
|
-
const
|
|
36
|
-
LoggerInstance.log(
|
|
37
|
-
`createBridgeComponent instance from props >>>`,
|
|
38
|
-
instance,
|
|
39
|
-
);
|
|
34
|
+
const instance = getInstance();
|
|
35
|
+
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
40
36
|
|
|
41
37
|
const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
|
|
42
38
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
@@ -99,6 +95,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
99
95
|
const renderFn = bridgeInfo?.render || ReactDOM.render;
|
|
100
96
|
renderFn?.(rootComponentWithErrorBoundary, info.dom);
|
|
101
97
|
}
|
|
98
|
+
|
|
102
99
|
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
|
|
103
100
|
},
|
|
104
101
|
|
|
@@ -106,6 +103,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
106
103
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
107
104
|
dom: info.dom,
|
|
108
105
|
});
|
|
106
|
+
|
|
109
107
|
instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit(info);
|
|
110
108
|
|
|
111
109
|
// call destroy function
|
|
@@ -117,9 +115,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
117
115
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
118
116
|
}
|
|
119
117
|
|
|
120
|
-
|
|
121
|
-
info,
|
|
122
|
-
);
|
|
118
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit(info);
|
|
123
119
|
},
|
|
124
120
|
rawComponent: bridgeInfo.rootComponent,
|
|
125
121
|
__BRIDGE_FN__: (_args: T) => {},
|
package/src/remote/index.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import type { ProviderParams } from '@module-federation/bridge-shared';
|
|
|
10
10
|
import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
|
|
11
11
|
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
|
|
12
12
|
import { LoggerInstance, pathJoin, getRootDomDefaultClassName } from '../utils';
|
|
13
|
-
import
|
|
13
|
+
import { getInstance } from '@module-federation/runtime';
|
|
14
14
|
|
|
15
15
|
declare const __APP_VERSION__: string;
|
|
16
16
|
export interface RenderFnParams extends ProviderParams {
|
|
@@ -34,7 +34,6 @@ interface RemoteAppParams {
|
|
|
34
34
|
providerInfo: NonNullable<RemoteModule['provider']>;
|
|
35
35
|
exportName: string | number | symbol;
|
|
36
36
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
37
|
-
instance: FederationHost;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
const RemoteAppWrapper = forwardRef(function (
|
|
@@ -51,7 +50,6 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
51
50
|
className,
|
|
52
51
|
style,
|
|
53
52
|
fallback,
|
|
54
|
-
instance,
|
|
55
53
|
...resProps
|
|
56
54
|
} = props;
|
|
57
55
|
|
|
@@ -62,7 +60,8 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
62
60
|
|
|
63
61
|
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
64
62
|
const providerInfoRef = useRef<any>(null);
|
|
65
|
-
|
|
63
|
+
const hostInstance = getInstance();
|
|
64
|
+
LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
|
|
66
65
|
|
|
67
66
|
useEffect(() => {
|
|
68
67
|
const renderTimeout = setTimeout(() => {
|
|
@@ -85,16 +84,18 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
85
84
|
|
|
86
85
|
LoggerInstance.log(
|
|
87
86
|
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
88
|
-
|
|
87
|
+
hostInstance,
|
|
89
88
|
);
|
|
90
89
|
const beforeBridgeRenderRes =
|
|
91
|
-
|
|
90
|
+
hostInstance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
|
|
92
91
|
renderProps,
|
|
93
92
|
) || {};
|
|
94
93
|
// @ts-ignore
|
|
95
94
|
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
96
95
|
providerReturn.render(renderProps);
|
|
97
|
-
|
|
96
|
+
hostInstance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(
|
|
97
|
+
renderProps,
|
|
98
|
+
);
|
|
98
99
|
});
|
|
99
100
|
|
|
100
101
|
return () => {
|
|
@@ -106,7 +107,7 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
106
107
|
{ moduleName, basename, dom: renderDom.current },
|
|
107
108
|
);
|
|
108
109
|
|
|
109
|
-
|
|
110
|
+
hostInstance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
|
|
110
111
|
moduleName,
|
|
111
112
|
dom: renderDom.current,
|
|
112
113
|
basename,
|
|
@@ -120,7 +121,7 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
120
121
|
dom: renderDom.current,
|
|
121
122
|
});
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
hostInstance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
|
|
124
125
|
moduleName,
|
|
125
126
|
dom: renderDom.current,
|
|
126
127
|
basename,
|
package/vite.config.ts
CHANGED
|
@@ -21,14 +21,12 @@ export default defineConfig({
|
|
|
21
21
|
lib: {
|
|
22
22
|
entry: {
|
|
23
23
|
index: path.resolve(__dirname, 'src/index.ts'),
|
|
24
|
-
plugin: path.resolve(__dirname, 'src/plugin.ts'),
|
|
25
24
|
router: path.resolve(__dirname, 'src/router.tsx'),
|
|
26
25
|
'router-v5': path.resolve(__dirname, 'src/router-v5.tsx'),
|
|
27
26
|
'router-v6': path.resolve(__dirname, 'src/router-v6.tsx'),
|
|
28
27
|
},
|
|
29
28
|
formats: ['cjs', 'es'],
|
|
30
|
-
fileName: (format, entryName) =>
|
|
31
|
-
`${entryName}.${format.replace('cjs', '')}.js`,
|
|
29
|
+
fileName: (format, entryName) => `${entryName}.${format}.js`,
|
|
32
30
|
},
|
|
33
31
|
rollupOptions: {
|
|
34
32
|
external: [
|
|
@@ -38,6 +36,7 @@ export default defineConfig({
|
|
|
38
36
|
'react-router-dom/',
|
|
39
37
|
'react-router-dom/index.js',
|
|
40
38
|
'react-router-dom/dist/index.js',
|
|
39
|
+
'@module-federation/runtime',
|
|
41
40
|
],
|
|
42
41
|
plugins: [
|
|
43
42
|
{
|
package/dist/index..js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const plugin = require("./plugin-CfJaHqe4.cjs");
|
|
4
|
-
exports.BridgeReactPlugin = plugin.BridgeReactPlugin;
|
|
5
|
-
exports.createBridgeComponent = plugin.createBridgeComponent;
|
|
6
|
-
exports.createRemoteComponent = plugin.createRemoteComponent;
|