@module-federation/bridge-react 0.0.0-next-20250410121036 → 0.0.0-next-20250411200445
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 -8
- package/dist/index.cjs.js +136 -64
- package/dist/index.d.ts +1 -24
- package/dist/index.es.js +139 -67
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.es.js +1 -1
- package/package.json +4 -19
- package/src/index.ts +0 -6
- package/src/provider/compat.ts +60 -0
- package/src/provider/create.tsx +20 -73
- package/src/remote/create.tsx +2 -4
- package/src/types.ts +0 -19
- package/src/utils/index.ts +20 -0
- package/vite.config.ts +0 -54
- package/dist/internal/bridge-base-CW88-1Be.es.js +0 -103
- package/dist/internal/bridge-base-DBiwuddQ.cjs.js +0 -119
- package/dist/internal/react-error-boundary.esm-CMdlkNPP.es.js +0 -99
- package/dist/internal/react-error-boundary.esm-D8nxmvmv.cjs.js +0 -98
- package/dist/legacy.cjs.js +0 -4
- package/dist/legacy.d.ts +0 -104
- package/dist/legacy.es.js +0 -4
- package/dist/v16.cjs.js +0 -22
- package/dist/v16.d.ts +0 -104
- package/dist/v16.es.js +0 -22
- package/dist/v18.cjs.js +0 -15
- package/dist/v18.d.ts +0 -105
- package/dist/v18.es.js +0 -15
- package/dist/v19.cjs.js +0 -15
- package/dist/v19.d.ts +0 -106
- package/dist/v19.es.js +0 -15
- package/src/legacy.ts +0 -13
- package/src/provider/versions/bridge-base.tsx +0 -122
- package/src/provider/versions/legacy.ts +0 -42
- package/src/provider/versions/v18.ts +0 -47
- package/src/provider/versions/v19.ts +0 -48
- package/src/v18.ts +0 -9
- package/src/v19.ts +0 -9
- /package/dist/{internal/context.cjs.js → context-C79iMWYD.cjs} +0 -0
- /package/dist/{internal/context.es.js → context-Dbqf0szX.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- d802e00: feat(react-bridge): Add native support for React 19 in bridge-react with enhanced createRoot options
|
|
3
|
+
## 0.0.0-next-20250411200445
|
|
8
4
|
|
|
9
5
|
### Patch Changes
|
|
10
6
|
|
|
11
|
-
-
|
|
7
|
+
- Updated dependencies [6ce82d3]
|
|
12
8
|
- Updated dependencies [f4fb242]
|
|
13
|
-
- @module-federation/sdk@0.0.0-next-
|
|
14
|
-
- @module-federation/bridge-shared@0.0.0-next-
|
|
9
|
+
- @module-federation/sdk@0.0.0-next-20250411200445
|
|
10
|
+
- @module-federation/bridge-shared@0.0.0-next-20250411200445
|
|
15
11
|
|
|
16
12
|
## 0.11.4
|
|
17
13
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
4
|
const React = require("react");
|
|
4
|
-
const
|
|
5
|
-
const context = require("./internal/context.cjs.js");
|
|
5
|
+
const context = require("./context-C79iMWYD.cjs");
|
|
6
6
|
const ReactRouterDOM = require("react-router-dom");
|
|
7
7
|
const plugin = require("./plugin.cjs.js");
|
|
8
8
|
const ReactDOM = require("react-dom");
|
|
@@ -24,6 +24,101 @@ function _interopNamespaceDefault(e2) {
|
|
|
24
24
|
}
|
|
25
25
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
26
26
|
const ReactRouterDOM__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDOM);
|
|
27
|
+
const ErrorBoundaryContext = React.createContext(null);
|
|
28
|
+
const initialState = {
|
|
29
|
+
didCatch: false,
|
|
30
|
+
error: null
|
|
31
|
+
};
|
|
32
|
+
class ErrorBoundary extends React.Component {
|
|
33
|
+
constructor(props) {
|
|
34
|
+
super(props);
|
|
35
|
+
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
36
|
+
this.state = initialState;
|
|
37
|
+
}
|
|
38
|
+
static getDerivedStateFromError(error) {
|
|
39
|
+
return {
|
|
40
|
+
didCatch: true,
|
|
41
|
+
error
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
resetErrorBoundary() {
|
|
45
|
+
const {
|
|
46
|
+
error
|
|
47
|
+
} = this.state;
|
|
48
|
+
if (error !== null) {
|
|
49
|
+
var _this$props$onReset, _this$props;
|
|
50
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
51
|
+
args[_key] = arguments[_key];
|
|
52
|
+
}
|
|
53
|
+
(_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
|
|
54
|
+
args,
|
|
55
|
+
reason: "imperative-api"
|
|
56
|
+
});
|
|
57
|
+
this.setState(initialState);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
componentDidCatch(error, info) {
|
|
61
|
+
var _this$props$onError, _this$props2;
|
|
62
|
+
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
63
|
+
}
|
|
64
|
+
componentDidUpdate(prevProps, prevState) {
|
|
65
|
+
const {
|
|
66
|
+
didCatch
|
|
67
|
+
} = this.state;
|
|
68
|
+
const {
|
|
69
|
+
resetKeys
|
|
70
|
+
} = this.props;
|
|
71
|
+
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
72
|
+
var _this$props$onReset2, _this$props3;
|
|
73
|
+
(_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
|
|
74
|
+
next: resetKeys,
|
|
75
|
+
prev: prevProps.resetKeys,
|
|
76
|
+
reason: "keys"
|
|
77
|
+
});
|
|
78
|
+
this.setState(initialState);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
render() {
|
|
82
|
+
const {
|
|
83
|
+
children,
|
|
84
|
+
fallbackRender,
|
|
85
|
+
FallbackComponent,
|
|
86
|
+
fallback
|
|
87
|
+
} = this.props;
|
|
88
|
+
const {
|
|
89
|
+
didCatch,
|
|
90
|
+
error
|
|
91
|
+
} = this.state;
|
|
92
|
+
let childToRender = children;
|
|
93
|
+
if (didCatch) {
|
|
94
|
+
const props = {
|
|
95
|
+
error,
|
|
96
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
97
|
+
};
|
|
98
|
+
if (typeof fallbackRender === "function") {
|
|
99
|
+
childToRender = fallbackRender(props);
|
|
100
|
+
} else if (FallbackComponent) {
|
|
101
|
+
childToRender = React.createElement(FallbackComponent, props);
|
|
102
|
+
} else if (fallback !== void 0) {
|
|
103
|
+
childToRender = fallback;
|
|
104
|
+
} else {
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return React.createElement(ErrorBoundaryContext.Provider, {
|
|
109
|
+
value: {
|
|
110
|
+
didCatch,
|
|
111
|
+
error,
|
|
112
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
113
|
+
}
|
|
114
|
+
}, childToRender);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function hasArrayChanged() {
|
|
118
|
+
let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
119
|
+
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
120
|
+
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
121
|
+
}
|
|
27
122
|
function e() {
|
|
28
123
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
29
124
|
window.dispatchEvent(t);
|
|
@@ -51,8 +146,8 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
51
146
|
providerInfoRef.current = providerReturn;
|
|
52
147
|
setInitialized(true);
|
|
53
148
|
return () => {
|
|
54
|
-
var
|
|
55
|
-
if ((
|
|
149
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
150
|
+
if ((_a2 = providerInfoRef.current) == null ? void 0 : _a2.destroy) {
|
|
56
151
|
context.LoggerInstance.debug(
|
|
57
152
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
58
153
|
{ moduleName, basename, dom: renderDom.current }
|
|
@@ -81,7 +176,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
81
176
|
};
|
|
82
177
|
}, [moduleName]);
|
|
83
178
|
React.useEffect(() => {
|
|
84
|
-
var
|
|
179
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
85
180
|
if (!initialized || !providerInfoRef.current) return;
|
|
86
181
|
let renderProps = {
|
|
87
182
|
moduleName,
|
|
@@ -92,7 +187,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
92
187
|
...resProps
|
|
93
188
|
};
|
|
94
189
|
renderDom.current = rootRef.current;
|
|
95
|
-
const beforeBridgeRenderRes = ((_c = (_b = (
|
|
190
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
|
|
96
191
|
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
97
192
|
providerInfoRef.current.render(renderProps);
|
|
98
193
|
(_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
|
|
@@ -102,7 +197,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
102
197
|
});
|
|
103
198
|
function withRouterData(WrappedComponent) {
|
|
104
199
|
const Component = React.forwardRef(function(props, ref) {
|
|
105
|
-
var
|
|
200
|
+
var _a2;
|
|
106
201
|
if (props == null ? void 0 : props.basename) {
|
|
107
202
|
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename: props.basename, ref });
|
|
108
203
|
}
|
|
@@ -135,7 +230,7 @@ function withRouterData(WrappedComponent) {
|
|
|
135
230
|
const match = useRouteMatch == null ? void 0 : useRouteMatch();
|
|
136
231
|
if (useHistory) {
|
|
137
232
|
const history = useHistory == null ? void 0 : useHistory();
|
|
138
|
-
basename = (
|
|
233
|
+
basename = (_a2 = history == null ? void 0 : history.createHref) == null ? void 0 : _a2.call(history, { pathname: "/" });
|
|
139
234
|
}
|
|
140
235
|
if (match) {
|
|
141
236
|
basename = context.pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
@@ -223,27 +318,13 @@ function createLazyRemoteComponent(info) {
|
|
|
223
318
|
function createRemoteComponent(info) {
|
|
224
319
|
const LazyComponent = createLazyRemoteComponent(info);
|
|
225
320
|
return React.forwardRef((props, ref) => {
|
|
226
|
-
return /* @__PURE__ */ React.createElement(
|
|
227
|
-
reactErrorBoundary_esm.ErrorBoundary,
|
|
228
|
-
{
|
|
229
|
-
FallbackComponent: info.fallback
|
|
230
|
-
},
|
|
231
|
-
/* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref }))
|
|
232
|
-
);
|
|
321
|
+
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref })));
|
|
233
322
|
});
|
|
234
323
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const isReact18 = reactVersion.startsWith("18");
|
|
324
|
+
const isReact18 = (_a = ReactDOM.version) == null ? void 0 : _a.startsWith("18");
|
|
325
|
+
function createRoot(container, options) {
|
|
238
326
|
if (isReact18) {
|
|
239
|
-
|
|
240
|
-
return ReactDOM.createRoot(container, options);
|
|
241
|
-
} catch (e2) {
|
|
242
|
-
console.warn(
|
|
243
|
-
"Failed to use React 18 createRoot API, falling back to legacy API",
|
|
244
|
-
e2
|
|
245
|
-
);
|
|
246
|
-
}
|
|
327
|
+
return ReactDOM.createRoot(container, options);
|
|
247
328
|
}
|
|
248
329
|
return {
|
|
249
330
|
render(children) {
|
|
@@ -255,8 +336,7 @@ function defaultCreateRoot(container, options) {
|
|
|
255
336
|
};
|
|
256
337
|
}
|
|
257
338
|
function createBridgeComponent({
|
|
258
|
-
createRoot =
|
|
259
|
-
defaultRootOptions,
|
|
339
|
+
createRoot: createRoot$1 = createRoot,
|
|
260
340
|
...bridgeInfo
|
|
261
341
|
}) {
|
|
262
342
|
return () => {
|
|
@@ -280,7 +360,7 @@ function createBridgeComponent({
|
|
|
280
360
|
};
|
|
281
361
|
return {
|
|
282
362
|
async render(info) {
|
|
283
|
-
var
|
|
363
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
284
364
|
context.LoggerInstance.debug(`createBridgeComponent render Info`, info);
|
|
285
365
|
const {
|
|
286
366
|
moduleName,
|
|
@@ -288,46 +368,38 @@ function createBridgeComponent({
|
|
|
288
368
|
basename,
|
|
289
369
|
memoryRoute,
|
|
290
370
|
fallback,
|
|
291
|
-
rootOptions,
|
|
292
371
|
...propsInfo
|
|
293
372
|
} = info;
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
};
|
|
298
|
-
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)) || {};
|
|
299
|
-
const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(
|
|
300
|
-
reactErrorBoundary_esm.ErrorBoundary,
|
|
373
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(info)) || {};
|
|
374
|
+
const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
|
|
375
|
+
RawComponent,
|
|
301
376
|
{
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
324
|
-
if ("render" in root) {
|
|
325
|
-
root.render(rootComponentWithErrorBoundary);
|
|
377
|
+
appInfo: {
|
|
378
|
+
moduleName,
|
|
379
|
+
basename,
|
|
380
|
+
memoryRoute
|
|
381
|
+
},
|
|
382
|
+
propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
|
|
383
|
+
}
|
|
384
|
+
));
|
|
385
|
+
if (bridgeInfo.render) {
|
|
386
|
+
await Promise.resolve(
|
|
387
|
+
bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
388
|
+
).then((root) => rootMap.set(dom, root));
|
|
389
|
+
} else {
|
|
390
|
+
let root = rootMap.get(dom);
|
|
391
|
+
if (!root) {
|
|
392
|
+
root = createRoot$1(dom);
|
|
393
|
+
rootMap.set(dom, root);
|
|
394
|
+
}
|
|
395
|
+
if ("render" in root) {
|
|
396
|
+
root.render(rootComponentWithErrorBoundary);
|
|
397
|
+
}
|
|
326
398
|
}
|
|
327
399
|
((_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)) || {};
|
|
328
400
|
},
|
|
329
401
|
destroy(info) {
|
|
330
|
-
var
|
|
402
|
+
var _a2, _b, _c;
|
|
331
403
|
const { dom } = info;
|
|
332
404
|
context.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
333
405
|
const root = rootMap.get(dom);
|
|
@@ -335,11 +407,11 @@ function createBridgeComponent({
|
|
|
335
407
|
if ("unmount" in root) {
|
|
336
408
|
root.unmount();
|
|
337
409
|
} else {
|
|
338
|
-
ReactDOM.unmountComponentAtNode(
|
|
410
|
+
ReactDOM.unmountComponentAtNode(root);
|
|
339
411
|
}
|
|
340
412
|
rootMap.delete(dom);
|
|
341
413
|
}
|
|
342
|
-
(_c = (_b = (
|
|
414
|
+
(_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
|
|
343
415
|
}
|
|
344
416
|
};
|
|
345
417
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { default as default_2 } from 'react';
|
|
2
2
|
import * as React_2 from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Creates a bridge component factory that automatically detects and uses
|
|
6
|
-
* the appropriate React version (16/17, 18, or 19)
|
|
7
|
-
*/
|
|
8
|
-
export declare function createBridgeComponent<T>({ createRoot, defaultRootOptions, ...bridgeInfo }: ProviderFnParams<T>): () => {
|
|
4
|
+
export declare function createBridgeComponent<T>({ createRoot, ...bridgeInfo }: ProviderFnParams<T>): () => {
|
|
9
5
|
render(info: RenderParams): Promise<void>;
|
|
10
6
|
destroy(info: DestroyParams): void;
|
|
11
7
|
};
|
|
@@ -38,16 +34,6 @@ declare interface ProviderFnParams<T> {
|
|
|
38
34
|
rootComponent: React_2.ComponentType<T>;
|
|
39
35
|
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
40
36
|
createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions) => Root;
|
|
41
|
-
/**
|
|
42
|
-
* Default options to pass to createRoot for React 18 and 19
|
|
43
|
-
* These options will be used when creating a root unless overridden by rootOptions in render params
|
|
44
|
-
* @example
|
|
45
|
-
* {
|
|
46
|
-
* identifierPrefix: 'app-',
|
|
47
|
-
* onRecoverableError: (err) => console.error(err)
|
|
48
|
-
* }
|
|
49
|
-
*/
|
|
50
|
-
defaultRootOptions?: CreateRootOptions;
|
|
51
37
|
}
|
|
52
38
|
|
|
53
39
|
/**
|
|
@@ -111,15 +97,6 @@ export declare interface RenderParams {
|
|
|
111
97
|
initialState?: Record<string, unknown>;
|
|
112
98
|
};
|
|
113
99
|
dom: HTMLElement;
|
|
114
|
-
/**
|
|
115
|
-
* Options to pass to createRoot for React 18 and 19
|
|
116
|
-
* @example
|
|
117
|
-
* {
|
|
118
|
-
* identifierPrefix: 'app-',
|
|
119
|
-
* onRecoverableError: (err) => console.error(err)
|
|
120
|
-
* }
|
|
121
|
-
*/
|
|
122
|
-
rootOptions?: CreateRootOptions;
|
|
123
100
|
[key: string]: unknown;
|
|
124
101
|
}
|
|
125
102
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,10 +1,105 @@
|
|
|
1
|
+
var _a;
|
|
1
2
|
import * as React from "react";
|
|
2
|
-
import React__default, { forwardRef, useRef, useState, useEffect, useContext } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, R as RouterContext } from "./internal/context.es.js";
|
|
3
|
+
import React__default, { createContext, Component, createElement, forwardRef, useRef, useState, useEffect, useContext } from "react";
|
|
4
|
+
import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, R as RouterContext } from "./context-Dbqf0szX.js";
|
|
5
5
|
import * as ReactRouterDOM from "react-router-dom";
|
|
6
6
|
import { federationRuntime } from "./plugin.es.js";
|
|
7
7
|
import ReactDOM from "react-dom";
|
|
8
|
+
const ErrorBoundaryContext = createContext(null);
|
|
9
|
+
const initialState = {
|
|
10
|
+
didCatch: false,
|
|
11
|
+
error: null
|
|
12
|
+
};
|
|
13
|
+
class ErrorBoundary extends Component {
|
|
14
|
+
constructor(props) {
|
|
15
|
+
super(props);
|
|
16
|
+
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
17
|
+
this.state = initialState;
|
|
18
|
+
}
|
|
19
|
+
static getDerivedStateFromError(error) {
|
|
20
|
+
return {
|
|
21
|
+
didCatch: true,
|
|
22
|
+
error
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
resetErrorBoundary() {
|
|
26
|
+
const {
|
|
27
|
+
error
|
|
28
|
+
} = this.state;
|
|
29
|
+
if (error !== null) {
|
|
30
|
+
var _this$props$onReset, _this$props;
|
|
31
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
32
|
+
args[_key] = arguments[_key];
|
|
33
|
+
}
|
|
34
|
+
(_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
|
|
35
|
+
args,
|
|
36
|
+
reason: "imperative-api"
|
|
37
|
+
});
|
|
38
|
+
this.setState(initialState);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
componentDidCatch(error, info) {
|
|
42
|
+
var _this$props$onError, _this$props2;
|
|
43
|
+
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
44
|
+
}
|
|
45
|
+
componentDidUpdate(prevProps, prevState) {
|
|
46
|
+
const {
|
|
47
|
+
didCatch
|
|
48
|
+
} = this.state;
|
|
49
|
+
const {
|
|
50
|
+
resetKeys
|
|
51
|
+
} = this.props;
|
|
52
|
+
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
53
|
+
var _this$props$onReset2, _this$props3;
|
|
54
|
+
(_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
|
|
55
|
+
next: resetKeys,
|
|
56
|
+
prev: prevProps.resetKeys,
|
|
57
|
+
reason: "keys"
|
|
58
|
+
});
|
|
59
|
+
this.setState(initialState);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
render() {
|
|
63
|
+
const {
|
|
64
|
+
children,
|
|
65
|
+
fallbackRender,
|
|
66
|
+
FallbackComponent,
|
|
67
|
+
fallback
|
|
68
|
+
} = this.props;
|
|
69
|
+
const {
|
|
70
|
+
didCatch,
|
|
71
|
+
error
|
|
72
|
+
} = this.state;
|
|
73
|
+
let childToRender = children;
|
|
74
|
+
if (didCatch) {
|
|
75
|
+
const props = {
|
|
76
|
+
error,
|
|
77
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
78
|
+
};
|
|
79
|
+
if (typeof fallbackRender === "function") {
|
|
80
|
+
childToRender = fallbackRender(props);
|
|
81
|
+
} else if (FallbackComponent) {
|
|
82
|
+
childToRender = createElement(FallbackComponent, props);
|
|
83
|
+
} else if (fallback !== void 0) {
|
|
84
|
+
childToRender = fallback;
|
|
85
|
+
} else {
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return createElement(ErrorBoundaryContext.Provider, {
|
|
90
|
+
value: {
|
|
91
|
+
didCatch,
|
|
92
|
+
error,
|
|
93
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
94
|
+
}
|
|
95
|
+
}, childToRender);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function hasArrayChanged() {
|
|
99
|
+
let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
100
|
+
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
101
|
+
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
102
|
+
}
|
|
8
103
|
function e() {
|
|
9
104
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
10
105
|
window.dispatchEvent(t);
|
|
@@ -32,8 +127,8 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
32
127
|
providerInfoRef.current = providerReturn;
|
|
33
128
|
setInitialized(true);
|
|
34
129
|
return () => {
|
|
35
|
-
var
|
|
36
|
-
if ((
|
|
130
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
131
|
+
if ((_a2 = providerInfoRef.current) == null ? void 0 : _a2.destroy) {
|
|
37
132
|
LoggerInstance.debug(
|
|
38
133
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
39
134
|
{ moduleName, basename, dom: renderDom.current }
|
|
@@ -62,7 +157,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
62
157
|
};
|
|
63
158
|
}, [moduleName]);
|
|
64
159
|
useEffect(() => {
|
|
65
|
-
var
|
|
160
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
66
161
|
if (!initialized || !providerInfoRef.current) return;
|
|
67
162
|
let renderProps = {
|
|
68
163
|
moduleName,
|
|
@@ -73,7 +168,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
73
168
|
...resProps
|
|
74
169
|
};
|
|
75
170
|
renderDom.current = rootRef.current;
|
|
76
|
-
const beforeBridgeRenderRes = ((_c = (_b = (
|
|
171
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
|
|
77
172
|
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
78
173
|
providerInfoRef.current.render(renderProps);
|
|
79
174
|
(_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
|
|
@@ -82,8 +177,8 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
82
177
|
return /* @__PURE__ */ React__default.createElement("div", { className: rootComponentClassName, style, ref: rootRef });
|
|
83
178
|
});
|
|
84
179
|
function withRouterData(WrappedComponent) {
|
|
85
|
-
const
|
|
86
|
-
var
|
|
180
|
+
const Component2 = forwardRef(function(props, ref) {
|
|
181
|
+
var _a2;
|
|
87
182
|
if (props == null ? void 0 : props.basename) {
|
|
88
183
|
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename: props.basename, ref });
|
|
89
184
|
}
|
|
@@ -116,7 +211,7 @@ function withRouterData(WrappedComponent) {
|
|
|
116
211
|
const match = useRouteMatch == null ? void 0 : useRouteMatch();
|
|
117
212
|
if (useHistory) {
|
|
118
213
|
const history = useHistory == null ? void 0 : useHistory();
|
|
119
|
-
basename = (
|
|
214
|
+
basename = (_a2 = history == null ? void 0 : history.createHref) == null ? void 0 : _a2.call(history, { pathname: "/" });
|
|
120
215
|
}
|
|
121
216
|
if (match) {
|
|
122
217
|
basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
@@ -149,7 +244,7 @@ function withRouterData(WrappedComponent) {
|
|
|
149
244
|
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename, ref });
|
|
150
245
|
});
|
|
151
246
|
return forwardRef(function(props, ref) {
|
|
152
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
247
|
+
return /* @__PURE__ */ React__default.createElement(Component2, { ...props, ref });
|
|
153
248
|
});
|
|
154
249
|
}
|
|
155
250
|
const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
@@ -204,27 +299,13 @@ function createLazyRemoteComponent(info) {
|
|
|
204
299
|
function createRemoteComponent(info) {
|
|
205
300
|
const LazyComponent = createLazyRemoteComponent(info);
|
|
206
301
|
return forwardRef((props, ref) => {
|
|
207
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
208
|
-
ErrorBoundary,
|
|
209
|
-
{
|
|
210
|
-
FallbackComponent: info.fallback
|
|
211
|
-
},
|
|
212
|
-
/* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props, ref }))
|
|
213
|
-
);
|
|
302
|
+
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, ref })));
|
|
214
303
|
});
|
|
215
304
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const isReact18 = reactVersion.startsWith("18");
|
|
305
|
+
const isReact18 = (_a = ReactDOM.version) == null ? void 0 : _a.startsWith("18");
|
|
306
|
+
function createRoot(container, options) {
|
|
219
307
|
if (isReact18) {
|
|
220
|
-
|
|
221
|
-
return ReactDOM.createRoot(container, options);
|
|
222
|
-
} catch (e2) {
|
|
223
|
-
console.warn(
|
|
224
|
-
"Failed to use React 18 createRoot API, falling back to legacy API",
|
|
225
|
-
e2
|
|
226
|
-
);
|
|
227
|
-
}
|
|
308
|
+
return ReactDOM.createRoot(container, options);
|
|
228
309
|
}
|
|
229
310
|
return {
|
|
230
311
|
render(children) {
|
|
@@ -236,8 +317,7 @@ function defaultCreateRoot(container, options) {
|
|
|
236
317
|
};
|
|
237
318
|
}
|
|
238
319
|
function createBridgeComponent({
|
|
239
|
-
createRoot =
|
|
240
|
-
defaultRootOptions,
|
|
320
|
+
createRoot: createRoot$1 = createRoot,
|
|
241
321
|
...bridgeInfo
|
|
242
322
|
}) {
|
|
243
323
|
return () => {
|
|
@@ -261,7 +341,7 @@ function createBridgeComponent({
|
|
|
261
341
|
};
|
|
262
342
|
return {
|
|
263
343
|
async render(info) {
|
|
264
|
-
var
|
|
344
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
265
345
|
LoggerInstance.debug(`createBridgeComponent render Info`, info);
|
|
266
346
|
const {
|
|
267
347
|
moduleName,
|
|
@@ -269,46 +349,38 @@ function createBridgeComponent({
|
|
|
269
349
|
basename,
|
|
270
350
|
memoryRoute,
|
|
271
351
|
fallback,
|
|
272
|
-
rootOptions,
|
|
273
352
|
...propsInfo
|
|
274
353
|
} = info;
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
};
|
|
279
|
-
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)) || {};
|
|
280
|
-
const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(
|
|
281
|
-
ErrorBoundary,
|
|
354
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(info)) || {};
|
|
355
|
+
const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
|
|
356
|
+
RawComponent,
|
|
282
357
|
{
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
if ("render" in root) {
|
|
306
|
-
root.render(rootComponentWithErrorBoundary);
|
|
358
|
+
appInfo: {
|
|
359
|
+
moduleName,
|
|
360
|
+
basename,
|
|
361
|
+
memoryRoute
|
|
362
|
+
},
|
|
363
|
+
propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
|
|
364
|
+
}
|
|
365
|
+
));
|
|
366
|
+
if (bridgeInfo.render) {
|
|
367
|
+
await Promise.resolve(
|
|
368
|
+
bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
369
|
+
).then((root) => rootMap.set(dom, root));
|
|
370
|
+
} else {
|
|
371
|
+
let root = rootMap.get(dom);
|
|
372
|
+
if (!root) {
|
|
373
|
+
root = createRoot$1(dom);
|
|
374
|
+
rootMap.set(dom, root);
|
|
375
|
+
}
|
|
376
|
+
if ("render" in root) {
|
|
377
|
+
root.render(rootComponentWithErrorBoundary);
|
|
378
|
+
}
|
|
307
379
|
}
|
|
308
380
|
((_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)) || {};
|
|
309
381
|
},
|
|
310
382
|
destroy(info) {
|
|
311
|
-
var
|
|
383
|
+
var _a2, _b, _c;
|
|
312
384
|
const { dom } = info;
|
|
313
385
|
LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
314
386
|
const root = rootMap.get(dom);
|
|
@@ -316,11 +388,11 @@ function createBridgeComponent({
|
|
|
316
388
|
if ("unmount" in root) {
|
|
317
389
|
root.unmount();
|
|
318
390
|
} else {
|
|
319
|
-
ReactDOM.unmountComponentAtNode(
|
|
391
|
+
ReactDOM.unmountComponentAtNode(root);
|
|
320
392
|
}
|
|
321
393
|
rootMap.delete(dom);
|
|
322
394
|
}
|
|
323
|
-
(_c = (_b = (
|
|
395
|
+
(_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
|
|
324
396
|
}
|
|
325
397
|
};
|
|
326
398
|
};
|
package/dist/router-v5.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const ReactRouterDom$1 = require("react-router-dom/index.js");
|
|
5
|
-
const context = require("./
|
|
5
|
+
const context = require("./context-C79iMWYD.cjs");
|
|
6
6
|
const ReactRouterDom = require("react-router-dom/index.js");
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|