@module-federation/bridge-react 2.3.3 → 2.5.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.
Files changed (75) hide show
  1. package/dist/base.cjs.js +2 -2
  2. package/dist/base.es.js +3 -3
  3. package/dist/data-fetch-server-middleware.es.js +1 -1
  4. package/dist/data-fetch-utils.cjs.js +1 -1
  5. package/dist/data-fetch-utils.es.js +4 -4
  6. package/dist/data-fetch.cjs.js +22 -0
  7. package/dist/data-fetch.d.ts +140 -0
  8. package/dist/data-fetch.es.js +22 -0
  9. package/dist/index.cjs.js +2 -2
  10. package/dist/index.es.js +3 -3
  11. package/dist/{lazy-load-component-plugin-DZDwZ0Kz.js → lazy-load-component-plugin-8zeSnzyV.js} +1 -1
  12. package/dist/{lazy-load-component-plugin-Bf_HsMyF.mjs → lazy-load-component-plugin-B3GJRx1-.mjs} +2 -2
  13. package/dist/lazy-load-component-plugin.cjs.js +2 -2
  14. package/dist/lazy-load-component-plugin.es.js +2 -2
  15. package/dist/lazy-utils.es.js +17 -17
  16. package/dist/{prefetch-DYFX9hl9.js → prefetch-DVsz9M2C.js} +210 -82
  17. package/dist/{prefetch-ByDYONsx.mjs → prefetch-zNZ70qRm.mjs} +211 -83
  18. package/dist/{utils-D4k5eixv.mjs → utils-DGS4pYp8.mjs} +23 -23
  19. package/package.json +18 -10
  20. package/.turbo/turbo-build.log +0 -85
  21. package/CHANGELOG.md +0 -839
  22. package/__tests__/bridge.spec.tsx +0 -160
  23. package/__tests__/createLazyComponent.spec.tsx +0 -209
  24. package/__tests__/prefetch.spec.ts +0 -156
  25. package/__tests__/router.spec.tsx +0 -82
  26. package/__tests__/setupTests.ts +0 -8
  27. package/__tests__/util.ts +0 -36
  28. package/jest.config.ts +0 -21
  29. package/src/base.ts +0 -50
  30. package/src/index.ts +0 -50
  31. package/src/lazy/AwaitDataFetch.tsx +0 -217
  32. package/src/lazy/constant.ts +0 -30
  33. package/src/lazy/createLazyComponent.tsx +0 -411
  34. package/src/lazy/data-fetch/cache.ts +0 -291
  35. package/src/lazy/data-fetch/call-data-fetch.ts +0 -13
  36. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +0 -196
  37. package/src/lazy/data-fetch/index.ts +0 -16
  38. package/src/lazy/data-fetch/inject-data-fetch.ts +0 -109
  39. package/src/lazy/data-fetch/prefetch.ts +0 -112
  40. package/src/lazy/data-fetch/runtime-plugin.ts +0 -115
  41. package/src/lazy/index.ts +0 -35
  42. package/src/lazy/logger.ts +0 -6
  43. package/src/lazy/types.ts +0 -75
  44. package/src/lazy/utils.ts +0 -375
  45. package/src/lazy/wrapNoSSR.tsx +0 -10
  46. package/src/modern-app-env.d.ts +0 -2
  47. package/src/plugins/lazy-load-component-plugin.spec.ts +0 -21
  48. package/src/plugins/lazy-load-component-plugin.ts +0 -57
  49. package/src/provider/context.tsx +0 -4
  50. package/src/provider/plugin.ts +0 -22
  51. package/src/provider/versions/bridge-base.tsx +0 -153
  52. package/src/provider/versions/legacy.ts +0 -87
  53. package/src/provider/versions/v18.ts +0 -47
  54. package/src/provider/versions/v19.ts +0 -48
  55. package/src/remote/RemoteAppWrapper.tsx +0 -108
  56. package/src/remote/base-component/component.tsx +0 -2
  57. package/src/remote/base-component/create.tsx +0 -23
  58. package/src/remote/base-component/index.tsx +0 -10
  59. package/src/remote/createHelpers.tsx +0 -132
  60. package/src/remote/router-component/component.tsx +0 -104
  61. package/src/remote/router-component/create.tsx +0 -23
  62. package/src/remote/router-component/index.tsx +0 -10
  63. package/src/router/default.tsx +0 -73
  64. package/src/router/v5.tsx +0 -43
  65. package/src/router/v6.tsx +0 -74
  66. package/src/router/v7.tsx +0 -75
  67. package/src/types.ts +0 -147
  68. package/src/utils/index.ts +0 -44
  69. package/src/v18.ts +0 -9
  70. package/src/v19.ts +0 -9
  71. package/tsconfig.json +0 -42
  72. package/tsconfig.node.json +0 -11
  73. package/tsconfig.spec.json +0 -26
  74. package/vite.config.ts +0 -112
  75. package/vitest.config.ts +0 -27
@@ -1,4 +1,4 @@
1
- import { A as warn, x as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger, e as getDataFetchMap, i as initDataFetchMap, n as getDataFetchItem, M as MF_DATA_FETCH_STATUS, p as MF_DATA_FETCH_TYPE, B as DOWNGRADE_KEY, G as callAllDowngrade, H as callDowngrade, I as getDowngradeTag, J as composeKeyWithSeparator, k as getDataFetchInfo, m as getDataFetchMapKey } from "./utils-D4k5eixv.mjs";
1
+ import { B as warn, y as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger, e as getDataFetchMap, i as initDataFetchMap, o as getDataFetchItem, M as MF_DATA_FETCH_STATUS, q as MF_DATA_FETCH_TYPE, G as DOWNGRADE_KEY, H as callAllDowngrade, I as callDowngrade, J as getDowngradeTag, K as composeKeyWithSeparator, m as getDataFetchInfo, n as getDataFetchMapKey } from "./utils-DGS4pYp8.mjs";
2
2
  import { i as isBrowserEnvValue } from "./logger-DwWkXsWl.mjs";
3
3
  async function safeWrapper(callback, disableWarn) {
4
4
  try {
@@ -104,6 +104,8 @@ function createScript(info) {
104
104
  function createLink(info) {
105
105
  let link = null;
106
106
  let needAttach = true;
107
+ let timeout = 2e4;
108
+ let timeoutId;
107
109
  const links = document.getElementsByTagName("link");
108
110
  for (let i = 0; i < links.length; i++) {
109
111
  const l = links[i];
@@ -119,19 +121,42 @@ function createLink(info) {
119
121
  link = document.createElement("link");
120
122
  link.setAttribute("href", info.url);
121
123
  let createLinkRes = void 0;
124
+ let shouldApplyAttrs = true;
122
125
  const attrs = info.attrs;
123
126
  if (info.createLinkHook) {
124
127
  createLinkRes = info.createLinkHook(info.url, attrs);
125
- if (createLinkRes instanceof HTMLLinkElement) link = createLinkRes;
128
+ if (createLinkRes instanceof HTMLLinkElement) {
129
+ link = createLinkRes;
130
+ shouldApplyAttrs = false;
131
+ } else if (typeof createLinkRes === "object") {
132
+ if ("link" in createLinkRes && createLinkRes.link) {
133
+ link = createLinkRes.link;
134
+ shouldApplyAttrs = false;
135
+ }
136
+ if ("timeout" in createLinkRes && createLinkRes.timeout) timeout = createLinkRes.timeout;
137
+ }
126
138
  }
127
- if (attrs && !createLinkRes) Object.keys(attrs).forEach((name) => {
139
+ if (attrs && shouldApplyAttrs) Object.keys(attrs).forEach((name) => {
128
140
  if (link && !link.getAttribute(name)) link.setAttribute(name, attrs[name]);
129
141
  });
130
142
  }
143
+ if (!needAttach) {
144
+ Promise.resolve().then(() => {
145
+ (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
146
+ });
147
+ return {
148
+ link,
149
+ needAttach
150
+ };
151
+ }
131
152
  const onLinkComplete = (prev, event) => {
153
+ if (timeoutId) clearTimeout(timeoutId);
132
154
  const onLinkCompleteCallback = () => {
133
- if ((event == null ? void 0 : event.type) === "error") (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(event));
134
- else (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
155
+ if ((event == null ? void 0 : event.type) === "error") {
156
+ const linkError = /* @__PURE__ */ new Error((event == null ? void 0 : event.isTimeout) ? `LinkNetworkError: Link "${info.url}" timed out.` : `LinkNetworkError: Failed to load link "${info.url}" - the URL is unreachable or the server returned an error.`);
157
+ linkError.name = "LinkNetworkError";
158
+ (info == null ? void 0 : info.onErrorCallback) && (info == null ? void 0 : info.onErrorCallback(linkError));
159
+ } else (info == null ? void 0 : info.cb) && (info == null ? void 0 : info.cb());
135
160
  };
136
161
  if (link) {
137
162
  link.onerror = null;
@@ -150,6 +175,12 @@ function createLink(info) {
150
175
  };
151
176
  link.onerror = onLinkComplete.bind(null, link.onerror);
152
177
  link.onload = onLinkComplete.bind(null, link.onload);
178
+ timeoutId = setTimeout(() => {
179
+ onLinkComplete(null, {
180
+ type: "error",
181
+ isTimeout: true
182
+ });
183
+ }, timeout);
153
184
  return {
154
185
  link,
155
186
  needAttach
@@ -493,6 +524,9 @@ const RUNTIME_009 = "RUNTIME-009";
493
524
  const RUNTIME_010 = "RUNTIME-010";
494
525
  const RUNTIME_011 = "RUNTIME-011";
495
526
  const RUNTIME_012 = "RUNTIME-012";
527
+ const RUNTIME_013 = "RUNTIME-013";
528
+ const RUNTIME_014 = "RUNTIME-014";
529
+ const RUNTIME_015 = "RUNTIME-015";
496
530
  const runtimeDescMap = {
497
531
  [RUNTIME_001]: "Failed to get remoteEntry exports.",
498
532
  [RUNTIME_002]: 'The remote entry interface does not contain "init"',
@@ -505,7 +539,10 @@ const runtimeDescMap = {
505
539
  [RUNTIME_009]: "Please call createInstance first.",
506
540
  [RUNTIME_010]: 'The name option cannot be changed after initialization. If you want to create a new instance with a different name, please use "createInstance" api.',
507
541
  [RUNTIME_011]: "The remoteEntry URL is missing from the remote snapshot.",
508
- [RUNTIME_012]: 'The getter for the shared module is not a function. This may be caused by setting "shared.import: false" without the host providing the corresponding lib.'
542
+ [RUNTIME_012]: 'The getter for the shared module is not a function. This may be caused by setting "shared.import: false" without the host providing the corresponding lib.',
543
+ [RUNTIME_013]: "The manifest is not a valid Module Federation manifest.",
544
+ [RUNTIME_014]: "The remote does not expose the requested module.",
545
+ [RUNTIME_015]: "Remote container initialization failed."
509
546
  };
510
547
  ({
511
548
  ...runtimeDescMap
@@ -546,7 +583,7 @@ function handleRemoteEntryLoaded(name, globalName, entry) {
546
583
  });
547
584
  return entryExports;
548
585
  }
549
- async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook, getEntryUrl }) {
586
+ async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook, getEntryUrl, resourceContext }) {
550
587
  const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
551
588
  if (remoteEntryExports) return remoteEntryExports;
552
589
  const url = getEntryUrl ? getEntryUrl(entry) : entry;
@@ -556,7 +593,11 @@ async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook
556
593
  const res = loaderHook.lifecycle.createScript.emit({
557
594
  url: url2,
558
595
  attrs,
559
- remoteInfo
596
+ remoteInfo,
597
+ resourceContext: resourceContext ? {
598
+ ...resourceContext,
599
+ url: url2
600
+ } : void 0
560
601
  });
561
602
  if (!res) return;
562
603
  if (res instanceof HTMLScriptElement) return res;
@@ -572,7 +613,7 @@ async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook
572
613
  }, originalMsg);
573
614
  });
574
615
  }
575
- async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl }) {
616
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl, resourceContext }) {
576
617
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
577
618
  switch (type) {
578
619
  case "esm":
@@ -593,11 +634,12 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEnt
593
634
  name,
594
635
  remoteInfo,
595
636
  loaderHook,
596
- getEntryUrl
637
+ getEntryUrl,
638
+ resourceContext
597
639
  });
598
640
  }
599
641
  }
600
- async function loadEntryNode({ remoteInfo, loaderHook }) {
642
+ async function loadEntryNode({ remoteInfo, loaderHook, resourceContext }) {
601
643
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
602
644
  const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
603
645
  if (remoteEntryExports) return remoteEntryExports;
@@ -611,7 +653,11 @@ async function loadEntryNode({ remoteInfo, loaderHook }) {
611
653
  const res = loaderHook.lifecycle.createScript.emit({
612
654
  url,
613
655
  attrs,
614
- remoteInfo
656
+ remoteInfo,
657
+ resourceContext: resourceContext ? {
658
+ ...resourceContext,
659
+ url
660
+ } : void 0
615
661
  });
616
662
  if (!res) return;
617
663
  if ("url" in res) return res;
@@ -627,13 +673,14 @@ function getRemoteEntryUniqueKey(remoteInfo) {
627
673
  return composeKeyWithSeparator(name, entry);
628
674
  }
629
675
  async function getRemoteEntry(params) {
630
- const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false } = params;
676
+ const { origin, remoteEntryExports, remoteInfo, getEntryUrl, resourceContext, _inErrorHandling = false } = params;
631
677
  const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
632
678
  if (remoteEntryExports) return remoteEntryExports;
633
679
  if (!globalLoading[uniqueKey]) {
634
680
  const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
635
681
  const loaderHook = origin.loaderHook;
636
682
  globalLoading[uniqueKey] = loadEntryHook.emit({
683
+ origin,
637
684
  loaderHook,
638
685
  remoteInfo,
639
686
  remoteEntryExports
@@ -643,11 +690,20 @@ async function getRemoteEntry(params) {
643
690
  remoteInfo,
644
691
  remoteEntryExports,
645
692
  loaderHook,
646
- getEntryUrl
693
+ getEntryUrl,
694
+ resourceContext
647
695
  }) : loadEntryNode({
648
696
  remoteInfo,
649
- loaderHook
697
+ loaderHook,
698
+ resourceContext
650
699
  });
700
+ }).then(async (res) => {
701
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
702
+ origin,
703
+ remoteInfo,
704
+ remoteEntryExports: res
705
+ });
706
+ return res;
651
707
  }).catch(async (err) => {
652
708
  const uniqueKey2 = getRemoteEntryUniqueKey(remoteInfo);
653
709
  const isScriptExecutionError = err instanceof Error && err.message.includes("ScriptExecutionError");
@@ -666,8 +722,21 @@ async function getRemoteEntry(params) {
666
722
  globalLoading,
667
723
  uniqueKey: uniqueKey2
668
724
  });
669
- if (RemoteEntryExports) return RemoteEntryExports;
725
+ if (RemoteEntryExports) {
726
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
727
+ origin,
728
+ remoteInfo,
729
+ remoteEntryExports: RemoteEntryExports,
730
+ recovered: true
731
+ });
732
+ return RemoteEntryExports;
733
+ }
670
734
  }
735
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
736
+ origin,
737
+ remoteInfo,
738
+ error: err
739
+ });
671
740
  throw err;
672
741
  });
673
742
  }
@@ -682,22 +751,113 @@ function getRemoteInfo(remote) {
682
751
  shareScope: remote.shareScope || DEFAULT_SCOPE
683
752
  };
684
753
  }
685
- function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
754
+ function isTimeoutError(error2) {
755
+ if (!(error2 instanceof Error)) return false;
756
+ return error2.message.includes("timed out") || error2.name.includes("Timeout");
757
+ }
758
+ function createAssetResult(context, url, status, error2) {
759
+ return {
760
+ url,
761
+ status,
762
+ resourceType: context.resourceType,
763
+ initiator: context.initiator,
764
+ id: context.id,
765
+ error: error2
766
+ };
767
+ }
768
+ async function waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, context) {
769
+ const cachedRemote = host.moduleCache.get(entryRemoteInfo.name);
770
+ const url = entryRemoteInfo.entry;
771
+ if (cachedRemote == null ? void 0 : cachedRemote.remoteEntryExports) return createAssetResult(context, url, "cached");
772
+ try {
773
+ if (!await getRemoteEntry({
774
+ origin: host,
775
+ remoteInfo: entryRemoteInfo,
776
+ remoteEntryExports: cachedRemote == null ? void 0 : cachedRemote.remoteEntryExports,
777
+ resourceContext: {
778
+ ...context,
779
+ url
780
+ }
781
+ })) throw new Error(`Failed to load remoteEntry "${url}".`);
782
+ return createAssetResult(context, url, "success");
783
+ } catch (error2) {
784
+ return createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2);
785
+ }
786
+ }
787
+ function waitForLinkPreload({ host, remoteInfo, url, attrs, context, needDeleteLink }) {
788
+ return new Promise((resolve) => {
789
+ const { link, needAttach } = createLink({
790
+ url,
791
+ cb: () => {
792
+ resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
793
+ },
794
+ onErrorCallback: (error2) => {
795
+ resolve(createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2));
796
+ },
797
+ attrs,
798
+ createLinkHook: (hookUrl, hookAttrs) => {
799
+ const res = host.loaderHook.lifecycle.createLink.emit({
800
+ url: hookUrl,
801
+ attrs: hookAttrs,
802
+ remoteInfo,
803
+ resourceContext: {
804
+ ...context,
805
+ url: hookUrl
806
+ }
807
+ });
808
+ if (res instanceof HTMLLinkElement) return res;
809
+ return res;
810
+ },
811
+ needDeleteLink
812
+ });
813
+ needAttach && document.head.appendChild(link);
814
+ });
815
+ }
816
+ function waitForScriptPreload({ host, remoteInfo, url, attrs, context }) {
817
+ return new Promise((resolve) => {
818
+ const { script, needAttach } = createScript({
819
+ url,
820
+ cb: () => {
821
+ resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
822
+ },
823
+ onErrorCallback: (error2) => {
824
+ resolve(createAssetResult(context, url, isTimeoutError(error2) ? "timeout" : "error", error2));
825
+ },
826
+ attrs,
827
+ createScriptHook: (hookUrl, hookAttrs) => {
828
+ const res = host.loaderHook.lifecycle.createScript.emit({
829
+ url: hookUrl,
830
+ attrs: hookAttrs,
831
+ remoteInfo,
832
+ resourceContext: {
833
+ ...context,
834
+ url: hookUrl
835
+ }
836
+ });
837
+ if (res instanceof HTMLScriptElement) return res;
838
+ return res;
839
+ },
840
+ needDeleteScript: true
841
+ });
842
+ needAttach && document.head.appendChild(script);
843
+ });
844
+ }
845
+ function createResourceContext(baseContext, resourceType) {
846
+ return {
847
+ ...baseContext,
848
+ resourceType
849
+ };
850
+ }
851
+ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseContext = {
852
+ initiator: "preloadRemote",
853
+ id: remoteInfo.name
854
+ }) {
686
855
  const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
856
+ const results = [];
687
857
  if (host.options.inBrowser) {
688
858
  entryAssets.forEach((asset) => {
689
- const { moduleInfo } = asset;
690
- const module = host.moduleCache.get(remoteInfo.name);
691
- if (module) getRemoteEntry({
692
- origin: host,
693
- remoteInfo: moduleInfo,
694
- remoteEntryExports: module.remoteEntryExports
695
- });
696
- else getRemoteEntry({
697
- origin: host,
698
- remoteInfo: moduleInfo,
699
- remoteEntryExports: void 0
700
- });
859
+ const { moduleInfo: entryRemoteInfo } = asset;
860
+ results.push(waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, createResourceContext(baseContext, "remoteEntry")));
701
861
  });
702
862
  if (useLinkPreload) {
703
863
  const defaultAttrs = {
@@ -705,21 +865,13 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
705
865
  as: "style"
706
866
  };
707
867
  cssAssets.forEach((cssUrl) => {
708
- const { link: cssEl, needAttach } = createLink({
868
+ results.push(waitForLinkPreload({
869
+ host,
870
+ remoteInfo,
709
871
  url: cssUrl,
710
- cb: () => {
711
- },
712
872
  attrs: defaultAttrs,
713
- createLinkHook: (url, attrs) => {
714
- const res = host.loaderHook.lifecycle.createLink.emit({
715
- url,
716
- attrs,
717
- remoteInfo
718
- });
719
- if (res instanceof HTMLLinkElement) return res;
720
- }
721
- });
722
- needAttach && document.head.appendChild(cssEl);
873
+ context: createResourceContext(baseContext, "css")
874
+ }));
723
875
  });
724
876
  } else {
725
877
  const defaultAttrs = {
@@ -727,22 +879,14 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
727
879
  type: "text/css"
728
880
  };
729
881
  cssAssets.forEach((cssUrl) => {
730
- const { link: cssEl, needAttach } = createLink({
882
+ results.push(waitForLinkPreload({
883
+ host,
884
+ remoteInfo,
731
885
  url: cssUrl,
732
- cb: () => {
733
- },
734
886
  attrs: defaultAttrs,
735
- createLinkHook: (url, attrs) => {
736
- const res = host.loaderHook.lifecycle.createLink.emit({
737
- url,
738
- attrs,
739
- remoteInfo
740
- });
741
- if (res instanceof HTMLLinkElement) return res;
742
- },
743
- needDeleteLink: false
744
- });
745
- needAttach && document.head.appendChild(cssEl);
887
+ needDeleteLink: false,
888
+ context: createResourceContext(baseContext, "css")
889
+ }));
746
890
  });
747
891
  }
748
892
  if (useLinkPreload) {
@@ -751,21 +895,13 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
751
895
  as: "script"
752
896
  };
753
897
  jsAssetsWithoutEntry.forEach((jsUrl) => {
754
- const { link: linkEl, needAttach } = createLink({
898
+ results.push(waitForLinkPreload({
899
+ host,
900
+ remoteInfo,
755
901
  url: jsUrl,
756
- cb: () => {
757
- },
758
902
  attrs: defaultAttrs,
759
- createLinkHook: (url, attrs) => {
760
- const res = host.loaderHook.lifecycle.createLink.emit({
761
- url,
762
- attrs,
763
- remoteInfo
764
- });
765
- if (res instanceof HTMLLinkElement) return res;
766
- }
767
- });
768
- needAttach && document.head.appendChild(linkEl);
903
+ context: createResourceContext(baseContext, "js")
904
+ }));
769
905
  });
770
906
  } else {
771
907
  const defaultAttrs = {
@@ -773,25 +909,17 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
773
909
  type: (remoteInfo == null ? void 0 : remoteInfo.type) === "module" ? "module" : "text/javascript"
774
910
  };
775
911
  jsAssetsWithoutEntry.forEach((jsUrl) => {
776
- const { script: scriptEl, needAttach } = createScript({
912
+ results.push(waitForScriptPreload({
913
+ host,
914
+ remoteInfo,
777
915
  url: jsUrl,
778
- cb: () => {
779
- },
780
916
  attrs: defaultAttrs,
781
- createScriptHook: (url, attrs) => {
782
- const res = host.loaderHook.lifecycle.createScript.emit({
783
- url,
784
- attrs,
785
- remoteInfo
786
- });
787
- if (res instanceof HTMLScriptElement) return res;
788
- },
789
- needDeleteScript: true
790
- });
791
- needAttach && document.head.appendChild(scriptEl);
917
+ context: createResourceContext(baseContext, "js")
918
+ }));
792
919
  });
793
920
  }
794
921
  }
922
+ return Promise.all(results);
795
923
  }
796
924
  var helpers_default = {
797
925
  utils: {
@@ -1987,17 +1987,17 @@ function getLoadedRemoteInfos(id, instance) {
1987
1987
  };
1988
1988
  }
1989
1989
  export {
1990
- warn as A,
1991
- DOWNGRADE_KEY as B,
1990
+ setDataFetchItemLoadedStatus as A,
1991
+ warn as B,
1992
1992
  CacheSize as C,
1993
1993
  DATA_FETCH_QUERY as D,
1994
1994
  ERROR_TYPE as E,
1995
1995
  FS_HREF as F,
1996
- callAllDowngrade as G,
1997
- callDowngrade as H,
1998
- getDowngradeTag as I,
1999
- composeKeyWithSeparator as J,
2000
- flushDataFetch as K,
1996
+ DOWNGRADE_KEY as G,
1997
+ callAllDowngrade as H,
1998
+ callDowngrade as I,
1999
+ getDowngradeTag as J,
2000
+ composeKeyWithSeparator as K,
2001
2001
  LOAD_REMOTE_ERROR_PREFIX as L,
2002
2002
  MF_DATA_FETCH_STATUS as M,
2003
2003
  getDataFetchCache as N,
@@ -2006,25 +2006,25 @@ export {
2006
2006
  cache as c,
2007
2007
  configureCache as d,
2008
2008
  getDataFetchMap as e,
2009
- fetchData as f,
2009
+ flushDataFetch as f,
2010
2010
  generateKey as g,
2011
- loadDataFetchModule as h,
2011
+ fetchData as h,
2012
2012
  initDataFetchMap as i,
2013
- isDataLoaderExpose as j,
2014
- getDataFetchInfo as k,
2013
+ loadDataFetchModule as j,
2014
+ isDataLoaderExpose as k,
2015
2015
  logger as l,
2016
- getDataFetchMapKey as m,
2017
- getDataFetchItem as n,
2018
- DATA_FETCH_CLIENT_SUFFIX as o,
2019
- MF_DATA_FETCH_TYPE as p,
2020
- isCSROnly as q,
2016
+ getDataFetchInfo as m,
2017
+ getDataFetchMapKey as n,
2018
+ getDataFetchItem as o,
2019
+ DATA_FETCH_CLIENT_SUFFIX as p,
2020
+ MF_DATA_FETCH_TYPE as q,
2021
2021
  revalidateTag as r,
2022
2022
  setSSREnv as s,
2023
- isServerEnv as t,
2024
- getDataFetchIdWithErrorMsgs as u,
2025
- DATA_FETCH_ERROR_PREFIX as v,
2026
- wrapDataFetchId as w,
2027
- DATA_FETCH_FUNCTION as x,
2028
- getLoadedRemoteInfos as y,
2029
- setDataFetchItemLoadedStatus as z
2023
+ isCSROnly as t,
2024
+ isServerEnv as u,
2025
+ getDataFetchIdWithErrorMsgs as v,
2026
+ DATA_FETCH_ERROR_PREFIX as w,
2027
+ wrapDataFetchId as x,
2028
+ DATA_FETCH_FUNCTION as y,
2029
+ getLoadedRemoteInfos as z
2030
2030
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "2.3.3",
3
+ "version": "2.5.0",
4
4
  "sideEffects": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,6 +12,10 @@
12
12
  "url": "git+https://github.com/module-federation/core.git",
13
13
  "directory": "packages/bridge/bridge-react"
14
14
  },
15
+ "files": [
16
+ "dist/",
17
+ "README.md"
18
+ ],
15
19
  "main": "./dist/index.cjs.js",
16
20
  "module": "./dist/index.es.js",
17
21
  "types": "./dist/index.d.ts",
@@ -71,6 +75,11 @@
71
75
  "import": "./dist/data-fetch-utils.es.js",
72
76
  "require": "./dist/data-fetch-utils.cjs.js"
73
77
  },
78
+ "./data-fetch": {
79
+ "types": "./dist/data-fetch.d.ts",
80
+ "import": "./dist/data-fetch.es.js",
81
+ "require": "./dist/data-fetch.cjs.js"
82
+ },
74
83
  "./data-fetch-server-middleware": {
75
84
  "types": "./dist/data-fetch-server-middleware.d.ts",
76
85
  "import": "./dist/data-fetch-server-middleware.es.js",
@@ -121,6 +130,9 @@
121
130
  "data-fetch-utils": [
122
131
  "./dist/data-fetch-utils.d.ts"
123
132
  ],
133
+ "data-fetch": [
134
+ "./dist/data-fetch.d.ts"
135
+ ],
124
136
  "data-fetch-server-middleware": [
125
137
  "./dist/data-fetch-server-middleware.d.ts"
126
138
  ]
@@ -128,14 +140,13 @@
128
140
  },
129
141
  "dependencies": {
130
142
  "lru-cache": "10.4.3",
131
- "@module-federation/sdk": "2.3.3"
143
+ "@module-federation/sdk": "2.5.0"
132
144
  },
133
145
  "peerDependencies": {
134
146
  "react": ">=16.9.0",
135
147
  "react-dom": ">=16.9.0",
136
148
  "react-router-dom": "^4 || ^5 || ^6 || ^7",
137
- "react-router": "^6 || ^7",
138
- "hono": "^4.12.7"
149
+ "react-router": "^6 || ^7"
139
150
  },
140
151
  "peerDependenciesMeta": {
141
152
  "react-router-dom": {
@@ -143,9 +154,6 @@
143
154
  },
144
155
  "react-router": {
145
156
  "optional": true
146
- },
147
- "hono": {
148
- "optional": true
149
157
  }
150
158
  },
151
159
  "devDependencies": {
@@ -166,9 +174,9 @@
166
174
  "vite-plugin-dts": "^4.3.0",
167
175
  "hono": "4.12.7",
168
176
  "vitest": "1.6.0",
169
- "@module-federation/runtime": "2.3.3",
170
- "@module-federation/bridge-shared": "2.3.3",
171
- "@module-federation/runtime-core": "2.3.3"
177
+ "@module-federation/runtime-core": "2.5.0",
178
+ "@module-federation/bridge-shared": "2.5.0",
179
+ "@module-federation/runtime": "2.5.0"
172
180
  },
173
181
  "scripts": {
174
182
  "dev": "vite",