@module-federation/bridge-react 0.0.0-next-20241113115843 → 0.0.0-next-20241114065146
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 +3 -13
- package/dist/context-BBLu8BlQ.cjs +336 -0
- package/dist/context-BcyT-d0V.js +337 -0
- package/dist/index.cjs.js +17 -2863
- package/dist/index.d.ts +4 -11
- package/dist/index.es.js +17 -2863
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +2 -2
- package/dist/router.es.js +2 -2
- package/package.json +3 -4
- package/src/create.tsx +2 -2
- package/src/provider.tsx +6 -33
- package/src/remote/index.tsx +3 -42
- package/src/router-v5.tsx +1 -0
- package/src/router.tsx +1 -1
- package/src/utils.ts +0 -22
- package/dist/context-3_giwitw.js +0 -857
- package/dist/context-C9uJCrqC.cjs +0 -856
package/dist/router-v5.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const ReactRouterDom$1 = require("react-router-dom/index.js");
|
|
5
|
-
const context = require("./context-
|
|
5
|
+
const context = require("./context-BBLu8BlQ.cjs");
|
|
6
6
|
const ReactRouterDom = require("react-router-dom/index.js");
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
package/dist/router-v5.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default, { useContext } from "react";
|
|
2
2
|
import * as ReactRouterDom$1 from "react-router-dom/index.js";
|
|
3
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-
|
|
3
|
+
import { R as RouterContext, L as LoggerInstance } from "./context-BcyT-d0V.js";
|
|
4
4
|
export * from "react-router-dom/index.js";
|
|
5
5
|
function WraperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
package/dist/router-v6.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const ReactRouterDom = require("react-router-dom/dist/index.js");
|
|
5
|
-
const context = require("./context-
|
|
5
|
+
const context = require("./context-BBLu8BlQ.cjs");
|
|
6
6
|
function _interopNamespaceDefault(e) {
|
|
7
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
8
|
if (e) {
|
package/dist/router-v6.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { useContext } from "react";
|
|
2
2
|
import * as ReactRouterDom from "react-router-dom/dist/index.js";
|
|
3
3
|
export * from "react-router-dom/dist/index.js";
|
|
4
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-
|
|
4
|
+
import { R as RouterContext, L as LoggerInstance } from "./context-BcyT-d0V.js";
|
|
5
5
|
function WraperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
|
7
7
|
const routerContextProps = useContext(RouterContext) || {};
|
package/dist/router.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const ReactRouterDom = require("react-router-dom/");
|
|
5
|
-
const context = require("./context-
|
|
5
|
+
const context = require("./context-BBLu8BlQ.cjs");
|
|
6
6
|
function _interopNamespaceDefault(e) {
|
|
7
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
8
|
if (e) {
|
|
@@ -65,7 +65,7 @@ function WrapperRouterProvider(props) {
|
|
|
65
65
|
return /* @__PURE__ */ React.createElement(RouterProvider, { router: MemeoryRouterInstance });
|
|
66
66
|
} else {
|
|
67
67
|
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
68
|
-
basename: routerContextProps.basename
|
|
68
|
+
basename: routerContextProps.basename,
|
|
69
69
|
future: router.future,
|
|
70
70
|
window: router.window
|
|
71
71
|
});
|
package/dist/router.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { useContext } from "react";
|
|
2
2
|
import * as ReactRouterDom from "react-router-dom/";
|
|
3
3
|
export * from "react-router-dom/";
|
|
4
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-
|
|
4
|
+
import { R as RouterContext, L as LoggerInstance } from "./context-BcyT-d0V.js";
|
|
5
5
|
function WrapperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
|
7
7
|
const routerContextProps = useContext(RouterContext) || {};
|
|
@@ -47,7 +47,7 @@ function WrapperRouterProvider(props) {
|
|
|
47
47
|
return /* @__PURE__ */ React__default.createElement(RouterProvider, { router: MemeoryRouterInstance });
|
|
48
48
|
} else {
|
|
49
49
|
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
50
|
-
basename: routerContextProps.basename
|
|
50
|
+
basename: routerContextProps.basename,
|
|
51
51
|
future: router.future,
|
|
52
52
|
window: router.window
|
|
53
53
|
});
|
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-20241114065146",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -41,9 +41,8 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@loadable/component": "^5.16.4",
|
|
43
43
|
"react-error-boundary": "^4.0.13",
|
|
44
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
45
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
46
|
-
"@module-federation/runtime": "0.0.0-next-20241113115843"
|
|
44
|
+
"@module-federation/bridge-shared": "0.0.0-next-20241114065146",
|
|
45
|
+
"@module-federation/sdk": "0.0.0-next-20241114065146"
|
|
47
46
|
},
|
|
48
47
|
"peerDependencies": {
|
|
49
48
|
"react": ">=16.9.0",
|
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,24 +2,15 @@ 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';
|
|
12
|
-
import {
|
|
11
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
13
12
|
|
|
14
|
-
type RenderParams = RenderFnParams & {
|
|
15
|
-
[key: string]: unknown;
|
|
16
|
-
};
|
|
17
|
-
type DestroyParams = {
|
|
18
|
-
moduleName: string;
|
|
19
|
-
dom: HTMLElement;
|
|
20
|
-
};
|
|
21
13
|
type RootType = HTMLElement | ReactDOMClient.Root;
|
|
22
|
-
|
|
23
14
|
type ProviderFnParams<T> = {
|
|
24
15
|
rootComponent: React.ComponentType<T>;
|
|
25
16
|
render?: (
|
|
@@ -31,9 +22,6 @@ type ProviderFnParams<T> = {
|
|
|
31
22
|
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
32
23
|
return () => {
|
|
33
24
|
const rootMap = new Map<any, RootType>();
|
|
34
|
-
const instance = getInstance();
|
|
35
|
-
LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
36
|
-
|
|
37
25
|
const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
|
|
38
26
|
const { appInfo, propsInfo, ...restProps } = info;
|
|
39
27
|
const { moduleName, memoryRoute, basename = '/' } = appInfo;
|
|
@@ -49,7 +37,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
49
37
|
};
|
|
50
38
|
|
|
51
39
|
return {
|
|
52
|
-
async render(info:
|
|
40
|
+
async render(info: RenderFnParams & any) {
|
|
53
41
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
54
42
|
const {
|
|
55
43
|
moduleName,
|
|
@@ -59,10 +47,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
59
47
|
fallback,
|
|
60
48
|
...propsInfo
|
|
61
49
|
} = info;
|
|
62
|
-
|
|
63
|
-
const beforeBridgeRenderRes =
|
|
64
|
-
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
|
|
65
|
-
|
|
66
50
|
const rootComponentWithErrorBoundary = (
|
|
67
51
|
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
68
52
|
<ErrorBoundary FallbackComponent={fallback}>
|
|
@@ -72,13 +56,11 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
72
56
|
basename,
|
|
73
57
|
memoryRoute,
|
|
74
58
|
}}
|
|
75
|
-
propsInfo={
|
|
76
|
-
{ ...propsInfo, ...beforeBridgeRenderRes?.extraProps } as T
|
|
77
|
-
}
|
|
59
|
+
propsInfo={propsInfo}
|
|
78
60
|
/>
|
|
79
61
|
</ErrorBoundary>
|
|
80
62
|
);
|
|
81
|
-
|
|
63
|
+
|
|
82
64
|
if (atLeastReact18(React)) {
|
|
83
65
|
if (bridgeInfo?.render) {
|
|
84
66
|
// in case bridgeInfo?.render is an async function, resolve this to promise
|
|
@@ -95,18 +77,11 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
95
77
|
const renderFn = bridgeInfo?.render || ReactDOM.render;
|
|
96
78
|
renderFn?.(rootComponentWithErrorBoundary, info.dom);
|
|
97
79
|
}
|
|
98
|
-
|
|
99
|
-
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
|
|
100
80
|
},
|
|
101
|
-
|
|
102
|
-
async destroy(info: DestroyParams) {
|
|
81
|
+
async destroy(info: { dom: HTMLElement }) {
|
|
103
82
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
104
83
|
dom: info.dom,
|
|
105
84
|
});
|
|
106
|
-
|
|
107
|
-
instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit(info);
|
|
108
|
-
|
|
109
|
-
// call destroy function
|
|
110
85
|
if (atLeastReact18(React)) {
|
|
111
86
|
const root = rootMap.get(info.dom);
|
|
112
87
|
(root as ReactDOMClient.Root)?.unmount();
|
|
@@ -114,8 +89,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
114
89
|
} else {
|
|
115
90
|
ReactDOM.unmountComponentAtNode(info.dom);
|
|
116
91
|
}
|
|
117
|
-
|
|
118
|
-
instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit(info);
|
|
119
92
|
},
|
|
120
93
|
rawComponent: bridgeInfo.rootComponent,
|
|
121
94
|
__BRIDGE_FN__: (_args: T) => {},
|
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 { LoggerInstance, pathJoin, getRootDomDefaultClassName } from '../utils';
|
|
13
|
-
import { getInstance } from '@module-federation/runtime';
|
|
14
13
|
|
|
15
14
|
declare const __APP_VERSION__: string;
|
|
16
15
|
export interface RenderFnParams extends ProviderParams {
|
|
@@ -60,15 +59,13 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
60
59
|
|
|
61
60
|
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
62
61
|
const providerInfoRef = useRef<any>(null);
|
|
63
|
-
const hostInstance = getInstance();
|
|
64
|
-
LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
|
|
65
62
|
|
|
66
63
|
useEffect(() => {
|
|
67
64
|
const renderTimeout = setTimeout(() => {
|
|
68
65
|
const providerReturn = providerInfo();
|
|
69
66
|
providerInfoRef.current = providerReturn;
|
|
70
67
|
|
|
71
|
-
|
|
68
|
+
const renderProps = {
|
|
72
69
|
moduleName,
|
|
73
70
|
dom: rootRef.current,
|
|
74
71
|
basename,
|
|
@@ -81,21 +78,7 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
81
78
|
`createRemoteComponent LazyComponent render >>>`,
|
|
82
79
|
renderProps,
|
|
83
80
|
);
|
|
84
|
-
|
|
85
|
-
LoggerInstance.log(
|
|
86
|
-
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
87
|
-
hostInstance,
|
|
88
|
-
);
|
|
89
|
-
const beforeBridgeRenderRes =
|
|
90
|
-
hostInstance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
|
|
91
|
-
renderProps,
|
|
92
|
-
) || {};
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
95
81
|
providerReturn.render(renderProps);
|
|
96
|
-
hostInstance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(
|
|
97
|
-
renderProps,
|
|
98
|
-
);
|
|
99
82
|
});
|
|
100
83
|
|
|
101
84
|
return () => {
|
|
@@ -106,39 +89,17 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
106
89
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
107
90
|
{ moduleName, basename, dom: renderDom.current },
|
|
108
91
|
);
|
|
109
|
-
|
|
110
|
-
hostInstance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
|
|
111
|
-
moduleName,
|
|
112
|
-
dom: renderDom.current,
|
|
113
|
-
basename,
|
|
114
|
-
memoryRoute,
|
|
115
|
-
fallback,
|
|
116
|
-
...resProps,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
92
|
providerInfoRef.current?.destroy({
|
|
120
|
-
moduleName,
|
|
121
|
-
dom: renderDom.current,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
hostInstance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
|
|
125
|
-
moduleName,
|
|
126
93
|
dom: renderDom.current,
|
|
127
|
-
basename,
|
|
128
|
-
memoryRoute,
|
|
129
|
-
fallback,
|
|
130
|
-
...resProps,
|
|
131
94
|
});
|
|
132
95
|
}
|
|
133
96
|
});
|
|
134
97
|
};
|
|
135
98
|
}, []);
|
|
136
99
|
|
|
137
|
-
// bridge-remote-root
|
|
138
|
-
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props?.className}`;
|
|
139
100
|
return (
|
|
140
101
|
<div
|
|
141
|
-
className={
|
|
102
|
+
className={props?.className}
|
|
142
103
|
style={props?.style}
|
|
143
104
|
ref={rootRef}
|
|
144
105
|
></div>
|
package/src/router-v5.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import React, { useContext } from 'react';
|
|
|
2
2
|
// The upper alias react-router-dom$ into this file avoids the loop
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
import * as ReactRouterDom from 'react-router-dom/index.js';
|
|
5
|
+
|
|
5
6
|
import { RouterContext } from './context';
|
|
6
7
|
import { LoggerInstance } from './utils';
|
|
7
8
|
|
package/src/router.tsx
CHANGED
|
@@ -59,7 +59,7 @@ function WrapperRouterProvider(
|
|
|
59
59
|
return <RouterProvider router={MemeoryRouterInstance} />;
|
|
60
60
|
} else {
|
|
61
61
|
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
62
|
-
basename: routerContextProps.basename
|
|
62
|
+
basename: routerContextProps.basename,
|
|
63
63
|
future: router.future,
|
|
64
64
|
window: router.window,
|
|
65
65
|
});
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FederationHost } from '@module-federation/runtime';
|
|
3
2
|
import { createLogger } from '@module-federation/sdk';
|
|
4
3
|
|
|
5
4
|
export const LoggerInstance = createLogger(
|
|
@@ -42,24 +41,3 @@ export function pathJoin(...args: string[]) {
|
|
|
42
41
|
}, '');
|
|
43
42
|
return res || '/';
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
export const getModuleName = (id: string) => {
|
|
47
|
-
if (!id) {
|
|
48
|
-
return id;
|
|
49
|
-
}
|
|
50
|
-
// separate module name without detailed module path
|
|
51
|
-
// @vmok-e2e/edenx-demo-app2/button -> @vmok-e2e/edenx-demo-app2
|
|
52
|
-
const idArray = id.split('/');
|
|
53
|
-
if (idArray.length < 2) {
|
|
54
|
-
return id;
|
|
55
|
-
}
|
|
56
|
-
return idArray[0] + '/' + idArray[1];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const getRootDomDefaultClassName = (moduleName: string) => {
|
|
60
|
-
if (!moduleName) {
|
|
61
|
-
return '';
|
|
62
|
-
}
|
|
63
|
-
const name = getModuleName(moduleName).replace(/\@/, '').replace(/\//, '-');
|
|
64
|
-
return `bridge-root-component-${name}`;
|
|
65
|
-
};
|