@module-federation/vite 1.16.1 → 1.16.3

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/lib/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_packageUtils = require("./packageUtils-CbbnJvKu.cjs");
2
+ const require_packageUtils = require("./packageUtils-se-UDhCa.cjs");
3
3
  let fs = require("fs");
4
4
  fs = require_packageUtils.__toESM(fs);
5
5
  let module$1 = require("module");
@@ -418,24 +418,51 @@ function getSuffix(name) {
418
418
  }
419
419
  const patternMap = {};
420
420
  const cacheMap = {};
421
+ const VITE_ID_PREFIX = "/@id/";
422
+ const VITE_ENCODED_NULL_BYTE_PREFIX = `${VITE_ID_PREFIX}__x00__`;
423
+ function escapeRegExp$1(value) {
424
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
425
+ }
426
+ function createViteEncodedIdPrefixRegExp(sourcePrefix = "") {
427
+ return new RegExp(`^(?:${escapeRegExp$1(VITE_ENCODED_NULL_BYTE_PREFIX)})?${sourcePrefix}`);
428
+ }
429
+ function toViteEncodedId(id) {
430
+ return `${VITE_ENCODED_NULL_BYTE_PREFIX}${id}`;
431
+ }
432
+ function decodeViteId(id) {
433
+ if (!id.startsWith("/@id/")) return id;
434
+ const viteId = id.slice(5);
435
+ return viteId.startsWith("__x00__") ? `\0${viteId.slice(7)}` : viteId;
436
+ }
421
437
  function assertModuleFound(tag, str = "") {
422
438
  const module = VirtualModule.findModule(tag, str);
423
439
  if (!module) throw require_packageUtils.createModuleFederationError(`Module Federation shared module '${str}' not found. Please ensure it's installed as a dependency in your package.json.`);
424
440
  return module;
425
441
  }
426
- var VirtualModule = class {
442
+ function normalizeVirtualModuleId(id) {
443
+ const decoded = decodeViteId(id).replace(/^\0+/, "");
444
+ const queryIndex = decoded.indexOf("?");
445
+ const hashIndex = decoded.indexOf("#");
446
+ const endIndex = queryIndex === -1 ? hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
447
+ return endIndex === -1 ? decoded : decoded.slice(0, endIndex);
448
+ }
449
+ var VirtualModule = class VirtualModule {
427
450
  name;
428
451
  tag;
429
452
  suffix;
430
453
  inited = false;
431
454
  code;
432
- static findModule(tag, str = "") {
455
+ static findName(tag, str = "") {
433
456
  if (!patternMap[tag]) patternMap[tag] = new RegExp(`(.*${require_packageUtils.packageNameEncode(tag)}(.+?)${require_packageUtils.packageNameEncode(tag)}.*)`);
434
- const moduleName = (str.match(patternMap[tag]) || [])[2];
435
- if (moduleName) return cacheMap[tag][require_packageUtils.packageNameDecode(moduleName)];
457
+ const moduleName = (normalizeVirtualModuleId(str).match(patternMap[tag]) || [])[2];
458
+ return moduleName ? require_packageUtils.packageNameDecode(moduleName) : void 0;
459
+ }
460
+ static findModule(tag, str = "") {
461
+ const moduleName = VirtualModule.findName(tag, str);
462
+ return moduleName ? cacheMap[tag][moduleName] : void 0;
436
463
  }
437
464
  static findById(id) {
438
- const normalized = id.replace(/^\0+/, "").replace(/^\/@id\//, "").replace(/^__x00__/, "").replace(/[?#].*$/, "");
465
+ const normalized = normalizeVirtualModuleId(id);
439
466
  for (const modules of Object.values(cacheMap)) for (const module of Object.values(modules)) if (module.getImportId() === normalized) return module;
440
467
  }
441
468
  constructor(name, tag = "__mf_v__", suffix = "") {
@@ -749,11 +776,9 @@ function getPackageEsmEntryPath(pkg) {
749
776
  resolveSubpathWithRequire: false
750
777
  }) || resolvePackageEntryFromProjectRoot(pkg);
751
778
  }
752
- function getEsmNamedExports(pkg) {
779
+ function getEsmNamedExportsFromFile(entryPath) {
753
780
  let source = "";
754
- let entryPath;
755
781
  try {
756
- entryPath = getPackageEsmEntryPath(pkg);
757
782
  if (!entryPath) return [];
758
783
  const { initSync, parse } = localRequire("es-module-lexer");
759
784
  initSync();
@@ -768,6 +793,48 @@ function getEsmNamedExports(pkg) {
768
793
  return source ? getNamedExportsViaRegex(source, entryPath) : [];
769
794
  }
770
795
  }
796
+ function getEsmNamedExports(pkg) {
797
+ return getEsmNamedExportsFromFile(getPackageEsmEntryPath(pkg));
798
+ }
799
+ function resolveConfiguredImportPath(importSource) {
800
+ if (pathe.default.isAbsolute(importSource)) return resolveFileLikeModule(importSource);
801
+ const projectRoot = require_packageUtils.getPackageDetectionCwd();
802
+ if (importSource.startsWith(".")) return resolveFileLikeModule(pathe.default.resolve(projectRoot, importSource));
803
+ const esmEntry = require_packageUtils.getInstalledPackageEntry(importSource, {
804
+ conditions: [
805
+ "browser",
806
+ "import",
807
+ "module",
808
+ "default"
809
+ ],
810
+ resolveSubpathWithRequire: false
811
+ });
812
+ if (esmEntry) return esmEntry;
813
+ try {
814
+ return (0, module$1.createRequire)(new URL(`file://${pathe.default.join(projectRoot, "package.json")}`)).resolve(importSource);
815
+ } catch {
816
+ return;
817
+ }
818
+ }
819
+ function resolveFileLikeModule(filePath) {
820
+ if ((0, fs.existsSync)(filePath) && !(0, fs.statSync)(filePath).isDirectory()) return filePath;
821
+ const extensions = [
822
+ ".ts",
823
+ ".tsx",
824
+ ".js",
825
+ ".jsx",
826
+ ".mjs",
827
+ ".mts"
828
+ ];
829
+ for (const ext of extensions) {
830
+ const candidate = filePath + ext;
831
+ if ((0, fs.existsSync)(candidate) && !(0, fs.statSync)(candidate).isDirectory()) return candidate;
832
+ }
833
+ for (const ext of extensions) {
834
+ const candidate = pathe.default.join(filePath, "index" + ext);
835
+ if ((0, fs.existsSync)(candidate) && !(0, fs.statSync)(candidate).isDirectory()) return candidate;
836
+ }
837
+ }
771
838
  function resolveRelativeModule(filePath, specifier) {
772
839
  const dir = pathe.default.dirname(filePath);
773
840
  const exact = pathe.default.resolve(dir, specifier);
@@ -837,6 +904,14 @@ function getPackageNamedExports(pkg) {
837
904
  return getEsmNamedExports(pkg);
838
905
  }
839
906
  }
907
+ function getSharedNamedExports(pkg, shareItem) {
908
+ const configuredImport = shareItem?.shareConfig.import;
909
+ if (typeof configuredImport === "string") {
910
+ const configuredNamedExports = getEsmNamedExportsFromFile(resolveConfiguredImportPath(configuredImport));
911
+ if (configuredNamedExports.length > 0) return configuredNamedExports;
912
+ }
913
+ return getPackageNamedExports(pkg);
914
+ }
840
915
  function getLocalProviderImportPath(pkg) {
841
916
  try {
842
917
  const resolved = (0, module$1.createRequire)(new URL(`file://${pathe.default.join(require_packageUtils.getPackageDetectionCwd(), "package.json")}`)).resolve(pkg);
@@ -907,6 +982,20 @@ function writePreBuildLibPath(pkg, shareItem) {
907
982
  if (!preBuildCacheMap[pkg]) preBuildCacheMap[pkg] = new VirtualModule(pkg, PREBUILD_TAG, ".js");
908
983
  preBuildShareItemMap[pkg] = shareItem;
909
984
  const importSource = getConcreteSharedImportSource(pkg, shareItem) || pkg;
985
+ if (pkg === "react/compiler-runtime") {
986
+ preBuildCacheMap[pkg].writeSync(`
987
+ const __mfCacheGlobalKey = "__mf_module_cache__";
988
+ export const c = function(size) {
989
+ const cache = globalThis[__mfCacheGlobalKey]?.share;
990
+ const sharedReact = cache?.['react'];
991
+ const reactExports = sharedReact?.default ?? sharedReact;
992
+ const internals = reactExports?.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
993
+ return internals?.H?.useMemoCache(size);
994
+ };
995
+ export default { c };
996
+ `, true);
997
+ return;
998
+ }
910
999
  if (pkg === "react/jsx-dev-runtime") {
911
1000
  preBuildCacheMap[pkg].writeSync(`
912
1001
  import __mfPrebuildDefault from ${escapeGeneratedStringLiteral(importSource)};
@@ -930,7 +1019,7 @@ function writePreBuildLibPath(pkg, shareItem) {
930
1019
  `, true);
931
1020
  return;
932
1021
  }
933
- const namedExports = getPackageNamedExports(pkg);
1022
+ const namedExports = getSharedNamedExports(pkg, shareItem);
934
1023
  if (namedExports.length > 0) {
935
1024
  const namedExportVars = namedExports.map((_name, i) => `__mf_${i}`);
936
1025
  const declarations = namedExports.map((name, i) => `const ${namedExportVars[i]} = __mfPrebuildExports[${escapeGeneratedStringLiteral(name)}];`).join("\n ");
@@ -970,7 +1059,28 @@ function getLoadShareModulePath(pkg, isRolldown) {
970
1059
  if (!loadShareCacheMap[pkg]) getLoadShareImportId(pkg, isRolldown);
971
1060
  return loadShareCacheMap[pkg].getImportId();
972
1061
  }
973
- function generateDeferredHostProvidedExports(namedExports, pkg) {
1062
+ function toViteOptimizedDepVirtualId(id) {
1063
+ return toViteEncodedId(id);
1064
+ }
1065
+ function getCachedLoadSharePkg(id) {
1066
+ const normalized = normalizeVirtualModuleId(id);
1067
+ if (!normalized.startsWith("virtual:mf:")) return;
1068
+ const pkg = VirtualModule.findName(LOAD_SHARE_TAG, normalized);
1069
+ if (!pkg) return;
1070
+ return pkg;
1071
+ }
1072
+ function materializeCachedLoadShareModule(options) {
1073
+ const pkg = getCachedLoadSharePkg(options.id);
1074
+ if (!pkg) return;
1075
+ const key = options.findSharedKey(pkg, options.shared);
1076
+ if (!key) return;
1077
+ const shareItem = options.shared[key];
1078
+ writeLoadShareModule(pkg, shareItem, options.command, options.isRolldown);
1079
+ if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(pkg, shareItem);
1080
+ options.addUsedShares(pkg);
1081
+ options.writeLocalSharedImportMap();
1082
+ }
1083
+ function generateDeferredHostProvidedExports(namedExports, pkg, cacheKey) {
974
1084
  const namedExportVars = namedExports.map((_name, i) => `__mf_${i}`);
975
1085
  const declarations = ["let __mf_default;", ...namedExportVars.map((name) => `let ${name};`)].join("\n ");
976
1086
  const assignments = [...namedExports.map((name, i) => `${namedExportVars[i]} = exportModule[${escapeGeneratedStringLiteral(name)}];`), "__mf_default = exportModule.default ?? exportModule;"].join("\n ");
@@ -979,10 +1089,10 @@ function generateDeferredHostProvidedExports(namedExports, pkg) {
979
1089
  const __mfApplyHostProvidedExports = (exportModule) => {
980
1090
  ${assignments}
981
1091
  };
982
- let exportModule = __mfModuleCache.share[${escapeGeneratedStringLiteral(pkg)}];
1092
+ let exportModule = __mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}];
983
1093
  if (exportModule === undefined) {
984
1094
  initPromise.then(() => {
985
- exportModule = __mfModuleCache.share[${escapeGeneratedStringLiteral(pkg)}];
1095
+ exportModule = __mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}];
986
1096
  if (exportModule === undefined) {
987
1097
  throw new Error("[Module Federation] Shared module ${pkg} was imported before federation bootstrap finished.");
988
1098
  }
@@ -1013,13 +1123,14 @@ const normalizeLocalShareModuleCode = `const __mfNormalizeShareModule = (mod) =>
1013
1123
  function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
1014
1124
  if (!loadShareCacheMap[pkg]) loadShareCacheMap[pkg] = new VirtualModule(pkg, LOAD_SHARE_TAG, ".mjs");
1015
1125
  const importLine = getRuntimeModuleCacheBootstrapCode();
1126
+ const cacheKey = require_packageUtils.getSharedCacheKey(pkg, shareItem);
1016
1127
  if (shareItem.shareConfig.import === false) {
1017
1128
  const namedExports = getPackageNamedExports(pkg);
1018
1129
  let exportLine;
1019
- if (namedExports.length > 0) exportLine = generateDeferredHostProvidedExports(namedExports, pkg);
1130
+ if (namedExports.length > 0) exportLine = generateDeferredHostProvidedExports(namedExports, pkg, cacheKey);
1020
1131
  else {
1021
1132
  require_packageUtils.mfWarn(`Shared dependency "${pkg}" has import: false but is not installed locally.\n Named imports (e.g. import { ... } from '${pkg}') will not work in production builds.\n Install it as a devDependency to enable named export detection.`);
1022
- exportLine = generateDeferredHostProvidedExports([], pkg);
1133
+ exportLine = generateDeferredHostProvidedExports([], pkg, cacheKey);
1023
1134
  }
1024
1135
  loadShareCacheMap[pkg].writeSync(`
1025
1136
  ${getRuntimeInitPromiseBootstrapCode()}
@@ -1036,7 +1147,7 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
1036
1147
  const lazyLocalFallbackSource = concreteSharedImportSource || localProviderPath || sharedImportSource;
1037
1148
  const skipServePrebuildWarmup = command !== "build" && (pkg === "lit" || pkg.startsWith("lit/"));
1038
1149
  const usesLazyLocalFallback = isWorkspacePackage && shareItem.shareConfig.singleton === true;
1039
- const namedExports = getPackageNamedExports(pkg);
1150
+ const namedExports = getSharedNamedExports(pkg, shareItem);
1040
1151
  let exportLine;
1041
1152
  if (namedExports.length > 0) {
1042
1153
  const destructure = `const { ${namedExports.map((name, i) => `${name}: __mf_${i}`).join(", ")} } = exportModule;`;
@@ -1060,11 +1171,11 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown) {
1060
1171
  ${devDynamicImportLine}
1061
1172
  ${importLine}
1062
1173
  ${normalizeLocalShareModuleCode}
1063
- let exportModule = __mfModuleCache.share[${escapeGeneratedStringLiteral(pkg)}]
1174
+ let exportModule = __mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}]
1064
1175
  if (exportModule === undefined) {
1065
1176
  ${usesLazyLocalFallback ? `exportModule = __mfNormalizeShareModule(await import(${escapeGeneratedStringLiteral(lazyLocalFallbackSource)}));
1066
- __mfModuleCache.share[${escapeGeneratedStringLiteral(pkg)}] = exportModule;` : `exportModule = __mfNormalizeShareModule(__mfLocalShare);
1067
- __mfModuleCache.share[${escapeGeneratedStringLiteral(pkg)}] = exportModule;`}
1177
+ __mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}] = exportModule;` : `exportModule = __mfNormalizeShareModule(__mfLocalShare);
1178
+ __mfModuleCache.share[${escapeGeneratedStringLiteral(cacheKey)}] = exportModule;`}
1068
1179
  }
1069
1180
  ${exportLine}
1070
1181
  `, true);
@@ -1136,7 +1247,7 @@ function generateLocalSharedImportMap() {
1136
1247
  version: ${JSON.stringify(shareItem.version)},
1137
1248
  scope: [${JSON.stringify(shareItem.scope)}],
1138
1249
  loaded: false,
1139
- from: ${JSON.stringify(options.internalName)},
1250
+ from: ${JSON.stringify(options.name)},
1140
1251
  async get () {
1141
1252
  if (${shareItem.shareConfig.import === false}) {
1142
1253
  throw new Error(\`[Module Federation] Shared module '\${${JSON.stringify(key)}}' must be provided by host\`);
@@ -1218,8 +1329,9 @@ function getShareItemForPreload(pkg) {
1218
1329
  if (isExplicitSharedKey(pkg)) return shared[pkg];
1219
1330
  if (isExplicitSharedKey(wildcardKey)) return shared[wildcardKey];
1220
1331
  }
1221
- function generateSharedCacheSeedItem(pkg, importPath) {
1222
- return `if (__mfModuleCache.share[${JSON.stringify(pkg)}] === undefined) {
1332
+ function generateSharedCacheSeedItem(pkg, shareItem, importPath) {
1333
+ const cacheKey = require_packageUtils.getSharedCacheKey(pkg, shareItem);
1334
+ return `if (__mfModuleCache.share[${JSON.stringify(cacheKey)}] === undefined) {
1223
1335
  const mod = await import(${JSON.stringify(importPath)});
1224
1336
  ${normalizeRuntimeShareCode}
1225
1337
  const normalizedModule = __mfNormalizeRuntimeShare(mod);
@@ -1228,7 +1340,7 @@ function generateSharedCacheSeedItem(pkg, importPath) {
1228
1340
  value: true,
1229
1341
  enumerable: false
1230
1342
  });
1231
- __mfModuleCache.share[${JSON.stringify(pkg)}] = exportModule;
1343
+ __mfModuleCache.share[${JSON.stringify(cacheKey)}] = exportModule;
1232
1344
  }`;
1233
1345
  }
1234
1346
  const normalizeRuntimeShareCode = `const __mfNormalizeRuntimeShare = (mod) => {
@@ -1246,7 +1358,7 @@ function generateDirectSharedCacheSeedCode(command = "build") {
1246
1358
  return getOrderedUsedShares().map((pkg) => {
1247
1359
  const shareItem = getShareItemForPreload(pkg);
1248
1360
  if (!shareItem || shareItem.shareConfig.import === false) return null;
1249
- return generateSharedCacheSeedItem(pkg, command === "serve" ? getLocalSharedPackagePath(pkg, shareItem) : getDirectSharedCacheSeedImportPath(pkg, shareItem));
1361
+ return generateSharedCacheSeedItem(pkg, shareItem, command === "serve" ? getLocalSharedPackagePath(pkg, shareItem) : getDirectSharedCacheSeedImportPath(pkg, shareItem));
1250
1362
  }).filter((item) => item !== null).join("\n");
1251
1363
  }
1252
1364
  function getBrowserImportPath(importPath) {
@@ -1268,7 +1380,7 @@ function generateHostAutoInitSharedCacheSeedCode(command = "build") {
1268
1380
  if (command === "build") return "";
1269
1381
  return getHostAutoInitSharedSeedItems().map(({ pkg, shareItem }) => {
1270
1382
  if (!shareItem) return null;
1271
- return generateSharedCacheSeedItem(pkg, getBrowserImportPath(getDirectSharedCacheSeedImportPath(pkg, shareItem)));
1383
+ return generateSharedCacheSeedItem(pkg, shareItem, getBrowserImportPath(getDirectSharedCacheSeedImportPath(pkg, shareItem)));
1272
1384
  }).filter((item) => item !== null).join("\n");
1273
1385
  }
1274
1386
  const REMOTE_ENTRY_ID = "virtual:mf-REMOTE_ENTRY_ID";
@@ -1306,7 +1418,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
1306
1418
  ${getRuntimeModuleCacheBootstrapCode()}
1307
1419
  const initTokens = {}
1308
1420
  const shareScopeName = ${JSON.stringify(options.shareScope)}
1309
- const mfName = ${JSON.stringify(options.internalName)}
1421
+ const mfName = ${JSON.stringify(options.name)}
1310
1422
  let localSharedImportMapPromise
1311
1423
  let exposesMapPromise
1312
1424
  const shouldRetrySharedInitError = ${command !== "build"} && ((error) => {
@@ -1348,6 +1460,28 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
1348
1460
 
1349
1461
  async function init(shared = {}, initScope = []) {
1350
1462
  const {usedShared, usedRemotes} = await getLocalSharedImportMap()
1463
+ try {
1464
+ const allInstances = globalThis.__FEDERATION__?.__SHARE__;
1465
+ if (allInstances) {
1466
+ ${normalizeRuntimeShareCode}
1467
+ for (const [, scopes] of Object.entries(allInstances)) {
1468
+ const scopeShare = scopes?.['${options.shareScope}'];
1469
+ if (!scopeShare) continue;
1470
+ for (const [pkg, versionMap] of Object.entries(scopeShare)) {
1471
+ for (const [version, provider] of Object.entries(versionMap)) {
1472
+ if (!provider.lib) continue;
1473
+ const cacheKey = provider.shareConfig?.singleton ? pkg : \`\${pkg}@\${version}\`;
1474
+ if (__mfModuleCache.share[cacheKey] !== undefined) continue;
1475
+ const mod = typeof provider.lib === "function" ? provider.lib() : provider.lib;
1476
+ const resolved = await Promise.resolve(mod);
1477
+ __mfModuleCache.share[cacheKey] = __mfNormalizeRuntimeShare(resolved);
1478
+ }
1479
+ }
1480
+ }
1481
+ }
1482
+ } catch (e) {
1483
+ console.error('[Module Federation] Failed to bridge external shared modules', e)
1484
+ }
1351
1485
  ${generateDirectSharedCacheSeedCode(command)}
1352
1486
  const __browserPlugins = [${pluginImportNames.filter((item) => !isSsrOnlyPlugin(item[1])).map((item) => `${item[0]}(${item[2]})`).join(", ")}];
1353
1487
  const __ssrPlugins = typeof globalThis.window === 'undefined'
@@ -1384,7 +1518,8 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
1384
1518
  console.error('[Module Federation]', e)
1385
1519
  }
1386
1520
  for (const [pkg, share] of Object.entries(usedShared)) {
1387
- if (share.shareConfig?.import !== false || __mfModuleCache.share[pkg] !== undefined) continue;
1521
+ const cacheKey = share.shareConfig?.singleton || !share.version ? pkg : \`\${pkg}@\${share.version}\`;
1522
+ if (share.shareConfig?.import !== false || __mfModuleCache.share[cacheKey] !== undefined) continue;
1388
1523
  ${normalizeRuntimeShareCode}
1389
1524
  const versions = shared?.[pkg];
1390
1525
  const provider = versions && versions[Object.keys(versions)[0]];
@@ -1392,7 +1527,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
1392
1527
  const factory = provider.lib || (provider.loading ? await provider.loading : await provider.get?.());
1393
1528
  const mod = typeof factory === "function" ? factory() : factory;
1394
1529
  const resolved = await Promise.resolve(mod);
1395
- __mfModuleCache.share[pkg] = __mfNormalizeRuntimeShare(resolved);
1530
+ __mfModuleCache.share[cacheKey] = __mfNormalizeRuntimeShare(resolved);
1396
1531
  }
1397
1532
  return initRes
1398
1533
  }
@@ -1426,7 +1561,8 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build") {
1426
1561
  ${normalizeRuntimeShareCode}
1427
1562
  ${shouldPreloadShares ? `
1428
1563
  for (const [pkg, share] of Object.entries(usedShared)) {
1429
- if (__mfModuleCache.share[pkg] !== undefined) {
1564
+ const cacheKey = share.shareConfig?.singleton || !share.version ? pkg : \`\${pkg}@\${share.version}\`;
1565
+ if (__mfModuleCache.share[cacheKey] !== undefined) {
1430
1566
  continue;
1431
1567
  }
1432
1568
  await runtime.loadShare(pkg, {
@@ -1434,7 +1570,7 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build") {
1434
1570
  }).then((factory) => {
1435
1571
  const mod = typeof factory === "function" ? factory() : factory;
1436
1572
  return Promise.resolve(mod).then((resolved) => {
1437
- __mfModuleCache.share[pkg] = __mfNormalizeRuntimeShare(resolved);
1573
+ __mfModuleCache.share[cacheKey] = __mfNormalizeRuntimeShare(resolved);
1438
1574
  });
1439
1575
  });
1440
1576
  }
@@ -1802,7 +1938,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
1802
1938
  return inject === "entry" || !htmlFilePath;
1803
1939
  }
1804
1940
  function normalizeDevHtmlProxyId(id) {
1805
- return id.replace(/^\0/, "").replace(/^\/@id\//, "").replace(/^__x00__/, "");
1941
+ return decodeViteId(id).replace(/^\0/, "");
1806
1942
  }
1807
1943
  function normalizeModuleId(id) {
1808
1944
  return id.split("?")[0].replace(/\\/g, "/");
@@ -1836,7 +1972,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
1836
1972
  configResolved(config) {
1837
1973
  viteConfig = config;
1838
1974
  const resolvedEntryPath = getEntryPath();
1839
- if (resolvedEntryPath.startsWith("virtual:mf")) devEntryPath = config.base + "@id/" + resolvedEntryPath;
1975
+ if (resolvedEntryPath.startsWith("virtual:mf")) devEntryPath = config.base + VITE_ID_PREFIX.slice(1) + resolvedEntryPath;
1840
1976
  else {
1841
1977
  const normalized = resolvedEntryPath.replace(/\\\\?/g, "/");
1842
1978
  const root = config.root.replace(/\\\\?/g, "/").replace(/\/$/, "");
@@ -1877,10 +2013,10 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
1877
2013
  const base = viteConfig.base.replace(/\/$/, "");
1878
2014
  const stripBase = (p) => base && p.startsWith(base + "/") ? p.slice(base.length) : p;
1879
2015
  const html = rewriteEntryScripts(c, (originalSrc) => {
1880
- return `/@id/__x00__${DEV_HTML_PROXY_PREFIX}${new URLSearchParams({
2016
+ return toViteEncodedId(`${DEV_HTML_PROXY_PREFIX}${new URLSearchParams({
1881
2017
  init: sanitizeDevEntryPath(stripBase(devEntryPath)),
1882
2018
  entry: sanitizeDevEntryPath(stripBase(originalSrc))
1883
- }).toString()}`;
2019
+ }).toString()}`);
1884
2020
  });
1885
2021
  return html === c ? injectEntryScript(c, stripBase(devEntryPath)) : html;
1886
2022
  }
@@ -2826,9 +2962,19 @@ const processModuleAssets = (bundle, filesMap, moduleMatcher, options = {}) => {
2826
2962
  foundCssViaMetadata = true;
2827
2963
  }
2828
2964
  if (!foundCssViaMetadata && chunkContainsCssModules(fileData.modules)) for (const cssAsset of Array.from(bundleCssAssets)) trackAsset(filesMap, matchKey, cssAsset, false, "css");
2829
- if (fileData.dynamicImports) for (const dynamicImport of fileData.dynamicImports) {
2830
- if (!bundle[dynamicImport]) continue;
2831
- trackAsset(filesMap, matchKey, dynamicImport, true, isCSSFile(dynamicImport) ? "css" : "js");
2965
+ const visited = /* @__PURE__ */ new Set();
2966
+ const queue = [fileName];
2967
+ for (let queueIndex = 0; queueIndex < queue.length; queueIndex++) {
2968
+ const cur = queue[queueIndex];
2969
+ if (visited.has(cur)) continue;
2970
+ visited.add(cur);
2971
+ const chunk = bundle[cur];
2972
+ if (!chunk || chunk.type !== "chunk") continue;
2973
+ if (chunk.dynamicImports) for (const dynamicImport of chunk.dynamicImports) {
2974
+ if (!bundle[dynamicImport]) continue;
2975
+ trackAsset(filesMap, matchKey, dynamicImport, true, isCSSFile(dynamicImport) ? "css" : "js");
2976
+ }
2977
+ if (chunk.imports) for (const imp of chunk.imports) queue.push(imp);
2832
2978
  }
2833
2979
  }
2834
2980
  }
@@ -2876,7 +3022,11 @@ const buildFileToShareKeyMap = async (shareKeys, resolveFn) => {
2876
3022
  //#endregion
2877
3023
  //#region src/utils/pathNormalization.ts
2878
3024
  const COMMON_SHARED_SUBPATHS = {
2879
- react: ["react/jsx-runtime", "react/jsx-dev-runtime"],
3025
+ react: [
3026
+ "react/jsx-runtime",
3027
+ "react/jsx-dev-runtime",
3028
+ "react/compiler-runtime"
3029
+ ],
2880
3030
  "react-dom": [
2881
3031
  "react-dom/client",
2882
3032
  "react-dom/server",
@@ -2929,7 +3079,7 @@ function getCommonSharedSubpathFromNodeModulePath(source, sharedKey) {
2929
3079
  */
2930
3080
  function resolvePublicPath(options, viteBase, originalBase) {
2931
3081
  if (options.publicPath && options.publicPath !== "auto") return options.publicPath;
2932
- if (originalBase === "") return "auto";
3082
+ if (!originalBase) return "auto";
2933
3083
  if (viteBase) return ensureTrailingSlash(viteBase);
2934
3084
  return "auto";
2935
3085
  }
@@ -3011,11 +3161,11 @@ function generateRemoteEntrySSR(options) {
3011
3161
  */
3012
3162
  async function init(shared = {}, initScope = []) {
3013
3163
  const initRes = runtimeInit({
3014
- name: ${JSON.stringify(options.internalName)},
3164
+ name: ${JSON.stringify(options.name)},
3015
3165
  remotes: [],
3016
3166
  shared: {},
3017
3167
  });
3018
- const initToken = { from: ${JSON.stringify(options.internalName)} };
3168
+ const initToken = { from: ${JSON.stringify(options.name)} };
3019
3169
  if (initScope.indexOf(initToken) >= 0) return;
3020
3170
  initScope.push(initToken);
3021
3171
  initRes.initShareScopeMap(${JSON.stringify(options.shareScope)}, shared);
@@ -3431,7 +3581,8 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
3431
3581
  if (id.includes(getHostAutoInitPath())) {
3432
3582
  if (_command === "serve") {
3433
3583
  const host = typeof viteConfig.server?.host === "string" && viteConfig.server.host !== "0.0.0.0" ? viteConfig.server.host : "localhost";
3434
- const publicPath = JSON.stringify(resolvePublicPath(options, viteConfig.base) + options.filename);
3584
+ const resolvedPublicPath = resolvePublicPath(options, viteConfig.base);
3585
+ const publicPath = JSON.stringify((resolvedPublicPath === "auto" ? "/" : resolvedPublicPath) + options.filename);
3435
3586
  const fallbackOrigin = `//${host}:${viteConfig.server?.port}`;
3436
3587
  const ssrRemoteEntry = "data:text/javascript," + encodeURIComponent("export async function init(){return {loadRemote:async()=>({}),loadShare:async()=>({})}}");
3437
3588
  return `
@@ -3595,6 +3746,7 @@ function isBuildConfigImporter(importer) {
3595
3746
  }
3596
3747
  function matchesSharedSource(source, key) {
3597
3748
  const keyBase = key.endsWith("/") ? key.slice(0, -1) : key;
3749
+ if (keyBase === "vue" && (source === "vue/dist/vue.esm-bundler.js" || source === "vue/dist/vue.runtime.esm-bundler.js")) return true;
3598
3750
  if (key.endsWith("/")) return source === keyBase || source.startsWith(`${keyBase}/`);
3599
3751
  if (getCommonSharedSubpaths(keyBase).includes(source)) return true;
3600
3752
  return source === keyBase;
@@ -3606,9 +3758,16 @@ function findSharedKey(source, shared) {
3606
3758
  function findSharedKeyForSource(source, shared) {
3607
3759
  const key = findSharedKey(source, shared);
3608
3760
  if (key) return key;
3761
+ const explicitSharedSubpathKeys = Object.keys(shared || {}).filter((sharedKey) => require_packageUtils.getPackageName(sharedKey) !== sharedKey && !sharedKey.endsWith("/"));
3609
3762
  if (isNodeModulePath(source)) {
3610
- const explicitSubpathKey = getMatchingNodeModuleSubpath(source, Object.keys(shared || {}).filter((sharedKey) => sharedKey.includes("/") && !sharedKey.endsWith("/")));
3763
+ const explicitSubpathKey = getMatchingNodeModuleSubpath(source, explicitSharedSubpathKeys);
3611
3764
  if (explicitSubpathKey) return explicitSubpathKey;
3765
+ const normalizedSource = normalizeNodeModulePath(source);
3766
+ const explicitSubpathEntryKey = explicitSharedSubpathKeys.find((sharedKey) => {
3767
+ const entry = require_packageUtils.getInstalledPackageEntry(sharedKey, { cwd: require_packageUtils.getPackageDetectionCwd() });
3768
+ return entry ? normalizeNodeModulePath(entry) === normalizedSource : false;
3769
+ });
3770
+ if (explicitSubpathEntryKey) return explicitSubpathEntryKey;
3612
3771
  }
3613
3772
  const packageName = require_packageUtils.getPackageNameFromNodeModulePath(source);
3614
3773
  return packageName ? findSharedKey(packageName, shared) : void 0;
@@ -3653,6 +3812,7 @@ function proxySharedModule(options) {
3653
3812
  let useRolldown = false;
3654
3813
  const savePrebuild = new PromiseStore();
3655
3814
  let devServer;
3815
+ const materializedLoadShareSources = /* @__PURE__ */ new Set();
3656
3816
  return [
3657
3817
  {
3658
3818
  name: "generateLocalSharedImportMap",
@@ -3709,6 +3869,12 @@ function proxySharedModule(options) {
3709
3869
  name: "proxyPreBuildShared:resolve-shared-loadShare",
3710
3870
  enforce: "pre",
3711
3871
  async resolveId(source, importer) {
3872
+ function shouldSkipTaggedImporterProxy(sharedKey, tag) {
3873
+ if (!importer?.includes(tag)) return false;
3874
+ const taggedModule = VirtualModule.findModule(tag, importer);
3875
+ if (!taggedModule) return true;
3876
+ return taggedModule.name === sharedKey || matchesSharedSource(source, taggedModule.name);
3877
+ }
3712
3878
  const key = findSharedKeyForSource(source, shared);
3713
3879
  if (!key) return;
3714
3880
  if (useDirectReactImport && key === "react") return;
@@ -3717,15 +3883,18 @@ function proxySharedModule(options) {
3717
3883
  if (useDirectReactImport && source === "react") return;
3718
3884
  if (importer && importer.includes("localSharedImportMap")) return;
3719
3885
  if (importer && (importer.includes("hostAutoInit") || importer.includes("__H_A_I__"))) return;
3720
- if (importer && importer.includes("__loadShare__")) return;
3721
- if (importer && importer.includes("__prebuild__")) return;
3722
- const shareSource = isNodeModulePath(source) ? getCommonSharedSubpathFromNodeModulePath(source, key) || key : source;
3886
+ if (shouldSkipTaggedImporterProxy(key, "__loadShare__")) return;
3887
+ if (shouldSkipTaggedImporterProxy(key, "__prebuild__")) return;
3888
+ const shareSource = key === "vue" && source.startsWith("vue/dist/") ? key : isNodeModulePath(source) ? getCommonSharedSubpathFromNodeModulePath(source, key) || key : source;
3723
3889
  const loadSharePath = getLoadShareModulePath(shareSource, useRolldown);
3724
- writeLoadShareModule(shareSource, shared[key], _command, useRolldown);
3725
- if (shared[key].shareConfig.import !== false) writePreBuildLibPath(shareSource, shared[key]);
3726
- addUsedShares(shareSource);
3727
- writeLocalSharedImportMap();
3728
- refreshHostAutoInit();
3890
+ if (!materializedLoadShareSources.has(shareSource)) {
3891
+ materializedLoadShareSources.add(shareSource);
3892
+ writeLoadShareModule(shareSource, shared[key], _command, useRolldown);
3893
+ if (shared[key].shareConfig.import !== false) writePreBuildLibPath(shareSource, shared[key]);
3894
+ addUsedShares(shareSource);
3895
+ writeLocalSharedImportMap();
3896
+ refreshHostAutoInit();
3897
+ }
3729
3898
  return this.resolve(loadSharePath, importer, { skipSelf: true });
3730
3899
  }
3731
3900
  },
@@ -3806,19 +3975,8 @@ function applyRewrites(code, imports, id) {
3806
3975
  const ms = new CodeRewriter(code);
3807
3976
  let changed = false;
3808
3977
  let counter = 0;
3809
- for (const imp of imports) switch (imp.kind) {
3810
- case "static": {
3811
- const src = JSON.stringify(imp.source);
3812
- if (imp.namespaceLocal && !imp.defaultLocal && imp.named.length === 0) ms.overwrite(imp.start, imp.end, `import { __moduleExports as ${imp.namespaceLocal} } from ${src};`);
3813
- else {
3814
- const nsId = `__mf_ns_${counter++}`;
3815
- const importParts = [];
3816
- if (imp.defaultLocal) importParts.push(`default as ${imp.defaultLocal}`);
3817
- importParts.push(`__moduleExports as ${nsId}`);
3818
- let rewrite = `import { ${importParts.join(", ")} } from ${src};`;
3819
- if (imp.named.length > 0) {
3820
- const isProxyId = `__mf_is_proxy_${counter++}`;
3821
- const namedProxyHelper = `function __mfCreateNamedRemoteProxy(ns, key) {
3978
+ let namedProxyHelperDeclared = false;
3979
+ const namedProxyHelper = `function __mfCreateNamedRemoteProxy(ns, key) {
3822
3980
  const target = function (...args) {
3823
3981
  const value = ns[key];
3824
3982
  return typeof value === "function" ? value.apply(this, args) : value;
@@ -3836,13 +3994,29 @@ function applyRewrites(code, imports, id) {
3836
3994
  }
3837
3995
  });
3838
3996
  }`;
3997
+ for (const imp of imports) switch (imp.kind) {
3998
+ case "static": {
3999
+ const src = JSON.stringify(imp.source);
4000
+ if (imp.namespaceLocal && !imp.defaultLocal && imp.named.length === 0) ms.overwrite(imp.start, imp.end, `import { __moduleExports as ${imp.namespaceLocal} } from ${src};`);
4001
+ else {
4002
+ const nsId = `__mf_ns_${counter++}`;
4003
+ const importParts = [];
4004
+ if (imp.defaultLocal) importParts.push(`default as ${imp.defaultLocal}`);
4005
+ importParts.push(`__moduleExports as ${nsId}`);
4006
+ let rewrite = `import { ${importParts.join(", ")} } from ${src};`;
4007
+ if (imp.named.length > 0) {
4008
+ const isProxyId = `__mf_is_proxy_${counter++}`;
3839
4009
  const tempNames = imp.named.map((_s) => `__mf_named_${counter++}`);
3840
4010
  const destructParts = imp.named.map((s, index) => `${s.imported}: ${tempNames[index]}`);
3841
4011
  const bindingLines = imp.named.map((s, index) => {
3842
4012
  const temp = tempNames[index];
3843
4013
  return `const ${s.local} = ${isProxyId} ? __mfCreateNamedRemoteProxy(${nsId}, ${JSON.stringify(s.imported)}) : ${temp};`;
3844
4014
  });
3845
- rewrite += `\n${namedProxyHelper}\nconst ${isProxyId} = ${nsId} && ${nsId}.__mf_is_remote_proxy;`;
4015
+ if (!namedProxyHelperDeclared) {
4016
+ rewrite += `\n${namedProxyHelper}`;
4017
+ namedProxyHelperDeclared = true;
4018
+ }
4019
+ rewrite += `\nconst ${isProxyId} = ${nsId} && ${nsId}.__mf_is_remote_proxy;`;
3846
4020
  rewrite += `\nconst { ${destructParts.join(", ")} } = ${isProxyId} ? {} : ${nsId};`;
3847
4021
  rewrite += `\n${bindingLines.join("\n")}`;
3848
4022
  }
@@ -4244,7 +4418,7 @@ function pluginSSRRemoteEntry(options) {
4244
4418
  try {
4245
4419
  result = await fetchFn(id, importer, opts);
4246
4420
  } catch (fetchErr) {
4247
- const bareId = id.startsWith("/@id/") ? id.slice(5).replace(/^__x00__/, "\0") : id;
4421
+ const bareId = decodeViteId(id);
4248
4422
  try {
4249
4423
  const { createRequire } = await import("module");
4250
4424
  const resolved = createRequire(new URL(`file://${server.config.root}/package.json`)).resolve(bareId.replace(/^\0/, ""));
@@ -4499,6 +4673,8 @@ var normalizeOptimizeDeps_default = {
4499
4673
  //#endregion
4500
4674
  //#region src/index.ts
4501
4675
  const patchedManualChunks = /* @__PURE__ */ new WeakSet();
4676
+ const PRELOAD_HELPER_CHUNK = "vite-preload-helper";
4677
+ const PRELOAD_HELPER_TEST = /\0?vite\/preload-helper/;
4502
4678
  function normalizeVinextRscPreloadHints(code) {
4503
4679
  return code.replace(/(:HL\[[^\]\n]*?,)"stylesheet"/g, "$1\"style\"").replace(/(:HL\[[^\]\n]*?,)\\"stylesheet\\"/g, "$1\\\"style\\\"");
4504
4680
  }
@@ -4566,6 +4742,14 @@ function isFederationHtmlPreloadDependency(dep, includeSharedRuntime = false) {
4566
4742
  if (file.includes("__mfe_internal__") || file.includes("virtual_mf-") || file.includes("virtualExposes") || file.includes("localSharedImportMap") || file.includes("hostInit")) return true;
4567
4743
  return includeSharedRuntime && (file.includes("preload-helper") || file.includes("rolldown-runtime") || file.startsWith("dist-"));
4568
4744
  }
4745
+ function canResolveSharedSubpath(subpath, projectRoot) {
4746
+ try {
4747
+ (0, module$1.createRequire)(new URL(`file://${projectRoot}/package.json`)).resolve(subpath);
4748
+ return true;
4749
+ } catch {
4750
+ return false;
4751
+ }
4752
+ }
4569
4753
  /**
4570
4754
  * Plugin that runs FIRST to register generated virtual modules in the config hook.
4571
4755
  * This prevents 504 "Outdated Optimize Dep" errors by ensuring ids are known
@@ -4632,7 +4816,7 @@ function createEarlyVirtualModulesPlugin(options) {
4632
4816
  optimizeDeps.esbuildOptions.plugins.push({
4633
4817
  name: "module-federation:optimize-shared-proxy",
4634
4818
  setup(build) {
4635
- build.onResolve({ filter: /^virtual:mf:/ }, (args) => ({
4819
+ build.onResolve({ filter: createViteEncodedIdPrefixRegExp("virtual:mf:") }, (args) => ({
4636
4820
  path: args.path,
4637
4821
  external: true
4638
4822
  }));
@@ -4652,15 +4836,15 @@ function createEarlyVirtualModulesPlugin(options) {
4652
4836
  const key = findSharedKey(args.path, shared);
4653
4837
  if (!key) return;
4654
4838
  const shareItem = shared[key];
4655
- const loadSharePath = getLoadShareModulePath(args.path, isRolldown);
4839
+ const optimizedLoadSharePath = toViteOptimizedDepVirtualId(getLoadShareModulePath(args.path, isRolldown));
4656
4840
  writeLoadShareModule(args.path, shareItem, _command, isRolldown);
4657
4841
  if (shareItem.shareConfig?.import !== false) writePreBuildLibPath(args.path, shareItem);
4658
4842
  addUsedShares(args.path);
4659
4843
  return {
4660
4844
  loader: "js",
4661
4845
  resolveDir: root,
4662
- contents: `import * as __mfShared from ${JSON.stringify(loadSharePath)};
4663
- export * from ${JSON.stringify(loadSharePath)};
4846
+ contents: `import * as __mfShared from ${JSON.stringify(optimizedLoadSharePath)};
4847
+ export * from ${JSON.stringify(optimizedLoadSharePath)};
4664
4848
  export default __mfShared.default ?? __mfShared;`
4665
4849
  };
4666
4850
  });
@@ -4674,9 +4858,11 @@ export default __mfShared.default ?? __mfShared;`
4674
4858
  if (_command === "serve" && shareItem.shareConfig?.import !== false) {
4675
4859
  const optimizeDeps = config.optimizeDeps ??= {};
4676
4860
  optimizeDeps.include ??= [];
4861
+ optimizeDeps.exclude ??= [];
4677
4862
  for (const subpath of getCommonSharedSubpaths(key)) {
4678
4863
  writePreBuildLibPath(subpath, shareItem);
4679
- optimizeDeps.include.push(subpath);
4864
+ if (canResolveSharedSubpath(subpath, root)) optimizeDeps.include.push(subpath);
4865
+ else optimizeDeps.exclude.push(subpath);
4680
4866
  }
4681
4867
  }
4682
4868
  continue;
@@ -4700,7 +4886,8 @@ export default __mfShared.default ?? __mfShared;`
4700
4886
  writeLoadShareModule(subpath, shareItem, _command, isRolldown);
4701
4887
  writePreBuildLibPath(subpath, shareItem);
4702
4888
  addUsedShares(subpath);
4703
- optimizeDeps.include.push(subpath);
4889
+ if (canResolveSharedSubpath(subpath, root)) optimizeDeps.include.push(subpath);
4890
+ else optimizeDeps.exclude.push(subpath);
4704
4891
  }
4705
4892
  }
4706
4893
  }
@@ -4721,6 +4908,7 @@ export default __mfShared.default ?? __mfShared;`
4721
4908
  "react-dom",
4722
4909
  "react/jsx-runtime",
4723
4910
  "react/jsx-dev-runtime",
4911
+ "react/compiler-runtime",
4724
4912
  "@module-federation/runtime",
4725
4913
  "@module-federation/runtime-core",
4726
4914
  "@module-federation/sdk"
@@ -4744,7 +4932,7 @@ export default __mfShared.default ?? __mfShared;`
4744
4932
  const SSR_ONLY_PLUGINS = new Set(["@module-federation/vite/ssrEntryLoader"]);
4745
4933
  function loadPluginDts(options) {
4746
4934
  if (options.dts === false) return [];
4747
- return [Promise.resolve().then(() => require("./pluginDts-BEOKyKQ-.cjs")).then(({ default: pluginDts }) => pluginDts(options))];
4935
+ return [Promise.resolve().then(() => require("./pluginDts-7EoFboCu.cjs")).then(({ default: pluginDts }) => pluginDts(options))];
4748
4936
  }
4749
4937
  function federation(mfUserOptions) {
4750
4938
  if (isTestEnv()) return [];
@@ -4761,7 +4949,19 @@ function federation(mfUserOptions) {
4761
4949
  name: "vite:module-federation-virtual-modules",
4762
4950
  enforce: "pre",
4763
4951
  resolveId(id) {
4764
- const virtualModule = VirtualModule.findById(id);
4952
+ let virtualModule = VirtualModule.findById(id);
4953
+ if (!virtualModule) {
4954
+ materializeCachedLoadShareModule({
4955
+ id,
4956
+ shared: options.shared,
4957
+ command,
4958
+ isRolldown: require_packageUtils.getIsRolldown(this),
4959
+ findSharedKey,
4960
+ addUsedShares,
4961
+ writeLocalSharedImportMap
4962
+ });
4963
+ virtualModule = VirtualModule.findById(id);
4964
+ }
4765
4965
  if (!virtualModule) return;
4766
4966
  return virtualModule.getResolvedId();
4767
4967
  },
@@ -4780,7 +4980,8 @@ function federation(mfUserOptions) {
4780
4980
  resolveId(id) {
4781
4981
  const reactServerEntryMap = {
4782
4982
  "react/jsx-runtime": "react/cjs/react-jsx-runtime.production.js",
4783
- "react/jsx-dev-runtime": "react/cjs/react-jsx-dev-runtime.production.js"
4983
+ "react/jsx-dev-runtime": "react/cjs/react-jsx-dev-runtime.production.js",
4984
+ "react/compiler-runtime": "react/cjs/react-compiler-runtime.production.js"
4784
4985
  };
4785
4986
  if (!(id in reactServerEntryMap)) return;
4786
4987
  const environmentName = this.environment?.name;
@@ -4882,6 +5083,8 @@ function federation(mfUserOptions) {
4882
5083
  }
4883
5084
  if (!output?.codeSplitting || typeof output.codeSplitting !== "object") return;
4884
5085
  if (!("groups" in output.codeSplitting)) return;
5086
+ const groups = output.codeSplitting.groups;
5087
+ if (Array.isArray(groups) && groups.some((group) => typeof group?.name === "function" && patchedManualChunks.has(group.name))) return;
4885
5088
  delete output.codeSplitting.groups;
4886
5089
  if (Object.keys(output.codeSplitting).length === 0) delete output.codeSplitting;
4887
5090
  if (warnedAboutCodeSplittingGroups) return;
@@ -4889,27 +5092,45 @@ function federation(mfUserOptions) {
4889
5092
  require_packageUtils.mfWarn("Ignoring `output.codeSplitting.groups` because it conflicts with module federation. Grouping shared dependency init wrappers with their dependent modules can break runtime init order and cause standalone remotes to fail before mount.");
4890
5093
  };
4891
5094
  let warnedAboutManualChunks = false;
4892
- const applyManualChunks = (output) => {
5095
+ const applyManualChunks = (output, useCodeSplitting) => {
4893
5096
  ensureCodeSplitting(output);
4894
5097
  const isPatchedByPlugin = typeof output.manualChunks === "function" && patchedManualChunks.has(output.manualChunks);
4895
5098
  if (output.manualChunks && !isPatchedByPlugin && !warnedAboutManualChunks) {
4896
5099
  warnedAboutManualChunks = true;
4897
5100
  require_packageUtils.mfWarn("Ignoring `output.manualChunks` because it conflicts with module federation. Module federation transforms shared dependency imports with async init wrappers, and grouping these transformed modules into a single chunk creates circular async dependencies that cause the application to silently hang.");
4898
5101
  }
4899
- const mfManualChunks = function(id) {
5102
+ const mfChunkName = function(id) {
4900
5103
  if (id.includes(runtimeInitId)) return "runtimeInit";
4901
5104
  if (id.includes("__loadShare__")) {
4902
5105
  const match = id.match(/([^/\\]+__loadShare__[^/\\]+)/);
4903
5106
  return match ? match[1] : "loadShare";
4904
5107
  }
5108
+ return null;
5109
+ };
5110
+ patchedManualChunks.add(mfChunkName);
5111
+ if (!useCodeSplitting) {
5112
+ const mfManualChunks = function(id) {
5113
+ return mfChunkName(id) ?? void 0;
5114
+ };
5115
+ patchedManualChunks.add(mfManualChunks);
5116
+ output.manualChunks = mfManualChunks;
5117
+ return;
5118
+ }
5119
+ const groups = [{
5120
+ name: PRELOAD_HELPER_CHUNK,
5121
+ test: PRELOAD_HELPER_TEST,
5122
+ priority: 100
5123
+ }, { name: mfChunkName }];
5124
+ output.codeSplitting = {
5125
+ ...output.codeSplitting || {},
5126
+ groups
4905
5127
  };
4906
- patchedManualChunks.add(mfManualChunks);
4907
- output.manualChunks = mfManualChunks;
5128
+ delete output.manualChunks;
4908
5129
  };
4909
5130
  config.build.rollupOptions = config.build.rollupOptions || {};
4910
5131
  const rollupOutput = config.build.rollupOptions.output;
4911
- if (Array.isArray(rollupOutput)) rollupOutput.forEach((output) => applyManualChunks(output));
4912
- else applyManualChunks(config.build.rollupOptions.output ||= {});
5132
+ if (Array.isArray(rollupOutput)) rollupOutput.forEach((output) => applyManualChunks(output, false));
5133
+ else applyManualChunks(config.build.rollupOptions.output ||= {}, false);
4913
5134
  const buildWithRolldown = config.build;
4914
5135
  buildWithRolldown.rolldownOptions = buildWithRolldown.rolldownOptions || {};
4915
5136
  const rolldownOutput = buildWithRolldown.rolldownOptions.output;
@@ -4919,10 +5140,10 @@ function federation(mfUserOptions) {
4919
5140
  assetFileNames: output.assetFileNames
4920
5141
  });
4921
5142
  if (Array.isArray(rolldownOutput)) {
4922
- rolldownOutput.forEach((output) => applyManualChunks(output));
5143
+ rolldownOutput.forEach((output) => applyManualChunks(output, true));
4923
5144
  desiredRolldownOutput = rolldownOutput.map((output) => snapshotRolldownOutput(output));
4924
5145
  } else {
4925
- applyManualChunks(buildWithRolldown.rolldownOptions.output ||= {});
5146
+ applyManualChunks(buildWithRolldown.rolldownOptions.output ||= {}, true);
4926
5147
  desiredRolldownOutput = [snapshotRolldownOutput(buildWithRolldown.rolldownOptions.output)];
4927
5148
  }
4928
5149
  },