@module-federation/bridge-react 0.0.0-docs-remove-invalid-lark-link-20251205062649
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 +728 -0
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/__tests__/bridge.spec.tsx +160 -0
- package/__tests__/createLazyComponent.spec.tsx +209 -0
- package/__tests__/prefetch.spec.ts +156 -0
- package/__tests__/router.spec.tsx +82 -0
- package/__tests__/setupTests.ts +8 -0
- package/__tests__/util.ts +36 -0
- package/dist/base.cjs.js +29 -0
- package/dist/base.d.ts +311 -0
- package/dist/base.es.js +30 -0
- package/dist/bridge-base-CPSTBjEp.mjs +211 -0
- package/dist/bridge-base-RStDxH71.js +226 -0
- package/dist/createHelpers-B_L612IN.js +190 -0
- package/dist/createHelpers-Ui5pt7je.mjs +191 -0
- package/dist/data-fetch-server-middleware.cjs.js +163 -0
- package/dist/data-fetch-server-middleware.d.ts +15 -0
- package/dist/data-fetch-server-middleware.es.js +164 -0
- package/dist/data-fetch-utils.cjs.js +24 -0
- package/dist/data-fetch-utils.d.ts +81 -0
- package/dist/data-fetch-utils.es.js +26 -0
- package/dist/index-DRSBaSu3.js +45 -0
- package/dist/index-DyQNwY2M.mjs +46 -0
- package/dist/index.cjs.js +125 -0
- package/dist/index.d.ts +299 -0
- package/dist/index.es.js +109 -0
- package/dist/index.esm-BWaKho-8.js +491 -0
- package/dist/index.esm-CPwSeCvw.mjs +492 -0
- package/dist/lazy-load-component-plugin-CSRkMmKF.js +521 -0
- package/dist/lazy-load-component-plugin-DXqhuywC.mjs +522 -0
- package/dist/lazy-load-component-plugin.cjs.js +6 -0
- package/dist/lazy-load-component-plugin.d.ts +16 -0
- package/dist/lazy-load-component-plugin.es.js +6 -0
- package/dist/lazy-utils.cjs.js +24 -0
- package/dist/lazy-utils.d.ts +149 -0
- package/dist/lazy-utils.es.js +24 -0
- package/dist/plugin.cjs.js +14 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.es.js +14 -0
- package/dist/prefetch-A3QkU5oZ.js +1272 -0
- package/dist/prefetch-zMJL79zx.mjs +1273 -0
- package/dist/router-v5.cjs.js +55 -0
- package/dist/router-v5.d.ts +18 -0
- package/dist/router-v5.es.js +32 -0
- package/dist/router-v6.cjs.js +84 -0
- package/dist/router-v6.d.ts +20 -0
- package/dist/router-v6.es.js +61 -0
- package/dist/router-v7.cjs.js +83 -0
- package/dist/router-v7.d.ts +20 -0
- package/dist/router-v7.es.js +61 -0
- package/dist/router.cjs.js +82 -0
- package/dist/router.d.ts +20 -0
- package/dist/router.es.js +60 -0
- package/dist/utils-dUgb9Jkm.mjs +2016 -0
- package/dist/utils-tM9yE73c.js +2015 -0
- package/dist/v18.cjs.js +15 -0
- package/dist/v18.d.ts +114 -0
- package/dist/v18.es.js +15 -0
- package/dist/v19.cjs.js +15 -0
- package/dist/v19.d.ts +115 -0
- package/dist/v19.es.js +15 -0
- package/jest.config.ts +21 -0
- package/package.json +173 -0
- package/project.json +23 -0
- package/src/base.ts +50 -0
- package/src/index.ts +50 -0
- package/src/lazy/AwaitDataFetch.tsx +215 -0
- package/src/lazy/constant.ts +30 -0
- package/src/lazy/createLazyComponent.tsx +411 -0
- package/src/lazy/data-fetch/cache.ts +291 -0
- package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
- package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
- package/src/lazy/data-fetch/index.ts +16 -0
- package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
- package/src/lazy/data-fetch/prefetch.ts +112 -0
- package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
- package/src/lazy/index.ts +35 -0
- package/src/lazy/logger.ts +6 -0
- package/src/lazy/types.ts +75 -0
- package/src/lazy/utils.ts +372 -0
- package/src/lazy/wrapNoSSR.tsx +10 -0
- package/src/modern-app-env.d.ts +2 -0
- package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
- package/src/plugins/lazy-load-component-plugin.ts +57 -0
- package/src/provider/context.tsx +4 -0
- package/src/provider/plugin.ts +22 -0
- package/src/provider/versions/bridge-base.tsx +150 -0
- package/src/provider/versions/legacy.ts +87 -0
- package/src/provider/versions/v18.ts +47 -0
- package/src/provider/versions/v19.ts +48 -0
- package/src/remote/RemoteAppWrapper.tsx +108 -0
- package/src/remote/base-component/component.tsx +2 -0
- package/src/remote/base-component/create.tsx +23 -0
- package/src/remote/base-component/index.tsx +10 -0
- package/src/remote/createHelpers.tsx +130 -0
- package/src/remote/router-component/component.tsx +104 -0
- package/src/remote/router-component/create.tsx +23 -0
- package/src/remote/router-component/index.tsx +10 -0
- package/src/router/default.tsx +73 -0
- package/src/router/v5.tsx +43 -0
- package/src/router/v6.tsx +74 -0
- package/src/router/v7.tsx +75 -0
- package/src/types.ts +147 -0
- package/src/utils/index.ts +44 -0
- package/src/v18.ts +9 -0
- package/src/v19.ts +9 -0
- package/tsconfig.json +42 -0
- package/tsconfig.node.json +11 -0
- package/tsconfig.spec.json +26 -0
- package/vite.config.ts +112 -0
- package/vitest.config.ts +27 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Component, createElement, createContext } from "react";
|
|
3
|
+
import { L as LoggerInstance, R as RouterContext } from "./index-DyQNwY2M.mjs";
|
|
4
|
+
import { federationRuntime } from "./plugin.es.js";
|
|
5
|
+
const ErrorBoundaryContext = createContext(null);
|
|
6
|
+
const initialState = {
|
|
7
|
+
didCatch: false,
|
|
8
|
+
error: null
|
|
9
|
+
};
|
|
10
|
+
class ErrorBoundary extends Component {
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super(props);
|
|
13
|
+
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
14
|
+
this.state = initialState;
|
|
15
|
+
}
|
|
16
|
+
static getDerivedStateFromError(error) {
|
|
17
|
+
return {
|
|
18
|
+
didCatch: true,
|
|
19
|
+
error
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
resetErrorBoundary() {
|
|
23
|
+
const {
|
|
24
|
+
error
|
|
25
|
+
} = this.state;
|
|
26
|
+
if (error !== null) {
|
|
27
|
+
var _this$props$onReset, _this$props;
|
|
28
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
29
|
+
args[_key] = arguments[_key];
|
|
30
|
+
}
|
|
31
|
+
(_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
|
|
32
|
+
args,
|
|
33
|
+
reason: "imperative-api"
|
|
34
|
+
});
|
|
35
|
+
this.setState(initialState);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
componentDidCatch(error, info) {
|
|
39
|
+
var _this$props$onError, _this$props2;
|
|
40
|
+
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
41
|
+
}
|
|
42
|
+
componentDidUpdate(prevProps, prevState) {
|
|
43
|
+
const {
|
|
44
|
+
didCatch
|
|
45
|
+
} = this.state;
|
|
46
|
+
const {
|
|
47
|
+
resetKeys
|
|
48
|
+
} = this.props;
|
|
49
|
+
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
50
|
+
var _this$props$onReset2, _this$props3;
|
|
51
|
+
(_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
|
|
52
|
+
next: resetKeys,
|
|
53
|
+
prev: prevProps.resetKeys,
|
|
54
|
+
reason: "keys"
|
|
55
|
+
});
|
|
56
|
+
this.setState(initialState);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
render() {
|
|
60
|
+
const {
|
|
61
|
+
children,
|
|
62
|
+
fallbackRender,
|
|
63
|
+
FallbackComponent,
|
|
64
|
+
fallback
|
|
65
|
+
} = this.props;
|
|
66
|
+
const {
|
|
67
|
+
didCatch,
|
|
68
|
+
error
|
|
69
|
+
} = this.state;
|
|
70
|
+
let childToRender = children;
|
|
71
|
+
if (didCatch) {
|
|
72
|
+
const props = {
|
|
73
|
+
error,
|
|
74
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
75
|
+
};
|
|
76
|
+
if (typeof fallbackRender === "function") {
|
|
77
|
+
childToRender = fallbackRender(props);
|
|
78
|
+
} else if (FallbackComponent) {
|
|
79
|
+
childToRender = createElement(FallbackComponent, props);
|
|
80
|
+
} else if (fallback !== void 0) {
|
|
81
|
+
childToRender = fallback;
|
|
82
|
+
} else {
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return createElement(ErrorBoundaryContext.Provider, {
|
|
87
|
+
value: {
|
|
88
|
+
didCatch,
|
|
89
|
+
error,
|
|
90
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
91
|
+
}
|
|
92
|
+
}, childToRender);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function hasArrayChanged() {
|
|
96
|
+
let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
97
|
+
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
98
|
+
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
99
|
+
}
|
|
100
|
+
function createBaseBridgeComponent({
|
|
101
|
+
createRoot,
|
|
102
|
+
defaultRootOptions,
|
|
103
|
+
...bridgeInfo
|
|
104
|
+
}) {
|
|
105
|
+
return () => {
|
|
106
|
+
const rootMap = /* @__PURE__ */ new Map();
|
|
107
|
+
const instance = federationRuntime.instance;
|
|
108
|
+
LoggerInstance.debug(
|
|
109
|
+
`createBridgeComponent instance from props >>>`,
|
|
110
|
+
instance
|
|
111
|
+
);
|
|
112
|
+
const RawComponent = (info) => {
|
|
113
|
+
const { appInfo, propsInfo, ...restProps } = info;
|
|
114
|
+
const { moduleName, memoryRoute, basename = "/" } = appInfo;
|
|
115
|
+
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(
|
|
116
|
+
bridgeInfo.rootComponent,
|
|
117
|
+
{
|
|
118
|
+
...propsInfo,
|
|
119
|
+
basename,
|
|
120
|
+
...restProps
|
|
121
|
+
}
|
|
122
|
+
));
|
|
123
|
+
};
|
|
124
|
+
const DefaultFallback = ({ error }) => /* @__PURE__ */ React.createElement("div", { role: "alert" }, /* @__PURE__ */ React.createElement("p", null, "Something went wrong:"), /* @__PURE__ */ React.createElement("pre", { style: { color: "red" } }, error.message));
|
|
125
|
+
const BridgeWrapper = ({
|
|
126
|
+
basename,
|
|
127
|
+
moduleName,
|
|
128
|
+
memoryRoute,
|
|
129
|
+
propsInfo,
|
|
130
|
+
fallback
|
|
131
|
+
}) => /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback || DefaultFallback }, /* @__PURE__ */ React.createElement(
|
|
132
|
+
RawComponent,
|
|
133
|
+
{
|
|
134
|
+
appInfo: {
|
|
135
|
+
moduleName,
|
|
136
|
+
basename,
|
|
137
|
+
memoryRoute
|
|
138
|
+
},
|
|
139
|
+
propsInfo
|
|
140
|
+
}
|
|
141
|
+
));
|
|
142
|
+
return {
|
|
143
|
+
async render(info) {
|
|
144
|
+
var _a, _b, _c, _d, _e, _f;
|
|
145
|
+
LoggerInstance.debug(`createBridgeComponent render Info`, info);
|
|
146
|
+
const {
|
|
147
|
+
moduleName,
|
|
148
|
+
dom,
|
|
149
|
+
basename,
|
|
150
|
+
memoryRoute,
|
|
151
|
+
fallback,
|
|
152
|
+
rootOptions,
|
|
153
|
+
...propsInfo
|
|
154
|
+
} = info;
|
|
155
|
+
const mergedRootOptions = {
|
|
156
|
+
...defaultRootOptions,
|
|
157
|
+
...rootOptions
|
|
158
|
+
};
|
|
159
|
+
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)) || {};
|
|
160
|
+
const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(
|
|
161
|
+
BridgeWrapper,
|
|
162
|
+
{
|
|
163
|
+
basename,
|
|
164
|
+
moduleName,
|
|
165
|
+
memoryRoute,
|
|
166
|
+
fallback,
|
|
167
|
+
propsInfo: {
|
|
168
|
+
...propsInfo,
|
|
169
|
+
basename,
|
|
170
|
+
...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
if (bridgeInfo.render) {
|
|
175
|
+
await Promise.resolve(
|
|
176
|
+
bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
177
|
+
).then((root) => rootMap.set(dom, root));
|
|
178
|
+
} else {
|
|
179
|
+
let root = rootMap.get(dom);
|
|
180
|
+
if (!root && createRoot) {
|
|
181
|
+
root = createRoot(dom, mergedRootOptions);
|
|
182
|
+
rootMap.set(dom, root);
|
|
183
|
+
}
|
|
184
|
+
if (root && "render" in root) {
|
|
185
|
+
root.render(rootComponentWithErrorBoundary);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
((_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)) || {};
|
|
189
|
+
},
|
|
190
|
+
destroy(info) {
|
|
191
|
+
var _a, _b, _c;
|
|
192
|
+
const { dom } = info;
|
|
193
|
+
LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
194
|
+
const root = rootMap.get(dom);
|
|
195
|
+
if (root) {
|
|
196
|
+
if ("unmount" in root) {
|
|
197
|
+
root.unmount();
|
|
198
|
+
} else {
|
|
199
|
+
LoggerInstance.warn("Root does not have unmount method");
|
|
200
|
+
}
|
|
201
|
+
rootMap.delete(dom);
|
|
202
|
+
}
|
|
203
|
+
(_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);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
export {
|
|
209
|
+
ErrorBoundary as E,
|
|
210
|
+
createBaseBridgeComponent as c
|
|
211
|
+
};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const React = require("react");
|
|
3
|
+
const index = require("./index-DRSBaSu3.js");
|
|
4
|
+
const plugin = require("./plugin.cjs.js");
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
+
if (e) {
|
|
8
|
+
for (const k in e) {
|
|
9
|
+
if (k !== "default") {
|
|
10
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: () => e[k]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
22
|
+
const ErrorBoundaryContext = React.createContext(null);
|
|
23
|
+
const initialState = {
|
|
24
|
+
didCatch: false,
|
|
25
|
+
error: null
|
|
26
|
+
};
|
|
27
|
+
class ErrorBoundary extends React.Component {
|
|
28
|
+
constructor(props) {
|
|
29
|
+
super(props);
|
|
30
|
+
this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
|
|
31
|
+
this.state = initialState;
|
|
32
|
+
}
|
|
33
|
+
static getDerivedStateFromError(error) {
|
|
34
|
+
return {
|
|
35
|
+
didCatch: true,
|
|
36
|
+
error
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
resetErrorBoundary() {
|
|
40
|
+
const {
|
|
41
|
+
error
|
|
42
|
+
} = this.state;
|
|
43
|
+
if (error !== null) {
|
|
44
|
+
var _this$props$onReset, _this$props;
|
|
45
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
46
|
+
args[_key] = arguments[_key];
|
|
47
|
+
}
|
|
48
|
+
(_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
|
|
49
|
+
args,
|
|
50
|
+
reason: "imperative-api"
|
|
51
|
+
});
|
|
52
|
+
this.setState(initialState);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
componentDidCatch(error, info) {
|
|
56
|
+
var _this$props$onError, _this$props2;
|
|
57
|
+
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
|
|
58
|
+
}
|
|
59
|
+
componentDidUpdate(prevProps, prevState) {
|
|
60
|
+
const {
|
|
61
|
+
didCatch
|
|
62
|
+
} = this.state;
|
|
63
|
+
const {
|
|
64
|
+
resetKeys
|
|
65
|
+
} = this.props;
|
|
66
|
+
if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
|
|
67
|
+
var _this$props$onReset2, _this$props3;
|
|
68
|
+
(_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
|
|
69
|
+
next: resetKeys,
|
|
70
|
+
prev: prevProps.resetKeys,
|
|
71
|
+
reason: "keys"
|
|
72
|
+
});
|
|
73
|
+
this.setState(initialState);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
render() {
|
|
77
|
+
const {
|
|
78
|
+
children,
|
|
79
|
+
fallbackRender,
|
|
80
|
+
FallbackComponent,
|
|
81
|
+
fallback
|
|
82
|
+
} = this.props;
|
|
83
|
+
const {
|
|
84
|
+
didCatch,
|
|
85
|
+
error
|
|
86
|
+
} = this.state;
|
|
87
|
+
let childToRender = children;
|
|
88
|
+
if (didCatch) {
|
|
89
|
+
const props = {
|
|
90
|
+
error,
|
|
91
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
92
|
+
};
|
|
93
|
+
if (typeof fallbackRender === "function") {
|
|
94
|
+
childToRender = fallbackRender(props);
|
|
95
|
+
} else if (FallbackComponent) {
|
|
96
|
+
childToRender = React.createElement(FallbackComponent, props);
|
|
97
|
+
} else if (fallback !== void 0) {
|
|
98
|
+
childToRender = fallback;
|
|
99
|
+
} else {
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return React.createElement(ErrorBoundaryContext.Provider, {
|
|
104
|
+
value: {
|
|
105
|
+
didCatch,
|
|
106
|
+
error,
|
|
107
|
+
resetErrorBoundary: this.resetErrorBoundary
|
|
108
|
+
}
|
|
109
|
+
}, childToRender);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function hasArrayChanged() {
|
|
113
|
+
let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
114
|
+
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
115
|
+
return a.length !== b.length || a.some((item, index2) => !Object.is(item, b[index2]));
|
|
116
|
+
}
|
|
117
|
+
function createBaseBridgeComponent({
|
|
118
|
+
createRoot,
|
|
119
|
+
defaultRootOptions,
|
|
120
|
+
...bridgeInfo
|
|
121
|
+
}) {
|
|
122
|
+
return () => {
|
|
123
|
+
const rootMap = /* @__PURE__ */ new Map();
|
|
124
|
+
const instance = plugin.federationRuntime.instance;
|
|
125
|
+
index.LoggerInstance.debug(
|
|
126
|
+
`createBridgeComponent instance from props >>>`,
|
|
127
|
+
instance
|
|
128
|
+
);
|
|
129
|
+
const RawComponent = (info) => {
|
|
130
|
+
const { appInfo, propsInfo, ...restProps } = info;
|
|
131
|
+
const { moduleName, memoryRoute, basename = "/" } = appInfo;
|
|
132
|
+
return /* @__PURE__ */ React__namespace.createElement(index.RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(
|
|
133
|
+
bridgeInfo.rootComponent,
|
|
134
|
+
{
|
|
135
|
+
...propsInfo,
|
|
136
|
+
basename,
|
|
137
|
+
...restProps
|
|
138
|
+
}
|
|
139
|
+
));
|
|
140
|
+
};
|
|
141
|
+
const DefaultFallback = ({ error }) => /* @__PURE__ */ React__namespace.createElement("div", { role: "alert" }, /* @__PURE__ */ React__namespace.createElement("p", null, "Something went wrong:"), /* @__PURE__ */ React__namespace.createElement("pre", { style: { color: "red" } }, error.message));
|
|
142
|
+
const BridgeWrapper = ({
|
|
143
|
+
basename,
|
|
144
|
+
moduleName,
|
|
145
|
+
memoryRoute,
|
|
146
|
+
propsInfo,
|
|
147
|
+
fallback
|
|
148
|
+
}) => /* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback || DefaultFallback }, /* @__PURE__ */ React__namespace.createElement(
|
|
149
|
+
RawComponent,
|
|
150
|
+
{
|
|
151
|
+
appInfo: {
|
|
152
|
+
moduleName,
|
|
153
|
+
basename,
|
|
154
|
+
memoryRoute
|
|
155
|
+
},
|
|
156
|
+
propsInfo
|
|
157
|
+
}
|
|
158
|
+
));
|
|
159
|
+
return {
|
|
160
|
+
async render(info) {
|
|
161
|
+
var _a, _b, _c, _d, _e, _f;
|
|
162
|
+
index.LoggerInstance.debug(`createBridgeComponent render Info`, info);
|
|
163
|
+
const {
|
|
164
|
+
moduleName,
|
|
165
|
+
dom,
|
|
166
|
+
basename,
|
|
167
|
+
memoryRoute,
|
|
168
|
+
fallback,
|
|
169
|
+
rootOptions,
|
|
170
|
+
...propsInfo
|
|
171
|
+
} = info;
|
|
172
|
+
const mergedRootOptions = {
|
|
173
|
+
...defaultRootOptions,
|
|
174
|
+
...rootOptions
|
|
175
|
+
};
|
|
176
|
+
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)) || {};
|
|
177
|
+
const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(
|
|
178
|
+
BridgeWrapper,
|
|
179
|
+
{
|
|
180
|
+
basename,
|
|
181
|
+
moduleName,
|
|
182
|
+
memoryRoute,
|
|
183
|
+
fallback,
|
|
184
|
+
propsInfo: {
|
|
185
|
+
...propsInfo,
|
|
186
|
+
basename,
|
|
187
|
+
...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
if (bridgeInfo.render) {
|
|
192
|
+
await Promise.resolve(
|
|
193
|
+
bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
194
|
+
).then((root) => rootMap.set(dom, root));
|
|
195
|
+
} else {
|
|
196
|
+
let root = rootMap.get(dom);
|
|
197
|
+
if (!root && createRoot) {
|
|
198
|
+
root = createRoot(dom, mergedRootOptions);
|
|
199
|
+
rootMap.set(dom, root);
|
|
200
|
+
}
|
|
201
|
+
if (root && "render" in root) {
|
|
202
|
+
root.render(rootComponentWithErrorBoundary);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
((_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)) || {};
|
|
206
|
+
},
|
|
207
|
+
destroy(info) {
|
|
208
|
+
var _a, _b, _c;
|
|
209
|
+
const { dom } = info;
|
|
210
|
+
index.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
211
|
+
const root = rootMap.get(dom);
|
|
212
|
+
if (root) {
|
|
213
|
+
if ("unmount" in root) {
|
|
214
|
+
root.unmount();
|
|
215
|
+
} else {
|
|
216
|
+
index.LoggerInstance.warn("Root does not have unmount method");
|
|
217
|
+
}
|
|
218
|
+
rootMap.delete(dom);
|
|
219
|
+
}
|
|
220
|
+
(_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);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
226
|
+
exports.createBaseBridgeComponent = createBaseBridgeComponent;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const bridgeBase = require("./bridge-base-RStDxH71.js");
|
|
3
|
+
const ReactDOM = require("react-dom");
|
|
4
|
+
const index = require("./index-DRSBaSu3.js");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const plugin = require("./plugin.cjs.js");
|
|
7
|
+
function createReact16Or17Root(container) {
|
|
8
|
+
return {
|
|
9
|
+
render(children) {
|
|
10
|
+
const reactVersion = ReactDOM.version || "";
|
|
11
|
+
const isReact18 = reactVersion.startsWith("18");
|
|
12
|
+
const isReact19 = reactVersion.startsWith("19");
|
|
13
|
+
if (isReact19) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`React 19 detected in legacy mode. This is not supported. Please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v19'`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
if (isReact18) {
|
|
19
|
+
index.LoggerInstance.warn(
|
|
20
|
+
`[Bridge-React] React 18 detected in legacy mode. For better compatibility, please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v18'`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
ReactDOM.render(children, container);
|
|
24
|
+
},
|
|
25
|
+
unmount() {
|
|
26
|
+
ReactDOM.unmountComponentAtNode(container);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createBridgeComponent(bridgeInfo) {
|
|
31
|
+
const fullBridgeInfo = {
|
|
32
|
+
createRoot: createReact16Or17Root,
|
|
33
|
+
...bridgeInfo
|
|
34
|
+
};
|
|
35
|
+
return bridgeBase.createBaseBridgeComponent(fullBridgeInfo);
|
|
36
|
+
}
|
|
37
|
+
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
38
|
+
const {
|
|
39
|
+
moduleName,
|
|
40
|
+
memoryRoute,
|
|
41
|
+
basename,
|
|
42
|
+
providerInfo,
|
|
43
|
+
className,
|
|
44
|
+
style,
|
|
45
|
+
fallback,
|
|
46
|
+
loading,
|
|
47
|
+
...resProps
|
|
48
|
+
} = props;
|
|
49
|
+
const instance = plugin.federationRuntime.instance;
|
|
50
|
+
const rootRef = ref && "current" in ref ? ref : React.useRef(null);
|
|
51
|
+
const renderDom = React.useRef(null);
|
|
52
|
+
const providerInfoRef = React.useRef(null);
|
|
53
|
+
const [initialized, setInitialized] = React.useState(false);
|
|
54
|
+
index.LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
if (initialized) return;
|
|
57
|
+
const providerReturn = providerInfo();
|
|
58
|
+
providerInfoRef.current = providerReturn;
|
|
59
|
+
setInitialized(true);
|
|
60
|
+
return () => {
|
|
61
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
62
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
63
|
+
index.LoggerInstance.debug(
|
|
64
|
+
`createRemoteAppComponent LazyComponent destroy >>>`,
|
|
65
|
+
{ moduleName, basename, dom: renderDom.current }
|
|
66
|
+
);
|
|
67
|
+
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
68
|
+
moduleName,
|
|
69
|
+
dom: renderDom.current,
|
|
70
|
+
basename,
|
|
71
|
+
memoryRoute,
|
|
72
|
+
fallback,
|
|
73
|
+
...resProps
|
|
74
|
+
});
|
|
75
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
76
|
+
moduleName,
|
|
77
|
+
dom: renderDom.current
|
|
78
|
+
});
|
|
79
|
+
(_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
80
|
+
moduleName,
|
|
81
|
+
dom: renderDom.current,
|
|
82
|
+
basename,
|
|
83
|
+
memoryRoute,
|
|
84
|
+
fallback,
|
|
85
|
+
...resProps
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}, [moduleName]);
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
var _a, _b, _c, _d, _e, _f;
|
|
92
|
+
if (!initialized || !providerInfoRef.current) return;
|
|
93
|
+
let renderProps = {
|
|
94
|
+
moduleName,
|
|
95
|
+
dom: rootRef.current,
|
|
96
|
+
basename,
|
|
97
|
+
memoryRoute,
|
|
98
|
+
fallback,
|
|
99
|
+
...resProps
|
|
100
|
+
};
|
|
101
|
+
renderDom.current = rootRef.current;
|
|
102
|
+
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)) || {};
|
|
103
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
104
|
+
providerInfoRef.current.render(renderProps);
|
|
105
|
+
(_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);
|
|
106
|
+
}, [initialized, ...Object.values(props)]);
|
|
107
|
+
const rootComponentClassName = `${index.getRootDomDefaultClassName(moduleName)} ${className || ""}`;
|
|
108
|
+
return /* @__PURE__ */ React.createElement("div", { className: rootComponentClassName, style, ref: rootRef }, loading);
|
|
109
|
+
});
|
|
110
|
+
function createLazyRemoteComponentFactory(RemoteApp) {
|
|
111
|
+
return function createLazyRemoteComponent(info) {
|
|
112
|
+
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
113
|
+
return React.lazy(async () => {
|
|
114
|
+
index.LoggerInstance.debug(
|
|
115
|
+
`createRemoteAppComponent LazyComponent create >>>`,
|
|
116
|
+
{
|
|
117
|
+
lazyComponent: info.loader,
|
|
118
|
+
exportName
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
try {
|
|
122
|
+
const m = await info.loader();
|
|
123
|
+
const moduleName = m && m[Symbol.for("mf_module_id")];
|
|
124
|
+
index.LoggerInstance.debug(
|
|
125
|
+
`createRemoteAppComponent LazyComponent loadRemote info >>>`,
|
|
126
|
+
{ name: moduleName, module: m, exportName }
|
|
127
|
+
);
|
|
128
|
+
const exportFn = m[exportName];
|
|
129
|
+
if (exportName in m && typeof exportFn === "function") {
|
|
130
|
+
const RemoteAppComponent = React.forwardRef((props, ref) => {
|
|
131
|
+
return /* @__PURE__ */ React.createElement(
|
|
132
|
+
RemoteApp,
|
|
133
|
+
{
|
|
134
|
+
moduleName,
|
|
135
|
+
providerInfo: exportFn,
|
|
136
|
+
exportName: info.export || "default",
|
|
137
|
+
fallback: info.fallback,
|
|
138
|
+
loading: info.loading,
|
|
139
|
+
ref,
|
|
140
|
+
...props
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
default: RemoteAppComponent
|
|
146
|
+
};
|
|
147
|
+
} else {
|
|
148
|
+
index.LoggerInstance.debug(
|
|
149
|
+
`createRemoteAppComponent LazyComponent module not found >>>`,
|
|
150
|
+
{ name: moduleName, module: m, exportName }
|
|
151
|
+
);
|
|
152
|
+
throw Error(
|
|
153
|
+
`Make sure that ${moduleName} has the correct export when export is ${String(
|
|
154
|
+
exportName
|
|
155
|
+
)}`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function createRemoteAppComponentFactory(RemoteApp) {
|
|
165
|
+
const createLazyRemoteComponent = createLazyRemoteComponentFactory(RemoteApp);
|
|
166
|
+
return function createRemoteAppComponent(info) {
|
|
167
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
168
|
+
return React.forwardRef((props, ref) => {
|
|
169
|
+
return /* @__PURE__ */ React.createElement(
|
|
170
|
+
bridgeBase.ErrorBoundary,
|
|
171
|
+
{
|
|
172
|
+
FallbackComponent: info.fallback
|
|
173
|
+
},
|
|
174
|
+
/* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref }))
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function createDeprecatedRemoteComponentFactory(createFn) {
|
|
180
|
+
return function createRemoteComponent(info) {
|
|
181
|
+
index.LoggerInstance.warn(
|
|
182
|
+
`createRemoteComponent is deprecated, please use createRemoteAppComponent instead!`
|
|
183
|
+
);
|
|
184
|
+
return createFn(info);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
exports.RemoteAppWrapper = RemoteAppWrapper;
|
|
188
|
+
exports.createBridgeComponent = createBridgeComponent;
|
|
189
|
+
exports.createDeprecatedRemoteComponentFactory = createDeprecatedRemoteComponentFactory;
|
|
190
|
+
exports.createRemoteAppComponentFactory = createRemoteAppComponentFactory;
|