@module-federation/bridge-react 0.0.0-feat-support-bridge-react-router-v7-20251015102312
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 +670 -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/bridge-base-29j7dZKh.mjs +201 -0
- package/dist/bridge-base-CTNdBioh.js +216 -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-Dm-M9ouh.mjs +46 -0
- package/dist/index-DqCpgmgH.js +45 -0
- package/dist/index.cjs.js +293 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.es.js +276 -0
- package/dist/index.esm-CzoIcLts.js +459 -0
- package/dist/index.esm-JLwyxgUK.mjs +460 -0
- package/dist/lazy-load-component-plugin-B4fdMQTL.js +521 -0
- package/dist/lazy-load-component-plugin-ijw36GA0.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-Bgm31z9s.js +1272 -0
- package/dist/prefetch-DjeoxOeZ.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-0HFFqmd4.js +2015 -0
- package/dist/utils-BTpxHmva.mjs +2016 -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 +144 -0
- package/project.json +23 -0
- package/src/index.ts +45 -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 +127 -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/component.tsx +211 -0
- package/src/remote/create.tsx +103 -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 +106 -0
- package/vitest.config.ts +27 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-29j7dZKh.mjs";
|
|
2
|
+
import ReactDOM from "react-dom";
|
|
3
|
+
import { L as LoggerInstance, p as pathJoin, g as getRootDomDefaultClassName } from "./index-Dm-M9ouh.mjs";
|
|
4
|
+
import React__default, { forwardRef, useContext, useState, useEffect, useRef } from "react";
|
|
5
|
+
import * as ReactRouterDOM from "react-router-dom";
|
|
6
|
+
import { federationRuntime } from "./plugin.es.js";
|
|
7
|
+
import { b, a, c, l } from "./lazy-load-component-plugin-ijw36GA0.mjs";
|
|
8
|
+
import { C, b as b2, E, e, h, c as c2, d, r, s } from "./utils-BTpxHmva.mjs";
|
|
9
|
+
import { callDataFetch } from "./data-fetch-utils.es.js";
|
|
10
|
+
import { p } from "./prefetch-DjeoxOeZ.mjs";
|
|
11
|
+
function createReact16Or17Root(container) {
|
|
12
|
+
return {
|
|
13
|
+
render(children) {
|
|
14
|
+
const reactVersion = ReactDOM.version || "";
|
|
15
|
+
const isReact18 = reactVersion.startsWith("18");
|
|
16
|
+
const isReact19 = reactVersion.startsWith("19");
|
|
17
|
+
if (isReact19) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`React 19 detected in legacy mode. This is not supported. Please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v19'`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
if (isReact18) {
|
|
23
|
+
LoggerInstance.warn(
|
|
24
|
+
`[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'`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
ReactDOM.render(children, container);
|
|
28
|
+
},
|
|
29
|
+
unmount() {
|
|
30
|
+
ReactDOM.unmountComponentAtNode(container);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createBridgeComponent(bridgeInfo) {
|
|
35
|
+
const fullBridgeInfo = {
|
|
36
|
+
createRoot: createReact16Or17Root,
|
|
37
|
+
...bridgeInfo
|
|
38
|
+
};
|
|
39
|
+
return createBaseBridgeComponent(fullBridgeInfo);
|
|
40
|
+
}
|
|
41
|
+
function e2() {
|
|
42
|
+
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
43
|
+
window.dispatchEvent(t);
|
|
44
|
+
}
|
|
45
|
+
const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
46
|
+
const {
|
|
47
|
+
moduleName,
|
|
48
|
+
memoryRoute,
|
|
49
|
+
basename,
|
|
50
|
+
providerInfo,
|
|
51
|
+
className,
|
|
52
|
+
style,
|
|
53
|
+
fallback,
|
|
54
|
+
loading,
|
|
55
|
+
...resProps
|
|
56
|
+
} = props;
|
|
57
|
+
const instance = federationRuntime.instance;
|
|
58
|
+
const rootRef = ref && "current" in ref ? ref : useRef(null);
|
|
59
|
+
const renderDom = useRef(null);
|
|
60
|
+
const providerInfoRef = useRef(null);
|
|
61
|
+
const [initialized, setInitialized] = useState(false);
|
|
62
|
+
LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (initialized) return;
|
|
65
|
+
const providerReturn = providerInfo();
|
|
66
|
+
providerInfoRef.current = providerReturn;
|
|
67
|
+
setInitialized(true);
|
|
68
|
+
return () => {
|
|
69
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
70
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
71
|
+
LoggerInstance.debug(
|
|
72
|
+
`createRemoteAppComponent LazyComponent destroy >>>`,
|
|
73
|
+
{ moduleName, basename, dom: renderDom.current }
|
|
74
|
+
);
|
|
75
|
+
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
76
|
+
moduleName,
|
|
77
|
+
dom: renderDom.current,
|
|
78
|
+
basename,
|
|
79
|
+
memoryRoute,
|
|
80
|
+
fallback,
|
|
81
|
+
...resProps
|
|
82
|
+
});
|
|
83
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
84
|
+
moduleName,
|
|
85
|
+
dom: renderDom.current
|
|
86
|
+
});
|
|
87
|
+
(_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
88
|
+
moduleName,
|
|
89
|
+
dom: renderDom.current,
|
|
90
|
+
basename,
|
|
91
|
+
memoryRoute,
|
|
92
|
+
fallback,
|
|
93
|
+
...resProps
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}, [moduleName]);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
var _a, _b, _c, _d, _e, _f;
|
|
100
|
+
if (!initialized || !providerInfoRef.current) return;
|
|
101
|
+
let renderProps = {
|
|
102
|
+
moduleName,
|
|
103
|
+
dom: rootRef.current,
|
|
104
|
+
basename,
|
|
105
|
+
memoryRoute,
|
|
106
|
+
fallback,
|
|
107
|
+
...resProps
|
|
108
|
+
};
|
|
109
|
+
renderDom.current = rootRef.current;
|
|
110
|
+
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)) || {};
|
|
111
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
112
|
+
providerInfoRef.current.render(renderProps);
|
|
113
|
+
(_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);
|
|
114
|
+
}, [initialized, ...Object.values(props)]);
|
|
115
|
+
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${className || ""}`;
|
|
116
|
+
return /* @__PURE__ */ React__default.createElement("div", { className: rootComponentClassName, style, ref: rootRef }, loading);
|
|
117
|
+
});
|
|
118
|
+
function withRouterData(WrappedComponent) {
|
|
119
|
+
const Component = forwardRef(function(props, ref) {
|
|
120
|
+
var _a;
|
|
121
|
+
if (props == null ? void 0 : props.basename) {
|
|
122
|
+
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename: props.basename, ref });
|
|
123
|
+
}
|
|
124
|
+
let enableDispathPopstate = false;
|
|
125
|
+
let routerContextVal;
|
|
126
|
+
try {
|
|
127
|
+
ReactRouterDOM.useLocation();
|
|
128
|
+
enableDispathPopstate = true;
|
|
129
|
+
} catch {
|
|
130
|
+
enableDispathPopstate = false;
|
|
131
|
+
}
|
|
132
|
+
let basename = "/";
|
|
133
|
+
if (!props.basename && enableDispathPopstate) {
|
|
134
|
+
const ReactRouterDOMAny = ReactRouterDOM;
|
|
135
|
+
const useRouteMatch = ReactRouterDOMAny["useRouteMatch"];
|
|
136
|
+
const useHistory = ReactRouterDOMAny["useHistory"];
|
|
137
|
+
const useHref = ReactRouterDOMAny["useHref"];
|
|
138
|
+
const UNSAFE_RouteContext = ReactRouterDOMAny["UNSAFE_RouteContext"];
|
|
139
|
+
if (UNSAFE_RouteContext) {
|
|
140
|
+
if (useHref) {
|
|
141
|
+
basename = useHref == null ? void 0 : useHref("/");
|
|
142
|
+
}
|
|
143
|
+
routerContextVal = useContext(UNSAFE_RouteContext);
|
|
144
|
+
if (routerContextVal && routerContextVal.matches && routerContextVal.matches.length > 0) {
|
|
145
|
+
const matchIndex = routerContextVal.matches.length - 1;
|
|
146
|
+
const pathnameBase = routerContextVal.matches[matchIndex].pathnameBase;
|
|
147
|
+
basename = pathJoin(basename, pathnameBase || "/");
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
const match = useRouteMatch == null ? void 0 : useRouteMatch();
|
|
151
|
+
if (useHistory) {
|
|
152
|
+
const history = useHistory == null ? void 0 : useHistory();
|
|
153
|
+
basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
|
|
154
|
+
}
|
|
155
|
+
if (match) {
|
|
156
|
+
basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
LoggerInstance.debug(`createRemoteAppComponent withRouterData >>>`, {
|
|
161
|
+
...props,
|
|
162
|
+
basename,
|
|
163
|
+
routerContextVal,
|
|
164
|
+
enableDispathPopstate
|
|
165
|
+
});
|
|
166
|
+
if (enableDispathPopstate) {
|
|
167
|
+
const location = ReactRouterDOM.useLocation();
|
|
168
|
+
const [pathname, setPathname] = useState(location.pathname);
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (pathname !== "" && pathname !== location.pathname) {
|
|
171
|
+
LoggerInstance.debug(
|
|
172
|
+
`createRemoteAppComponent dispatchPopstateEnv >>>`,
|
|
173
|
+
{
|
|
174
|
+
name: props.name,
|
|
175
|
+
pathname: location.pathname
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
e2();
|
|
179
|
+
}
|
|
180
|
+
setPathname(location.pathname);
|
|
181
|
+
}, [location]);
|
|
182
|
+
}
|
|
183
|
+
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename, ref });
|
|
184
|
+
});
|
|
185
|
+
return forwardRef(function(props, ref) {
|
|
186
|
+
return /* @__PURE__ */ React__default.createElement(Component, { ...props, ref });
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
190
|
+
function createLazyRemoteComponent(info) {
|
|
191
|
+
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
192
|
+
return React__default.lazy(async () => {
|
|
193
|
+
LoggerInstance.debug(`createRemoteAppComponent LazyComponent create >>>`, {
|
|
194
|
+
lazyComponent: info.loader,
|
|
195
|
+
exportName
|
|
196
|
+
});
|
|
197
|
+
try {
|
|
198
|
+
const m = await info.loader();
|
|
199
|
+
const moduleName = m && m[Symbol.for("mf_module_id")];
|
|
200
|
+
LoggerInstance.debug(
|
|
201
|
+
`createRemoteAppComponent LazyComponent loadRemote info >>>`,
|
|
202
|
+
{ name: moduleName, module: m, exportName }
|
|
203
|
+
);
|
|
204
|
+
const exportFn = m[exportName];
|
|
205
|
+
if (exportName in m && typeof exportFn === "function") {
|
|
206
|
+
const RemoteAppComponent = forwardRef((props, ref) => {
|
|
207
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
208
|
+
RemoteApp,
|
|
209
|
+
{
|
|
210
|
+
moduleName,
|
|
211
|
+
providerInfo: exportFn,
|
|
212
|
+
exportName: info.export || "default",
|
|
213
|
+
fallback: info.fallback,
|
|
214
|
+
loading: info.loading,
|
|
215
|
+
ref,
|
|
216
|
+
...props
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
default: RemoteAppComponent
|
|
222
|
+
};
|
|
223
|
+
} else {
|
|
224
|
+
LoggerInstance.debug(
|
|
225
|
+
`createRemoteAppComponent LazyComponent module not found >>>`,
|
|
226
|
+
{ name: moduleName, module: m, exportName }
|
|
227
|
+
);
|
|
228
|
+
throw Error(
|
|
229
|
+
`Make sure that ${moduleName} has the correct export when export is ${String(
|
|
230
|
+
exportName
|
|
231
|
+
)}`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
} catch (error) {
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function createRemoteAppComponent(info) {
|
|
240
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
241
|
+
return forwardRef((props, ref) => {
|
|
242
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
243
|
+
ErrorBoundary,
|
|
244
|
+
{
|
|
245
|
+
FallbackComponent: info.fallback
|
|
246
|
+
},
|
|
247
|
+
/* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props, ref }))
|
|
248
|
+
);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
function createRemoteComponent(info) {
|
|
252
|
+
LoggerInstance.warn(
|
|
253
|
+
`createRemoteComponent is deprecated, please use createRemoteAppComponent instead!`
|
|
254
|
+
);
|
|
255
|
+
return createRemoteAppComponent(info);
|
|
256
|
+
}
|
|
257
|
+
export {
|
|
258
|
+
C as CacheSize,
|
|
259
|
+
b2 as CacheTime,
|
|
260
|
+
E as ERROR_TYPE,
|
|
261
|
+
b as autoFetchDataPlugin,
|
|
262
|
+
e as cache,
|
|
263
|
+
callDataFetch,
|
|
264
|
+
h as clearStore,
|
|
265
|
+
a as collectSSRAssets,
|
|
266
|
+
c2 as configureCache,
|
|
267
|
+
createBridgeComponent,
|
|
268
|
+
c as createLazyComponent,
|
|
269
|
+
createRemoteAppComponent,
|
|
270
|
+
createRemoteComponent,
|
|
271
|
+
d as generateKey,
|
|
272
|
+
l as lazyLoadComponentPlugin,
|
|
273
|
+
p as prefetch,
|
|
274
|
+
r as revalidateTag,
|
|
275
|
+
s as setSSREnv
|
|
276
|
+
};
|