@module-federation/bridge-react 0.0.0-next-20250707074728 → 0.0.0-next-20250708033956
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/__tests__/bridge.spec.tsx +7 -7
- package/dist/{bridge-base-P6pEjY1q.js → bridge-base-BoshEggF.mjs} +1 -1
- package/dist/{bridge-base-BBH982Tz.cjs → bridge-base-UGCwcMnG.js} +1 -1
- package/dist/data-fetch-runtime-plugin.cjs.js +73 -0
- package/dist/data-fetch-runtime-plugin.d.ts +6 -0
- package/dist/data-fetch-runtime-plugin.es.js +74 -0
- package/dist/data-fetch-server-middleware.cjs.js +163 -0
- package/dist/data-fetch-server-middleware.d.ts +6 -0
- package/dist/data-fetch-server-middleware.es.js +164 -0
- package/dist/data-fetch-utils.cjs.js +1273 -0
- package/dist/data-fetch-utils.d.ts +77 -0
- package/dist/data-fetch-utils.es.js +1275 -0
- package/dist/index-C0fDZB5b.js +45 -0
- package/dist/index-CqxytsLY.mjs +46 -0
- package/dist/index.cjs.js +461 -9
- package/dist/index.d.ts +143 -0
- package/dist/index.es.js +464 -11
- package/dist/index.esm-BCeUd-x9.mjs +418 -0
- package/dist/index.esm-j_1sIRzg.js +417 -0
- package/dist/inject-data-fetch-CAvi-gSf.js +79 -0
- package/dist/inject-data-fetch-errCdqBS.mjs +80 -0
- package/dist/lazy-utils.cjs.js +24 -0
- package/dist/lazy-utils.d.ts +140 -0
- package/dist/lazy-utils.es.js +24 -0
- package/dist/plugin.d.ts +4 -4
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.es.js +1 -1
- package/dist/utils-Bk8hGjjF.mjs +2016 -0
- package/dist/utils-iEVlDmyk.js +2015 -0
- package/dist/v18.cjs.js +1 -1
- package/dist/v18.es.js +1 -1
- package/dist/v19.cjs.js +1 -1
- package/dist/v19.es.js +1 -1
- package/package.json +45 -5
- package/src/index.ts +30 -1
- package/src/lazy/AwaitDataFetch.tsx +215 -0
- package/src/lazy/constant.ts +30 -0
- package/src/lazy/createLazyComponent.tsx +404 -0
- package/src/lazy/data-fetch/cache.ts +296 -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 +15 -0
- package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
- package/src/lazy/data-fetch/prefetch.ts +102 -0
- package/src/lazy/data-fetch/runtime-plugin.ts +116 -0
- package/src/lazy/index.ts +31 -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/provider/plugin.ts +4 -4
- package/src/remote/component.tsx +3 -3
- package/src/remote/create.tsx +17 -4
- package/tsconfig.json +1 -1
- package/vite.config.ts +13 -0
- package/dist/index-Cv3p6r66.cjs +0 -235
- package/dist/index-D4yt7Udv.js +0 -236
package/dist/index.es.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-
|
|
1
|
+
import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-BoshEggF.mjs";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
|
-
import React__default, { forwardRef, useRef, useState, useEffect, useContext } from "react";
|
|
4
|
-
import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin } from "./index-
|
|
3
|
+
import React__default, { forwardRef, useRef, useState, useEffect, useContext, Suspense } from "react";
|
|
4
|
+
import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin } from "./index-CqxytsLY.mjs";
|
|
5
5
|
import * as ReactRouterDOM from "react-router-dom";
|
|
6
6
|
import { federationRuntime } from "./plugin.es.js";
|
|
7
|
+
import { default as default2 } from "./data-fetch-runtime-plugin.es.js";
|
|
8
|
+
import { s as getDataFetchIdWithErrorMsgs, t as DATA_FETCH_ERROR_PREFIX, E as ERROR_TYPE, w as wrapDataFetchId, L as LOAD_REMOTE_ERROR_PREFIX, l as logger, n as DATA_FETCH_FUNCTION, u as getLoadedRemoteInfos, a as getDataFetchMapKey, g as getDataFetchInfo, m as fetchData$1, v as setDataFetchItemLoadedStatus, F as FS_HREF, b as getDataFetchItem, M as MF_DATA_FETCH_TYPE } from "./utils-Bk8hGjjF.mjs";
|
|
9
|
+
import { C, y, B, H, z, A, G, x } from "./utils-Bk8hGjjF.mjs";
|
|
10
|
+
import { callDataFetch, prefetch } from "./data-fetch-utils.es.js";
|
|
7
11
|
function createReact16Or17Root(container) {
|
|
8
12
|
return {
|
|
9
13
|
render(children) {
|
|
@@ -64,7 +68,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
64
68
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
65
69
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
66
70
|
LoggerInstance.debug(
|
|
67
|
-
`
|
|
71
|
+
`createRemoteAppComponent LazyComponent destroy >>>`,
|
|
68
72
|
{ moduleName, basename, dom: renderDom.current }
|
|
69
73
|
);
|
|
70
74
|
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
@@ -152,7 +156,7 @@ function withRouterData(WrappedComponent) {
|
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
|
-
LoggerInstance.debug(`
|
|
159
|
+
LoggerInstance.debug(`createRemoteAppComponent withRouterData >>>`, {
|
|
156
160
|
...props,
|
|
157
161
|
basename,
|
|
158
162
|
routerContextVal,
|
|
@@ -164,7 +168,7 @@ function withRouterData(WrappedComponent) {
|
|
|
164
168
|
useEffect(() => {
|
|
165
169
|
if (pathname !== "" && pathname !== location.pathname) {
|
|
166
170
|
LoggerInstance.debug(
|
|
167
|
-
`
|
|
171
|
+
`createRemoteAppComponent dispatchPopstateEnv >>>`,
|
|
168
172
|
{
|
|
169
173
|
name: props.name,
|
|
170
174
|
pathname: location.pathname
|
|
@@ -185,7 +189,7 @@ const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
|
185
189
|
function createLazyRemoteComponent(info) {
|
|
186
190
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
187
191
|
return React__default.lazy(async () => {
|
|
188
|
-
LoggerInstance.debug(`
|
|
192
|
+
LoggerInstance.debug(`createRemoteAppComponent LazyComponent create >>>`, {
|
|
189
193
|
lazyComponent: info.loader,
|
|
190
194
|
exportName
|
|
191
195
|
});
|
|
@@ -193,7 +197,7 @@ function createLazyRemoteComponent(info) {
|
|
|
193
197
|
const m = await info.loader();
|
|
194
198
|
const moduleName = m && m[Symbol.for("mf_module_id")];
|
|
195
199
|
LoggerInstance.debug(
|
|
196
|
-
`
|
|
200
|
+
`createRemoteAppComponent LazyComponent loadRemote info >>>`,
|
|
197
201
|
{ name: moduleName, module: m, exportName }
|
|
198
202
|
);
|
|
199
203
|
const exportFn = m[exportName];
|
|
@@ -216,7 +220,7 @@ function createLazyRemoteComponent(info) {
|
|
|
216
220
|
};
|
|
217
221
|
} else {
|
|
218
222
|
LoggerInstance.debug(
|
|
219
|
-
`
|
|
223
|
+
`createRemoteAppComponent LazyComponent module not found >>>`,
|
|
220
224
|
{ name: moduleName, module: m, exportName }
|
|
221
225
|
);
|
|
222
226
|
throw Error(
|
|
@@ -230,7 +234,7 @@ function createLazyRemoteComponent(info) {
|
|
|
230
234
|
}
|
|
231
235
|
});
|
|
232
236
|
}
|
|
233
|
-
function
|
|
237
|
+
function createRemoteAppComponent(info) {
|
|
234
238
|
const LazyComponent = createLazyRemoteComponent(info);
|
|
235
239
|
return forwardRef((props, ref) => {
|
|
236
240
|
return /* @__PURE__ */ React__default.createElement(
|
|
@@ -242,7 +246,456 @@ function createRemoteComponent(info) {
|
|
|
242
246
|
);
|
|
243
247
|
});
|
|
244
248
|
}
|
|
249
|
+
function createRemoteComponent(info) {
|
|
250
|
+
LoggerInstance.warn(
|
|
251
|
+
`createRemoteAppComponent is deprecated, please use createRemoteAppComponent instead!`
|
|
252
|
+
);
|
|
253
|
+
return createRemoteAppComponent(info);
|
|
254
|
+
}
|
|
255
|
+
function isPromise(obj) {
|
|
256
|
+
return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
257
|
+
}
|
|
258
|
+
const AWAIT_ERROR_PREFIX = "<Await /> caught the following error during render: ";
|
|
259
|
+
const transformError = (err) => {
|
|
260
|
+
const errMsg = err instanceof Error ? err.message : err;
|
|
261
|
+
const originalMsg = errMsg.replace(AWAIT_ERROR_PREFIX, "");
|
|
262
|
+
const dataFetchMapKey = getDataFetchIdWithErrorMsgs(originalMsg);
|
|
263
|
+
if (originalMsg.indexOf(DATA_FETCH_ERROR_PREFIX) === 0) {
|
|
264
|
+
return {
|
|
265
|
+
error: new Error(
|
|
266
|
+
originalMsg.replace(DATA_FETCH_ERROR_PREFIX, "").replace(wrapDataFetchId(dataFetchMapKey), "")
|
|
267
|
+
),
|
|
268
|
+
errorType: ERROR_TYPE.DATA_FETCH,
|
|
269
|
+
dataFetchMapKey
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
if (originalMsg.indexOf(LOAD_REMOTE_ERROR_PREFIX) === 0) {
|
|
273
|
+
return {
|
|
274
|
+
error: new Error(
|
|
275
|
+
originalMsg.replace(LOAD_REMOTE_ERROR_PREFIX, "").replace(wrapDataFetchId(dataFetchMapKey), "")
|
|
276
|
+
),
|
|
277
|
+
errorType: ERROR_TYPE.LOAD_REMOTE,
|
|
278
|
+
dataFetchMapKey
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
error: new Error(originalMsg.replace(wrapDataFetchId(dataFetchMapKey), "")),
|
|
283
|
+
errorType: ERROR_TYPE.UNKNOWN,
|
|
284
|
+
dataFetchMapKey
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
const DefaultLoading = /* @__PURE__ */ React__default.createElement(React__default.Fragment, null);
|
|
288
|
+
const DefaultErrorElement = (_data) => /* @__PURE__ */ React__default.createElement("div", null, "Error");
|
|
289
|
+
function AwaitDataFetch({
|
|
290
|
+
resolve,
|
|
291
|
+
loading = DefaultLoading,
|
|
292
|
+
errorElement = DefaultErrorElement,
|
|
293
|
+
children,
|
|
294
|
+
params,
|
|
295
|
+
delayLoading
|
|
296
|
+
}) {
|
|
297
|
+
const dataRef = useRef();
|
|
298
|
+
const data = dataRef.current || resolve;
|
|
299
|
+
const getData = isPromise(data) ? fetchData(data, dataRef) : () => data;
|
|
300
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
301
|
+
AwaitSuspense,
|
|
302
|
+
{
|
|
303
|
+
params,
|
|
304
|
+
loading,
|
|
305
|
+
errorElement,
|
|
306
|
+
delayLoading,
|
|
307
|
+
resolve: getData
|
|
308
|
+
},
|
|
309
|
+
children
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
const DelayedLoading = ({
|
|
313
|
+
delayLoading,
|
|
314
|
+
children
|
|
315
|
+
}) => {
|
|
316
|
+
const [show, setShow] = useState(false);
|
|
317
|
+
const timerSet = useRef(false);
|
|
318
|
+
if (!delayLoading) {
|
|
319
|
+
return children;
|
|
320
|
+
}
|
|
321
|
+
if (typeof window !== "undefined" && !show && !timerSet.current) {
|
|
322
|
+
timerSet.current = true;
|
|
323
|
+
setTimeout(() => {
|
|
324
|
+
setShow(true);
|
|
325
|
+
}, delayLoading);
|
|
326
|
+
}
|
|
327
|
+
return show ? children : null;
|
|
328
|
+
};
|
|
329
|
+
function AwaitSuspense({
|
|
330
|
+
resolve,
|
|
331
|
+
children,
|
|
332
|
+
loading = DefaultLoading,
|
|
333
|
+
errorElement = DefaultErrorElement,
|
|
334
|
+
delayLoading
|
|
335
|
+
}) {
|
|
336
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
337
|
+
Suspense,
|
|
338
|
+
{
|
|
339
|
+
fallback: /* @__PURE__ */ React__default.createElement(DelayedLoading, { delayLoading }, loading)
|
|
340
|
+
},
|
|
341
|
+
/* @__PURE__ */ React__default.createElement(ResolveAwait, { resolve, errorElement }, children)
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
function ResolveAwait({
|
|
345
|
+
children,
|
|
346
|
+
resolve,
|
|
347
|
+
errorElement,
|
|
348
|
+
params
|
|
349
|
+
}) {
|
|
350
|
+
const data = resolve();
|
|
351
|
+
logger.debug("resolve data: ", data);
|
|
352
|
+
if (typeof data === "string" && data.indexOf(AWAIT_ERROR_PREFIX) === 0) {
|
|
353
|
+
const transformedError = transformError(data);
|
|
354
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, typeof errorElement === "function" ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, globalThis.FEDERATION_SSR && /* @__PURE__ */ React__default.createElement(
|
|
355
|
+
"script",
|
|
356
|
+
{
|
|
357
|
+
suppressHydrationWarning: true,
|
|
358
|
+
dangerouslySetInnerHTML: {
|
|
359
|
+
__html: String.raw`
|
|
360
|
+
globalThis['${DATA_FETCH_FUNCTION}'] = globalThis['${DATA_FETCH_FUNCTION}'] || []
|
|
361
|
+
globalThis['${DATA_FETCH_FUNCTION}'].push([${transformedError.dataFetchMapKey ? `'${transformedError.dataFetchMapKey}'` : ""},${params ? JSON.stringify(params) : null},true]);`
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
), errorElement(transformedError)) : errorElement);
|
|
365
|
+
}
|
|
366
|
+
const toRender = typeof children === "function" ? children(data) : children;
|
|
367
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, toRender);
|
|
368
|
+
}
|
|
369
|
+
const fetchData = (promise, ref) => {
|
|
370
|
+
let data;
|
|
371
|
+
let status = "pending";
|
|
372
|
+
const suspender = promise.then((res) => {
|
|
373
|
+
status = "success";
|
|
374
|
+
data = res;
|
|
375
|
+
ref.current = res;
|
|
376
|
+
}).catch((e2) => {
|
|
377
|
+
status = "success";
|
|
378
|
+
console.warn(e2);
|
|
379
|
+
data = AWAIT_ERROR_PREFIX + e2;
|
|
380
|
+
});
|
|
381
|
+
return () => {
|
|
382
|
+
if (status === "pending") {
|
|
383
|
+
throw suspender;
|
|
384
|
+
}
|
|
385
|
+
return data;
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
function getTargetModuleInfo(id, instance) {
|
|
389
|
+
if (!instance) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const loadedRemoteInfo = getLoadedRemoteInfos(id, instance);
|
|
393
|
+
if (!loadedRemoteInfo) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
const snapshot = loadedRemoteInfo.snapshot;
|
|
397
|
+
if (!snapshot) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
|
|
401
|
+
if (!publicPath) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const modules = "modules" in snapshot ? snapshot.modules : [];
|
|
405
|
+
const targetModule = modules.find(
|
|
406
|
+
(m) => m.modulePath === loadedRemoteInfo.expose
|
|
407
|
+
);
|
|
408
|
+
if (!targetModule) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
|
|
412
|
+
if (!remoteEntry) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
module: targetModule,
|
|
417
|
+
publicPath,
|
|
418
|
+
remoteEntry
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
function collectSSRAssets(options) {
|
|
422
|
+
const {
|
|
423
|
+
id,
|
|
424
|
+
injectLink = true,
|
|
425
|
+
injectScript = false
|
|
426
|
+
} = typeof options === "string" ? { id: options } : options;
|
|
427
|
+
const links = [];
|
|
428
|
+
const scripts = [];
|
|
429
|
+
const instance = options.instance;
|
|
430
|
+
if (!instance || !injectLink && !injectScript) {
|
|
431
|
+
return [...scripts, ...links];
|
|
432
|
+
}
|
|
433
|
+
const moduleAndPublicPath = getTargetModuleInfo(id, instance);
|
|
434
|
+
if (!moduleAndPublicPath) {
|
|
435
|
+
return [...scripts, ...links];
|
|
436
|
+
}
|
|
437
|
+
const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
|
|
438
|
+
if (injectLink) {
|
|
439
|
+
[...targetModule.assets.css.sync, ...targetModule.assets.css.async].sort().forEach((file, index) => {
|
|
440
|
+
links.push(
|
|
441
|
+
/* @__PURE__ */ React__default.createElement(
|
|
442
|
+
"link",
|
|
443
|
+
{
|
|
444
|
+
key: `${file.split(".")[0]}_${index}`,
|
|
445
|
+
href: `${publicPath}${file}`,
|
|
446
|
+
rel: "stylesheet",
|
|
447
|
+
type: "text/css"
|
|
448
|
+
}
|
|
449
|
+
)
|
|
450
|
+
);
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
if (injectScript) {
|
|
454
|
+
scripts.push(
|
|
455
|
+
/* @__PURE__ */ React__default.createElement(
|
|
456
|
+
"script",
|
|
457
|
+
{
|
|
458
|
+
async: true,
|
|
459
|
+
key: remoteEntry.split(".")[0],
|
|
460
|
+
src: `${publicPath}${remoteEntry}`,
|
|
461
|
+
crossOrigin: "anonymous"
|
|
462
|
+
}
|
|
463
|
+
)
|
|
464
|
+
);
|
|
465
|
+
[...targetModule.assets.js.sync].sort().forEach((file, index) => {
|
|
466
|
+
scripts.push(
|
|
467
|
+
/* @__PURE__ */ React__default.createElement(
|
|
468
|
+
"script",
|
|
469
|
+
{
|
|
470
|
+
key: `${file.split(".")[0]}_${index}`,
|
|
471
|
+
async: true,
|
|
472
|
+
src: `${publicPath}${file}`,
|
|
473
|
+
crossOrigin: "anonymous"
|
|
474
|
+
}
|
|
475
|
+
)
|
|
476
|
+
);
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
return [...scripts, ...links];
|
|
480
|
+
}
|
|
481
|
+
function getServerNeedRemoteInfo(loadedRemoteInfo, id, noSSR) {
|
|
482
|
+
var _a;
|
|
483
|
+
if (noSSR || typeof window !== "undefined" && window.location.href !== window[FS_HREF]) {
|
|
484
|
+
if (!(loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.version)) {
|
|
485
|
+
throw new Error(`${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} version is empty`);
|
|
486
|
+
}
|
|
487
|
+
const { snapshot } = loadedRemoteInfo;
|
|
488
|
+
if (!snapshot) {
|
|
489
|
+
throw new Error(`${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} snapshot is empty`);
|
|
490
|
+
}
|
|
491
|
+
const dataFetchItem = getDataFetchItem(id);
|
|
492
|
+
const isFetchServer = ((_a = dataFetchItem == null ? void 0 : dataFetchItem[0]) == null ? void 0 : _a[1]) === MF_DATA_FETCH_TYPE.FETCH_SERVER;
|
|
493
|
+
if (isFetchServer && (!("ssrPublicPath" in snapshot) || !snapshot.ssrPublicPath)) {
|
|
494
|
+
throw new Error(
|
|
495
|
+
`ssrPublicPath is required while fetching ${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} data in SSR project!`
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
if (isFetchServer && (!("ssrRemoteEntry" in snapshot) || !snapshot.ssrRemoteEntry)) {
|
|
499
|
+
throw new Error(
|
|
500
|
+
`ssrRemoteEntry is required while loading ${loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.name} data loader in SSR project!`
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
return {
|
|
504
|
+
name: loadedRemoteInfo.name,
|
|
505
|
+
version: loadedRemoteInfo.version,
|
|
506
|
+
ssrPublicPath: "ssrPublicPath" in snapshot ? snapshot.ssrPublicPath || "" : "",
|
|
507
|
+
ssrRemoteEntry: "ssrRemoteEntry" in snapshot ? snapshot.ssrRemoteEntry || "" : "",
|
|
508
|
+
globalName: loadedRemoteInfo.entryGlobalName
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
return void 0;
|
|
512
|
+
}
|
|
513
|
+
function createLazyComponent(options) {
|
|
514
|
+
const { instance, cacheData } = options;
|
|
515
|
+
if (!instance) {
|
|
516
|
+
throw new Error("instance is required for createLazyComponent!");
|
|
517
|
+
}
|
|
518
|
+
let dataCache = null;
|
|
519
|
+
const exportName = (options == null ? void 0 : options.export) || "default";
|
|
520
|
+
const callLoader = async () => {
|
|
521
|
+
logger.debug("callLoader start", Date.now());
|
|
522
|
+
const m = await options.loader();
|
|
523
|
+
logger.debug("callLoader end", Date.now());
|
|
524
|
+
if (!m) {
|
|
525
|
+
throw new Error("load remote failed");
|
|
526
|
+
}
|
|
527
|
+
return m;
|
|
528
|
+
};
|
|
529
|
+
const getData = async (noSSR) => {
|
|
530
|
+
let loadedRemoteInfo;
|
|
531
|
+
let moduleId;
|
|
532
|
+
try {
|
|
533
|
+
const m = await callLoader();
|
|
534
|
+
moduleId = m && m[Symbol.for("mf_module_id")];
|
|
535
|
+
if (!moduleId) {
|
|
536
|
+
throw new Error("moduleId is empty");
|
|
537
|
+
}
|
|
538
|
+
loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
|
|
539
|
+
if (!loadedRemoteInfo) {
|
|
540
|
+
throw new Error(`can not find loaded remote('${moduleId}') info!`);
|
|
541
|
+
}
|
|
542
|
+
} catch (e2) {
|
|
543
|
+
const errMsg = `${LOAD_REMOTE_ERROR_PREFIX}${e2}`;
|
|
544
|
+
logger.debug(e2);
|
|
545
|
+
throw new Error(errMsg);
|
|
546
|
+
}
|
|
547
|
+
let dataFetchMapKey;
|
|
548
|
+
try {
|
|
549
|
+
dataFetchMapKey = getDataFetchMapKey(
|
|
550
|
+
getDataFetchInfo({
|
|
551
|
+
name: loadedRemoteInfo.name,
|
|
552
|
+
alias: loadedRemoteInfo.alias,
|
|
553
|
+
id: moduleId,
|
|
554
|
+
remoteSnapshot: loadedRemoteInfo.snapshot
|
|
555
|
+
}),
|
|
556
|
+
{ name: instance.name, version: instance.options.version }
|
|
557
|
+
);
|
|
558
|
+
logger.debug("getData dataFetchMapKey: ", dataFetchMapKey);
|
|
559
|
+
if (!dataFetchMapKey) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const data = await fetchData$1(
|
|
563
|
+
dataFetchMapKey,
|
|
564
|
+
{
|
|
565
|
+
...options.dataFetchParams,
|
|
566
|
+
isDowngrade: false
|
|
567
|
+
},
|
|
568
|
+
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR)
|
|
569
|
+
);
|
|
570
|
+
setDataFetchItemLoadedStatus(dataFetchMapKey);
|
|
571
|
+
logger.debug("get data res: \n", data);
|
|
572
|
+
dataCache = data;
|
|
573
|
+
return data;
|
|
574
|
+
} catch (err) {
|
|
575
|
+
const errMsg = `${DATA_FETCH_ERROR_PREFIX}${wrapDataFetchId(dataFetchMapKey)}${err}`;
|
|
576
|
+
logger.debug(errMsg);
|
|
577
|
+
throw new Error(errMsg);
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
const LazyComponent = React__default.lazy(async () => {
|
|
581
|
+
const m = await callLoader();
|
|
582
|
+
const moduleId = m && m[Symbol.for("mf_module_id")];
|
|
583
|
+
const loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
|
|
584
|
+
loadedRemoteInfo == null ? void 0 : loadedRemoteInfo.snapshot;
|
|
585
|
+
const dataFetchMapKey = loadedRemoteInfo ? getDataFetchMapKey(
|
|
586
|
+
getDataFetchInfo({
|
|
587
|
+
name: loadedRemoteInfo.name,
|
|
588
|
+
alias: loadedRemoteInfo.alias,
|
|
589
|
+
id: moduleId,
|
|
590
|
+
remoteSnapshot: loadedRemoteInfo.snapshot
|
|
591
|
+
}),
|
|
592
|
+
{ name: instance.name, version: instance == null ? void 0 : instance.options.version }
|
|
593
|
+
) : void 0;
|
|
594
|
+
logger.debug("LazyComponent dataFetchMapKey: ", dataFetchMapKey);
|
|
595
|
+
const assets = collectSSRAssets({
|
|
596
|
+
id: moduleId,
|
|
597
|
+
instance
|
|
598
|
+
});
|
|
599
|
+
const Com = m[exportName];
|
|
600
|
+
if (exportName in m && typeof Com === "function") {
|
|
601
|
+
return {
|
|
602
|
+
default: (props) => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, globalThis.FEDERATION_SSR && dataFetchMapKey && /* @__PURE__ */ React__default.createElement(
|
|
603
|
+
"script",
|
|
604
|
+
{
|
|
605
|
+
suppressHydrationWarning: true,
|
|
606
|
+
dangerouslySetInnerHTML: {
|
|
607
|
+
__html: String.raw`
|
|
608
|
+
globalThis['${DATA_FETCH_FUNCTION}'] = globalThis['${DATA_FETCH_FUNCTION}'] || [];
|
|
609
|
+
globalThis['${DATA_FETCH_FUNCTION}'].push(['${dataFetchMapKey}',${JSON.stringify(props.mfData)}]);
|
|
610
|
+
`
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
), globalThis.FEDERATION_SSR && assets, /* @__PURE__ */ React__default.createElement(Com, { ...props }))
|
|
614
|
+
};
|
|
615
|
+
} else {
|
|
616
|
+
throw Error(
|
|
617
|
+
`Make sure that ${moduleId} has the correct export when export is ${String(
|
|
618
|
+
exportName
|
|
619
|
+
)}`
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
return (props) => {
|
|
624
|
+
const { key, ...args } = props;
|
|
625
|
+
if (cacheData && dataCache) {
|
|
626
|
+
return /* @__PURE__ */ React__default.createElement(LazyComponent, { ...args, mfData: dataCache });
|
|
627
|
+
}
|
|
628
|
+
if (!options.noSSR) {
|
|
629
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
630
|
+
AwaitDataFetch,
|
|
631
|
+
{
|
|
632
|
+
resolve: getData(options.noSSR),
|
|
633
|
+
loading: options.loading,
|
|
634
|
+
delayLoading: options.delayLoading,
|
|
635
|
+
errorElement: options.fallback
|
|
636
|
+
},
|
|
637
|
+
(data) => /* @__PURE__ */ React__default.createElement(LazyComponent, { ...args, mfData: data })
|
|
638
|
+
);
|
|
639
|
+
} else {
|
|
640
|
+
const [data, setData] = useState(null);
|
|
641
|
+
const [loading, setLoading] = useState(true);
|
|
642
|
+
const [error, setError] = useState(null);
|
|
643
|
+
useEffect(() => {
|
|
644
|
+
let isMounted = true;
|
|
645
|
+
const fetchDataAsync = async () => {
|
|
646
|
+
try {
|
|
647
|
+
setLoading(true);
|
|
648
|
+
const result = await getData(options.noSSR);
|
|
649
|
+
if (isMounted) {
|
|
650
|
+
setData(result);
|
|
651
|
+
}
|
|
652
|
+
} catch (e2) {
|
|
653
|
+
if (isMounted) {
|
|
654
|
+
setError(transformError(e2));
|
|
655
|
+
}
|
|
656
|
+
} finally {
|
|
657
|
+
if (isMounted) {
|
|
658
|
+
setLoading(false);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
fetchDataAsync();
|
|
663
|
+
return () => {
|
|
664
|
+
isMounted = false;
|
|
665
|
+
};
|
|
666
|
+
}, []);
|
|
667
|
+
if (loading) {
|
|
668
|
+
return /* @__PURE__ */ React__default.createElement(DelayedLoading, { delayLoading: options.delayLoading }, options.loading);
|
|
669
|
+
}
|
|
670
|
+
if (error) {
|
|
671
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, typeof options.fallback === "function" ? options.fallback(error) : options.fallback);
|
|
672
|
+
}
|
|
673
|
+
return /* @__PURE__ */ React__default.createElement(LazyComponent, { ...args, mfData: data });
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function wrapNoSSR(createLazyComponentFn) {
|
|
678
|
+
return (options) => {
|
|
679
|
+
return createLazyComponentFn({ ...options, noSSR: true });
|
|
680
|
+
};
|
|
681
|
+
}
|
|
245
682
|
export {
|
|
683
|
+
C as CacheSize,
|
|
684
|
+
y as CacheTime,
|
|
685
|
+
ERROR_TYPE,
|
|
686
|
+
default2 as autoFetchDataPlugin,
|
|
687
|
+
B as cache,
|
|
688
|
+
callDataFetch,
|
|
689
|
+
H as clearStore,
|
|
690
|
+
collectSSRAssets,
|
|
691
|
+
z as configureCache,
|
|
246
692
|
createBridgeComponent,
|
|
247
|
-
|
|
693
|
+
createLazyComponent,
|
|
694
|
+
createRemoteAppComponent,
|
|
695
|
+
createRemoteComponent,
|
|
696
|
+
A as generateKey,
|
|
697
|
+
prefetch,
|
|
698
|
+
G as revalidateTag,
|
|
699
|
+
x as setSSREnv,
|
|
700
|
+
wrapNoSSR
|
|
248
701
|
};
|