@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/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20241118100312
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
- @module-federation/bridge-shared@0.0.0-next-20241118092546
|
|
7
|
+
- @module-federation/runtime@0.0.0-next-20241118100312
|
|
8
|
+
- @module-federation/sdk@0.0.0-next-20241118100312
|
|
9
|
+
- @module-federation/bridge-shared@0.0.0-next-20241118100312
|
|
11
10
|
|
|
12
11
|
## 0.7.4
|
|
13
12
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,448 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const context = require("./context-BcJ-YlNr.cjs");
|
|
5
|
+
const ReactRouterDOM = require("react-router-dom");
|
|
6
|
+
const runtime = require("@module-federation/runtime");
|
|
7
|
+
const ReactDOM = require("react-dom");
|
|
8
|
+
function _interopNamespaceDefault(e2) {
|
|
9
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
+
if (e2) {
|
|
11
|
+
for (const k in e2) {
|
|
12
|
+
if (k !== "default") {
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e2, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: () => e2[k]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e2;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
25
|
+
const ReactRouterDOM__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDOM);
|
|
26
|
+
const ErrorBoundaryContext = React.createContext(null);
|
|
27
|
+
const initialState = {
|
|
28
|
+
didCatch: false,
|
|
29
|
+
error: null
|
|
30
|
+
};
|
|
31
|
+
class ErrorBoundary extends React.Component {
|
|
32
|
+
constructor(props) {
|
|
33
|
+
super(props);
|
|
34
|
+
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
35
|
+
this.state = initialState;
|
|
36
|
+
}
|
|
37
|
+
static getDerivedStateFromError(error) {
|
|
38
|
+
return {
|
|
39
|
+
didCatch: true,
|
|
40
|
+
error
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
resetErrorBoundary() {
|
|
44
|
+
const {
|
|
45
|
+
error
|
|
46
|
+
} = this.state;
|
|
47
|
+
if (error !== null) {
|
|
48
|
+
var _this$props$onReset, _this$props;
|
|
49
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
50
|
+
args[_key] = arguments[_key];
|
|
51
|
+
}
|
|
52
|
+
(_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
|
|
53
|
+
args,
|
|
54
|
+
reason: "imperative-api"
|
|
55
|
+
});
|
|
56
|
+
this.setState(initialState);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
componentDidCatch(error, info) {
|
|
60
|
+
var _this$props$onError, _this$props2;
|
|
61
|
+
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
62
|
+
}
|
|
63
|
+
componentDidUpdate(prevProps, prevState) {
|
|
64
|
+
const {
|
|
65
|
+
didCatch
|
|
66
|
+
} = this.state;
|
|
67
|
+
const {
|
|
68
|
+
resetKeys
|
|
69
|
+
} = this.props;
|
|
70
|
+
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
71
|
+
var _this$props$onReset2, _this$props3;
|
|
72
|
+
(_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
|
|
73
|
+
next: resetKeys,
|
|
74
|
+
prev: prevProps.resetKeys,
|
|
75
|
+
reason: "keys"
|
|
76
|
+
});
|
|
77
|
+
this.setState(initialState);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
render() {
|
|
81
|
+
const {
|
|
82
|
+
children,
|
|
83
|
+
fallbackRender,
|
|
84
|
+
FallbackComponent,
|
|
85
|
+
fallback
|
|
86
|
+
} = this.props;
|
|
87
|
+
const {
|
|
88
|
+
didCatch,
|
|
89
|
+
error
|
|
90
|
+
} = this.state;
|
|
91
|
+
let childToRender = children;
|
|
92
|
+
if (didCatch) {
|
|
93
|
+
const props = {
|
|
94
|
+
error,
|
|
95
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
96
|
+
};
|
|
97
|
+
if (typeof fallbackRender === "function") {
|
|
98
|
+
childToRender = fallbackRender(props);
|
|
99
|
+
} else if (FallbackComponent) {
|
|
100
|
+
childToRender = React.createElement(FallbackComponent, props);
|
|
101
|
+
} else if (fallback === null || React.isValidElement(fallback)) {
|
|
102
|
+
childToRender = fallback;
|
|
103
|
+
} else {
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return React.createElement(ErrorBoundaryContext.Provider, {
|
|
108
|
+
value: {
|
|
109
|
+
didCatch,
|
|
110
|
+
error,
|
|
111
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
112
|
+
}
|
|
113
|
+
}, childToRender);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function hasArrayChanged() {
|
|
117
|
+
let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
118
|
+
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
119
|
+
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
120
|
+
}
|
|
121
|
+
function e() {
|
|
122
|
+
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
123
|
+
window.dispatchEvent(t);
|
|
124
|
+
}
|
|
125
|
+
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
126
|
+
const RemoteApp2 = () => {
|
|
127
|
+
context.LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
128
|
+
const {
|
|
129
|
+
moduleName,
|
|
130
|
+
memoryRoute,
|
|
131
|
+
basename,
|
|
132
|
+
providerInfo,
|
|
133
|
+
className,
|
|
134
|
+
style,
|
|
135
|
+
fallback,
|
|
136
|
+
...resProps
|
|
137
|
+
} = props;
|
|
138
|
+
const rootRef = ref && "current" in ref ? ref : React.useRef(null);
|
|
139
|
+
const renderDom = React.useRef(null);
|
|
140
|
+
const providerInfoRef = React.useRef(null);
|
|
141
|
+
const hostInstance = runtime.getInstance();
|
|
142
|
+
context.LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
|
|
143
|
+
React.useEffect(() => {
|
|
144
|
+
const renderTimeout = setTimeout(() => {
|
|
145
|
+
var _a, _b, _c, _d, _e, _f;
|
|
146
|
+
const providerReturn = providerInfo();
|
|
147
|
+
providerInfoRef.current = providerReturn;
|
|
148
|
+
let renderProps = {
|
|
149
|
+
moduleName,
|
|
150
|
+
dom: rootRef.current,
|
|
151
|
+
basename,
|
|
152
|
+
memoryRoute,
|
|
153
|
+
fallback,
|
|
154
|
+
...resProps
|
|
155
|
+
};
|
|
156
|
+
renderDom.current = rootRef.current;
|
|
157
|
+
context.LoggerInstance.log(
|
|
158
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
159
|
+
renderProps
|
|
160
|
+
);
|
|
161
|
+
context.LoggerInstance.log(
|
|
162
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
163
|
+
hostInstance
|
|
164
|
+
);
|
|
165
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(
|
|
166
|
+
renderProps
|
|
167
|
+
)) || {};
|
|
168
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
169
|
+
providerReturn.render(renderProps);
|
|
170
|
+
(_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
|
|
171
|
+
renderProps
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
return () => {
|
|
175
|
+
clearTimeout(renderTimeout);
|
|
176
|
+
setTimeout(() => {
|
|
177
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
178
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
179
|
+
context.LoggerInstance.log(
|
|
180
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
181
|
+
{ moduleName, basename, dom: renderDom.current }
|
|
182
|
+
);
|
|
183
|
+
(_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
184
|
+
moduleName,
|
|
185
|
+
dom: renderDom.current,
|
|
186
|
+
basename,
|
|
187
|
+
memoryRoute,
|
|
188
|
+
fallback,
|
|
189
|
+
...resProps
|
|
190
|
+
});
|
|
191
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
192
|
+
moduleName,
|
|
193
|
+
dom: renderDom.current
|
|
194
|
+
});
|
|
195
|
+
(_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
196
|
+
moduleName,
|
|
197
|
+
dom: renderDom.current,
|
|
198
|
+
basename,
|
|
199
|
+
memoryRoute,
|
|
200
|
+
fallback,
|
|
201
|
+
...resProps
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
}, []);
|
|
207
|
+
const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
208
|
+
return /* @__PURE__ */ React.createElement(
|
|
209
|
+
"div",
|
|
210
|
+
{
|
|
211
|
+
className: rootComponentClassName,
|
|
212
|
+
style: props == null ? void 0 : props.style,
|
|
213
|
+
ref: rootRef
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
RemoteApp2["__APP_VERSION__"] = "0.7.4";
|
|
218
|
+
return /* @__PURE__ */ React.createElement(RemoteApp2, null);
|
|
219
|
+
});
|
|
220
|
+
function withRouterData(WrappedComponent) {
|
|
221
|
+
const Component = React.forwardRef(function(props, ref) {
|
|
222
|
+
var _a;
|
|
223
|
+
let enableDispathPopstate = false;
|
|
224
|
+
let routerContextVal;
|
|
225
|
+
try {
|
|
226
|
+
ReactRouterDOM__namespace.useLocation();
|
|
227
|
+
enableDispathPopstate = true;
|
|
228
|
+
} catch {
|
|
229
|
+
enableDispathPopstate = false;
|
|
230
|
+
}
|
|
231
|
+
let basename = "/";
|
|
232
|
+
if (!props.basename && enableDispathPopstate) {
|
|
233
|
+
const ReactRouterDOMAny = ReactRouterDOM__namespace;
|
|
234
|
+
const useRouteMatch = ReactRouterDOMAny["useRouteMatch"];
|
|
235
|
+
const useHistory = ReactRouterDOMAny["useHistory"];
|
|
236
|
+
const useHref = ReactRouterDOMAny["useHref"];
|
|
237
|
+
const UNSAFE_RouteContext = ReactRouterDOMAny["UNSAFE_RouteContext"];
|
|
238
|
+
if (UNSAFE_RouteContext) {
|
|
239
|
+
if (useHref) {
|
|
240
|
+
basename = useHref == null ? void 0 : useHref("/");
|
|
241
|
+
}
|
|
242
|
+
routerContextVal = React.useContext(UNSAFE_RouteContext);
|
|
243
|
+
if (routerContextVal && routerContextVal.matches && routerContextVal.matches.length > 0) {
|
|
244
|
+
const matchIndex = routerContextVal.matches.length - 1;
|
|
245
|
+
const pathnameBase = routerContextVal.matches[matchIndex].pathnameBase;
|
|
246
|
+
basename = context.pathJoin(basename, pathnameBase || "/");
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
const match = useRouteMatch == null ? void 0 : useRouteMatch();
|
|
250
|
+
if (useHistory) {
|
|
251
|
+
const history = useHistory == null ? void 0 : useHistory();
|
|
252
|
+
basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
|
|
253
|
+
}
|
|
254
|
+
if (match) {
|
|
255
|
+
basename = context.pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
context.LoggerInstance.log(`createRemoteComponent withRouterData >>>`, {
|
|
260
|
+
...props,
|
|
261
|
+
basename,
|
|
262
|
+
routerContextVal,
|
|
263
|
+
enableDispathPopstate
|
|
264
|
+
});
|
|
265
|
+
if (enableDispathPopstate) {
|
|
266
|
+
const location = ReactRouterDOM__namespace.useLocation();
|
|
267
|
+
const [pathname, setPathname] = React.useState(location.pathname);
|
|
268
|
+
React.useEffect(() => {
|
|
269
|
+
if (pathname !== "" && pathname !== location.pathname) {
|
|
270
|
+
context.LoggerInstance.log(`createRemoteComponent dispatchPopstateEnv >>>`, {
|
|
271
|
+
name: props.name,
|
|
272
|
+
pathname: location.pathname
|
|
273
|
+
});
|
|
274
|
+
e();
|
|
275
|
+
}
|
|
276
|
+
setPathname(location.pathname);
|
|
277
|
+
}, [location]);
|
|
278
|
+
}
|
|
279
|
+
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename, ref });
|
|
280
|
+
});
|
|
281
|
+
return React.forwardRef(function(props, ref) {
|
|
282
|
+
return /* @__PURE__ */ React.createElement(Component, { ...props, ref });
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
286
|
+
function createLazyRemoteComponent(info) {
|
|
287
|
+
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
288
|
+
return React.lazy(async () => {
|
|
289
|
+
context.LoggerInstance.log(`createRemoteComponent LazyComponent create >>>`, {
|
|
290
|
+
lazyComponent: info.loader,
|
|
291
|
+
exportName
|
|
292
|
+
});
|
|
293
|
+
try {
|
|
294
|
+
const m2 = await info.loader();
|
|
295
|
+
const moduleName = m2 && m2[Symbol.for("mf_module_id")];
|
|
296
|
+
context.LoggerInstance.log(
|
|
297
|
+
`createRemoteComponent LazyComponent loadRemote info >>>`,
|
|
298
|
+
{ name: moduleName, module: m2, exportName }
|
|
299
|
+
);
|
|
300
|
+
const exportFn = m2[exportName];
|
|
301
|
+
if (exportName in m2 && typeof exportFn === "function") {
|
|
302
|
+
const RemoteAppComponent = React.forwardRef((props, ref) => {
|
|
303
|
+
return /* @__PURE__ */ React.createElement(
|
|
304
|
+
RemoteApp,
|
|
305
|
+
{
|
|
306
|
+
moduleName,
|
|
307
|
+
providerInfo: exportFn,
|
|
308
|
+
exportName: info.export || "default",
|
|
309
|
+
fallback: info.fallback,
|
|
310
|
+
ref,
|
|
311
|
+
...props
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
});
|
|
315
|
+
return {
|
|
316
|
+
default: RemoteAppComponent
|
|
317
|
+
};
|
|
318
|
+
} else {
|
|
319
|
+
context.LoggerInstance.log(
|
|
320
|
+
`createRemoteComponent LazyComponent module not found >>>`,
|
|
321
|
+
{ name: moduleName, module: m2, exportName }
|
|
322
|
+
);
|
|
323
|
+
throw Error(
|
|
324
|
+
`Make sure that ${moduleName} has the correct export when export is ${String(
|
|
325
|
+
exportName
|
|
326
|
+
)}`
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
} catch (error) {
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
function createRemoteComponent(info) {
|
|
335
|
+
return React.forwardRef(
|
|
336
|
+
(props, ref) => {
|
|
337
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
338
|
+
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref })));
|
|
339
|
+
}
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
var client = {};
|
|
343
|
+
var m = ReactDOM;
|
|
344
|
+
if (process.env.NODE_ENV === "production") {
|
|
345
|
+
client.createRoot = m.createRoot;
|
|
346
|
+
client.hydrateRoot = m.hydrateRoot;
|
|
347
|
+
} else {
|
|
348
|
+
var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
349
|
+
client.createRoot = function(c, o) {
|
|
350
|
+
i.usingClientEntryPoint = true;
|
|
351
|
+
try {
|
|
352
|
+
return m.createRoot(c, o);
|
|
353
|
+
} finally {
|
|
354
|
+
i.usingClientEntryPoint = false;
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
client.hydrateRoot = function(c, h, o) {
|
|
358
|
+
i.usingClientEntryPoint = true;
|
|
359
|
+
try {
|
|
360
|
+
return m.hydrateRoot(c, h, o);
|
|
361
|
+
} finally {
|
|
362
|
+
i.usingClientEntryPoint = false;
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function createBridgeComponent(bridgeInfo) {
|
|
367
|
+
return () => {
|
|
368
|
+
const rootMap = /* @__PURE__ */ new Map();
|
|
369
|
+
const instance = runtime.getInstance();
|
|
370
|
+
context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
|
|
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(info);
|
|
440
|
+
},
|
|
441
|
+
rawComponent: bridgeInfo.rootComponent,
|
|
442
|
+
__BRIDGE_FN__: (_args) => {
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
exports.createBridgeComponent = createBridgeComponent;
|
|
448
|
+
exports.createRemoteComponent = createRemoteComponent;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,9 @@ import { ComponentType } from 'react';
|
|
|
2
2
|
import { default as default_2 } from 'react';
|
|
3
3
|
import { default as default_3 } from 'react-dom/client';
|
|
4
4
|
import { ErrorInfo } from 'react';
|
|
5
|
-
import { FederationHost } from '@module-federation/runtime';
|
|
6
|
-
import { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
7
5
|
import { PropsWithChildren } from 'react';
|
|
8
6
|
import * as React_2 from 'react';
|
|
9
7
|
|
|
10
|
-
export declare function BridgeReactPlugin(): FederationRuntimePlugin;
|
|
11
|
-
|
|
12
8
|
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
|
|
13
9
|
render(info: RenderParams): Promise<void>;
|
|
14
10
|
destroy(info: DestroyParams): Promise<void>;
|
|
@@ -16,7 +12,12 @@ export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>
|
|
|
16
12
|
__BRIDGE_FN__: (_args: T) => void;
|
|
17
13
|
};
|
|
18
14
|
|
|
19
|
-
export declare function createRemoteComponent<T, E extends keyof T>(info:
|
|
15
|
+
export declare function createRemoteComponent<T, E extends keyof T>(info: {
|
|
16
|
+
loader: () => Promise<T>;
|
|
17
|
+
loading: default_2.ReactNode;
|
|
18
|
+
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
19
|
+
export?: E;
|
|
20
|
+
}): default_2.ForwardRefExoticComponent<default_2.PropsWithoutRef<ProviderParams & ("__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.RefAttributes<HTMLDivElement>>;
|
|
20
21
|
|
|
21
22
|
declare type DestroyParams = {
|
|
22
23
|
moduleName: string;
|
|
@@ -47,18 +48,9 @@ declare type FallbackProps = {
|
|
|
47
48
|
resetErrorBoundary: (...args: any[]) => void;
|
|
48
49
|
};
|
|
49
50
|
|
|
50
|
-
declare type LazyRemoteComponentInfo<T, E extends keyof T> = {
|
|
51
|
-
loader: () => Promise<T>;
|
|
52
|
-
loading: default_2.ReactNode;
|
|
53
|
-
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
54
|
-
export?: E;
|
|
55
|
-
instance?: FederationHost;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
51
|
declare type ProviderFnParams<T> = {
|
|
59
52
|
rootComponent: React_2.ComponentType<T>;
|
|
60
53
|
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
61
|
-
instance?: FederationHost;
|
|
62
54
|
};
|
|
63
55
|
|
|
64
56
|
export declare interface ProviderParams {
|