@module-federation/bridge-react 0.0.0-next-20250223132729 → 0.0.0-next-20250224060203
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 +10 -5
- package/dist/index.cjs.js +88 -74
- package/dist/index.es.js +89 -75
- package/package.json +4 -4
- package/src/provider/create.tsx +3 -8
- package/src/remote/component.tsx +96 -82
- package/src/remote/create.tsx +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20250224060203
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [624ad6b]
|
|
8
|
+
- Updated dependencies [5d988c2]
|
|
9
|
+
- @module-federation/sdk@0.0.0-next-20250224060203
|
|
10
|
+
- @module-federation/bridge-shared@0.0.0-next-20250224060203
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
## 0.9.0
|
|
8
13
|
|
|
9
14
|
### Patch Changes
|
|
10
15
|
|
|
11
|
-
- @module-federation/sdk@0.
|
|
12
|
-
- @module-federation/bridge-shared@0.
|
|
16
|
+
- @module-federation/sdk@0.9.0
|
|
17
|
+
- @module-federation/bridge-shared@0.9.0
|
|
13
18
|
|
|
14
19
|
## 0.8.12
|
|
15
20
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -123,78 +123,97 @@ function e() {
|
|
|
123
123
|
window.dispatchEvent(t);
|
|
124
124
|
}
|
|
125
125
|
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
126
|
-
const {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
150
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
151
|
-
context.LoggerInstance.debug(
|
|
152
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
153
|
-
{ moduleName, basename, dom: renderDom.current }
|
|
154
|
-
);
|
|
155
|
-
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
156
|
-
moduleName,
|
|
157
|
-
dom: renderDom.current,
|
|
158
|
-
basename,
|
|
159
|
-
memoryRoute,
|
|
160
|
-
fallback,
|
|
161
|
-
...resProps
|
|
162
|
-
});
|
|
163
|
-
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
164
|
-
moduleName,
|
|
165
|
-
dom: renderDom.current
|
|
166
|
-
});
|
|
167
|
-
(_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
126
|
+
const RemoteApp2 = () => {
|
|
127
|
+
context.LoggerInstance.debug(`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 instance = plugin.federationRuntime.instance;
|
|
139
|
+
const rootRef = ref && "current" in ref ? ref : React.useRef(null);
|
|
140
|
+
const renderDom = React.useRef(null);
|
|
141
|
+
const providerInfoRef = React.useRef(null);
|
|
142
|
+
context.LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
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 = {
|
|
168
149
|
moduleName,
|
|
169
|
-
dom:
|
|
150
|
+
dom: rootRef.current,
|
|
170
151
|
basename,
|
|
171
152
|
memoryRoute,
|
|
172
153
|
fallback,
|
|
173
154
|
...resProps
|
|
155
|
+
};
|
|
156
|
+
renderDom.current = rootRef.current;
|
|
157
|
+
context.LoggerInstance.debug(
|
|
158
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
159
|
+
renderProps
|
|
160
|
+
);
|
|
161
|
+
context.LoggerInstance.debug(
|
|
162
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
163
|
+
instance
|
|
164
|
+
);
|
|
165
|
+
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(
|
|
166
|
+
renderProps
|
|
167
|
+
)) || {};
|
|
168
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
169
|
+
providerReturn.render(renderProps);
|
|
170
|
+
(_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);
|
|
171
|
+
});
|
|
172
|
+
return () => {
|
|
173
|
+
clearTimeout(renderTimeout);
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
176
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
177
|
+
context.LoggerInstance.debug(
|
|
178
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
179
|
+
{ moduleName, basename, dom: renderDom.current }
|
|
180
|
+
);
|
|
181
|
+
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
182
|
+
moduleName,
|
|
183
|
+
dom: renderDom.current,
|
|
184
|
+
basename,
|
|
185
|
+
memoryRoute,
|
|
186
|
+
fallback,
|
|
187
|
+
...resProps
|
|
188
|
+
});
|
|
189
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
190
|
+
moduleName,
|
|
191
|
+
dom: renderDom.current
|
|
192
|
+
});
|
|
193
|
+
(_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
194
|
+
moduleName,
|
|
195
|
+
dom: renderDom.current,
|
|
196
|
+
basename,
|
|
197
|
+
memoryRoute,
|
|
198
|
+
fallback,
|
|
199
|
+
...resProps
|
|
200
|
+
});
|
|
201
|
+
}
|
|
174
202
|
});
|
|
203
|
+
};
|
|
204
|
+
}, []);
|
|
205
|
+
const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
206
|
+
return /* @__PURE__ */ React.createElement(
|
|
207
|
+
"div",
|
|
208
|
+
{
|
|
209
|
+
className: rootComponentClassName,
|
|
210
|
+
style: props == null ? void 0 : props.style,
|
|
211
|
+
ref: rootRef
|
|
175
212
|
}
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (!initialized || !providerInfoRef.current)
|
|
181
|
-
return;
|
|
182
|
-
let renderProps = {
|
|
183
|
-
moduleName,
|
|
184
|
-
dom: rootRef.current,
|
|
185
|
-
basename,
|
|
186
|
-
memoryRoute,
|
|
187
|
-
fallback,
|
|
188
|
-
...resProps
|
|
189
|
-
};
|
|
190
|
-
renderDom.current = rootRef.current;
|
|
191
|
-
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)) || {};
|
|
192
|
-
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
193
|
-
providerInfoRef.current.render(renderProps);
|
|
194
|
-
(_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);
|
|
195
|
-
}, [initialized, ...Object.values(props)]);
|
|
196
|
-
const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${className || ""}`;
|
|
197
|
-
return /* @__PURE__ */ React.createElement("div", { className: rootComponentClassName, style, ref: rootRef });
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
RemoteApp2["__APP_VERSION__"] = "0.9.0";
|
|
216
|
+
return /* @__PURE__ */ React.createElement(RemoteApp2, null);
|
|
198
217
|
});
|
|
199
218
|
function withRouterData(WrappedComponent) {
|
|
200
219
|
const Component = React.forwardRef(function(props, ref) {
|
|
@@ -317,9 +336,9 @@ function createLazyRemoteComponent(info) {
|
|
|
317
336
|
});
|
|
318
337
|
}
|
|
319
338
|
function createRemoteComponent(info) {
|
|
320
|
-
const LazyComponent = createLazyRemoteComponent(info);
|
|
321
339
|
return React.forwardRef(
|
|
322
340
|
(props, ref) => {
|
|
341
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
323
342
|
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref })));
|
|
324
343
|
}
|
|
325
344
|
);
|
|
@@ -387,13 +406,9 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
387
406
|
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
388
407
|
).then((root) => rootMap.set(info.dom, root));
|
|
389
408
|
} else {
|
|
390
|
-
|
|
391
|
-
let root = rootMap.get(info.dom);
|
|
392
|
-
if (!root) {
|
|
393
|
-
root = createRoot(info.dom);
|
|
394
|
-
rootMap.set(info.dom, root);
|
|
395
|
-
}
|
|
409
|
+
const root = createRoot(info.dom);
|
|
396
410
|
root.render(rootComponentWithErrorBoundary);
|
|
411
|
+
rootMap.set(info.dom, root);
|
|
397
412
|
}
|
|
398
413
|
((_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)) || {};
|
|
399
414
|
},
|
|
@@ -401,7 +416,6 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
401
416
|
var _a, _b, _c;
|
|
402
417
|
context.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
403
418
|
const root = rootMap.get(info.dom);
|
|
404
|
-
console.log("--------createBridgeComponent destroy Info", info);
|
|
405
419
|
if (root) {
|
|
406
420
|
if ("unmount" in root) {
|
|
407
421
|
root.unmount();
|
|
@@ -410,7 +424,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
410
424
|
}
|
|
411
425
|
rootMap.delete(info.dom);
|
|
412
426
|
}
|
|
413
|
-
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.
|
|
427
|
+
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.destroyBridge) == null ? void 0 : _c.emit(info);
|
|
414
428
|
}
|
|
415
429
|
};
|
|
416
430
|
};
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import React__default, { createContext, Component, createElement, forwardRef, useRef,
|
|
2
|
+
import React__default, { createContext, Component, createElement, forwardRef, useRef, useEffect, useContext, useState } from "react";
|
|
3
3
|
import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, R as RouterContext } from "./context-BwUPFSB2.js";
|
|
4
4
|
import * as ReactRouterDOM from "react-router-dom";
|
|
5
5
|
import { federationRuntime } from "./plugin.es.js";
|
|
@@ -104,78 +104,97 @@ function e() {
|
|
|
104
104
|
window.dispatchEvent(t);
|
|
105
105
|
}
|
|
106
106
|
const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
107
|
-
const {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
131
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
132
|
-
LoggerInstance.debug(
|
|
133
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
134
|
-
{ moduleName, basename, dom: renderDom.current }
|
|
135
|
-
);
|
|
136
|
-
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
137
|
-
moduleName,
|
|
138
|
-
dom: renderDom.current,
|
|
139
|
-
basename,
|
|
140
|
-
memoryRoute,
|
|
141
|
-
fallback,
|
|
142
|
-
...resProps
|
|
143
|
-
});
|
|
144
|
-
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
145
|
-
moduleName,
|
|
146
|
-
dom: renderDom.current
|
|
147
|
-
});
|
|
148
|
-
(_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
107
|
+
const RemoteApp2 = () => {
|
|
108
|
+
LoggerInstance.debug(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
109
|
+
const {
|
|
110
|
+
moduleName,
|
|
111
|
+
memoryRoute,
|
|
112
|
+
basename,
|
|
113
|
+
providerInfo,
|
|
114
|
+
className,
|
|
115
|
+
style,
|
|
116
|
+
fallback,
|
|
117
|
+
...resProps
|
|
118
|
+
} = props;
|
|
119
|
+
const instance = federationRuntime.instance;
|
|
120
|
+
const rootRef = ref && "current" in ref ? ref : useRef(null);
|
|
121
|
+
const renderDom = useRef(null);
|
|
122
|
+
const providerInfoRef = useRef(null);
|
|
123
|
+
LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
const renderTimeout = setTimeout(() => {
|
|
126
|
+
var _a, _b, _c, _d, _e, _f;
|
|
127
|
+
const providerReturn = providerInfo();
|
|
128
|
+
providerInfoRef.current = providerReturn;
|
|
129
|
+
let renderProps = {
|
|
149
130
|
moduleName,
|
|
150
|
-
dom:
|
|
131
|
+
dom: rootRef.current,
|
|
151
132
|
basename,
|
|
152
133
|
memoryRoute,
|
|
153
134
|
fallback,
|
|
154
135
|
...resProps
|
|
136
|
+
};
|
|
137
|
+
renderDom.current = rootRef.current;
|
|
138
|
+
LoggerInstance.debug(
|
|
139
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
140
|
+
renderProps
|
|
141
|
+
);
|
|
142
|
+
LoggerInstance.debug(
|
|
143
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
144
|
+
instance
|
|
145
|
+
);
|
|
146
|
+
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(
|
|
147
|
+
renderProps
|
|
148
|
+
)) || {};
|
|
149
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
150
|
+
providerReturn.render(renderProps);
|
|
151
|
+
(_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);
|
|
152
|
+
});
|
|
153
|
+
return () => {
|
|
154
|
+
clearTimeout(renderTimeout);
|
|
155
|
+
setTimeout(() => {
|
|
156
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
157
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
158
|
+
LoggerInstance.debug(
|
|
159
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
160
|
+
{ moduleName, basename, dom: renderDom.current }
|
|
161
|
+
);
|
|
162
|
+
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
163
|
+
moduleName,
|
|
164
|
+
dom: renderDom.current,
|
|
165
|
+
basename,
|
|
166
|
+
memoryRoute,
|
|
167
|
+
fallback,
|
|
168
|
+
...resProps
|
|
169
|
+
});
|
|
170
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
171
|
+
moduleName,
|
|
172
|
+
dom: renderDom.current
|
|
173
|
+
});
|
|
174
|
+
(_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
175
|
+
moduleName,
|
|
176
|
+
dom: renderDom.current,
|
|
177
|
+
basename,
|
|
178
|
+
memoryRoute,
|
|
179
|
+
fallback,
|
|
180
|
+
...resProps
|
|
181
|
+
});
|
|
182
|
+
}
|
|
155
183
|
});
|
|
184
|
+
};
|
|
185
|
+
}, []);
|
|
186
|
+
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
|
|
187
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
188
|
+
"div",
|
|
189
|
+
{
|
|
190
|
+
className: rootComponentClassName,
|
|
191
|
+
style: props == null ? void 0 : props.style,
|
|
192
|
+
ref: rootRef
|
|
156
193
|
}
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (!initialized || !providerInfoRef.current)
|
|
162
|
-
return;
|
|
163
|
-
let renderProps = {
|
|
164
|
-
moduleName,
|
|
165
|
-
dom: rootRef.current,
|
|
166
|
-
basename,
|
|
167
|
-
memoryRoute,
|
|
168
|
-
fallback,
|
|
169
|
-
...resProps
|
|
170
|
-
};
|
|
171
|
-
renderDom.current = rootRef.current;
|
|
172
|
-
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)) || {};
|
|
173
|
-
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
174
|
-
providerInfoRef.current.render(renderProps);
|
|
175
|
-
(_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);
|
|
176
|
-
}, [initialized, ...Object.values(props)]);
|
|
177
|
-
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${className || ""}`;
|
|
178
|
-
return /* @__PURE__ */ React__default.createElement("div", { className: rootComponentClassName, style, ref: rootRef });
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
RemoteApp2["__APP_VERSION__"] = "0.9.0";
|
|
197
|
+
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
|
|
179
198
|
});
|
|
180
199
|
function withRouterData(WrappedComponent) {
|
|
181
200
|
const Component2 = forwardRef(function(props, ref) {
|
|
@@ -298,9 +317,9 @@ function createLazyRemoteComponent(info) {
|
|
|
298
317
|
});
|
|
299
318
|
}
|
|
300
319
|
function createRemoteComponent(info) {
|
|
301
|
-
const LazyComponent = createLazyRemoteComponent(info);
|
|
302
320
|
return forwardRef(
|
|
303
321
|
(props, ref) => {
|
|
322
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
304
323
|
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 })));
|
|
305
324
|
}
|
|
306
325
|
);
|
|
@@ -368,13 +387,9 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
368
387
|
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
|
|
369
388
|
).then((root) => rootMap.set(info.dom, root));
|
|
370
389
|
} else {
|
|
371
|
-
|
|
372
|
-
let root = rootMap.get(info.dom);
|
|
373
|
-
if (!root) {
|
|
374
|
-
root = createRoot(info.dom);
|
|
375
|
-
rootMap.set(info.dom, root);
|
|
376
|
-
}
|
|
390
|
+
const root = createRoot(info.dom);
|
|
377
391
|
root.render(rootComponentWithErrorBoundary);
|
|
392
|
+
rootMap.set(info.dom, root);
|
|
378
393
|
}
|
|
379
394
|
((_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)) || {};
|
|
380
395
|
},
|
|
@@ -382,7 +397,6 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
382
397
|
var _a, _b, _c;
|
|
383
398
|
LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
384
399
|
const root = rootMap.get(info.dom);
|
|
385
|
-
console.log("--------createBridgeComponent destroy Info", info);
|
|
386
400
|
if (root) {
|
|
387
401
|
if ("unmount" in root) {
|
|
388
402
|
root.unmount();
|
|
@@ -391,7 +405,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
391
405
|
}
|
|
392
406
|
rootMap.delete(info.dom);
|
|
393
407
|
}
|
|
394
|
-
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.
|
|
408
|
+
(_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.destroyBridge) == null ? void 0 : _c.emit(info);
|
|
395
409
|
}
|
|
396
410
|
};
|
|
397
411
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250224060203",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@loadable/component": "^5.16.4",
|
|
48
48
|
"react-error-boundary": "^4.1.2",
|
|
49
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
50
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
49
|
+
"@module-federation/bridge-shared": "0.0.0-next-20250224060203",
|
|
50
|
+
"@module-federation/sdk": "0.0.0-next-20250224060203"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": ">=16.9.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"typescript": "^5.2.2",
|
|
69
69
|
"vite": "^5.2.14",
|
|
70
70
|
"vite-plugin-dts": "^4.3.0",
|
|
71
|
-
"@module-federation/runtime": "0.0.0-next-
|
|
71
|
+
"@module-federation/runtime": "0.0.0-next-20250224060203"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"dev": "vite",
|
package/src/provider/create.tsx
CHANGED
|
@@ -86,13 +86,9 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
86
86
|
bridgeInfo?.render(rootComponentWithErrorBoundary, dom),
|
|
87
87
|
).then((root: RootType) => rootMap.set(info.dom, root));
|
|
88
88
|
} else {
|
|
89
|
-
|
|
90
|
-
let root = rootMap.get(info.dom);
|
|
91
|
-
if (!root) {
|
|
92
|
-
root = createRoot(info.dom);
|
|
93
|
-
rootMap.set(info.dom, root);
|
|
94
|
-
}
|
|
89
|
+
const root = createRoot(info.dom);
|
|
95
90
|
root.render(rootComponentWithErrorBoundary);
|
|
91
|
+
rootMap.set(info.dom, root);
|
|
96
92
|
}
|
|
97
93
|
|
|
98
94
|
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
|
|
@@ -101,7 +97,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
101
97
|
destroy(info: DestroyParams) {
|
|
102
98
|
LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
103
99
|
const root = rootMap.get(info.dom);
|
|
104
|
-
console.log('--------createBridgeComponent destroy Info', info);
|
|
105
100
|
if (root) {
|
|
106
101
|
if ('unmount' in root) {
|
|
107
102
|
root.unmount();
|
|
@@ -110,7 +105,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
110
105
|
}
|
|
111
106
|
rootMap.delete(info.dom);
|
|
112
107
|
}
|
|
113
|
-
instance?.bridgeHook?.lifecycle?.
|
|
108
|
+
instance?.bridgeHook?.lifecycle?.destroyBridge?.emit(info);
|
|
114
109
|
},
|
|
115
110
|
};
|
|
116
111
|
};
|
package/src/remote/component.tsx
CHANGED
|
@@ -40,98 +40,112 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
40
40
|
props: RemoteAppParams & RenderFnParams,
|
|
41
41
|
ref,
|
|
42
42
|
) {
|
|
43
|
-
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const rootRef: React.MutableRefObject<HTMLDivElement | null> =
|
|
56
|
-
ref && 'current' in ref
|
|
57
|
-
? (ref as React.MutableRefObject<HTMLDivElement | null>)
|
|
58
|
-
: useRef(null);
|
|
59
|
-
|
|
60
|
-
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
61
|
-
const providerInfoRef = useRef<any>(null);
|
|
62
|
-
const [initialized, setInitialized] = useState(false);
|
|
63
|
-
|
|
64
|
-
LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
65
|
-
|
|
66
|
-
// 初始化远程组件
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (initialized) return;
|
|
69
|
-
|
|
70
|
-
const providerReturn = providerInfo();
|
|
71
|
-
providerInfoRef.current = providerReturn;
|
|
72
|
-
setInitialized(true);
|
|
73
|
-
|
|
74
|
-
return () => {
|
|
75
|
-
if (providerInfoRef.current?.destroy) {
|
|
76
|
-
LoggerInstance.debug(
|
|
77
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
78
|
-
{ moduleName, basename, dom: renderDom.current },
|
|
79
|
-
);
|
|
43
|
+
const RemoteApp = () => {
|
|
44
|
+
LoggerInstance.debug(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
45
|
+
const {
|
|
46
|
+
moduleName,
|
|
47
|
+
memoryRoute,
|
|
48
|
+
basename,
|
|
49
|
+
providerInfo,
|
|
50
|
+
className,
|
|
51
|
+
style,
|
|
52
|
+
fallback,
|
|
53
|
+
...resProps
|
|
54
|
+
} = props;
|
|
80
55
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
fallback,
|
|
87
|
-
...resProps,
|
|
88
|
-
});
|
|
56
|
+
const instance = federationRuntime.instance;
|
|
57
|
+
const rootRef: React.MutableRefObject<HTMLDivElement | null> =
|
|
58
|
+
ref && 'current' in ref
|
|
59
|
+
? (ref as React.MutableRefObject<HTMLDivElement | null>)
|
|
60
|
+
: useRef(null);
|
|
89
61
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
dom: renderDom.current,
|
|
93
|
-
});
|
|
62
|
+
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
63
|
+
const providerInfoRef = useRef<any>(null);
|
|
94
64
|
|
|
95
|
-
|
|
65
|
+
LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const renderTimeout = setTimeout(() => {
|
|
69
|
+
const providerReturn = providerInfo();
|
|
70
|
+
providerInfoRef.current = providerReturn;
|
|
71
|
+
|
|
72
|
+
let renderProps = {
|
|
96
73
|
moduleName,
|
|
97
|
-
dom:
|
|
74
|
+
dom: rootRef.current,
|
|
98
75
|
basename,
|
|
99
76
|
memoryRoute,
|
|
100
77
|
fallback,
|
|
101
78
|
...resProps,
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
79
|
+
};
|
|
80
|
+
renderDom.current = rootRef.current;
|
|
81
|
+
LoggerInstance.debug(
|
|
82
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
83
|
+
renderProps,
|
|
84
|
+
);
|
|
106
85
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
86
|
+
LoggerInstance.debug(
|
|
87
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
88
|
+
instance,
|
|
89
|
+
);
|
|
90
|
+
const beforeBridgeRenderRes =
|
|
91
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
|
|
92
|
+
renderProps,
|
|
93
|
+
) || {};
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
96
|
+
providerReturn.render(renderProps);
|
|
97
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(renderProps);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return () => {
|
|
101
|
+
clearTimeout(renderTimeout);
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
if (providerInfoRef.current?.destroy) {
|
|
104
|
+
LoggerInstance.debug(
|
|
105
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
106
|
+
{ moduleName, basename, dom: renderDom.current },
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
|
|
110
|
+
moduleName,
|
|
111
|
+
dom: renderDom.current,
|
|
112
|
+
basename,
|
|
113
|
+
memoryRoute,
|
|
114
|
+
fallback,
|
|
115
|
+
...resProps,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
providerInfoRef.current?.destroy({
|
|
119
|
+
moduleName,
|
|
120
|
+
dom: renderDom.current,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
|
|
124
|
+
moduleName,
|
|
125
|
+
dom: renderDom.current,
|
|
126
|
+
basename,
|
|
127
|
+
memoryRoute,
|
|
128
|
+
fallback,
|
|
129
|
+
...resProps,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
}, []);
|
|
135
|
+
|
|
136
|
+
// bridge-remote-root
|
|
137
|
+
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props?.className}`;
|
|
138
|
+
return (
|
|
139
|
+
<div
|
|
140
|
+
className={rootComponentClassName}
|
|
141
|
+
style={props?.style}
|
|
142
|
+
ref={rootRef}
|
|
143
|
+
></div>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
110
146
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
dom: rootRef.current,
|
|
114
|
-
basename,
|
|
115
|
-
memoryRoute,
|
|
116
|
-
fallback,
|
|
117
|
-
...resProps,
|
|
118
|
-
};
|
|
119
|
-
renderDom.current = rootRef.current;
|
|
120
|
-
|
|
121
|
-
const beforeBridgeRenderRes =
|
|
122
|
-
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(renderProps) ||
|
|
123
|
-
{};
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
126
|
-
providerInfoRef.current.render(renderProps);
|
|
127
|
-
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(renderProps);
|
|
128
|
-
}, [initialized, ...Object.values(props)]);
|
|
129
|
-
|
|
130
|
-
// bridge-remote-root
|
|
131
|
-
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${className || ''}`;
|
|
132
|
-
return (
|
|
133
|
-
<div className={rootComponentClassName} style={style} ref={rootRef}></div>
|
|
134
|
-
);
|
|
147
|
+
(RemoteApp as any)['__APP_VERSION__'] = __APP_VERSION__;
|
|
148
|
+
return <RemoteApp />;
|
|
135
149
|
});
|
|
136
150
|
|
|
137
151
|
interface ExtraDataProps {
|
package/src/remote/create.tsx
CHANGED
|
@@ -100,9 +100,9 @@ export function createRemoteComponent<T, E extends keyof T>(
|
|
|
100
100
|
: {}
|
|
101
101
|
: {};
|
|
102
102
|
|
|
103
|
-
const LazyComponent = createLazyRemoteComponent(info);
|
|
104
103
|
return forwardRef<HTMLDivElement, ProviderParams & RawComponentType>(
|
|
105
104
|
(props, ref) => {
|
|
105
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
106
106
|
return (
|
|
107
107
|
<ErrorBoundary FallbackComponent={info.fallback}>
|
|
108
108
|
<React.Suspense fallback={info.loading}>
|