@module-federation/bridge-react 0.0.0-next-20240725035430 → 0.0.0-next-20240725061440
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 -3
- package/dist/index.cjs.js +75 -103
- package/dist/index.d.ts +6 -19
- package/dist/index.es.js +77 -105
- package/package.json +2 -12
- package/src/create.tsx +22 -22
- package/src/provider.tsx +23 -37
- package/src/remote/index.tsx +56 -69
- package/src/router.tsx +0 -2
- package/vite.config.ts +0 -4
- package/dist/router-v5.cjs.js +0 -80
- package/dist/router-v5.d.ts +0 -8
- package/dist/router-v5.es.js +0 -63
- package/dist/router-v6.cjs.js +0 -87
- package/dist/router-v6.d.ts +0 -11
- package/dist/router-v6.es.js +0 -64
- package/src/router-v5.tsx +0 -78
- package/src/router-v6.tsx +0 -76
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240725061440
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- @module-federation/bridge-shared@0.0.0-next-20240725035430
|
|
7
|
+
- @module-federation/bridge-shared@0.0.0-next-20240725061440
|
|
9
8
|
|
|
10
9
|
## 0.3.1
|
|
11
10
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -117,61 +117,55 @@ function hasArrayChanged() {
|
|
|
117
117
|
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
118
118
|
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
119
119
|
}
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
dom: rootRef.current,
|
|
141
|
-
basename,
|
|
142
|
-
memoryRoute,
|
|
143
|
-
...resProps
|
|
144
|
-
};
|
|
145
|
-
renderDom.current = rootRef.current;
|
|
146
|
-
context.LoggerInstance.log(
|
|
147
|
-
`createRemoteComponent LazyComponent render >>>`,
|
|
148
|
-
renderProps
|
|
149
|
-
);
|
|
150
|
-
providerReturn.render(renderProps);
|
|
151
|
-
});
|
|
152
|
-
return () => {
|
|
153
|
-
clearTimeout(renderTimeout);
|
|
154
|
-
setTimeout(() => {
|
|
155
|
-
var _a, _b;
|
|
156
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
157
|
-
context.LoggerInstance.log(
|
|
158
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
159
|
-
{ name, basename, dom: renderDom.current }
|
|
160
|
-
);
|
|
161
|
-
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
162
|
-
dom: renderDom.current
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
});
|
|
120
|
+
const RemoteApp = ({
|
|
121
|
+
name,
|
|
122
|
+
memoryRoute,
|
|
123
|
+
basename,
|
|
124
|
+
providerInfo,
|
|
125
|
+
...resProps
|
|
126
|
+
}) => {
|
|
127
|
+
const rootRef = React.useRef(null);
|
|
128
|
+
const renderDom = React.useRef(null);
|
|
129
|
+
const providerInfoRef = React.useRef(null);
|
|
130
|
+
React.useEffect(() => {
|
|
131
|
+
const renderTimeout = setTimeout(() => {
|
|
132
|
+
const providerReturn = providerInfo();
|
|
133
|
+
providerInfoRef.current = providerReturn;
|
|
134
|
+
const renderProps = {
|
|
135
|
+
name,
|
|
136
|
+
dom: rootRef.current,
|
|
137
|
+
basename,
|
|
138
|
+
memoryRoute,
|
|
139
|
+
...resProps
|
|
166
140
|
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
141
|
+
renderDom.current = rootRef.current;
|
|
142
|
+
context.LoggerInstance.log(
|
|
143
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
144
|
+
renderProps
|
|
145
|
+
);
|
|
146
|
+
providerReturn.render(renderProps);
|
|
147
|
+
});
|
|
148
|
+
return () => {
|
|
149
|
+
clearTimeout(renderTimeout);
|
|
150
|
+
setTimeout(() => {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
153
|
+
context.LoggerInstance.log(
|
|
154
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
155
|
+
{ name, basename, dom: renderDom.current }
|
|
156
|
+
);
|
|
157
|
+
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
158
|
+
dom: renderDom.current
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
}, []);
|
|
164
|
+
return /* @__PURE__ */ React.createElement("div", { ref: rootRef });
|
|
165
|
+
};
|
|
166
|
+
RemoteApp["__APP_VERSION__"] = "0.3.1";
|
|
173
167
|
function withRouterData(WrappedComponent) {
|
|
174
|
-
|
|
168
|
+
return (props) => {
|
|
175
169
|
var _a;
|
|
176
170
|
let enableDispathPopstate = false;
|
|
177
171
|
let routerContextVal;
|
|
@@ -229,13 +223,10 @@ function withRouterData(WrappedComponent) {
|
|
|
229
223
|
setPathname(location.pathname);
|
|
230
224
|
}, [location]);
|
|
231
225
|
}
|
|
232
|
-
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename
|
|
233
|
-
}
|
|
234
|
-
return React.forwardRef(function(props, ref) {
|
|
235
|
-
return /* @__PURE__ */ React.createElement(Component, { ...props, ref });
|
|
236
|
-
});
|
|
226
|
+
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename });
|
|
227
|
+
};
|
|
237
228
|
}
|
|
238
|
-
const RemoteApp = withRouterData(
|
|
229
|
+
const RemoteApp$1 = withRouterData(RemoteApp);
|
|
239
230
|
function createLazyRemoteComponent(info) {
|
|
240
231
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
241
232
|
return React.lazy(async () => {
|
|
@@ -252,14 +243,13 @@ function createLazyRemoteComponent(info) {
|
|
|
252
243
|
);
|
|
253
244
|
const exportFn = m2[exportName];
|
|
254
245
|
if (exportName in m2 && typeof exportFn === "function") {
|
|
255
|
-
const RemoteAppComponent = React.forwardRef((props,
|
|
246
|
+
const RemoteAppComponent = React.forwardRef((props, _ref) => {
|
|
256
247
|
return /* @__PURE__ */ React.createElement(
|
|
257
|
-
RemoteApp,
|
|
248
|
+
RemoteApp$1,
|
|
258
249
|
{
|
|
259
250
|
name: moduleName,
|
|
260
251
|
providerInfo: exportFn,
|
|
261
252
|
exportName: info.export || "default",
|
|
262
|
-
ref,
|
|
263
253
|
...props
|
|
264
254
|
}
|
|
265
255
|
);
|
|
@@ -284,10 +274,10 @@ function createLazyRemoteComponent(info) {
|
|
|
284
274
|
});
|
|
285
275
|
}
|
|
286
276
|
function createRemoteComponent(info) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props
|
|
290
|
-
}
|
|
277
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
278
|
+
return (props) => {
|
|
279
|
+
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props })));
|
|
280
|
+
};
|
|
291
281
|
}
|
|
292
282
|
var client = {};
|
|
293
283
|
var m = ReactDOM;
|
|
@@ -317,50 +307,32 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
317
307
|
return () => {
|
|
318
308
|
const rootMap = /* @__PURE__ */ new Map();
|
|
319
309
|
const RawComponent = (info) => {
|
|
320
|
-
const { appInfo, propsInfo
|
|
310
|
+
const { appInfo, propsInfo } = info;
|
|
321
311
|
const { name, memoryRoute, basename = "/" } = appInfo;
|
|
322
|
-
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename
|
|
312
|
+
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename }));
|
|
323
313
|
};
|
|
324
314
|
return {
|
|
325
|
-
|
|
315
|
+
render(info) {
|
|
326
316
|
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
327
317
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
328
318
|
if (context.atLeastReact18(React__namespace)) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
),
|
|
342
|
-
info.dom
|
|
343
|
-
)).then((root) => rootMap.set(info.dom, root));
|
|
344
|
-
} else {
|
|
345
|
-
const root = client.createRoot(info.dom);
|
|
346
|
-
root.render(
|
|
347
|
-
/* @__PURE__ */ React__namespace.createElement(
|
|
348
|
-
RawComponent,
|
|
349
|
-
{
|
|
350
|
-
propsInfo,
|
|
351
|
-
appInfo: {
|
|
352
|
-
name,
|
|
353
|
-
basename,
|
|
354
|
-
memoryRoute
|
|
355
|
-
}
|
|
319
|
+
const root = client.createRoot(info.dom);
|
|
320
|
+
rootMap.set(info.dom, root);
|
|
321
|
+
root.render(
|
|
322
|
+
/* @__PURE__ */ React__namespace.createElement(
|
|
323
|
+
RawComponent,
|
|
324
|
+
{
|
|
325
|
+
propsInfo,
|
|
326
|
+
appInfo: {
|
|
327
|
+
name,
|
|
328
|
+
basename,
|
|
329
|
+
memoryRoute
|
|
356
330
|
}
|
|
357
|
-
|
|
358
|
-
)
|
|
359
|
-
|
|
360
|
-
}
|
|
331
|
+
}
|
|
332
|
+
)
|
|
333
|
+
);
|
|
361
334
|
} else {
|
|
362
|
-
|
|
363
|
-
renderFunc(
|
|
335
|
+
ReactDOM.render(
|
|
364
336
|
/* @__PURE__ */ React__namespace.createElement(
|
|
365
337
|
RawComponent,
|
|
366
338
|
{
|
|
@@ -376,7 +348,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
376
348
|
);
|
|
377
349
|
}
|
|
378
350
|
},
|
|
379
|
-
|
|
351
|
+
destroy(info) {
|
|
380
352
|
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
381
353
|
dom: info.dom
|
|
382
354
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
|
-
import { CSSProperties } from 'react';
|
|
3
2
|
import { default as default_2 } from 'react';
|
|
4
|
-
import { default as default_3 } from 'react-dom/client';
|
|
5
3
|
import { ErrorInfo } from 'react';
|
|
6
|
-
import { ForwardRefExoticComponent } from 'react';
|
|
7
4
|
import { PropsWithChildren } from 'react';
|
|
8
|
-
import { PropsWithoutRef } from 'react';
|
|
9
5
|
import * as React_2 from 'react';
|
|
10
|
-
import { RefAttributes } from 'react';
|
|
11
6
|
|
|
12
7
|
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
|
|
13
|
-
render(info: RenderFnParams & any):
|
|
8
|
+
render(info: RenderFnParams & any): void;
|
|
14
9
|
destroy(info: {
|
|
15
10
|
dom: HTMLElement;
|
|
16
|
-
}):
|
|
11
|
+
}): void;
|
|
17
12
|
rawComponent: React_2.ComponentType<T>;
|
|
18
13
|
__BRIDGE_FN__: (_args: T) => void;
|
|
19
14
|
};
|
|
@@ -23,7 +18,10 @@ export declare function createRemoteComponent<T, E extends keyof T>(info: {
|
|
|
23
18
|
loading: default_2.ReactNode;
|
|
24
19
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
25
20
|
export?: E;
|
|
26
|
-
}):
|
|
21
|
+
}): (props: {
|
|
22
|
+
basename?: ProviderParams['basename'];
|
|
23
|
+
memoryRoute?: ProviderParams['memoryRoute'];
|
|
24
|
+
} & ("__BRIDGE_FN__" extends keyof (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never) ? (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"] extends (...args: any) => any ? Parameters<(T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"]>[0] : {} : {})) => default_2.JSX.Element;
|
|
27
25
|
|
|
28
26
|
declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {
|
|
29
27
|
fallback?: never;
|
|
@@ -51,7 +49,6 @@ declare type FallbackProps = {
|
|
|
51
49
|
|
|
52
50
|
declare type ProviderFnParams<T> = {
|
|
53
51
|
rootComponent: React_2.ComponentType<T>;
|
|
54
|
-
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
55
52
|
};
|
|
56
53
|
|
|
57
54
|
export declare interface ProviderParams {
|
|
@@ -60,20 +57,10 @@ export declare interface ProviderParams {
|
|
|
60
57
|
memoryRoute?: {
|
|
61
58
|
entryPath: string;
|
|
62
59
|
};
|
|
63
|
-
style?: CSSProperties;
|
|
64
|
-
className?: string | string[];
|
|
65
60
|
}
|
|
66
61
|
|
|
67
|
-
declare type RemoteProps = {
|
|
68
|
-
basename?: ProviderParams['basename'];
|
|
69
|
-
memoryRoute?: ProviderParams['memoryRoute'];
|
|
70
|
-
[key: string]: any;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
62
|
export declare interface RenderFnParams extends ProviderParams {
|
|
74
63
|
dom: HTMLElement;
|
|
75
64
|
}
|
|
76
65
|
|
|
77
|
-
declare type RootType = HTMLElement | default_3.Root;
|
|
78
|
-
|
|
79
66
|
export { }
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import React__default, { createContext, Component, createElement, isValidElement,
|
|
3
|
-
import {
|
|
2
|
+
import React__default, { createContext, Component, createElement, isValidElement, useContext, useState, useEffect, useRef, forwardRef } from "react";
|
|
3
|
+
import { p as pathJoin, L as LoggerInstance, f, a as atLeastReact18, R as RouterContext } from "./context-Bw2PEwa6.js";
|
|
4
4
|
import * as ReactRouterDOM from "react-router-dom";
|
|
5
5
|
import ReactDOM from "react-dom";
|
|
6
6
|
const ErrorBoundaryContext = createContext(null);
|
|
@@ -98,61 +98,55 @@ function hasArrayChanged() {
|
|
|
98
98
|
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
99
99
|
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
100
100
|
}
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
dom: rootRef.current,
|
|
122
|
-
basename,
|
|
123
|
-
memoryRoute,
|
|
124
|
-
...resProps
|
|
125
|
-
};
|
|
126
|
-
renderDom.current = rootRef.current;
|
|
127
|
-
LoggerInstance.log(
|
|
128
|
-
`createRemoteComponent LazyComponent render >>>`,
|
|
129
|
-
renderProps
|
|
130
|
-
);
|
|
131
|
-
providerReturn.render(renderProps);
|
|
132
|
-
});
|
|
133
|
-
return () => {
|
|
134
|
-
clearTimeout(renderTimeout);
|
|
135
|
-
setTimeout(() => {
|
|
136
|
-
var _a, _b;
|
|
137
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
138
|
-
LoggerInstance.log(
|
|
139
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
140
|
-
{ name, basename, dom: renderDom.current }
|
|
141
|
-
);
|
|
142
|
-
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
143
|
-
dom: renderDom.current
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
});
|
|
101
|
+
const RemoteApp = ({
|
|
102
|
+
name,
|
|
103
|
+
memoryRoute,
|
|
104
|
+
basename,
|
|
105
|
+
providerInfo,
|
|
106
|
+
...resProps
|
|
107
|
+
}) => {
|
|
108
|
+
const rootRef = useRef(null);
|
|
109
|
+
const renderDom = useRef(null);
|
|
110
|
+
const providerInfoRef = useRef(null);
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
const renderTimeout = setTimeout(() => {
|
|
113
|
+
const providerReturn = providerInfo();
|
|
114
|
+
providerInfoRef.current = providerReturn;
|
|
115
|
+
const renderProps = {
|
|
116
|
+
name,
|
|
117
|
+
dom: rootRef.current,
|
|
118
|
+
basename,
|
|
119
|
+
memoryRoute,
|
|
120
|
+
...resProps
|
|
147
121
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
122
|
+
renderDom.current = rootRef.current;
|
|
123
|
+
LoggerInstance.log(
|
|
124
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
125
|
+
renderProps
|
|
126
|
+
);
|
|
127
|
+
providerReturn.render(renderProps);
|
|
128
|
+
});
|
|
129
|
+
return () => {
|
|
130
|
+
clearTimeout(renderTimeout);
|
|
131
|
+
setTimeout(() => {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
134
|
+
LoggerInstance.log(
|
|
135
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
136
|
+
{ name, basename, dom: renderDom.current }
|
|
137
|
+
);
|
|
138
|
+
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
139
|
+
dom: renderDom.current
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
}, []);
|
|
145
|
+
return /* @__PURE__ */ React__default.createElement("div", { ref: rootRef });
|
|
146
|
+
};
|
|
147
|
+
RemoteApp["__APP_VERSION__"] = "0.3.1";
|
|
154
148
|
function withRouterData(WrappedComponent) {
|
|
155
|
-
|
|
149
|
+
return (props) => {
|
|
156
150
|
var _a;
|
|
157
151
|
let enableDispathPopstate = false;
|
|
158
152
|
let routerContextVal;
|
|
@@ -210,13 +204,10 @@ function withRouterData(WrappedComponent) {
|
|
|
210
204
|
setPathname(location.pathname);
|
|
211
205
|
}, [location]);
|
|
212
206
|
}
|
|
213
|
-
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename
|
|
214
|
-
}
|
|
215
|
-
return forwardRef(function(props, ref) {
|
|
216
|
-
return /* @__PURE__ */ React__default.createElement(Component2, { ...props, ref });
|
|
217
|
-
});
|
|
207
|
+
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename });
|
|
208
|
+
};
|
|
218
209
|
}
|
|
219
|
-
const RemoteApp = withRouterData(
|
|
210
|
+
const RemoteApp$1 = withRouterData(RemoteApp);
|
|
220
211
|
function createLazyRemoteComponent(info) {
|
|
221
212
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
222
213
|
return React__default.lazy(async () => {
|
|
@@ -233,14 +224,13 @@ function createLazyRemoteComponent(info) {
|
|
|
233
224
|
);
|
|
234
225
|
const exportFn = m2[exportName];
|
|
235
226
|
if (exportName in m2 && typeof exportFn === "function") {
|
|
236
|
-
const RemoteAppComponent = forwardRef((props,
|
|
227
|
+
const RemoteAppComponent = forwardRef((props, _ref) => {
|
|
237
228
|
return /* @__PURE__ */ React__default.createElement(
|
|
238
|
-
RemoteApp,
|
|
229
|
+
RemoteApp$1,
|
|
239
230
|
{
|
|
240
231
|
name: moduleName,
|
|
241
232
|
providerInfo: exportFn,
|
|
242
233
|
exportName: info.export || "default",
|
|
243
|
-
ref,
|
|
244
234
|
...props
|
|
245
235
|
}
|
|
246
236
|
);
|
|
@@ -265,10 +255,10 @@ function createLazyRemoteComponent(info) {
|
|
|
265
255
|
});
|
|
266
256
|
}
|
|
267
257
|
function createRemoteComponent(info) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return /* @__PURE__ */ React__default.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props
|
|
271
|
-
}
|
|
258
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
259
|
+
return (props) => {
|
|
260
|
+
return /* @__PURE__ */ React__default.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props })));
|
|
261
|
+
};
|
|
272
262
|
}
|
|
273
263
|
var client = {};
|
|
274
264
|
var m = ReactDOM;
|
|
@@ -298,50 +288,32 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
298
288
|
return () => {
|
|
299
289
|
const rootMap = /* @__PURE__ */ new Map();
|
|
300
290
|
const RawComponent = (info) => {
|
|
301
|
-
const { appInfo, propsInfo
|
|
291
|
+
const { appInfo, propsInfo } = info;
|
|
302
292
|
const { name, memoryRoute, basename = "/" } = appInfo;
|
|
303
|
-
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename
|
|
293
|
+
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename }));
|
|
304
294
|
};
|
|
305
295
|
return {
|
|
306
|
-
|
|
296
|
+
render(info) {
|
|
307
297
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
308
298
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
309
299
|
if (atLeastReact18(React)) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
),
|
|
323
|
-
info.dom
|
|
324
|
-
)).then((root) => rootMap.set(info.dom, root));
|
|
325
|
-
} else {
|
|
326
|
-
const root = client.createRoot(info.dom);
|
|
327
|
-
root.render(
|
|
328
|
-
/* @__PURE__ */ React.createElement(
|
|
329
|
-
RawComponent,
|
|
330
|
-
{
|
|
331
|
-
propsInfo,
|
|
332
|
-
appInfo: {
|
|
333
|
-
name,
|
|
334
|
-
basename,
|
|
335
|
-
memoryRoute
|
|
336
|
-
}
|
|
300
|
+
const root = client.createRoot(info.dom);
|
|
301
|
+
rootMap.set(info.dom, root);
|
|
302
|
+
root.render(
|
|
303
|
+
/* @__PURE__ */ React.createElement(
|
|
304
|
+
RawComponent,
|
|
305
|
+
{
|
|
306
|
+
propsInfo,
|
|
307
|
+
appInfo: {
|
|
308
|
+
name,
|
|
309
|
+
basename,
|
|
310
|
+
memoryRoute
|
|
337
311
|
}
|
|
338
|
-
|
|
339
|
-
)
|
|
340
|
-
|
|
341
|
-
}
|
|
312
|
+
}
|
|
313
|
+
)
|
|
314
|
+
);
|
|
342
315
|
} else {
|
|
343
|
-
|
|
344
|
-
renderFunc(
|
|
316
|
+
ReactDOM.render(
|
|
345
317
|
/* @__PURE__ */ React.createElement(
|
|
346
318
|
RawComponent,
|
|
347
319
|
{
|
|
@@ -357,7 +329,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
357
329
|
);
|
|
358
330
|
}
|
|
359
331
|
},
|
|
360
|
-
|
|
332
|
+
destroy(info) {
|
|
361
333
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
362
334
|
dom: info.dom
|
|
363
335
|
});
|
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-20240725061440",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,22 +20,12 @@
|
|
|
20
20
|
"import": "./dist/router.es.js",
|
|
21
21
|
"require": "./dist/router.cjs.js"
|
|
22
22
|
},
|
|
23
|
-
"./router-v5": {
|
|
24
|
-
"types": "./dist/router-v5.d.ts",
|
|
25
|
-
"import": "./dist/router-v5.es.js",
|
|
26
|
-
"require": "./dist/router-v5.cjs.js"
|
|
27
|
-
},
|
|
28
|
-
"./router-v6": {
|
|
29
|
-
"types": "./dist/router-v6.d.ts",
|
|
30
|
-
"import": "./dist/router-v6.es.js",
|
|
31
|
-
"require": "./dist/router-v6.cjs.js"
|
|
32
|
-
},
|
|
33
23
|
"./*": "./*"
|
|
34
24
|
},
|
|
35
25
|
"dependencies": {
|
|
36
26
|
"@loadable/component": "^5.16.4",
|
|
37
27
|
"react-error-boundary": "^4.0.13",
|
|
38
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
28
|
+
"@module-federation/bridge-shared": "0.0.0-next-20240725061440"
|
|
39
29
|
},
|
|
40
30
|
"peerDependencies": {
|
|
41
31
|
"react": ">=16.9.0",
|
package/src/create.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import type { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes } from 'react';
|
|
3
2
|
import type { ProviderParams } from '@module-federation/bridge-shared';
|
|
4
3
|
import { LoggerInstance } from './utils';
|
|
5
4
|
import {
|
|
@@ -7,9 +6,11 @@ import {
|
|
|
7
6
|
ErrorBoundaryPropsWithComponent,
|
|
8
7
|
} from 'react-error-boundary';
|
|
9
8
|
import RemoteApp from './remote';
|
|
9
|
+
|
|
10
10
|
export interface RenderFnParams extends ProviderParams {
|
|
11
11
|
dom?: any;
|
|
12
12
|
}
|
|
13
|
+
|
|
13
14
|
interface RemoteModule {
|
|
14
15
|
provider: () => {
|
|
15
16
|
render: (
|
|
@@ -52,13 +53,12 @@ function createLazyRemoteComponent<T, E extends keyof T>(info: {
|
|
|
52
53
|
basename?: ProviderParams['basename'];
|
|
53
54
|
memoryRoute?: ProviderParams['memoryRoute'];
|
|
54
55
|
}
|
|
55
|
-
>((props,
|
|
56
|
+
>((props, _ref) => {
|
|
56
57
|
return (
|
|
57
58
|
<RemoteApp
|
|
58
59
|
name={moduleName}
|
|
59
60
|
providerInfo={exportFn}
|
|
60
61
|
exportName={info.export || 'default'}
|
|
61
|
-
ref={ref}
|
|
62
62
|
{...props}
|
|
63
63
|
/>
|
|
64
64
|
);
|
|
@@ -84,35 +84,35 @@ function createLazyRemoteComponent<T, E extends keyof T>(info: {
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
type RemoteProps = {
|
|
88
|
-
basename?: ProviderParams['basename'];
|
|
89
|
-
memoryRoute?: ProviderParams['memoryRoute'];
|
|
90
|
-
[key: string]: any;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
87
|
export function createRemoteComponent<T, E extends keyof T>(info: {
|
|
94
88
|
loader: () => Promise<T>;
|
|
95
89
|
loading: React.ReactNode;
|
|
96
90
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
97
91
|
export?: E;
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
92
|
+
}) {
|
|
93
|
+
type ExportType = T[E] extends (...args: any) => any
|
|
94
|
+
? ReturnType<T[E]>
|
|
95
|
+
: never;
|
|
96
|
+
type RawComponentType = '__BRIDGE_FN__' extends keyof ExportType
|
|
97
|
+
? ExportType['__BRIDGE_FN__'] extends (...args: any) => any
|
|
98
|
+
? Parameters<ExportType['__BRIDGE_FN__']>[0]
|
|
99
|
+
: {}
|
|
100
|
+
: {};
|
|
107
101
|
|
|
108
|
-
|
|
109
|
-
|
|
102
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
props: {
|
|
106
|
+
basename?: ProviderParams['basename'];
|
|
107
|
+
memoryRoute?: ProviderParams['memoryRoute'];
|
|
108
|
+
} & RawComponentType,
|
|
109
|
+
) => {
|
|
110
110
|
return (
|
|
111
111
|
<ErrorBoundary FallbackComponent={info.fallback}>
|
|
112
112
|
<React.Suspense fallback={info.loading}>
|
|
113
|
-
<LazyComponent {...props}
|
|
113
|
+
<LazyComponent {...props} />
|
|
114
114
|
</React.Suspense>
|
|
115
115
|
</ErrorBoundary>
|
|
116
116
|
);
|
|
117
|
-
}
|
|
117
|
+
};
|
|
118
118
|
}
|