@module-federation/bridge-react 0.0.0-next-20240726084328 → 0.0.0-next-20240731082143
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 +14 -2
- package/dist/index.cjs.js +74 -111
- package/dist/index.d.ts +7 -15
- package/dist/index.es.js +76 -113
- package/package.json +2 -12
- package/src/create.tsx +24 -19
- package/src/provider.tsx +23 -37
- package/src/remote/index.tsx +55 -78
- 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,10 +1,22 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240731082143
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- @module-federation/bridge-shared@0.0.0-next-
|
|
7
|
+
- @module-federation/bridge-shared@0.0.0-next-20240731082143
|
|
8
|
+
|
|
9
|
+
## 0.3.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- @module-federation/bridge-shared@0.3.3
|
|
14
|
+
|
|
15
|
+
## 0.3.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- @module-federation/bridge-shared@0.3.2
|
|
8
20
|
|
|
9
21
|
## 0.3.1
|
|
10
22
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -117,70 +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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
|
140
|
+
};
|
|
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
|
+
});
|
|
145
160
|
}
|
|
146
|
-
const renderProps = {
|
|
147
|
-
name,
|
|
148
|
-
// dom: rootRef.current,
|
|
149
|
-
dom: domElement,
|
|
150
|
-
basename,
|
|
151
|
-
memoryRoute,
|
|
152
|
-
...resProps
|
|
153
|
-
};
|
|
154
|
-
renderDom.current = rootRef.current;
|
|
155
|
-
context.LoggerInstance.log(
|
|
156
|
-
`createRemoteComponent LazyComponent render >>>`,
|
|
157
|
-
renderProps
|
|
158
|
-
);
|
|
159
|
-
providerReturn.render(renderProps);
|
|
160
161
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
context.LoggerInstance.log(
|
|
167
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
168
|
-
{ name, basename, dom: renderDom.current }
|
|
169
|
-
);
|
|
170
|
-
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
171
|
-
dom: renderDom.current
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
};
|
|
176
|
-
}, []);
|
|
177
|
-
return dom ? null : /* @__PURE__ */ React.createElement("div", { className: props == null ? void 0 : props.className, style: props == null ? void 0 : props.style, ref: rootRef });
|
|
178
|
-
};
|
|
179
|
-
RemoteApp2["__APP_VERSION__"] = "0.3.1";
|
|
180
|
-
return /* @__PURE__ */ React.createElement(RemoteApp2, null);
|
|
181
|
-
});
|
|
162
|
+
};
|
|
163
|
+
}, []);
|
|
164
|
+
return /* @__PURE__ */ React.createElement("div", { ref: rootRef });
|
|
165
|
+
};
|
|
166
|
+
RemoteApp["__APP_VERSION__"] = "0.3.3";
|
|
182
167
|
function withRouterData(WrappedComponent) {
|
|
183
|
-
|
|
168
|
+
return (props) => {
|
|
184
169
|
var _a;
|
|
185
170
|
let enableDispathPopstate = false;
|
|
186
171
|
let routerContextVal;
|
|
@@ -238,13 +223,10 @@ function withRouterData(WrappedComponent) {
|
|
|
238
223
|
setPathname(location.pathname);
|
|
239
224
|
}, [location]);
|
|
240
225
|
}
|
|
241
|
-
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename
|
|
242
|
-
}
|
|
243
|
-
return React.forwardRef(function(props, ref) {
|
|
244
|
-
return /* @__PURE__ */ React.createElement(Component, { ...props, ref });
|
|
245
|
-
});
|
|
226
|
+
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename });
|
|
227
|
+
};
|
|
246
228
|
}
|
|
247
|
-
const RemoteApp = withRouterData(
|
|
229
|
+
const RemoteApp$1 = withRouterData(RemoteApp);
|
|
248
230
|
function createLazyRemoteComponent(info) {
|
|
249
231
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
250
232
|
return React.lazy(async () => {
|
|
@@ -261,14 +243,13 @@ function createLazyRemoteComponent(info) {
|
|
|
261
243
|
);
|
|
262
244
|
const exportFn = m2[exportName];
|
|
263
245
|
if (exportName in m2 && typeof exportFn === "function") {
|
|
264
|
-
const RemoteAppComponent = React.forwardRef((props,
|
|
246
|
+
const RemoteAppComponent = React.forwardRef((props, _ref) => {
|
|
265
247
|
return /* @__PURE__ */ React.createElement(
|
|
266
|
-
RemoteApp,
|
|
248
|
+
RemoteApp$1,
|
|
267
249
|
{
|
|
268
250
|
name: moduleName,
|
|
269
251
|
providerInfo: exportFn,
|
|
270
252
|
exportName: info.export || "default",
|
|
271
|
-
ref,
|
|
272
253
|
...props
|
|
273
254
|
}
|
|
274
255
|
);
|
|
@@ -293,10 +274,10 @@ function createLazyRemoteComponent(info) {
|
|
|
293
274
|
});
|
|
294
275
|
}
|
|
295
276
|
function createRemoteComponent(info) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props
|
|
299
|
-
}
|
|
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
|
+
};
|
|
300
281
|
}
|
|
301
282
|
var client = {};
|
|
302
283
|
var m = ReactDOM;
|
|
@@ -326,50 +307,32 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
326
307
|
return () => {
|
|
327
308
|
const rootMap = /* @__PURE__ */ new Map();
|
|
328
309
|
const RawComponent = (info) => {
|
|
329
|
-
const { appInfo, propsInfo
|
|
310
|
+
const { appInfo, propsInfo } = info;
|
|
330
311
|
const { name, memoryRoute, basename = "/" } = appInfo;
|
|
331
|
-
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 }));
|
|
332
313
|
};
|
|
333
314
|
return {
|
|
334
|
-
|
|
315
|
+
render(info) {
|
|
335
316
|
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
336
317
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
337
318
|
if (context.atLeastReact18(React__namespace)) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
),
|
|
351
|
-
info.dom
|
|
352
|
-
)).then((root) => rootMap.set(info.dom, root));
|
|
353
|
-
} else {
|
|
354
|
-
const root = client.createRoot(info.dom);
|
|
355
|
-
root.render(
|
|
356
|
-
/* @__PURE__ */ React__namespace.createElement(
|
|
357
|
-
RawComponent,
|
|
358
|
-
{
|
|
359
|
-
propsInfo,
|
|
360
|
-
appInfo: {
|
|
361
|
-
name,
|
|
362
|
-
basename,
|
|
363
|
-
memoryRoute
|
|
364
|
-
}
|
|
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
|
|
365
330
|
}
|
|
366
|
-
|
|
367
|
-
)
|
|
368
|
-
|
|
369
|
-
}
|
|
331
|
+
}
|
|
332
|
+
)
|
|
333
|
+
);
|
|
370
334
|
} else {
|
|
371
|
-
|
|
372
|
-
renderFunc(
|
|
335
|
+
ReactDOM.render(
|
|
373
336
|
/* @__PURE__ */ React__namespace.createElement(
|
|
374
337
|
RawComponent,
|
|
375
338
|
{
|
|
@@ -385,7 +348,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
385
348
|
);
|
|
386
349
|
}
|
|
387
350
|
},
|
|
388
|
-
|
|
351
|
+
destroy(info) {
|
|
389
352
|
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
390
353
|
dom: info.dom
|
|
391
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,8 +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
|
-
|
|
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,24 +49,18 @@ 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
|
-
export declare interface ProviderParams
|
|
54
|
+
export declare interface ProviderParams {
|
|
58
55
|
name?: string;
|
|
59
56
|
basename?: string;
|
|
60
57
|
memoryRoute?: {
|
|
61
58
|
entryPath: string;
|
|
62
59
|
};
|
|
63
|
-
props?: {
|
|
64
|
-
[key: string]: any;
|
|
65
|
-
};
|
|
66
60
|
}
|
|
67
61
|
|
|
68
62
|
export declare interface RenderFnParams extends ProviderParams {
|
|
69
63
|
dom: HTMLElement;
|
|
70
64
|
}
|
|
71
65
|
|
|
72
|
-
declare type RootType = HTMLElement | default_3.Root;
|
|
73
|
-
|
|
74
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,70 +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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
121
|
+
};
|
|
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
|
+
});
|
|
126
141
|
}
|
|
127
|
-
const renderProps = {
|
|
128
|
-
name,
|
|
129
|
-
// dom: rootRef.current,
|
|
130
|
-
dom: domElement,
|
|
131
|
-
basename,
|
|
132
|
-
memoryRoute,
|
|
133
|
-
...resProps
|
|
134
|
-
};
|
|
135
|
-
renderDom.current = rootRef.current;
|
|
136
|
-
LoggerInstance.log(
|
|
137
|
-
`createRemoteComponent LazyComponent render >>>`,
|
|
138
|
-
renderProps
|
|
139
|
-
);
|
|
140
|
-
providerReturn.render(renderProps);
|
|
141
142
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
LoggerInstance.log(
|
|
148
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
149
|
-
{ name, basename, dom: renderDom.current }
|
|
150
|
-
);
|
|
151
|
-
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
152
|
-
dom: renderDom.current
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
}, []);
|
|
158
|
-
return dom ? null : /* @__PURE__ */ React__default.createElement("div", { className: props == null ? void 0 : props.className, style: props == null ? void 0 : props.style, ref: rootRef });
|
|
159
|
-
};
|
|
160
|
-
RemoteApp2["__APP_VERSION__"] = "0.3.1";
|
|
161
|
-
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
|
|
162
|
-
});
|
|
143
|
+
};
|
|
144
|
+
}, []);
|
|
145
|
+
return /* @__PURE__ */ React__default.createElement("div", { ref: rootRef });
|
|
146
|
+
};
|
|
147
|
+
RemoteApp["__APP_VERSION__"] = "0.3.3";
|
|
163
148
|
function withRouterData(WrappedComponent) {
|
|
164
|
-
|
|
149
|
+
return (props) => {
|
|
165
150
|
var _a;
|
|
166
151
|
let enableDispathPopstate = false;
|
|
167
152
|
let routerContextVal;
|
|
@@ -219,13 +204,10 @@ function withRouterData(WrappedComponent) {
|
|
|
219
204
|
setPathname(location.pathname);
|
|
220
205
|
}, [location]);
|
|
221
206
|
}
|
|
222
|
-
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename
|
|
223
|
-
}
|
|
224
|
-
return forwardRef(function(props, ref) {
|
|
225
|
-
return /* @__PURE__ */ React__default.createElement(Component2, { ...props, ref });
|
|
226
|
-
});
|
|
207
|
+
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename });
|
|
208
|
+
};
|
|
227
209
|
}
|
|
228
|
-
const RemoteApp = withRouterData(
|
|
210
|
+
const RemoteApp$1 = withRouterData(RemoteApp);
|
|
229
211
|
function createLazyRemoteComponent(info) {
|
|
230
212
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
231
213
|
return React__default.lazy(async () => {
|
|
@@ -242,14 +224,13 @@ function createLazyRemoteComponent(info) {
|
|
|
242
224
|
);
|
|
243
225
|
const exportFn = m2[exportName];
|
|
244
226
|
if (exportName in m2 && typeof exportFn === "function") {
|
|
245
|
-
const RemoteAppComponent = forwardRef((props,
|
|
227
|
+
const RemoteAppComponent = forwardRef((props, _ref) => {
|
|
246
228
|
return /* @__PURE__ */ React__default.createElement(
|
|
247
|
-
RemoteApp,
|
|
229
|
+
RemoteApp$1,
|
|
248
230
|
{
|
|
249
231
|
name: moduleName,
|
|
250
232
|
providerInfo: exportFn,
|
|
251
233
|
exportName: info.export || "default",
|
|
252
|
-
ref,
|
|
253
234
|
...props
|
|
254
235
|
}
|
|
255
236
|
);
|
|
@@ -274,10 +255,10 @@ function createLazyRemoteComponent(info) {
|
|
|
274
255
|
});
|
|
275
256
|
}
|
|
276
257
|
function createRemoteComponent(info) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
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
|
|
280
|
-
}
|
|
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
|
+
};
|
|
281
262
|
}
|
|
282
263
|
var client = {};
|
|
283
264
|
var m = ReactDOM;
|
|
@@ -307,50 +288,32 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
307
288
|
return () => {
|
|
308
289
|
const rootMap = /* @__PURE__ */ new Map();
|
|
309
290
|
const RawComponent = (info) => {
|
|
310
|
-
const { appInfo, propsInfo
|
|
291
|
+
const { appInfo, propsInfo } = info;
|
|
311
292
|
const { name, memoryRoute, basename = "/" } = appInfo;
|
|
312
|
-
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 }));
|
|
313
294
|
};
|
|
314
295
|
return {
|
|
315
|
-
|
|
296
|
+
render(info) {
|
|
316
297
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
317
298
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
318
299
|
if (atLeastReact18(React)) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
),
|
|
332
|
-
info.dom
|
|
333
|
-
)).then((root) => rootMap.set(info.dom, root));
|
|
334
|
-
} else {
|
|
335
|
-
const root = client.createRoot(info.dom);
|
|
336
|
-
root.render(
|
|
337
|
-
/* @__PURE__ */ React.createElement(
|
|
338
|
-
RawComponent,
|
|
339
|
-
{
|
|
340
|
-
propsInfo,
|
|
341
|
-
appInfo: {
|
|
342
|
-
name,
|
|
343
|
-
basename,
|
|
344
|
-
memoryRoute
|
|
345
|
-
}
|
|
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
|
|
346
311
|
}
|
|
347
|
-
|
|
348
|
-
)
|
|
349
|
-
|
|
350
|
-
}
|
|
312
|
+
}
|
|
313
|
+
)
|
|
314
|
+
);
|
|
351
315
|
} else {
|
|
352
|
-
|
|
353
|
-
renderFunc(
|
|
316
|
+
ReactDOM.render(
|
|
354
317
|
/* @__PURE__ */ React.createElement(
|
|
355
318
|
RawComponent,
|
|
356
319
|
{
|
|
@@ -366,7 +329,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
366
329
|
);
|
|
367
330
|
}
|
|
368
331
|
},
|
|
369
|
-
|
|
332
|
+
destroy(info) {
|
|
370
333
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
371
334
|
dom: info.dom
|
|
372
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-20240731082143",
|
|
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-20240731082143"
|
|
39
29
|
},
|
|
40
30
|
"peerDependencies": {
|
|
41
31
|
"react": ">=16.9.0",
|