@module-federation/bridge-react 2.8.1 → 2.9.0
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/dist/base.cjs.js +3 -3
- package/dist/base.es.js +4 -4
- package/dist/{bridge-base-BaKy6CY_.mjs → bridge-base-CHnL6Q9P.mjs} +30 -6
- package/dist/{bridge-base-Ch33UJuN.js → bridge-base-DSYKAGGD.js} +30 -6
- package/dist/{createHelpers-BSHeKyd-.mjs → createHelpers-D3Sg5lKp.mjs} +29 -14
- package/dist/{createHelpers-19BP0xtB.js → createHelpers-D6thyyLv.js} +29 -14
- package/dist/data-fetch-utils.cjs.js +1 -1
- package/dist/data-fetch-utils.es.js +2 -2
- package/dist/data-fetch.cjs.js +2 -2
- package/dist/data-fetch.es.js +2 -2
- package/dist/index.cjs.js +24 -3
- package/dist/index.es.js +25 -4
- package/dist/lazy/HydratedStylesheetAssets.d.ts +4 -0
- package/dist/lazy/createLazyComponent.d.ts +1 -1
- package/dist/{lazy-load-component-plugin-DBTxuAYf.js → lazy-load-component-plugin-CRqjWQ5N.js} +169 -43
- package/dist/{lazy-load-component-plugin-DlagtX0O.mjs → lazy-load-component-plugin-CyRfqVSE.mjs} +170 -44
- package/dist/lazy-load-component-plugin.cjs.js +2 -2
- package/dist/lazy-load-component-plugin.es.js +2 -2
- package/dist/{prefetch-QJLnti7A.js → prefetch-CMvAw8F3.js} +126 -42
- package/dist/{prefetch-BzCq3MT3.mjs → prefetch-xvZIEaJL.mjs} +126 -42
- 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 +7 -7
|
@@ -492,6 +492,7 @@ const processModuleAlias = (name, subPath) => {
|
|
|
492
492
|
moduleName = moduleName + subPath;
|
|
493
493
|
return moduleName;
|
|
494
494
|
};
|
|
495
|
+
const MAX_PRELOADED_ASSETS = 2e3;
|
|
495
496
|
const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
|
|
496
497
|
const nativeGlobal = (() => {
|
|
497
498
|
try {
|
|
@@ -513,7 +514,7 @@ function includeOwnProperty(target, key) {
|
|
|
513
514
|
if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
|
|
514
515
|
const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
515
516
|
function setGlobalDefaultVal(target) {
|
|
516
|
-
var _a, _b, _c, _d, _e, _f;
|
|
517
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
517
518
|
if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
|
|
518
519
|
if (!includeOwnProperty(target, "__FEDERATION__")) {
|
|
519
520
|
definePropertyGlobalVal(target, "__FEDERATION__", {
|
|
@@ -522,7 +523,8 @@ function setGlobalDefaultVal(target) {
|
|
|
522
523
|
moduleInfo: {},
|
|
523
524
|
__SHARE__: {},
|
|
524
525
|
__MANIFEST_LOADING__: {},
|
|
525
|
-
__PRELOADED_MAP__: /* @__PURE__ */ new Map()
|
|
526
|
+
__PRELOADED_MAP__: /* @__PURE__ */ new Map(),
|
|
527
|
+
__PRELOADED_ASSETS__: /* @__PURE__ */ new Set()
|
|
526
528
|
});
|
|
527
529
|
definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
|
|
528
530
|
}
|
|
@@ -532,6 +534,7 @@ function setGlobalDefaultVal(target) {
|
|
|
532
534
|
(_d = target.__FEDERATION__).__SHARE__ ?? (_d.__SHARE__ = {});
|
|
533
535
|
(_e = target.__FEDERATION__).__MANIFEST_LOADING__ ?? (_e.__MANIFEST_LOADING__ = {});
|
|
534
536
|
(_f = target.__FEDERATION__).__PRELOADED_MAP__ ?? (_f.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
|
|
537
|
+
(_g = target.__FEDERATION__).__PRELOADED_ASSETS__ ?? (_g.__PRELOADED_ASSETS__ = /* @__PURE__ */ new Set());
|
|
535
538
|
}
|
|
536
539
|
setGlobalDefaultVal(CurrentGlobal);
|
|
537
540
|
setGlobalDefaultVal(nativeGlobal);
|
|
@@ -542,6 +545,15 @@ const getRemoteEntryExports = (name, globalName) => {
|
|
|
542
545
|
entryExports: CurrentGlobal[remoteEntryKey]
|
|
543
546
|
};
|
|
544
547
|
};
|
|
548
|
+
const getPreloadedAsset = (url) => CurrentGlobal.__FEDERATION__.__PRELOADED_ASSETS__.has(url);
|
|
549
|
+
const setPreloadedAsset = (url) => {
|
|
550
|
+
const preloadedAssets = CurrentGlobal.__FEDERATION__.__PRELOADED_ASSETS__;
|
|
551
|
+
preloadedAssets.add(url);
|
|
552
|
+
if (preloadedAssets.size > MAX_PRELOADED_ASSETS) {
|
|
553
|
+
const oldestUrl = preloadedAssets.values().next().value;
|
|
554
|
+
if (oldestUrl !== void 0) preloadedAssets.delete(oldestUrl);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
545
557
|
const DEFAULT_SCOPE = "default";
|
|
546
558
|
const DEFAULT_REMOTE_TYPE = "global";
|
|
547
559
|
function composeRemoteRequestId(remoteName, expose) {
|
|
@@ -622,21 +634,47 @@ const runtimeDescMap = {
|
|
|
622
634
|
...runtimeDescMap
|
|
623
635
|
});
|
|
624
636
|
const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
|
|
637
|
+
const remoteEntryLoadingOrigins = /* @__PURE__ */ new WeakMap();
|
|
638
|
+
const esmRemoteEntryLoadErrorMessages = [
|
|
639
|
+
"Failed to fetch dynamically imported module",
|
|
640
|
+
"Importing a module script failed",
|
|
641
|
+
"error loading dynamically imported module"
|
|
642
|
+
];
|
|
643
|
+
function isEsmRemoteEntryLoadError(err) {
|
|
644
|
+
if (!(err instanceof TypeError)) return false;
|
|
645
|
+
return esmRemoteEntryLoadErrorMessages.some((loadErrorMessage) => err.message.includes(loadErrorMessage));
|
|
646
|
+
}
|
|
625
647
|
function isEsmRemoteType(type) {
|
|
626
648
|
return type === "esm" || type === "module";
|
|
627
649
|
}
|
|
628
|
-
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
650
|
+
async function loadEsmEntry({ entry, remoteEntryExports, name, getEntryUrl }) {
|
|
629
651
|
return new Promise((resolve, reject) => {
|
|
652
|
+
const rejectEntry = (loadError) => {
|
|
653
|
+
if (isEsmRemoteEntryLoadError(loadError)) {
|
|
654
|
+
const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
|
|
655
|
+
try {
|
|
656
|
+
error(RUNTIME_008, runtimeDescMap, {
|
|
657
|
+
remoteName: name,
|
|
658
|
+
resourceUrl: url
|
|
659
|
+
}, originalMsg);
|
|
660
|
+
} catch (runtimeError) {
|
|
661
|
+
reject(runtimeError);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
reject(loadError);
|
|
666
|
+
};
|
|
667
|
+
const url = getEntryUrl ? getEntryUrl(entry) : entry;
|
|
630
668
|
try {
|
|
631
|
-
if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${
|
|
669
|
+
if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${url}")${importCallback}`)([resolve, rejectEntry]);
|
|
632
670
|
else import(
|
|
633
671
|
/* webpackIgnore: true */
|
|
634
672
|
/* @vite-ignore */
|
|
635
|
-
|
|
636
|
-
).then(resolve).catch(
|
|
673
|
+
url
|
|
674
|
+
).then(resolve).catch(rejectEntry);
|
|
637
675
|
else resolve(remoteEntryExports);
|
|
638
676
|
} catch (e) {
|
|
639
|
-
error(`Failed to load ESM entry from "${
|
|
677
|
+
error(`Failed to load ESM entry from "${url}". ${e instanceof Error ? e.message : String(e)}`);
|
|
640
678
|
}
|
|
641
679
|
});
|
|
642
680
|
}
|
|
@@ -694,7 +732,9 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEnt
|
|
|
694
732
|
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
695
733
|
if (isEsmRemoteType(type)) return loadEsmEntry({
|
|
696
734
|
entry,
|
|
697
|
-
remoteEntryExports
|
|
735
|
+
remoteEntryExports,
|
|
736
|
+
name,
|
|
737
|
+
getEntryUrl
|
|
698
738
|
});
|
|
699
739
|
if (type === "system") return loadSystemJsEntry({
|
|
700
740
|
entry,
|
|
@@ -746,7 +786,16 @@ function getRemoteEntryUniqueKey(remoteInfo) {
|
|
|
746
786
|
async function getRemoteEntry(params) {
|
|
747
787
|
const { origin, remoteEntryExports, remoteInfo, getEntryUrl, resourceContext, _inErrorHandling = false } = params;
|
|
748
788
|
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
749
|
-
if (remoteEntryExports)
|
|
789
|
+
if (remoteEntryExports) {
|
|
790
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
791
|
+
origin,
|
|
792
|
+
remoteInfo,
|
|
793
|
+
remoteEntryExports,
|
|
794
|
+
resourceContext,
|
|
795
|
+
cached: true
|
|
796
|
+
});
|
|
797
|
+
return remoteEntryExports;
|
|
798
|
+
}
|
|
750
799
|
if (!globalLoading[uniqueKey]) {
|
|
751
800
|
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
752
801
|
const loaderHook = origin.loaderHook;
|
|
@@ -754,7 +803,8 @@ async function getRemoteEntry(params) {
|
|
|
754
803
|
origin,
|
|
755
804
|
loaderHook,
|
|
756
805
|
remoteInfo,
|
|
757
|
-
remoteEntryExports
|
|
806
|
+
remoteEntryExports,
|
|
807
|
+
resourceContext
|
|
758
808
|
}).then((res) => {
|
|
759
809
|
if (res) return res;
|
|
760
810
|
return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : logger.isBrowserEnvValue) ? loadEntryDom({
|
|
@@ -772,46 +822,69 @@ async function getRemoteEntry(params) {
|
|
|
772
822
|
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
773
823
|
origin,
|
|
774
824
|
remoteInfo,
|
|
775
|
-
remoteEntryExports: res
|
|
825
|
+
remoteEntryExports: res,
|
|
826
|
+
resourceContext
|
|
776
827
|
});
|
|
777
828
|
return res;
|
|
778
|
-
}).catch(async (
|
|
779
|
-
const
|
|
780
|
-
|
|
781
|
-
if (err instanceof Error && err.message.includes(RUNTIME_008) && !isScriptExecutionError && !_inErrorHandling) {
|
|
829
|
+
}).catch(async (loadError) => {
|
|
830
|
+
const isScriptExecutionError = loadError instanceof Error && loadError.message.includes("ScriptExecutionError");
|
|
831
|
+
if (loadError instanceof Error && loadError.message.includes(RUNTIME_008) && !isScriptExecutionError && !_inErrorHandling) {
|
|
782
832
|
const wrappedGetRemoteEntry = (params2) => {
|
|
783
833
|
return getRemoteEntry({
|
|
784
834
|
...params2,
|
|
785
835
|
_inErrorHandling: true
|
|
786
836
|
});
|
|
787
837
|
};
|
|
788
|
-
const
|
|
838
|
+
const recoveredRemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
|
|
789
839
|
getRemoteEntry: wrappedGetRemoteEntry,
|
|
790
840
|
origin,
|
|
791
841
|
remoteInfo,
|
|
792
842
|
remoteEntryExports,
|
|
793
843
|
globalLoading,
|
|
794
|
-
uniqueKey
|
|
844
|
+
uniqueKey
|
|
795
845
|
});
|
|
796
|
-
if (
|
|
846
|
+
if (recoveredRemoteEntryExports) {
|
|
797
847
|
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
798
848
|
origin,
|
|
799
849
|
remoteInfo,
|
|
800
|
-
remoteEntryExports:
|
|
850
|
+
remoteEntryExports: recoveredRemoteEntryExports,
|
|
851
|
+
resourceContext,
|
|
852
|
+
error: loadError,
|
|
801
853
|
recovered: true
|
|
802
854
|
});
|
|
803
|
-
return
|
|
855
|
+
return recoveredRemoteEntryExports;
|
|
804
856
|
}
|
|
805
857
|
}
|
|
806
858
|
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
807
859
|
origin,
|
|
808
860
|
remoteInfo,
|
|
809
|
-
|
|
861
|
+
resourceContext,
|
|
862
|
+
error: loadError
|
|
810
863
|
});
|
|
811
|
-
throw
|
|
864
|
+
throw loadError;
|
|
812
865
|
});
|
|
866
|
+
remoteEntryLoadingOrigins.set(globalLoading[uniqueKey], origin);
|
|
813
867
|
}
|
|
814
|
-
|
|
868
|
+
const remoteEntryLoading = globalLoading[uniqueKey];
|
|
869
|
+
if (remoteEntryLoadingOrigins.get(remoteEntryLoading) !== origin) try {
|
|
870
|
+
const result = await remoteEntryLoading;
|
|
871
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
872
|
+
origin,
|
|
873
|
+
remoteInfo,
|
|
874
|
+
remoteEntryExports: result,
|
|
875
|
+
resourceContext
|
|
876
|
+
});
|
|
877
|
+
return result;
|
|
878
|
+
} catch (loadError) {
|
|
879
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
880
|
+
origin,
|
|
881
|
+
remoteInfo,
|
|
882
|
+
resourceContext,
|
|
883
|
+
error: loadError
|
|
884
|
+
});
|
|
885
|
+
throw loadError;
|
|
886
|
+
}
|
|
887
|
+
return remoteEntryLoading;
|
|
815
888
|
}
|
|
816
889
|
function getRemoteInfo(remote) {
|
|
817
890
|
return {
|
|
@@ -872,6 +945,12 @@ function createAssetResult(context, url, status, error2) {
|
|
|
872
945
|
error: error2
|
|
873
946
|
};
|
|
874
947
|
}
|
|
948
|
+
function preloadAssetOnce(context, url, recordPreloadedAssets, preload) {
|
|
949
|
+
if (!recordPreloadedAssets) return preload();
|
|
950
|
+
if (getPreloadedAsset(url)) return Promise.resolve(createAssetResult(context, url, "cached"));
|
|
951
|
+
setPreloadedAsset(url);
|
|
952
|
+
return preload();
|
|
953
|
+
}
|
|
875
954
|
async function waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, context) {
|
|
876
955
|
const cachedRemote = host.moduleCache.get(entryRemoteInfo.name);
|
|
877
956
|
const url = entryRemoteInfo.entry;
|
|
@@ -958,7 +1037,7 @@ function createResourceContext(baseContext, resourceType) {
|
|
|
958
1037
|
function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseContext = {
|
|
959
1038
|
initiator: "preloadRemote",
|
|
960
1039
|
id: remoteInfo.name
|
|
961
|
-
}) {
|
|
1040
|
+
}, recordPreloadedAssets = true) {
|
|
962
1041
|
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
963
1042
|
const results = [];
|
|
964
1043
|
if (host.options.inBrowser) {
|
|
@@ -972,13 +1051,14 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseCont
|
|
|
972
1051
|
as: "style"
|
|
973
1052
|
};
|
|
974
1053
|
cssAssets.forEach((cssUrl) => {
|
|
975
|
-
|
|
1054
|
+
const context = createResourceContext(baseContext, "css");
|
|
1055
|
+
results.push(preloadAssetOnce(context, cssUrl, recordPreloadedAssets, () => waitForLinkPreload({
|
|
976
1056
|
host,
|
|
977
1057
|
remoteInfo,
|
|
978
1058
|
url: cssUrl,
|
|
979
1059
|
attrs: defaultAttrs2,
|
|
980
|
-
context
|
|
981
|
-
}));
|
|
1060
|
+
context
|
|
1061
|
+
})));
|
|
982
1062
|
});
|
|
983
1063
|
} else {
|
|
984
1064
|
const defaultAttrs2 = {
|
|
@@ -986,14 +1066,15 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseCont
|
|
|
986
1066
|
type: "text/css"
|
|
987
1067
|
};
|
|
988
1068
|
cssAssets.forEach((cssUrl) => {
|
|
989
|
-
|
|
1069
|
+
const context = createResourceContext(baseContext, "css");
|
|
1070
|
+
results.push(preloadAssetOnce(context, cssUrl, recordPreloadedAssets, () => waitForLinkPreload({
|
|
990
1071
|
host,
|
|
991
1072
|
remoteInfo,
|
|
992
1073
|
url: cssUrl,
|
|
993
1074
|
attrs: defaultAttrs2,
|
|
994
1075
|
needDeleteLink: false,
|
|
995
|
-
context
|
|
996
|
-
}));
|
|
1076
|
+
context
|
|
1077
|
+
})));
|
|
997
1078
|
});
|
|
998
1079
|
}
|
|
999
1080
|
let preloadJsAsset = waitForScriptPreload;
|
|
@@ -1015,13 +1096,14 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseCont
|
|
|
1015
1096
|
};
|
|
1016
1097
|
}
|
|
1017
1098
|
jsAssetsWithoutEntry.forEach((jsUrl) => {
|
|
1018
|
-
|
|
1099
|
+
const context = createResourceContext(baseContext, "js");
|
|
1100
|
+
results.push(preloadAssetOnce(context, jsUrl, recordPreloadedAssets, () => preloadJsAsset({
|
|
1019
1101
|
host,
|
|
1020
1102
|
remoteInfo,
|
|
1021
1103
|
url: jsUrl,
|
|
1022
1104
|
attrs: defaultAttrs,
|
|
1023
|
-
context
|
|
1024
|
-
}));
|
|
1105
|
+
context
|
|
1106
|
+
})));
|
|
1025
1107
|
});
|
|
1026
1108
|
}
|
|
1027
1109
|
return Promise.all(results);
|
|
@@ -1067,25 +1149,27 @@ var Module$1 = class {
|
|
|
1067
1149
|
this.remoteInfo = remoteInfo;
|
|
1068
1150
|
this.host = host;
|
|
1069
1151
|
}
|
|
1070
|
-
async getEntry(expose) {
|
|
1071
|
-
|
|
1152
|
+
async getEntry(expose, resourceContext) {
|
|
1153
|
+
const effectiveResourceContext = resourceContext || {
|
|
1154
|
+
initiator: "loadRemote",
|
|
1155
|
+
id: composeRemoteRequestId(this.remoteInfo.name, expose),
|
|
1156
|
+
resourceType: "remoteEntry",
|
|
1157
|
+
url: this.remoteInfo.entry,
|
|
1158
|
+
expose
|
|
1159
|
+
};
|
|
1072
1160
|
const remoteEntryExports = await getRemoteEntry({
|
|
1073
1161
|
origin: this.host,
|
|
1074
1162
|
remoteInfo: this.remoteInfo,
|
|
1075
1163
|
remoteEntryExports: this.remoteEntryExports,
|
|
1076
|
-
resourceContext:
|
|
1077
|
-
initiator: "loadRemote",
|
|
1078
|
-
id: composeRemoteRequestId(this.remoteInfo.name, expose),
|
|
1079
|
-
resourceType: "remoteEntry"
|
|
1080
|
-
}
|
|
1164
|
+
resourceContext: effectiveResourceContext
|
|
1081
1165
|
});
|
|
1082
1166
|
assert(remoteEntryExports, `remoteEntryExports is undefined
|
|
1083
1167
|
${lazyUtils.safeToString(this.remoteInfo)}`);
|
|
1084
1168
|
this.remoteEntryExports = remoteEntryExports;
|
|
1085
1169
|
return this.remoteEntryExports;
|
|
1086
1170
|
}
|
|
1087
|
-
async init(id, remoteSnapshot, rawInitScope, expose) {
|
|
1088
|
-
const remoteEntryExports = await this.getEntry(expose);
|
|
1171
|
+
async init(id, remoteSnapshot, rawInitScope, expose, resourceContext) {
|
|
1172
|
+
const remoteEntryExports = await this.getEntry(expose, resourceContext);
|
|
1089
1173
|
if (this.inited) {
|
|
1090
1174
|
await this.host.loaderHook.lifecycle.afterInitRemote.emit({
|
|
1091
1175
|
id,
|
|
@@ -491,6 +491,7 @@ const processModuleAlias = (name, subPath) => {
|
|
|
491
491
|
moduleName = moduleName + subPath;
|
|
492
492
|
return moduleName;
|
|
493
493
|
};
|
|
494
|
+
const MAX_PRELOADED_ASSETS = 2e3;
|
|
494
495
|
const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
|
|
495
496
|
const nativeGlobal = (() => {
|
|
496
497
|
try {
|
|
@@ -512,7 +513,7 @@ function includeOwnProperty(target, key) {
|
|
|
512
513
|
if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
|
|
513
514
|
const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
514
515
|
function setGlobalDefaultVal(target) {
|
|
515
|
-
var _a, _b, _c, _d, _e, _f;
|
|
516
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
516
517
|
if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
|
|
517
518
|
if (!includeOwnProperty(target, "__FEDERATION__")) {
|
|
518
519
|
definePropertyGlobalVal(target, "__FEDERATION__", {
|
|
@@ -521,7 +522,8 @@ function setGlobalDefaultVal(target) {
|
|
|
521
522
|
moduleInfo: {},
|
|
522
523
|
__SHARE__: {},
|
|
523
524
|
__MANIFEST_LOADING__: {},
|
|
524
|
-
__PRELOADED_MAP__: /* @__PURE__ */ new Map()
|
|
525
|
+
__PRELOADED_MAP__: /* @__PURE__ */ new Map(),
|
|
526
|
+
__PRELOADED_ASSETS__: /* @__PURE__ */ new Set()
|
|
525
527
|
});
|
|
526
528
|
definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
|
|
527
529
|
}
|
|
@@ -531,6 +533,7 @@ function setGlobalDefaultVal(target) {
|
|
|
531
533
|
(_d = target.__FEDERATION__).__SHARE__ ?? (_d.__SHARE__ = {});
|
|
532
534
|
(_e = target.__FEDERATION__).__MANIFEST_LOADING__ ?? (_e.__MANIFEST_LOADING__ = {});
|
|
533
535
|
(_f = target.__FEDERATION__).__PRELOADED_MAP__ ?? (_f.__PRELOADED_MAP__ = /* @__PURE__ */ new Map());
|
|
536
|
+
(_g = target.__FEDERATION__).__PRELOADED_ASSETS__ ?? (_g.__PRELOADED_ASSETS__ = /* @__PURE__ */ new Set());
|
|
534
537
|
}
|
|
535
538
|
setGlobalDefaultVal(CurrentGlobal);
|
|
536
539
|
setGlobalDefaultVal(nativeGlobal);
|
|
@@ -541,6 +544,15 @@ const getRemoteEntryExports = (name, globalName) => {
|
|
|
541
544
|
entryExports: CurrentGlobal[remoteEntryKey]
|
|
542
545
|
};
|
|
543
546
|
};
|
|
547
|
+
const getPreloadedAsset = (url) => CurrentGlobal.__FEDERATION__.__PRELOADED_ASSETS__.has(url);
|
|
548
|
+
const setPreloadedAsset = (url) => {
|
|
549
|
+
const preloadedAssets = CurrentGlobal.__FEDERATION__.__PRELOADED_ASSETS__;
|
|
550
|
+
preloadedAssets.add(url);
|
|
551
|
+
if (preloadedAssets.size > MAX_PRELOADED_ASSETS) {
|
|
552
|
+
const oldestUrl = preloadedAssets.values().next().value;
|
|
553
|
+
if (oldestUrl !== void 0) preloadedAssets.delete(oldestUrl);
|
|
554
|
+
}
|
|
555
|
+
};
|
|
544
556
|
const DEFAULT_SCOPE = "default";
|
|
545
557
|
const DEFAULT_REMOTE_TYPE = "global";
|
|
546
558
|
function composeRemoteRequestId(remoteName, expose) {
|
|
@@ -621,21 +633,47 @@ const runtimeDescMap = {
|
|
|
621
633
|
...runtimeDescMap
|
|
622
634
|
});
|
|
623
635
|
const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
|
|
636
|
+
const remoteEntryLoadingOrigins = /* @__PURE__ */ new WeakMap();
|
|
637
|
+
const esmRemoteEntryLoadErrorMessages = [
|
|
638
|
+
"Failed to fetch dynamically imported module",
|
|
639
|
+
"Importing a module script failed",
|
|
640
|
+
"error loading dynamically imported module"
|
|
641
|
+
];
|
|
642
|
+
function isEsmRemoteEntryLoadError(err) {
|
|
643
|
+
if (!(err instanceof TypeError)) return false;
|
|
644
|
+
return esmRemoteEntryLoadErrorMessages.some((loadErrorMessage) => err.message.includes(loadErrorMessage));
|
|
645
|
+
}
|
|
624
646
|
function isEsmRemoteType(type) {
|
|
625
647
|
return type === "esm" || type === "module";
|
|
626
648
|
}
|
|
627
|
-
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
649
|
+
async function loadEsmEntry({ entry, remoteEntryExports, name, getEntryUrl }) {
|
|
628
650
|
return new Promise((resolve, reject) => {
|
|
651
|
+
const rejectEntry = (loadError) => {
|
|
652
|
+
if (isEsmRemoteEntryLoadError(loadError)) {
|
|
653
|
+
const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
|
|
654
|
+
try {
|
|
655
|
+
error(RUNTIME_008, runtimeDescMap, {
|
|
656
|
+
remoteName: name,
|
|
657
|
+
resourceUrl: url
|
|
658
|
+
}, originalMsg);
|
|
659
|
+
} catch (runtimeError) {
|
|
660
|
+
reject(runtimeError);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
reject(loadError);
|
|
665
|
+
};
|
|
666
|
+
const url = getEntryUrl ? getEntryUrl(entry) : entry;
|
|
629
667
|
try {
|
|
630
|
-
if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${
|
|
668
|
+
if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${url}")${importCallback}`)([resolve, rejectEntry]);
|
|
631
669
|
else import(
|
|
632
670
|
/* webpackIgnore: true */
|
|
633
671
|
/* @vite-ignore */
|
|
634
|
-
|
|
635
|
-
).then(resolve).catch(
|
|
672
|
+
url
|
|
673
|
+
).then(resolve).catch(rejectEntry);
|
|
636
674
|
else resolve(remoteEntryExports);
|
|
637
675
|
} catch (e) {
|
|
638
|
-
error(`Failed to load ESM entry from "${
|
|
676
|
+
error(`Failed to load ESM entry from "${url}". ${e instanceof Error ? e.message : String(e)}`);
|
|
639
677
|
}
|
|
640
678
|
});
|
|
641
679
|
}
|
|
@@ -693,7 +731,9 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEnt
|
|
|
693
731
|
const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
|
|
694
732
|
if (isEsmRemoteType(type)) return loadEsmEntry({
|
|
695
733
|
entry,
|
|
696
|
-
remoteEntryExports
|
|
734
|
+
remoteEntryExports,
|
|
735
|
+
name,
|
|
736
|
+
getEntryUrl
|
|
697
737
|
});
|
|
698
738
|
if (type === "system") return loadSystemJsEntry({
|
|
699
739
|
entry,
|
|
@@ -745,7 +785,16 @@ function getRemoteEntryUniqueKey(remoteInfo) {
|
|
|
745
785
|
async function getRemoteEntry(params) {
|
|
746
786
|
const { origin, remoteEntryExports, remoteInfo, getEntryUrl, resourceContext, _inErrorHandling = false } = params;
|
|
747
787
|
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
748
|
-
if (remoteEntryExports)
|
|
788
|
+
if (remoteEntryExports) {
|
|
789
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
790
|
+
origin,
|
|
791
|
+
remoteInfo,
|
|
792
|
+
remoteEntryExports,
|
|
793
|
+
resourceContext,
|
|
794
|
+
cached: true
|
|
795
|
+
});
|
|
796
|
+
return remoteEntryExports;
|
|
797
|
+
}
|
|
749
798
|
if (!globalLoading[uniqueKey]) {
|
|
750
799
|
const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
|
|
751
800
|
const loaderHook = origin.loaderHook;
|
|
@@ -753,7 +802,8 @@ async function getRemoteEntry(params) {
|
|
|
753
802
|
origin,
|
|
754
803
|
loaderHook,
|
|
755
804
|
remoteInfo,
|
|
756
|
-
remoteEntryExports
|
|
805
|
+
remoteEntryExports,
|
|
806
|
+
resourceContext
|
|
757
807
|
}).then((res) => {
|
|
758
808
|
if (res) return res;
|
|
759
809
|
return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : isBrowserEnvValue) ? loadEntryDom({
|
|
@@ -771,46 +821,69 @@ async function getRemoteEntry(params) {
|
|
|
771
821
|
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
772
822
|
origin,
|
|
773
823
|
remoteInfo,
|
|
774
|
-
remoteEntryExports: res
|
|
824
|
+
remoteEntryExports: res,
|
|
825
|
+
resourceContext
|
|
775
826
|
});
|
|
776
827
|
return res;
|
|
777
|
-
}).catch(async (
|
|
778
|
-
const
|
|
779
|
-
|
|
780
|
-
if (err instanceof Error && err.message.includes(RUNTIME_008) && !isScriptExecutionError && !_inErrorHandling) {
|
|
828
|
+
}).catch(async (loadError) => {
|
|
829
|
+
const isScriptExecutionError = loadError instanceof Error && loadError.message.includes("ScriptExecutionError");
|
|
830
|
+
if (loadError instanceof Error && loadError.message.includes(RUNTIME_008) && !isScriptExecutionError && !_inErrorHandling) {
|
|
781
831
|
const wrappedGetRemoteEntry = (params2) => {
|
|
782
832
|
return getRemoteEntry({
|
|
783
833
|
...params2,
|
|
784
834
|
_inErrorHandling: true
|
|
785
835
|
});
|
|
786
836
|
};
|
|
787
|
-
const
|
|
837
|
+
const recoveredRemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
|
|
788
838
|
getRemoteEntry: wrappedGetRemoteEntry,
|
|
789
839
|
origin,
|
|
790
840
|
remoteInfo,
|
|
791
841
|
remoteEntryExports,
|
|
792
842
|
globalLoading,
|
|
793
|
-
uniqueKey
|
|
843
|
+
uniqueKey
|
|
794
844
|
});
|
|
795
|
-
if (
|
|
845
|
+
if (recoveredRemoteEntryExports) {
|
|
796
846
|
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
797
847
|
origin,
|
|
798
848
|
remoteInfo,
|
|
799
|
-
remoteEntryExports:
|
|
849
|
+
remoteEntryExports: recoveredRemoteEntryExports,
|
|
850
|
+
resourceContext,
|
|
851
|
+
error: loadError,
|
|
800
852
|
recovered: true
|
|
801
853
|
});
|
|
802
|
-
return
|
|
854
|
+
return recoveredRemoteEntryExports;
|
|
803
855
|
}
|
|
804
856
|
}
|
|
805
857
|
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
806
858
|
origin,
|
|
807
859
|
remoteInfo,
|
|
808
|
-
|
|
860
|
+
resourceContext,
|
|
861
|
+
error: loadError
|
|
809
862
|
});
|
|
810
|
-
throw
|
|
863
|
+
throw loadError;
|
|
811
864
|
});
|
|
865
|
+
remoteEntryLoadingOrigins.set(globalLoading[uniqueKey], origin);
|
|
812
866
|
}
|
|
813
|
-
|
|
867
|
+
const remoteEntryLoading = globalLoading[uniqueKey];
|
|
868
|
+
if (remoteEntryLoadingOrigins.get(remoteEntryLoading) !== origin) try {
|
|
869
|
+
const result = await remoteEntryLoading;
|
|
870
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
871
|
+
origin,
|
|
872
|
+
remoteInfo,
|
|
873
|
+
remoteEntryExports: result,
|
|
874
|
+
resourceContext
|
|
875
|
+
});
|
|
876
|
+
return result;
|
|
877
|
+
} catch (loadError) {
|
|
878
|
+
await origin.loaderHook.lifecycle.afterLoadEntry.emit({
|
|
879
|
+
origin,
|
|
880
|
+
remoteInfo,
|
|
881
|
+
resourceContext,
|
|
882
|
+
error: loadError
|
|
883
|
+
});
|
|
884
|
+
throw loadError;
|
|
885
|
+
}
|
|
886
|
+
return remoteEntryLoading;
|
|
814
887
|
}
|
|
815
888
|
function getRemoteInfo(remote) {
|
|
816
889
|
return {
|
|
@@ -871,6 +944,12 @@ function createAssetResult(context, url, status, error2) {
|
|
|
871
944
|
error: error2
|
|
872
945
|
};
|
|
873
946
|
}
|
|
947
|
+
function preloadAssetOnce(context, url, recordPreloadedAssets, preload) {
|
|
948
|
+
if (!recordPreloadedAssets) return preload();
|
|
949
|
+
if (getPreloadedAsset(url)) return Promise.resolve(createAssetResult(context, url, "cached"));
|
|
950
|
+
setPreloadedAsset(url);
|
|
951
|
+
return preload();
|
|
952
|
+
}
|
|
874
953
|
async function waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, context) {
|
|
875
954
|
const cachedRemote = host.moduleCache.get(entryRemoteInfo.name);
|
|
876
955
|
const url = entryRemoteInfo.entry;
|
|
@@ -957,7 +1036,7 @@ function createResourceContext(baseContext, resourceType) {
|
|
|
957
1036
|
function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseContext = {
|
|
958
1037
|
initiator: "preloadRemote",
|
|
959
1038
|
id: remoteInfo.name
|
|
960
|
-
}) {
|
|
1039
|
+
}, recordPreloadedAssets = true) {
|
|
961
1040
|
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
962
1041
|
const results = [];
|
|
963
1042
|
if (host.options.inBrowser) {
|
|
@@ -971,13 +1050,14 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseCont
|
|
|
971
1050
|
as: "style"
|
|
972
1051
|
};
|
|
973
1052
|
cssAssets.forEach((cssUrl) => {
|
|
974
|
-
|
|
1053
|
+
const context = createResourceContext(baseContext, "css");
|
|
1054
|
+
results.push(preloadAssetOnce(context, cssUrl, recordPreloadedAssets, () => waitForLinkPreload({
|
|
975
1055
|
host,
|
|
976
1056
|
remoteInfo,
|
|
977
1057
|
url: cssUrl,
|
|
978
1058
|
attrs: defaultAttrs2,
|
|
979
|
-
context
|
|
980
|
-
}));
|
|
1059
|
+
context
|
|
1060
|
+
})));
|
|
981
1061
|
});
|
|
982
1062
|
} else {
|
|
983
1063
|
const defaultAttrs2 = {
|
|
@@ -985,14 +1065,15 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseCont
|
|
|
985
1065
|
type: "text/css"
|
|
986
1066
|
};
|
|
987
1067
|
cssAssets.forEach((cssUrl) => {
|
|
988
|
-
|
|
1068
|
+
const context = createResourceContext(baseContext, "css");
|
|
1069
|
+
results.push(preloadAssetOnce(context, cssUrl, recordPreloadedAssets, () => waitForLinkPreload({
|
|
989
1070
|
host,
|
|
990
1071
|
remoteInfo,
|
|
991
1072
|
url: cssUrl,
|
|
992
1073
|
attrs: defaultAttrs2,
|
|
993
1074
|
needDeleteLink: false,
|
|
994
|
-
context
|
|
995
|
-
}));
|
|
1075
|
+
context
|
|
1076
|
+
})));
|
|
996
1077
|
});
|
|
997
1078
|
}
|
|
998
1079
|
let preloadJsAsset = waitForScriptPreload;
|
|
@@ -1014,13 +1095,14 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseCont
|
|
|
1014
1095
|
};
|
|
1015
1096
|
}
|
|
1016
1097
|
jsAssetsWithoutEntry.forEach((jsUrl) => {
|
|
1017
|
-
|
|
1098
|
+
const context = createResourceContext(baseContext, "js");
|
|
1099
|
+
results.push(preloadAssetOnce(context, jsUrl, recordPreloadedAssets, () => preloadJsAsset({
|
|
1018
1100
|
host,
|
|
1019
1101
|
remoteInfo,
|
|
1020
1102
|
url: jsUrl,
|
|
1021
1103
|
attrs: defaultAttrs,
|
|
1022
|
-
context
|
|
1023
|
-
}));
|
|
1104
|
+
context
|
|
1105
|
+
})));
|
|
1024
1106
|
});
|
|
1025
1107
|
}
|
|
1026
1108
|
return Promise.all(results);
|
|
@@ -1066,25 +1148,27 @@ var Module$1 = class {
|
|
|
1066
1148
|
this.remoteInfo = remoteInfo;
|
|
1067
1149
|
this.host = host;
|
|
1068
1150
|
}
|
|
1069
|
-
async getEntry(expose) {
|
|
1070
|
-
|
|
1151
|
+
async getEntry(expose, resourceContext) {
|
|
1152
|
+
const effectiveResourceContext = resourceContext || {
|
|
1153
|
+
initiator: "loadRemote",
|
|
1154
|
+
id: composeRemoteRequestId(this.remoteInfo.name, expose),
|
|
1155
|
+
resourceType: "remoteEntry",
|
|
1156
|
+
url: this.remoteInfo.entry,
|
|
1157
|
+
expose
|
|
1158
|
+
};
|
|
1071
1159
|
const remoteEntryExports = await getRemoteEntry({
|
|
1072
1160
|
origin: this.host,
|
|
1073
1161
|
remoteInfo: this.remoteInfo,
|
|
1074
1162
|
remoteEntryExports: this.remoteEntryExports,
|
|
1075
|
-
resourceContext:
|
|
1076
|
-
initiator: "loadRemote",
|
|
1077
|
-
id: composeRemoteRequestId(this.remoteInfo.name, expose),
|
|
1078
|
-
resourceType: "remoteEntry"
|
|
1079
|
-
}
|
|
1163
|
+
resourceContext: effectiveResourceContext
|
|
1080
1164
|
});
|
|
1081
1165
|
assert(remoteEntryExports, `remoteEntryExports is undefined
|
|
1082
1166
|
${safeToString(this.remoteInfo)}`);
|
|
1083
1167
|
this.remoteEntryExports = remoteEntryExports;
|
|
1084
1168
|
return this.remoteEntryExports;
|
|
1085
1169
|
}
|
|
1086
|
-
async init(id, remoteSnapshot, rawInitScope, expose) {
|
|
1087
|
-
const remoteEntryExports = await this.getEntry(expose);
|
|
1170
|
+
async init(id, remoteSnapshot, rawInitScope, expose, resourceContext) {
|
|
1171
|
+
const remoteEntryExports = await this.getEntry(expose, resourceContext);
|
|
1088
1172
|
if (this.inited) {
|
|
1089
1173
|
await this.host.loaderHook.lifecycle.afterInitRemote.emit({
|
|
1090
1174
|
id,
|
package/dist/v18.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const client = require("react-dom/client");
|
|
4
|
-
const bridgeBase = require("./bridge-base-
|
|
4
|
+
const bridgeBase = require("./bridge-base-DSYKAGGD.js");
|
|
5
5
|
function createReact18Root(container, options) {
|
|
6
6
|
return client.createRoot(container, options);
|
|
7
7
|
}
|