@module-federation/bridge-react 0.0.0-next-20240723095610 → 0.0.0-next-20240724103050
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 +26 -3
- package/dist/index.cjs.js +75 -101
- package/dist/index.d.ts +6 -16
- package/dist/index.es.js +77 -103
- package/package.json +2 -12
- package/src/create.tsx +22 -22
- package/src/provider.tsx +23 -37
- package/src/remote/index.tsx +56 -67
- 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,34 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240724103050
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
7
|
+
- @module-federation/bridge-shared@0.0.0-next-20240724103050
|
|
8
|
+
|
|
9
|
+
## 0.3.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- @module-federation/bridge-shared@0.3.1
|
|
14
|
+
|
|
15
|
+
## 0.3.0
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- @module-federation/bridge-shared@0.3.0
|
|
20
|
+
|
|
21
|
+
## 0.2.8
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- @module-federation/bridge-shared@0.2.8
|
|
26
|
+
|
|
27
|
+
## 0.2.7
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- @module-federation/bridge-shared@0.2.7
|
|
9
32
|
|
|
10
33
|
## 0.2.6
|
|
11
34
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -117,59 +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
|
-
memoryRoute,
|
|
141
|
-
...resProps
|
|
142
|
-
};
|
|
143
|
-
renderDom.current = rootRef.current;
|
|
144
|
-
context.LoggerInstance.log(
|
|
145
|
-
`createRemoteComponent LazyComponent render >>>`,
|
|
146
|
-
renderProps
|
|
147
|
-
);
|
|
148
|
-
providerReturn.render(renderProps);
|
|
149
|
-
});
|
|
150
|
-
return () => {
|
|
151
|
-
clearTimeout(renderTimeout);
|
|
152
|
-
setTimeout(() => {
|
|
153
|
-
var _a, _b;
|
|
154
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
155
|
-
context.LoggerInstance.log(
|
|
156
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
157
|
-
{ name, basename, dom: renderDom.current }
|
|
158
|
-
);
|
|
159
|
-
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
160
|
-
dom: renderDom.current
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
});
|
|
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
|
|
164
140
|
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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";
|
|
171
167
|
function withRouterData(WrappedComponent) {
|
|
172
|
-
|
|
168
|
+
return (props) => {
|
|
173
169
|
var _a;
|
|
174
170
|
let enableDispathPopstate = false;
|
|
175
171
|
let routerContextVal;
|
|
@@ -227,13 +223,10 @@ function withRouterData(WrappedComponent) {
|
|
|
227
223
|
setPathname(location.pathname);
|
|
228
224
|
}, [location]);
|
|
229
225
|
}
|
|
230
|
-
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename
|
|
231
|
-
}
|
|
232
|
-
return React.forwardRef(function(props, ref) {
|
|
233
|
-
return /* @__PURE__ */ React.createElement(Component, { ...props, ref });
|
|
234
|
-
});
|
|
226
|
+
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename });
|
|
227
|
+
};
|
|
235
228
|
}
|
|
236
|
-
const RemoteApp = withRouterData(
|
|
229
|
+
const RemoteApp$1 = withRouterData(RemoteApp);
|
|
237
230
|
function createLazyRemoteComponent(info) {
|
|
238
231
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
239
232
|
return React.lazy(async () => {
|
|
@@ -250,14 +243,13 @@ function createLazyRemoteComponent(info) {
|
|
|
250
243
|
);
|
|
251
244
|
const exportFn = m2[exportName];
|
|
252
245
|
if (exportName in m2 && typeof exportFn === "function") {
|
|
253
|
-
const RemoteAppComponent = React.forwardRef((props,
|
|
246
|
+
const RemoteAppComponent = React.forwardRef((props, _ref) => {
|
|
254
247
|
return /* @__PURE__ */ React.createElement(
|
|
255
|
-
RemoteApp,
|
|
248
|
+
RemoteApp$1,
|
|
256
249
|
{
|
|
257
250
|
name: moduleName,
|
|
258
251
|
providerInfo: exportFn,
|
|
259
252
|
exportName: info.export || "default",
|
|
260
|
-
ref,
|
|
261
253
|
...props
|
|
262
254
|
}
|
|
263
255
|
);
|
|
@@ -282,10 +274,10 @@ function createLazyRemoteComponent(info) {
|
|
|
282
274
|
});
|
|
283
275
|
}
|
|
284
276
|
function createRemoteComponent(info) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props
|
|
288
|
-
}
|
|
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
|
+
};
|
|
289
281
|
}
|
|
290
282
|
var client = {};
|
|
291
283
|
var m = ReactDOM;
|
|
@@ -315,50 +307,32 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
315
307
|
return () => {
|
|
316
308
|
const rootMap = /* @__PURE__ */ new Map();
|
|
317
309
|
const RawComponent = (info) => {
|
|
318
|
-
const { appInfo, propsInfo
|
|
310
|
+
const { appInfo, propsInfo } = info;
|
|
319
311
|
const { name, memoryRoute, basename = "/" } = appInfo;
|
|
320
|
-
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 }));
|
|
321
313
|
};
|
|
322
314
|
return {
|
|
323
|
-
|
|
315
|
+
render(info) {
|
|
324
316
|
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
325
317
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
326
318
|
if (context.atLeastReact18(React__namespace)) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
),
|
|
340
|
-
info.dom
|
|
341
|
-
)).then((root) => rootMap.set(info.dom, root));
|
|
342
|
-
} else {
|
|
343
|
-
const root = client.createRoot(info.dom);
|
|
344
|
-
root.render(
|
|
345
|
-
/* @__PURE__ */ React__namespace.createElement(
|
|
346
|
-
RawComponent,
|
|
347
|
-
{
|
|
348
|
-
propsInfo,
|
|
349
|
-
appInfo: {
|
|
350
|
-
name,
|
|
351
|
-
basename,
|
|
352
|
-
memoryRoute
|
|
353
|
-
}
|
|
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
|
|
354
330
|
}
|
|
355
|
-
|
|
356
|
-
)
|
|
357
|
-
|
|
358
|
-
}
|
|
331
|
+
}
|
|
332
|
+
)
|
|
333
|
+
);
|
|
359
334
|
} else {
|
|
360
|
-
|
|
361
|
-
renderFunc(
|
|
335
|
+
ReactDOM.render(
|
|
362
336
|
/* @__PURE__ */ React__namespace.createElement(
|
|
363
337
|
RawComponent,
|
|
364
338
|
{
|
|
@@ -374,7 +348,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
374
348
|
);
|
|
375
349
|
}
|
|
376
350
|
},
|
|
377
|
-
|
|
351
|
+
destroy(info) {
|
|
378
352
|
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
379
353
|
dom: info.dom
|
|
380
354
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
import { default as default_2 } from 'react';
|
|
3
|
-
import { default as default_3 } from 'react-dom/client';
|
|
4
3
|
import { ErrorInfo } from 'react';
|
|
5
|
-
import { ForwardRefExoticComponent } from 'react';
|
|
6
4
|
import { PropsWithChildren } from 'react';
|
|
7
|
-
import { PropsWithoutRef } from 'react';
|
|
8
5
|
import * as React_2 from 'react';
|
|
9
|
-
import { RefAttributes } from 'react';
|
|
10
6
|
|
|
11
7
|
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
|
|
12
|
-
render(info: RenderFnParams & any):
|
|
8
|
+
render(info: RenderFnParams & any): void;
|
|
13
9
|
destroy(info: {
|
|
14
10
|
dom: HTMLElement;
|
|
15
|
-
}):
|
|
11
|
+
}): void;
|
|
16
12
|
rawComponent: React_2.ComponentType<T>;
|
|
17
13
|
__BRIDGE_FN__: (_args: T) => void;
|
|
18
14
|
};
|
|
@@ -22,7 +18,10 @@ export declare function createRemoteComponent<T, E extends keyof T>(info: {
|
|
|
22
18
|
loading: default_2.ReactNode;
|
|
23
19
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
24
20
|
export?: E;
|
|
25
|
-
}):
|
|
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;
|
|
26
25
|
|
|
27
26
|
declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {
|
|
28
27
|
fallback?: never;
|
|
@@ -50,7 +49,6 @@ declare type FallbackProps = {
|
|
|
50
49
|
|
|
51
50
|
declare type ProviderFnParams<T> = {
|
|
52
51
|
rootComponent: React_2.ComponentType<T>;
|
|
53
|
-
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
54
52
|
};
|
|
55
53
|
|
|
56
54
|
export declare interface ProviderParams {
|
|
@@ -61,16 +59,8 @@ export declare interface ProviderParams {
|
|
|
61
59
|
};
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
declare type RemoteProps = {
|
|
65
|
-
basename?: ProviderParams['basename'];
|
|
66
|
-
memoryRoute?: ProviderParams['memoryRoute'];
|
|
67
|
-
[key: string]: any;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
62
|
export declare interface RenderFnParams extends ProviderParams {
|
|
71
63
|
dom: HTMLElement;
|
|
72
64
|
}
|
|
73
65
|
|
|
74
|
-
declare type RootType = HTMLElement | default_3.Root;
|
|
75
|
-
|
|
76
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,59 +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
|
-
memoryRoute,
|
|
122
|
-
...resProps
|
|
123
|
-
};
|
|
124
|
-
renderDom.current = rootRef.current;
|
|
125
|
-
LoggerInstance.log(
|
|
126
|
-
`createRemoteComponent LazyComponent render >>>`,
|
|
127
|
-
renderProps
|
|
128
|
-
);
|
|
129
|
-
providerReturn.render(renderProps);
|
|
130
|
-
});
|
|
131
|
-
return () => {
|
|
132
|
-
clearTimeout(renderTimeout);
|
|
133
|
-
setTimeout(() => {
|
|
134
|
-
var _a, _b;
|
|
135
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
136
|
-
LoggerInstance.log(
|
|
137
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
138
|
-
{ name, basename, dom: renderDom.current }
|
|
139
|
-
);
|
|
140
|
-
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
141
|
-
dom: renderDom.current
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
});
|
|
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
|
|
145
121
|
};
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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";
|
|
152
148
|
function withRouterData(WrappedComponent) {
|
|
153
|
-
|
|
149
|
+
return (props) => {
|
|
154
150
|
var _a;
|
|
155
151
|
let enableDispathPopstate = false;
|
|
156
152
|
let routerContextVal;
|
|
@@ -208,13 +204,10 @@ function withRouterData(WrappedComponent) {
|
|
|
208
204
|
setPathname(location.pathname);
|
|
209
205
|
}, [location]);
|
|
210
206
|
}
|
|
211
|
-
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename
|
|
212
|
-
}
|
|
213
|
-
return forwardRef(function(props, ref) {
|
|
214
|
-
return /* @__PURE__ */ React__default.createElement(Component2, { ...props, ref });
|
|
215
|
-
});
|
|
207
|
+
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename });
|
|
208
|
+
};
|
|
216
209
|
}
|
|
217
|
-
const RemoteApp = withRouterData(
|
|
210
|
+
const RemoteApp$1 = withRouterData(RemoteApp);
|
|
218
211
|
function createLazyRemoteComponent(info) {
|
|
219
212
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
220
213
|
return React__default.lazy(async () => {
|
|
@@ -231,14 +224,13 @@ function createLazyRemoteComponent(info) {
|
|
|
231
224
|
);
|
|
232
225
|
const exportFn = m2[exportName];
|
|
233
226
|
if (exportName in m2 && typeof exportFn === "function") {
|
|
234
|
-
const RemoteAppComponent = forwardRef((props,
|
|
227
|
+
const RemoteAppComponent = forwardRef((props, _ref) => {
|
|
235
228
|
return /* @__PURE__ */ React__default.createElement(
|
|
236
|
-
RemoteApp,
|
|
229
|
+
RemoteApp$1,
|
|
237
230
|
{
|
|
238
231
|
name: moduleName,
|
|
239
232
|
providerInfo: exportFn,
|
|
240
233
|
exportName: info.export || "default",
|
|
241
|
-
ref,
|
|
242
234
|
...props
|
|
243
235
|
}
|
|
244
236
|
);
|
|
@@ -263,10 +255,10 @@ function createLazyRemoteComponent(info) {
|
|
|
263
255
|
});
|
|
264
256
|
}
|
|
265
257
|
function createRemoteComponent(info) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
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
|
|
269
|
-
}
|
|
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
|
+
};
|
|
270
262
|
}
|
|
271
263
|
var client = {};
|
|
272
264
|
var m = ReactDOM;
|
|
@@ -296,50 +288,32 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
296
288
|
return () => {
|
|
297
289
|
const rootMap = /* @__PURE__ */ new Map();
|
|
298
290
|
const RawComponent = (info) => {
|
|
299
|
-
const { appInfo, propsInfo
|
|
291
|
+
const { appInfo, propsInfo } = info;
|
|
300
292
|
const { name, memoryRoute, basename = "/" } = appInfo;
|
|
301
|
-
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 }));
|
|
302
294
|
};
|
|
303
295
|
return {
|
|
304
|
-
|
|
296
|
+
render(info) {
|
|
305
297
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
306
298
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
307
299
|
if (atLeastReact18(React)) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
),
|
|
321
|
-
info.dom
|
|
322
|
-
)).then((root) => rootMap.set(info.dom, root));
|
|
323
|
-
} else {
|
|
324
|
-
const root = client.createRoot(info.dom);
|
|
325
|
-
root.render(
|
|
326
|
-
/* @__PURE__ */ React.createElement(
|
|
327
|
-
RawComponent,
|
|
328
|
-
{
|
|
329
|
-
propsInfo,
|
|
330
|
-
appInfo: {
|
|
331
|
-
name,
|
|
332
|
-
basename,
|
|
333
|
-
memoryRoute
|
|
334
|
-
}
|
|
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
|
|
335
311
|
}
|
|
336
|
-
|
|
337
|
-
)
|
|
338
|
-
|
|
339
|
-
}
|
|
312
|
+
}
|
|
313
|
+
)
|
|
314
|
+
);
|
|
340
315
|
} else {
|
|
341
|
-
|
|
342
|
-
renderFunc(
|
|
316
|
+
ReactDOM.render(
|
|
343
317
|
/* @__PURE__ */ React.createElement(
|
|
344
318
|
RawComponent,
|
|
345
319
|
{
|
|
@@ -355,7 +329,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
355
329
|
);
|
|
356
330
|
}
|
|
357
331
|
},
|
|
358
|
-
|
|
332
|
+
destroy(info) {
|
|
359
333
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
360
334
|
dom: info.dom
|
|
361
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-20240724103050",
|
|
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-20240724103050"
|
|
39
29
|
},
|
|
40
30
|
"peerDependencies": {
|
|
41
31
|
"react": ">=16.9.0",
|