@module-federation/bridge-react 0.0.0-next-20250414091720 → 0.0.0-next-20250415111630
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 +8 -4
- package/dist/bridge-base-BQcdOEoU.cjs +119 -0
- package/dist/bridge-base-BbzPi965.js +103 -0
- package/dist/index.cjs.js +63 -135
- package/dist/index.d.ts +24 -1
- package/dist/index.es.js +66 -138
- package/dist/legacy.cjs.js +4 -0
- package/dist/legacy.d.ts +104 -0
- package/dist/legacy.es.js +4 -0
- package/dist/react-error-boundary.esm-CMdlkNPP.js +99 -0
- package/dist/react-error-boundary.esm-D8nxmvmv.cjs +98 -0
- package/dist/v16.cjs.js +22 -0
- package/dist/v16.d.ts +104 -0
- package/dist/v16.es.js +22 -0
- package/dist/v18.cjs.js +15 -0
- package/dist/v18.d.ts +105 -0
- package/dist/v18.es.js +15 -0
- package/dist/v19.cjs.js +15 -0
- package/dist/v19.d.ts +106 -0
- package/dist/v19.es.js +15 -0
- package/package.json +19 -4
- package/src/legacy.ts +13 -0
- package/src/provider/create.tsx +73 -20
- package/src/provider/versions/bridge-base.tsx +122 -0
- package/src/provider/versions/legacy.ts +42 -0
- package/src/provider/versions/v18.ts +47 -0
- package/src/provider/versions/v19.ts +48 -0
- package/src/remote/create.tsx +4 -2
- package/src/types.ts +19 -0
- package/src/utils/index.ts +0 -20
- package/src/v18.ts +9 -0
- package/src/v19.ts +9 -0
- package/vite.config.ts +5 -2
- package/src/provider/compat.ts +0 -60
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20250415111630
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d802e00: feat(react-bridge): Add native support for React 19 in bridge-react with enhanced createRoot options
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
7
|
-
-
|
|
11
|
+
- d0a11ff: feat(bridge-react): support react v19 in react compat file.
|
|
8
12
|
- Updated dependencies [f4fb242]
|
|
9
|
-
- @module-federation/sdk@0.0.0-next-
|
|
10
|
-
- @module-federation/bridge-shared@0.0.0-next-
|
|
13
|
+
- @module-federation/sdk@0.0.0-next-20250415111630
|
|
14
|
+
- @module-federation/bridge-shared@0.0.0-next-20250415111630
|
|
11
15
|
|
|
12
16
|
## 0.11.4
|
|
13
17
|
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const React = require("react");
|
|
3
|
+
const reactErrorBoundary_esm = require("./react-error-boundary.esm-D8nxmvmv.cjs");
|
|
4
|
+
const context = require("./context-C79iMWYD.cjs");
|
|
5
|
+
const plugin = require("./plugin.cjs.js");
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
+
if (e) {
|
|
9
|
+
for (const k in e) {
|
|
10
|
+
if (k !== "default") {
|
|
11
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: () => e[k]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
23
|
+
function createBaseBridgeComponent({
|
|
24
|
+
createRoot,
|
|
25
|
+
defaultRootOptions,
|
|
26
|
+
...bridgeInfo
|
|
27
|
+
}) {
|
|
28
|
+
return () => {
|
|
29
|
+
const rootMap = /* @__PURE__ */ new Map();
|
|
30
|
+
const instance = plugin.federationRuntime.instance;
|
|
31
|
+
context.LoggerInstance.debug(
|
|
32
|
+
`createBridgeComponent instance from props >>>`,
|
|
33
|
+
instance
|
|
34
|
+
);
|
|
35
|
+
const RawComponent = (info) => {
|
|
36
|
+
const { appInfo, propsInfo, ...restProps } = info;
|
|
37
|
+
const { moduleName, memoryRoute, basename = "/" } = appInfo;
|
|
38
|
+
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(
|
|
39
|
+
bridgeInfo.rootComponent,
|
|
40
|
+
{
|
|
41
|
+
...propsInfo,
|
|
42
|
+
basename,
|
|
43
|
+
...restProps
|
|
44
|
+
}
|
|
45
|
+
));
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
async render(info) {
|
|
49
|
+
var _a, _b, _c, _d, _e, _f;
|
|
50
|
+
context.LoggerInstance.debug(`createBridgeComponent render Info`, info);
|
|
51
|
+
const {
|
|
52
|
+
moduleName,
|
|
53
|
+
dom,
|
|
54
|
+
basename,
|
|
55
|
+
memoryRoute,
|
|
56
|
+
fallback,
|
|
57
|
+
rootOptions,
|
|
58
|
+
...propsInfo
|
|
59
|
+
} = info;
|
|
60
|
+
const mergedRootOptions = {
|
|
61
|
+
...defaultRootOptions,
|
|
62
|
+
...rootOptions
|
|
63
|
+
};
|
|
64
|
+
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)) || {};
|
|
65
|
+
const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(
|
|
66
|
+
reactErrorBoundary_esm.ErrorBoundary,
|
|
67
|
+
{
|
|
68
|
+
FallbackComponent: fallback
|
|
69
|
+
},
|
|
70
|
+
/* @__PURE__ */ React__namespace.createElement(
|
|
71
|
+
RawComponent,
|
|
72
|
+
{
|
|
73
|
+
appInfo: {
|
|
74
|
+
moduleName,
|
|
75
|
+
basename,
|
|
76
|
+
memoryRoute
|
|
77
|
+
},
|
|
78
|
+
propsInfo: {
|
|
79
|
+
...propsInfo,
|
|
80
|
+
...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
if (bridgeInfo.render) {
|
|
86
|
+
await Promise.resolve(
|
|
87
|
+
bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
88
|
+
).then((root) => rootMap.set(dom, root));
|
|
89
|
+
} else {
|
|
90
|
+
let root = rootMap.get(dom);
|
|
91
|
+
if (!root && createRoot) {
|
|
92
|
+
root = createRoot(dom, mergedRootOptions);
|
|
93
|
+
rootMap.set(dom, root);
|
|
94
|
+
}
|
|
95
|
+
if (root && "render" in root) {
|
|
96
|
+
root.render(rootComponentWithErrorBoundary);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
((_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)) || {};
|
|
100
|
+
},
|
|
101
|
+
destroy(info) {
|
|
102
|
+
var _a, _b, _c;
|
|
103
|
+
const { dom } = info;
|
|
104
|
+
context.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
105
|
+
const root = rootMap.get(dom);
|
|
106
|
+
if (root) {
|
|
107
|
+
if ("unmount" in root) {
|
|
108
|
+
root.unmount();
|
|
109
|
+
} else {
|
|
110
|
+
console.warn("Root does not have unmount method");
|
|
111
|
+
}
|
|
112
|
+
rootMap.delete(dom);
|
|
113
|
+
}
|
|
114
|
+
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
exports.createBaseBridgeComponent = createBaseBridgeComponent;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { E as ErrorBoundary } from "./react-error-boundary.esm-CMdlkNPP.js";
|
|
3
|
+
import { L as LoggerInstance, R as RouterContext } from "./context-Dbqf0szX.js";
|
|
4
|
+
import { federationRuntime } from "./plugin.es.js";
|
|
5
|
+
function createBaseBridgeComponent({
|
|
6
|
+
createRoot,
|
|
7
|
+
defaultRootOptions,
|
|
8
|
+
...bridgeInfo
|
|
9
|
+
}) {
|
|
10
|
+
return () => {
|
|
11
|
+
const rootMap = /* @__PURE__ */ new Map();
|
|
12
|
+
const instance = federationRuntime.instance;
|
|
13
|
+
LoggerInstance.debug(
|
|
14
|
+
`createBridgeComponent instance from props >>>`,
|
|
15
|
+
instance
|
|
16
|
+
);
|
|
17
|
+
const RawComponent = (info) => {
|
|
18
|
+
const { appInfo, propsInfo, ...restProps } = info;
|
|
19
|
+
const { moduleName, memoryRoute, basename = "/" } = appInfo;
|
|
20
|
+
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(
|
|
21
|
+
bridgeInfo.rootComponent,
|
|
22
|
+
{
|
|
23
|
+
...propsInfo,
|
|
24
|
+
basename,
|
|
25
|
+
...restProps
|
|
26
|
+
}
|
|
27
|
+
));
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
async render(info) {
|
|
31
|
+
var _a, _b, _c, _d, _e, _f;
|
|
32
|
+
LoggerInstance.debug(`createBridgeComponent render Info`, info);
|
|
33
|
+
const {
|
|
34
|
+
moduleName,
|
|
35
|
+
dom,
|
|
36
|
+
basename,
|
|
37
|
+
memoryRoute,
|
|
38
|
+
fallback,
|
|
39
|
+
rootOptions,
|
|
40
|
+
...propsInfo
|
|
41
|
+
} = info;
|
|
42
|
+
const mergedRootOptions = {
|
|
43
|
+
...defaultRootOptions,
|
|
44
|
+
...rootOptions
|
|
45
|
+
};
|
|
46
|
+
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)) || {};
|
|
47
|
+
const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(
|
|
48
|
+
ErrorBoundary,
|
|
49
|
+
{
|
|
50
|
+
FallbackComponent: fallback
|
|
51
|
+
},
|
|
52
|
+
/* @__PURE__ */ React.createElement(
|
|
53
|
+
RawComponent,
|
|
54
|
+
{
|
|
55
|
+
appInfo: {
|
|
56
|
+
moduleName,
|
|
57
|
+
basename,
|
|
58
|
+
memoryRoute
|
|
59
|
+
},
|
|
60
|
+
propsInfo: {
|
|
61
|
+
...propsInfo,
|
|
62
|
+
...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
if (bridgeInfo.render) {
|
|
68
|
+
await Promise.resolve(
|
|
69
|
+
bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
70
|
+
).then((root) => rootMap.set(dom, root));
|
|
71
|
+
} else {
|
|
72
|
+
let root = rootMap.get(dom);
|
|
73
|
+
if (!root && createRoot) {
|
|
74
|
+
root = createRoot(dom, mergedRootOptions);
|
|
75
|
+
rootMap.set(dom, root);
|
|
76
|
+
}
|
|
77
|
+
if (root && "render" in root) {
|
|
78
|
+
root.render(rootComponentWithErrorBoundary);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
((_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)) || {};
|
|
82
|
+
},
|
|
83
|
+
destroy(info) {
|
|
84
|
+
var _a, _b, _c;
|
|
85
|
+
const { dom } = info;
|
|
86
|
+
LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
87
|
+
const root = rootMap.get(dom);
|
|
88
|
+
if (root) {
|
|
89
|
+
if ("unmount" in root) {
|
|
90
|
+
root.unmount();
|
|
91
|
+
} else {
|
|
92
|
+
console.warn("Root does not have unmount method");
|
|
93
|
+
}
|
|
94
|
+
rootMap.delete(dom);
|
|
95
|
+
}
|
|
96
|
+
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
createBaseBridgeComponent as c
|
|
103
|
+
};
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
3
|
const React = require("react");
|
|
4
|
+
const reactErrorBoundary_esm = require("./react-error-boundary.esm-D8nxmvmv.cjs");
|
|
5
5
|
const context = require("./context-C79iMWYD.cjs");
|
|
6
6
|
const ReactRouterDOM = require("react-router-dom");
|
|
7
7
|
const plugin = require("./plugin.cjs.js");
|
|
@@ -24,101 +24,6 @@ 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
|
-
}
|
|
122
27
|
function e() {
|
|
123
28
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
124
29
|
window.dispatchEvent(t);
|
|
@@ -146,8 +51,8 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
146
51
|
providerInfoRef.current = providerReturn;
|
|
147
52
|
setInitialized(true);
|
|
148
53
|
return () => {
|
|
149
|
-
var
|
|
150
|
-
if ((
|
|
54
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
55
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
151
56
|
context.LoggerInstance.debug(
|
|
152
57
|
`createRemoteComponent LazyComponent destroy >>>`,
|
|
153
58
|
{ moduleName, basename, dom: renderDom.current }
|
|
@@ -176,7 +81,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
176
81
|
};
|
|
177
82
|
}, [moduleName]);
|
|
178
83
|
React.useEffect(() => {
|
|
179
|
-
var
|
|
84
|
+
var _a, _b, _c, _d, _e, _f;
|
|
180
85
|
if (!initialized || !providerInfoRef.current) return;
|
|
181
86
|
let renderProps = {
|
|
182
87
|
moduleName,
|
|
@@ -187,7 +92,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
187
92
|
...resProps
|
|
188
93
|
};
|
|
189
94
|
renderDom.current = rootRef.current;
|
|
190
|
-
const beforeBridgeRenderRes = ((_c = (_b = (
|
|
95
|
+
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(renderProps)) || {};
|
|
191
96
|
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
192
97
|
providerInfoRef.current.render(renderProps);
|
|
193
98
|
(_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);
|
|
@@ -197,7 +102,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
197
102
|
});
|
|
198
103
|
function withRouterData(WrappedComponent) {
|
|
199
104
|
const Component = React.forwardRef(function(props, ref) {
|
|
200
|
-
var
|
|
105
|
+
var _a;
|
|
201
106
|
if (props == null ? void 0 : props.basename) {
|
|
202
107
|
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename: props.basename, ref });
|
|
203
108
|
}
|
|
@@ -230,7 +135,7 @@ function withRouterData(WrappedComponent) {
|
|
|
230
135
|
const match = useRouteMatch == null ? void 0 : useRouteMatch();
|
|
231
136
|
if (useHistory) {
|
|
232
137
|
const history = useHistory == null ? void 0 : useHistory();
|
|
233
|
-
basename = (
|
|
138
|
+
basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
|
|
234
139
|
}
|
|
235
140
|
if (match) {
|
|
236
141
|
basename = context.pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
@@ -318,13 +223,27 @@ function createLazyRemoteComponent(info) {
|
|
|
318
223
|
function createRemoteComponent(info) {
|
|
319
224
|
const LazyComponent = createLazyRemoteComponent(info);
|
|
320
225
|
return React.forwardRef((props, ref) => {
|
|
321
|
-
return /* @__PURE__ */ React.createElement(
|
|
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
|
+
);
|
|
322
233
|
});
|
|
323
234
|
}
|
|
324
|
-
|
|
325
|
-
|
|
235
|
+
function defaultCreateRoot(container, options) {
|
|
236
|
+
const reactVersion = ReactDOM.version || "";
|
|
237
|
+
const isReact18 = reactVersion.startsWith("18");
|
|
326
238
|
if (isReact18) {
|
|
327
|
-
|
|
239
|
+
try {
|
|
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
|
+
}
|
|
328
247
|
}
|
|
329
248
|
return {
|
|
330
249
|
render(children) {
|
|
@@ -336,7 +255,8 @@ function createRoot(container, options) {
|
|
|
336
255
|
};
|
|
337
256
|
}
|
|
338
257
|
function createBridgeComponent({
|
|
339
|
-
createRoot
|
|
258
|
+
createRoot = defaultCreateRoot,
|
|
259
|
+
defaultRootOptions,
|
|
340
260
|
...bridgeInfo
|
|
341
261
|
}) {
|
|
342
262
|
return () => {
|
|
@@ -360,7 +280,7 @@ function createBridgeComponent({
|
|
|
360
280
|
};
|
|
361
281
|
return {
|
|
362
282
|
async render(info) {
|
|
363
|
-
var
|
|
283
|
+
var _a, _b, _c, _d, _e, _f;
|
|
364
284
|
context.LoggerInstance.debug(`createBridgeComponent render Info`, info);
|
|
365
285
|
const {
|
|
366
286
|
moduleName,
|
|
@@ -368,38 +288,46 @@ function createBridgeComponent({
|
|
|
368
288
|
basename,
|
|
369
289
|
memoryRoute,
|
|
370
290
|
fallback,
|
|
291
|
+
rootOptions,
|
|
371
292
|
...propsInfo
|
|
372
293
|
} = info;
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
|
|
294
|
+
const mergedRootOptions = {
|
|
295
|
+
...defaultRootOptions,
|
|
296
|
+
...rootOptions
|
|
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,
|
|
376
301
|
{
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
302
|
+
FallbackComponent: fallback
|
|
303
|
+
},
|
|
304
|
+
/* @__PURE__ */ React__namespace.createElement(
|
|
305
|
+
RawComponent,
|
|
306
|
+
{
|
|
307
|
+
appInfo: {
|
|
308
|
+
moduleName,
|
|
309
|
+
basename,
|
|
310
|
+
memoryRoute
|
|
311
|
+
},
|
|
312
|
+
propsInfo: {
|
|
313
|
+
...propsInfo,
|
|
314
|
+
...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
)
|
|
318
|
+
);
|
|
319
|
+
let root = rootMap.get(dom);
|
|
320
|
+
if (!root) {
|
|
321
|
+
root = createRoot(dom, mergedRootOptions);
|
|
322
|
+
rootMap.set(dom, root);
|
|
323
|
+
}
|
|
324
|
+
if ("render" in root) {
|
|
325
|
+
root.render(rootComponentWithErrorBoundary);
|
|
398
326
|
}
|
|
399
327
|
((_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)) || {};
|
|
400
328
|
},
|
|
401
329
|
destroy(info) {
|
|
402
|
-
var
|
|
330
|
+
var _a, _b, _c;
|
|
403
331
|
const { dom } = info;
|
|
404
332
|
context.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
405
333
|
const root = rootMap.get(dom);
|
|
@@ -407,11 +335,11 @@ function createBridgeComponent({
|
|
|
407
335
|
if ("unmount" in root) {
|
|
408
336
|
root.unmount();
|
|
409
337
|
} else {
|
|
410
|
-
ReactDOM.unmountComponentAtNode(
|
|
338
|
+
ReactDOM.unmountComponentAtNode(dom);
|
|
411
339
|
}
|
|
412
340
|
rootMap.delete(dom);
|
|
413
341
|
}
|
|
414
|
-
(_c = (_b = (
|
|
342
|
+
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
|
|
415
343
|
}
|
|
416
344
|
};
|
|
417
345
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { default as default_2 } from 'react';
|
|
2
2
|
import * as React_2 from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
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>): () => {
|
|
5
9
|
render(info: RenderParams): Promise<void>;
|
|
6
10
|
destroy(info: DestroyParams): void;
|
|
7
11
|
};
|
|
@@ -34,6 +38,16 @@ declare interface ProviderFnParams<T> {
|
|
|
34
38
|
rootComponent: React_2.ComponentType<T>;
|
|
35
39
|
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
36
40
|
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;
|
|
37
51
|
}
|
|
38
52
|
|
|
39
53
|
/**
|
|
@@ -97,6 +111,15 @@ export declare interface RenderParams {
|
|
|
97
111
|
initialState?: Record<string, unknown>;
|
|
98
112
|
};
|
|
99
113
|
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;
|
|
100
123
|
[key: string]: unknown;
|
|
101
124
|
}
|
|
102
125
|
|