@module-federation/bridge-react 0.0.0-next-20241118092546 → 0.0.0-next-20241118100312
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 -5
- package/dist/index.cjs.js +446 -4
- package/dist/index.d.ts +6 -14
- package/dist/index.es.js +429 -4
- package/dist/router-v6.cjs.js +2 -3
- package/dist/router-v6.d.ts +1 -1
- package/dist/router-v6.es.js +7 -7
- package/package.json +5 -10
- 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/src/router-v5.tsx +1 -1
- package/src/router-v6.tsx +1 -2
- package/src/utils.ts +1 -0
- package/vite.config.ts +10 -10
- package/dist/plugin-CfJaHqe4.cjs +0 -473
- package/dist/plugin-qjDRExZS.js +0 -457
- package/dist/plugin.cjs.js +0 -3
- package/dist/plugin.d.ts +0 -6
- package/dist/plugin.es.js +0 -4
- package/src/plugin.ts +0 -31
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/src/router-v5.tsx
CHANGED
|
@@ -36,7 +36,7 @@ function WraperRouter(
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// @ts-ignore
|
|
39
|
-
//
|
|
39
|
+
// cause export directly from react-router-dom/index.js will cause build falied.
|
|
40
40
|
// it will be replace by react-router-dom/index.js in building phase
|
|
41
41
|
export * from 'react-router-dom/';
|
|
42
42
|
|
package/src/router-v6.tsx
CHANGED
|
@@ -69,7 +69,6 @@ function WraperRouterProvider(
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
export * from 'react-router-dom/';
|
|
72
|
+
export * from 'react-router-dom/dist/index.js';
|
|
74
73
|
export { WraperRouter as BrowserRouter };
|
|
75
74
|
export { WraperRouterProvider as RouterProvider };
|
package/src/utils.ts
CHANGED
package/vite.config.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineConfig } from 'vite';
|
|
2
|
-
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import dts from 'vite-plugin-dts';
|
|
5
|
-
|
|
5
|
+
import react from '@vitejs/plugin-react';
|
|
6
6
|
import packageJson from './package.json';
|
|
7
7
|
|
|
8
8
|
const perDepsKeys = Object.keys(packageJson.peerDependencies);
|
|
@@ -21,7 +21,6 @@ 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'),
|
|
@@ -37,6 +36,7 @@ export default defineConfig({
|
|
|
37
36
|
'react-router-dom/',
|
|
38
37
|
'react-router-dom/index.js',
|
|
39
38
|
'react-router-dom/dist/index.js',
|
|
39
|
+
'@module-federation/runtime',
|
|
40
40
|
],
|
|
41
41
|
plugins: [
|
|
42
42
|
{
|
|
@@ -44,13 +44,13 @@ export default defineConfig({
|
|
|
44
44
|
generateBundle(options, bundle) {
|
|
45
45
|
for (const fileName in bundle) {
|
|
46
46
|
const chunk = bundle[fileName];
|
|
47
|
-
if (fileName.includes('router-v6') && chunk.type === 'chunk') {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
47
|
+
// if (fileName.includes('router-v6') && chunk.type === 'chunk') {
|
|
48
|
+
// chunk.code = chunk.code.replace(
|
|
49
|
+
// // Match 'react-router-dom/' followed by single quotes, double quotes, or backticks, replacing only 'react-router-dom/' to react-router-v6 dist file structure
|
|
50
|
+
// /react-router-dom\/(?=[\'\"\`])/g,
|
|
51
|
+
// 'react-router-dom/dist/index.js',
|
|
52
|
+
// );
|
|
53
|
+
// }
|
|
54
54
|
|
|
55
55
|
if (fileName.includes('router-v5') && chunk.type === 'chunk') {
|
|
56
56
|
chunk.code = chunk.code.replace(
|
package/dist/plugin-CfJaHqe4.cjs
DELETED
|
@@ -1,473 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const React = require("react");
|
|
3
|
-
const context = require("./context-BcJ-YlNr.cjs");
|
|
4
|
-
const ReactRouterDOM = require("react-router-dom");
|
|
5
|
-
const ReactDOM = require("react-dom");
|
|
6
|
-
function _interopNamespaceDefault(e2) {
|
|
7
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
-
if (e2) {
|
|
9
|
-
for (const k in e2) {
|
|
10
|
-
if (k !== "default") {
|
|
11
|
-
const d = Object.getOwnPropertyDescriptor(e2, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: () => e2[k]
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
n.default = e2;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
23
|
-
const ReactRouterDOM__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDOM);
|
|
24
|
-
const ErrorBoundaryContext = React.createContext(null);
|
|
25
|
-
const initialState = {
|
|
26
|
-
didCatch: false,
|
|
27
|
-
error: null
|
|
28
|
-
};
|
|
29
|
-
class ErrorBoundary extends React.Component {
|
|
30
|
-
constructor(props) {
|
|
31
|
-
super(props);
|
|
32
|
-
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
33
|
-
this.state = initialState;
|
|
34
|
-
}
|
|
35
|
-
static getDerivedStateFromError(error) {
|
|
36
|
-
return {
|
|
37
|
-
didCatch: true,
|
|
38
|
-
error
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
resetErrorBoundary() {
|
|
42
|
-
const {
|
|
43
|
-
error
|
|
44
|
-
} = this.state;
|
|
45
|
-
if (error !== null) {
|
|
46
|
-
var _this$props$onReset, _this$props;
|
|
47
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
48
|
-
args[_key] = arguments[_key];
|
|
49
|
-
}
|
|
50
|
-
(_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
|
|
51
|
-
args,
|
|
52
|
-
reason: "imperative-api"
|
|
53
|
-
});
|
|
54
|
-
this.setState(initialState);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
componentDidCatch(error, info) {
|
|
58
|
-
var _this$props$onError, _this$props2;
|
|
59
|
-
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
60
|
-
}
|
|
61
|
-
componentDidUpdate(prevProps, prevState) {
|
|
62
|
-
const {
|
|
63
|
-
didCatch
|
|
64
|
-
} = this.state;
|
|
65
|
-
const {
|
|
66
|
-
resetKeys
|
|
67
|
-
} = this.props;
|
|
68
|
-
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
69
|
-
var _this$props$onReset2, _this$props3;
|
|
70
|
-
(_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
|
|
71
|
-
next: resetKeys,
|
|
72
|
-
prev: prevProps.resetKeys,
|
|
73
|
-
reason: "keys"
|
|
74
|
-
});
|
|
75
|
-
this.setState(initialState);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
render() {
|
|
79
|
-
const {
|
|
80
|
-
children,
|
|
81
|
-
fallbackRender,
|
|
82
|
-
FallbackComponent,
|
|
83
|
-
fallback
|
|
84
|
-
} = this.props;
|
|
85
|
-
const {
|
|
86
|
-
didCatch,
|
|
87
|
-
error
|
|
88
|
-
} = this.state;
|
|
89
|
-
let childToRender = children;
|
|
90
|
-
if (didCatch) {
|
|
91
|
-
const props = {
|
|
92
|
-
error,
|
|
93
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
94
|
-
};
|
|
95
|
-
if (typeof fallbackRender === "function") {
|
|
96
|
-
childToRender = fallbackRender(props);
|
|
97
|
-
} else if (FallbackComponent) {
|
|
98
|
-
childToRender = React.createElement(FallbackComponent, props);
|
|
99
|
-
} else if (fallback === null || React.isValidElement(fallback)) {
|
|
100
|
-
childToRender = fallback;
|
|
101
|
-
} else {
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return React.createElement(ErrorBoundaryContext.Provider, {
|
|
106
|
-
value: {
|
|
107
|
-
didCatch,
|
|
108
|
-
error,
|
|
109
|
-
resetErrorBoundary: this.resetErrorBoundary
|
|
110
|
-
}
|
|
111
|
-
}, childToRender);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function hasArrayChanged() {
|
|
115
|
-
let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
116
|
-
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
117
|
-
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
118
|
-
}
|
|
119
|
-
function e() {
|
|
120
|
-
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
121
|
-
window.dispatchEvent(t);
|
|
122
|
-
}
|
|
123
|
-
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
124
|
-
const RemoteApp2 = () => {
|
|
125
|
-
context.LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
126
|
-
const {
|
|
127
|
-
moduleName,
|
|
128
|
-
memoryRoute,
|
|
129
|
-
basename,
|
|
130
|
-
providerInfo,
|
|
131
|
-
className,
|
|
132
|
-
style,
|
|
133
|
-
fallback,
|
|
134
|
-
instance,
|
|
135
|
-
...resProps
|
|
136
|
-
} = props;
|
|
137
|
-
const rootRef = ref && "current" in ref ? ref : React.useRef(null);
|
|
138
|
-
const renderDom = React.useRef(null);
|
|
139
|
-
const providerInfoRef = React.useRef(null);
|
|
140
|
-
context.LoggerInstance.log(`RemoteAppWrapper instance from props >>>`, instance);
|
|
141
|
-
React.useEffect(() => {
|
|
142
|
-
const renderTimeout = setTimeout(() => {
|
|
143
|
-
var _a, _b, _c, _d, _e, _f;
|
|
144
|
-
const providerReturn = providerInfo();
|
|
145
|
-
providerInfoRef.current = providerReturn;
|
|
146
|
-
let renderProps = {
|
|
147
|
-
moduleName,
|
|
148
|
-
dom: rootRef.current,
|
|
149
|
-
basename,
|
|
150
|
-
memoryRoute,
|
|
151
|
-
fallback,
|
|
152
|
-
...resProps
|
|
153
|
-
};
|
|
154
|
-
renderDom.current = rootRef.current;
|
|
155
|
-
context.LoggerInstance.log(
|
|
156
|
-
`createRemoteComponent LazyComponent render >>>`,
|
|
157
|
-
renderProps
|
|
158
|
-
);
|
|
159
|
-
context.LoggerInstance.log(
|
|
160
|
-
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
161
|
-
instance
|
|
162
|
-
);
|
|
163
|
-
const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(
|
|
164
|
-
renderProps
|
|
165
|
-
)) || {};
|
|
166
|
-
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
167
|
-
providerReturn.render(renderProps);
|
|
168
|
-
(_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
|
|
169
|
-
});
|
|
170
|
-
return () => {
|
|
171
|
-
clearTimeout(renderTimeout);
|
|
172
|
-
setTimeout(() => {
|
|
173
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
174
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
175
|
-
context.LoggerInstance.log(
|
|
176
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
177
|
-
{ moduleName, basename, dom: renderDom.current }
|
|
178
|
-
);
|
|
179
|
-
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
180
|
-
moduleName,
|
|
181
|
-
dom: renderDom.current,
|
|
182
|
-
basename,
|
|
183
|
-
memoryRoute,
|
|
184
|
-
fallback,
|
|
185
|
-
...resProps
|
|
186
|
-
});
|
|
187
|
-
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
188
|
-
moduleName,
|
|
189
|
-
dom: renderDom.current
|
|
190
|
-
});
|
|
191
|
-
(_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
192
|
-
moduleName,
|
|
193
|
-
dom: renderDom.current,
|
|
194
|
-
basename,
|
|
195
|
-
memoryRoute,
|
|
196
|
-
fallback,
|
|
197
|
-
...resProps
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
}, []);
|
|
203
|
-
const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
204
|
-
return /* @__PURE__ */ React.createElement(
|
|
205
|
-
"div",
|
|
206
|
-
{
|
|
207
|
-
className: rootComponentClassName,
|
|
208
|
-
style: props == null ? void 0 : props.style,
|
|
209
|
-
ref: rootRef
|
|
210
|
-
}
|
|
211
|
-
);
|
|
212
|
-
};
|
|
213
|
-
RemoteApp2["__APP_VERSION__"] = "0.7.4";
|
|
214
|
-
return /* @__PURE__ */ React.createElement(RemoteApp2, null);
|
|
215
|
-
});
|
|
216
|
-
function withRouterData(WrappedComponent) {
|
|
217
|
-
const Component = React.forwardRef(function(props, ref) {
|
|
218
|
-
var _a;
|
|
219
|
-
let enableDispathPopstate = false;
|
|
220
|
-
let routerContextVal;
|
|
221
|
-
try {
|
|
222
|
-
ReactRouterDOM__namespace.useLocation();
|
|
223
|
-
enableDispathPopstate = true;
|
|
224
|
-
} catch {
|
|
225
|
-
enableDispathPopstate = false;
|
|
226
|
-
}
|
|
227
|
-
let basename = "/";
|
|
228
|
-
if (!props.basename && enableDispathPopstate) {
|
|
229
|
-
const ReactRouterDOMAny = ReactRouterDOM__namespace;
|
|
230
|
-
const useRouteMatch = ReactRouterDOMAny["useRouteMatch"];
|
|
231
|
-
const useHistory = ReactRouterDOMAny["useHistory"];
|
|
232
|
-
const useHref = ReactRouterDOMAny["useHref"];
|
|
233
|
-
const UNSAFE_RouteContext = ReactRouterDOMAny["UNSAFE_RouteContext"];
|
|
234
|
-
if (UNSAFE_RouteContext) {
|
|
235
|
-
if (useHref) {
|
|
236
|
-
basename = useHref == null ? void 0 : useHref("/");
|
|
237
|
-
}
|
|
238
|
-
routerContextVal = React.useContext(UNSAFE_RouteContext);
|
|
239
|
-
if (routerContextVal && routerContextVal.matches && routerContextVal.matches.length > 0) {
|
|
240
|
-
const matchIndex = routerContextVal.matches.length - 1;
|
|
241
|
-
const pathnameBase = routerContextVal.matches[matchIndex].pathnameBase;
|
|
242
|
-
basename = context.pathJoin(basename, pathnameBase || "/");
|
|
243
|
-
}
|
|
244
|
-
} else {
|
|
245
|
-
const match = useRouteMatch == null ? void 0 : useRouteMatch();
|
|
246
|
-
if (useHistory) {
|
|
247
|
-
const history = useHistory == null ? void 0 : useHistory();
|
|
248
|
-
basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
|
|
249
|
-
}
|
|
250
|
-
if (match) {
|
|
251
|
-
basename = context.pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
context.LoggerInstance.log(`createRemoteComponent withRouterData >>>`, {
|
|
256
|
-
...props,
|
|
257
|
-
basename,
|
|
258
|
-
routerContextVal,
|
|
259
|
-
enableDispathPopstate
|
|
260
|
-
});
|
|
261
|
-
if (enableDispathPopstate) {
|
|
262
|
-
const location = ReactRouterDOM__namespace.useLocation();
|
|
263
|
-
const [pathname, setPathname] = React.useState(location.pathname);
|
|
264
|
-
React.useEffect(() => {
|
|
265
|
-
if (pathname !== "" && pathname !== location.pathname) {
|
|
266
|
-
context.LoggerInstance.log(`createRemoteComponent dispatchPopstateEnv >>>`, {
|
|
267
|
-
name: props.name,
|
|
268
|
-
pathname: location.pathname
|
|
269
|
-
});
|
|
270
|
-
e();
|
|
271
|
-
}
|
|
272
|
-
setPathname(location.pathname);
|
|
273
|
-
}, [location]);
|
|
274
|
-
}
|
|
275
|
-
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename, ref });
|
|
276
|
-
});
|
|
277
|
-
return React.forwardRef(function(props, ref) {
|
|
278
|
-
return /* @__PURE__ */ React.createElement(Component, { ...props, ref });
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
282
|
-
function createLazyRemoteComponent(info) {
|
|
283
|
-
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
284
|
-
return React.lazy(async () => {
|
|
285
|
-
context.LoggerInstance.log(`createRemoteComponent LazyComponent create >>>`, {
|
|
286
|
-
lazyComponent: info.loader,
|
|
287
|
-
exportName
|
|
288
|
-
});
|
|
289
|
-
try {
|
|
290
|
-
const m2 = await info.loader();
|
|
291
|
-
const moduleName = m2 && m2[Symbol.for("mf_module_id")];
|
|
292
|
-
context.LoggerInstance.log(
|
|
293
|
-
`createRemoteComponent LazyComponent loadRemote info >>>`,
|
|
294
|
-
{ name: moduleName, module: m2, exportName }
|
|
295
|
-
);
|
|
296
|
-
const exportFn = m2[exportName];
|
|
297
|
-
if (exportName in m2 && typeof exportFn === "function") {
|
|
298
|
-
const RemoteAppComponent = React.forwardRef((props, ref) => {
|
|
299
|
-
return /* @__PURE__ */ React.createElement(
|
|
300
|
-
RemoteApp,
|
|
301
|
-
{
|
|
302
|
-
moduleName,
|
|
303
|
-
providerInfo: exportFn,
|
|
304
|
-
exportName: info.export || "default",
|
|
305
|
-
fallback: info.fallback,
|
|
306
|
-
ref,
|
|
307
|
-
instance: info.instance,
|
|
308
|
-
...props
|
|
309
|
-
}
|
|
310
|
-
);
|
|
311
|
-
});
|
|
312
|
-
return {
|
|
313
|
-
default: RemoteAppComponent
|
|
314
|
-
};
|
|
315
|
-
} else {
|
|
316
|
-
context.LoggerInstance.log(
|
|
317
|
-
`createRemoteComponent LazyComponent module not found >>>`,
|
|
318
|
-
{ name: moduleName, module: m2, exportName }
|
|
319
|
-
);
|
|
320
|
-
throw Error(
|
|
321
|
-
`Make sure that ${moduleName} has the correct export when export is ${String(
|
|
322
|
-
exportName
|
|
323
|
-
)}`
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
} catch (error) {
|
|
327
|
-
throw error;
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
function createRemoteComponent(info) {
|
|
332
|
-
return React.forwardRef(
|
|
333
|
-
(props, ref) => {
|
|
334
|
-
const LazyComponent = createLazyRemoteComponent(info);
|
|
335
|
-
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref })));
|
|
336
|
-
}
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
var client = {};
|
|
340
|
-
var m = ReactDOM;
|
|
341
|
-
if (process.env.NODE_ENV === "production") {
|
|
342
|
-
client.createRoot = m.createRoot;
|
|
343
|
-
client.hydrateRoot = m.hydrateRoot;
|
|
344
|
-
} else {
|
|
345
|
-
var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
346
|
-
client.createRoot = function(c, o) {
|
|
347
|
-
i.usingClientEntryPoint = true;
|
|
348
|
-
try {
|
|
349
|
-
return m.createRoot(c, o);
|
|
350
|
-
} finally {
|
|
351
|
-
i.usingClientEntryPoint = false;
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
client.hydrateRoot = function(c, h, o) {
|
|
355
|
-
i.usingClientEntryPoint = true;
|
|
356
|
-
try {
|
|
357
|
-
return m.hydrateRoot(c, h, o);
|
|
358
|
-
} finally {
|
|
359
|
-
i.usingClientEntryPoint = false;
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
function createBridgeComponent(bridgeInfo) {
|
|
364
|
-
return () => {
|
|
365
|
-
const rootMap = /* @__PURE__ */ new Map();
|
|
366
|
-
const { instance } = bridgeInfo;
|
|
367
|
-
context.LoggerInstance.log(
|
|
368
|
-
`createBridgeComponent instance from props >>>`,
|
|
369
|
-
instance
|
|
370
|
-
);
|
|
371
|
-
const RawComponent = (info) => {
|
|
372
|
-
const { appInfo, propsInfo, ...restProps } = info;
|
|
373
|
-
const { moduleName, memoryRoute, basename = "/" } = appInfo;
|
|
374
|
-
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(
|
|
375
|
-
bridgeInfo.rootComponent,
|
|
376
|
-
{
|
|
377
|
-
...propsInfo,
|
|
378
|
-
basename,
|
|
379
|
-
...restProps
|
|
380
|
-
}
|
|
381
|
-
));
|
|
382
|
-
};
|
|
383
|
-
return {
|
|
384
|
-
async render(info) {
|
|
385
|
-
var _a, _b, _c, _d, _e, _f;
|
|
386
|
-
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
387
|
-
const {
|
|
388
|
-
moduleName,
|
|
389
|
-
dom,
|
|
390
|
-
basename,
|
|
391
|
-
memoryRoute,
|
|
392
|
-
fallback,
|
|
393
|
-
...propsInfo
|
|
394
|
-
} = info;
|
|
395
|
-
const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(info)) || {};
|
|
396
|
-
const rootComponentWithErrorBoundary = (
|
|
397
|
-
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
|
|
398
|
-
/* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
|
|
399
|
-
RawComponent,
|
|
400
|
-
{
|
|
401
|
-
appInfo: {
|
|
402
|
-
moduleName,
|
|
403
|
-
basename,
|
|
404
|
-
memoryRoute
|
|
405
|
-
},
|
|
406
|
-
propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
|
|
407
|
-
}
|
|
408
|
-
))
|
|
409
|
-
);
|
|
410
|
-
if (context.atLeastReact18(React__namespace)) {
|
|
411
|
-
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
|
|
412
|
-
Promise.resolve(
|
|
413
|
-
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
414
|
-
).then((root) => rootMap.set(info.dom, root));
|
|
415
|
-
} else {
|
|
416
|
-
const root = client.createRoot(info.dom);
|
|
417
|
-
root.render(rootComponentWithErrorBoundary);
|
|
418
|
-
rootMap.set(info.dom, root);
|
|
419
|
-
}
|
|
420
|
-
} else {
|
|
421
|
-
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
422
|
-
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
|
|
423
|
-
}
|
|
424
|
-
((_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(info)) || {};
|
|
425
|
-
},
|
|
426
|
-
async destroy(info) {
|
|
427
|
-
var _a, _b, _c, _d, _e, _f;
|
|
428
|
-
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
429
|
-
dom: info.dom
|
|
430
|
-
});
|
|
431
|
-
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeDestroy) == null ? void 0 : _c.emit(info);
|
|
432
|
-
if (context.atLeastReact18(React__namespace)) {
|
|
433
|
-
const root = rootMap.get(info.dom);
|
|
434
|
-
root == null ? void 0 : root.unmount();
|
|
435
|
-
rootMap.delete(info.dom);
|
|
436
|
-
} else {
|
|
437
|
-
ReactDOM.unmountComponentAtNode(info.dom);
|
|
438
|
-
}
|
|
439
|
-
(_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy) == null ? void 0 : _f.emit(
|
|
440
|
-
info
|
|
441
|
-
);
|
|
442
|
-
},
|
|
443
|
-
rawComponent: bridgeInfo.rootComponent,
|
|
444
|
-
__BRIDGE_FN__: (_args) => {
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
function BridgeReactPlugin() {
|
|
450
|
-
return {
|
|
451
|
-
name: "bridge-react-plugin",
|
|
452
|
-
beforeInit(args) {
|
|
453
|
-
const originalCreateRemoteComponent = createRemoteComponent;
|
|
454
|
-
args.origin.createRemoteComponent = function(info) {
|
|
455
|
-
return originalCreateRemoteComponent({
|
|
456
|
-
...info,
|
|
457
|
-
instance: args.origin
|
|
458
|
-
});
|
|
459
|
-
};
|
|
460
|
-
const originalCreateBridgeComponentt = createBridgeComponent;
|
|
461
|
-
args.origin.createBridgeComponent = function(info) {
|
|
462
|
-
return originalCreateBridgeComponentt({
|
|
463
|
-
...info,
|
|
464
|
-
instance: args.origin
|
|
465
|
-
});
|
|
466
|
-
};
|
|
467
|
-
return args;
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
exports.BridgeReactPlugin = BridgeReactPlugin;
|
|
472
|
-
exports.createBridgeComponent = createBridgeComponent;
|
|
473
|
-
exports.createRemoteComponent = createRemoteComponent;
|