remote-components 0.0.45 → 0.0.47

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 (71) hide show
  1. package/dist/html/host.cjs +202 -54
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +202 -54
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/html/remote.cjs +28 -28
  6. package/dist/html/remote.cjs.map +1 -1
  7. package/dist/html/remote.js +28 -28
  8. package/dist/html/remote.js.map +1 -1
  9. package/dist/internal/next/host/app-router-client.cjs +10 -5
  10. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  11. package/dist/internal/next/host/app-router-client.js +10 -5
  12. package/dist/internal/next/host/app-router-client.js.map +1 -1
  13. package/dist/internal/next/host/app-router-compat.cjs +9 -4
  14. package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
  15. package/dist/internal/next/host/app-router-compat.js +9 -4
  16. package/dist/internal/next/host/app-router-compat.js.map +1 -1
  17. package/dist/internal/shared/client/polyfill.cjs +3 -1
  18. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  19. package/dist/internal/shared/client/polyfill.js +3 -1
  20. package/dist/internal/shared/client/polyfill.js.map +1 -1
  21. package/dist/internal/shared/client/remote-component.cjs +158 -27
  22. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  23. package/dist/internal/shared/client/remote-component.js +158 -27
  24. package/dist/internal/shared/client/remote-component.js.map +1 -1
  25. package/dist/internal/shared/ssr/fetch-remote-component.cjs +4 -6
  26. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  27. package/dist/internal/shared/ssr/fetch-remote-component.js +4 -6
  28. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  29. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +9 -2
  30. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  31. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +6 -1
  32. package/dist/internal/shared/ssr/fetch-with-hooks.js +9 -2
  33. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  34. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +57 -0
  35. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +1 -0
  36. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +11 -0
  37. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +32 -0
  38. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +1 -0
  39. package/dist/internal/shared/utils/logger.cjs +55 -0
  40. package/dist/internal/shared/utils/logger.cjs.map +1 -0
  41. package/dist/internal/shared/utils/logger.d.ts +7 -0
  42. package/dist/internal/shared/utils/logger.js +28 -0
  43. package/dist/internal/shared/utils/logger.js.map +1 -0
  44. package/dist/next/config.cjs +22 -1
  45. package/dist/next/config.cjs.map +1 -1
  46. package/dist/next/config.js +22 -1
  47. package/dist/next/config.js.map +1 -1
  48. package/dist/next/host/client/index.cjs +207 -68
  49. package/dist/next/host/client/index.cjs.map +1 -1
  50. package/dist/next/host/client/index.js +207 -68
  51. package/dist/next/host/client/index.js.map +1 -1
  52. package/dist/next/proxy.cjs +128 -19
  53. package/dist/next/proxy.cjs.map +1 -1
  54. package/dist/next/proxy.d.ts +34 -6
  55. package/dist/next/proxy.js +125 -18
  56. package/dist/next/proxy.js.map +1 -1
  57. package/dist/react/index.cjs +199 -64
  58. package/dist/react/index.cjs.map +1 -1
  59. package/dist/react/index.js +199 -64
  60. package/dist/react/index.js.map +1 -1
  61. package/dist/shared/host/proxy.cjs +79 -0
  62. package/dist/shared/host/proxy.cjs.map +1 -0
  63. package/dist/shared/host/proxy.d.ts +29 -0
  64. package/dist/shared/host/proxy.js +54 -0
  65. package/dist/shared/host/proxy.js.map +1 -0
  66. package/dist/shared/remote/proxy.cjs +71 -0
  67. package/dist/shared/remote/proxy.cjs.map +1 -0
  68. package/dist/shared/remote/proxy.d.ts +38 -0
  69. package/dist/shared/remote/proxy.js +45 -0
  70. package/dist/shared/remote/proxy.js.map +1 -0
  71. package/package.json +10 -1
@@ -72,6 +72,48 @@ function applyOriginToNodes(doc, url) {
72
72
  }
73
73
  }
74
74
 
75
+ // src/shared/error.ts
76
+ var RemoteComponentsError = class extends Error {
77
+ code = "REMOTE_COMPONENTS_ERROR";
78
+ constructor(message, options) {
79
+ super(message, options);
80
+ this.name = "RemoteComponentsError";
81
+ }
82
+ };
83
+ function multipleRemoteComponentsError(url) {
84
+ return new RemoteComponentsError(
85
+ `Multiple Remote Components found at "${url}". When a page exposes multiple Remote Components you must specify the "name" prop to select which one to load.`
86
+ );
87
+ }
88
+ function failedToFetchRemoteComponentError(url, { status, statusText }, help = "Is the URL correct and accessible?") {
89
+ return new RemoteComponentsError(
90
+ `Failed to fetch Remote Component from "${url}". ${help}`,
91
+ { cause: new Error(`${status} ${statusText}`) }
92
+ );
93
+ }
94
+
95
+ // src/shared/utils/logger.ts
96
+ var PREFIX = "remote-components";
97
+ var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
98
+ function logDebug(location2, message) {
99
+ if (DEBUG) {
100
+ console.debug(`[${PREFIX}:${location2}]: ${message}`);
101
+ }
102
+ }
103
+ function logInfo(location2, message) {
104
+ console.info(`[${PREFIX}:${location2}]: ${message}`);
105
+ }
106
+ function logWarn(location2, message) {
107
+ console.warn(`[${PREFIX}:${location2}]: ${message}`);
108
+ }
109
+ function logError(location2, message, cause) {
110
+ console.error(
111
+ new RemoteComponentsError(`[${PREFIX}:${location2}]: ${message}`, {
112
+ cause
113
+ })
114
+ );
115
+ }
116
+
75
117
  // src/shared/client/polyfill.tsx
76
118
  import { jsx } from "react/jsx-runtime";
77
119
  function applyBundleUrlToSrc(bundle, src) {
@@ -167,7 +209,8 @@ function sharedPolyfills(shared) {
167
209
  ...props
168
210
  }) => {
169
211
  if (prefetch) {
170
- console.warn(
212
+ logWarn(
213
+ "Polyfill",
171
214
  "Next.js Link prefetch is not supported in remote components"
172
215
  );
173
216
  }
@@ -267,26 +310,6 @@ function sharedPolyfills(shared) {
267
310
  return polyfill;
268
311
  }
269
312
 
270
- // src/shared/error.ts
271
- var RemoteComponentsError = class extends Error {
272
- code = "REMOTE_COMPONENTS_ERROR";
273
- constructor(message, options) {
274
- super(message, options);
275
- this.name = "RemoteComponentsError";
276
- }
277
- };
278
- function multipleRemoteComponentsError(url) {
279
- return new RemoteComponentsError(
280
- `Multiple Remote Components found at "${url}". When a page exposes multiple Remote Components you must specify the "name" prop to select which one to load.`
281
- );
282
- }
283
- function failedToFetchRemoteComponentError(url, { status, statusText }, help = "Is the URL correct and accessible?") {
284
- return new RemoteComponentsError(
285
- `Failed to fetch Remote Component from "${url}". ${help}`,
286
- { cause: new Error(`${status} ${statusText}`) }
287
- );
288
- }
289
-
290
313
  // src/shared/client/component-loader.ts
291
314
  import * as React from "react";
292
315
  import * as JSXDevRuntime from "react/jsx-dev-runtime";
@@ -294,18 +317,6 @@ import * as JSXRuntime from "react/jsx-runtime";
294
317
  import * as ReactDOM from "react-dom";
295
318
  import * as ReactDOMClient from "react-dom/client";
296
319
 
297
- // src/shared/utils/logger.ts
298
- var PREFIX = "remote-components";
299
- var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
300
- function logDebug(location2, message) {
301
- if (DEBUG) {
302
- console.debug(`[${PREFIX}:${location2}]: ${message}`);
303
- }
304
- }
305
- function logWarn(location2, message) {
306
- console.warn(`[${PREFIX}:${location2}]: ${message}`);
307
- }
308
-
309
320
  // src/shared/webpack/next-client-pages-loader.ts
310
321
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
311
322
  const self = globalThis;
@@ -574,6 +585,34 @@ async function loadScripts(scripts) {
574
585
  );
575
586
  }
576
587
 
588
+ // src/shared/ssr/fetch-with-protected-rc-fallback.ts
589
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
590
+ async function fetchWithProtectedRcFallback(url, init) {
591
+ try {
592
+ const res = await fetch(url, init);
593
+ return res;
594
+ } catch (error) {
595
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
596
+ logInfo(
597
+ "FetchRemoteComponent",
598
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
599
+ );
600
+ const proxiedRes = await fetch(
601
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
602
+ );
603
+ if (proxiedRes.status === 200) {
604
+ return proxiedRes;
605
+ } else {
606
+ logError(
607
+ "FetchRemoteComponent",
608
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
609
+ );
610
+ }
611
+ }
612
+ throw error;
613
+ }
614
+ }
615
+
577
616
  // src/shared/utils/index.ts
578
617
  function escapeString(str) {
579
618
  return str.replace(/[^a-z0-9]/g, "_");
@@ -639,10 +678,19 @@ function createChunkLoader(runtime) {
639
678
  }
640
679
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
641
680
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
642
- fetch(url).then((res) => res.text()).then((code) => {
643
- if (code.includes("globalThis.TURBOPACK")) {
681
+ fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
682
+ const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
683
+ if (hasTurbopack) {
644
684
  return handleTurbopackChunk(code, bundle ?? "", url);
645
685
  }
686
+ logDebug(
687
+ "ChunkLoader",
688
+ `Chunk does not contain globalThis.TURBOPACK or self.TURBOPACK: "${url}"`
689
+ );
690
+ logDebug(
691
+ "ChunkLoader",
692
+ `First 500 chars of chunk: ${code.slice(0, 500)}`
693
+ );
646
694
  }).then(resolve).catch(reject);
647
695
  });
648
696
  return self.__remote_components_turbopack_chunk_loader_promise__[url];
@@ -664,7 +712,7 @@ async function handleTurbopackChunk(code, bundle, url) {
664
712
  const self = globalThis;
665
713
  const bundleKey = getBundleKey(bundle);
666
714
  logDebug("ChunkLoader", `Bundle key: "${bundleKey}"`);
667
- const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(
715
+ const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`).replace(
668
716
  /TURBOPACK_WORKER_LOCATION/g,
669
717
  `TURBOPACK_WORKER_LOCATION_${bundleKey}`
670
718
  ).replace(
@@ -683,6 +731,30 @@ async function handleTurbopackChunk(code, bundle, url) {
683
731
  )
684
732
  ).href}$1$2.js.map`
685
733
  );
734
+ if (!self[`TURBOPACK_${bundleKey}`]) {
735
+ const chunkData = [];
736
+ const turbopackObject = {
737
+ push: (item) => {
738
+ logDebug(
739
+ "ChunkLoader",
740
+ `TURBOPACK_${bundleKey}.push() called with item type: ${Array.isArray(item) ? "array" : typeof item}`
741
+ );
742
+ if (Array.isArray(item)) {
743
+ chunkData.push(item);
744
+ logDebug(
745
+ "ChunkLoader",
746
+ `TURBOPACK_${bundleKey} now has ${chunkData.length} chunks`
747
+ );
748
+ } else {
749
+ chunkData.push([item]);
750
+ }
751
+ return chunkData.length;
752
+ },
753
+ // Store chunks for later access
754
+ __chunks__: chunkData
755
+ };
756
+ self[`TURBOPACK_${bundleKey}`] = turbopackObject;
757
+ }
686
758
  logDebug("ChunkLoader", `Creating blob script for: "${url}"`);
687
759
  await new Promise((scriptResolve, scriptReject) => {
688
760
  const blob = new Blob([transformedCode], {
@@ -695,6 +767,21 @@ async function handleTurbopackChunk(code, bundle, url) {
695
767
  script.async = true;
696
768
  script.onload = () => {
697
769
  URL.revokeObjectURL(scriptUrl);
770
+ logDebug(
771
+ "ChunkLoader",
772
+ `Script loaded successfully for bundle "${bundle}"`
773
+ );
774
+ const turbopackBundle = self[`TURBOPACK_${bundleKey}`];
775
+ logDebug(
776
+ "ChunkLoader",
777
+ `TURBOPACK_${bundleKey} type: ${typeof turbopackBundle}, isArray: ${Array.isArray(turbopackBundle)}, keys: ${turbopackBundle ? Object.keys(turbopackBundle).slice(0, 10).join(", ") : "none"}`
778
+ );
779
+ if (turbopackBundle && typeof turbopackBundle === "object") {
780
+ logDebug(
781
+ "ChunkLoader",
782
+ `TURBOPACK_${bundleKey} length/size: ${Array.isArray(turbopackBundle) ? turbopackBundle.length : Object.keys(turbopackBundle).length}`
783
+ );
784
+ }
698
785
  scriptResolve(void 0);
699
786
  script.remove();
700
787
  };
@@ -741,14 +828,23 @@ async function handleTurbopackChunk(code, bundle, url) {
741
828
  }
742
829
  }
743
830
 
831
+ // src/shared/client/turbopack-patterns.ts
832
+ var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
833
+ var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
834
+ var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
835
+ var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
836
+ var ASYNC_MODULE_ALL_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<vCb>parentImport|t)=>Promise\.all\(\["[^"]+"\]\.map\((?<mapCb>chunk|t)=>\k<ctx>\.l\(\k<mapCb>\)\)\)\.then\(\(\)=>\k<vCb>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
837
+ var NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
838
+
744
839
  // src/shared/client/turbopack-module.ts
745
840
  function handleTurbopackModule(bundle, moduleId, id) {
746
841
  const self = globalThis;
747
842
  const bundleKey = getBundleKey(bundle);
748
- const modules = self[`TURBOPACK_${bundleKey}`];
749
- const moduleInit = findModuleInit(modules, moduleId);
750
- const exports = {};
751
- const moduleExports = { exports };
843
+ let modules = self[`TURBOPACK_${bundleKey}`];
844
+ if (modules && typeof modules === "object" && "__chunks__" in modules) {
845
+ const chunks = modules.__chunks__;
846
+ modules = chunks.flat();
847
+ }
752
848
  if (!self.__remote_components_turbopack_modules__) {
753
849
  self.__remote_components_turbopack_modules__ = {};
754
850
  }
@@ -758,6 +854,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
758
854
  if (self.__remote_components_turbopack_modules__[bundle][moduleId]) {
759
855
  return self.__remote_components_turbopack_modules__[bundle][moduleId];
760
856
  }
857
+ if (!modules) {
858
+ logError("TurbopackModule", `TURBOPACK_${bundleKey} is undefined`);
859
+ }
860
+ const moduleInit = findModuleInit(modules, moduleId);
861
+ const exports = {};
862
+ const moduleExports = { exports };
761
863
  if (typeof moduleInit !== "function") {
762
864
  throw new Error(
763
865
  `Module ${id} not found in bundle ${bundle} with id ${moduleId}`
@@ -770,7 +872,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
770
872
  if (!self.__remote_components_turbopack_global__[bundle]) {
771
873
  self.__remote_components_turbopack_global__[bundle] = {};
772
874
  }
773
- const allModules = modules?.flat() ?? [];
875
+ const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
774
876
  moduleInit(
775
877
  createTurbopackContext(
776
878
  bundle,
@@ -790,9 +892,26 @@ function handleTurbopackModule(bundle, moduleId, id) {
790
892
  return moduleExports.exports;
791
893
  }
792
894
  function findModuleInit(modules, moduleId) {
895
+ if (modules && !Array.isArray(modules) && typeof modules === "object") {
896
+ const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
897
+ if (normalizedId in modules) {
898
+ return modules[normalizedId];
899
+ }
900
+ if (typeof normalizedId === "number" && String(normalizedId) in modules) {
901
+ return modules[String(normalizedId)];
902
+ }
903
+ const matchingKey = Object.keys(modules).find(
904
+ (key) => typeof key === "string" && key.includes(String(moduleId))
905
+ );
906
+ if (matchingKey) {
907
+ return modules[matchingKey];
908
+ }
909
+ logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
910
+ return void 0;
911
+ }
793
912
  const allModules = modules?.flat() ?? [];
794
913
  if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
795
- const normalizedId = /^[0-9]+$/.test(moduleId) ? Number(moduleId) : moduleId;
914
+ const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
796
915
  let moduleIdIndex = allModules.indexOf(normalizedId);
797
916
  if (moduleIdIndex === -1) {
798
917
  moduleIdIndex = allModules.findIndex(
@@ -958,13 +1077,6 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
958
1077
  };
959
1078
  }
960
1079
 
961
- // src/shared/client/turbopack-patterns.ts
962
- var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
963
- var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
964
- var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
965
- var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
966
- var ASYNC_MODULE_ALL_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<vCb>parentImport|t)=>Promise\.all\(\["[^"]+"\]\.map\((?<mapCb>chunk|t)=>\k<ctx>\.l\(\k<mapCb>\)\)\)\.then\(\(\)=>\k<vCb>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
967
-
968
1080
  // src/shared/client/shared-modules.ts
969
1081
  async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {}) {
970
1082
  const self = globalThis;
@@ -973,10 +1085,14 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
973
1085
  self.__remote_shared_modules__[bundle] = {};
974
1086
  }
975
1087
  const bundleKey = getBundleKey(bundle);
976
- const modules = self[`TURBOPACK_${bundleKey}`];
1088
+ let modules = self[`TURBOPACK_${bundleKey}`];
1089
+ if (modules && typeof modules === "object" && "__chunks__" in modules) {
1090
+ const chunks = modules.__chunks__;
1091
+ modules = chunks.flat();
1092
+ }
977
1093
  let sharedModuleInitializer = null;
978
- if (modules && Array.isArray(modules)) {
979
- const allModules = modules.flat();
1094
+ if (modules) {
1095
+ const allModules = Array.isArray(modules) ? modules.flat() : Object.entries(modules).flat();
980
1096
  const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {
981
1097
  if (typeof idOrFunc !== "function") {
982
1098
  return false;
@@ -1009,6 +1125,11 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
1009
1125
  if (self.__remote_shared_modules__?.[bundle]) {
1010
1126
  if (hostShared[module]) {
1011
1127
  self.__remote_shared_modules__[bundle][id] = await hostShared[module](bundle);
1128
+ } else {
1129
+ logError(
1130
+ "SharedModules",
1131
+ `Host shared module "${module}" not found for ID ${id}`
1132
+ );
1012
1133
  }
1013
1134
  }
1014
1135
  })
@@ -1019,9 +1140,13 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
1019
1140
  Object.entries(remoteShared).map(async ([id, module]) => {
1020
1141
  if (self.__remote_shared_modules__?.[bundle]) {
1021
1142
  if (hostShared[module]) {
1022
- self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await hostShared[module](bundle);
1143
+ const normalizedId = id.replace("[app-ssr]", "[app-client]");
1144
+ self.__remote_shared_modules__[bundle][normalizedId] = await hostShared[module](bundle);
1023
1145
  } else {
1024
- console.error(`Shared module "${module}" not found for "${bundle}".`);
1146
+ logError(
1147
+ "SharedModules",
1148
+ `Shared module "${module}" not found for "${bundle}"`
1149
+ );
1025
1150
  }
1026
1151
  }
1027
1152
  })
@@ -1033,7 +1158,15 @@ function extractSharedModuleIds(shared, bundleKey, self) {
1033
1158
  if (asyncSharedModuleId) {
1034
1159
  const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
1035
1160
  let asyncSharedModule;
1036
- const newAllModules = self[`TURBOPACK_${bundleKey}`]?.flat() ?? [];
1161
+ let turbopackModules = self[`TURBOPACK_${bundleKey}`];
1162
+ if (turbopackModules && typeof turbopackModules === "object" && "__chunks__" in turbopackModules) {
1163
+ const chunks = turbopackModules.__chunks__;
1164
+ turbopackModules = chunks.flat();
1165
+ }
1166
+ const newAllModules = Array.isArray(turbopackModules) ? turbopackModules.flat() : turbopackModules ? Object.entries(turbopackModules).flatMap(([key2, value2]) => [
1167
+ key2,
1168
+ value2
1169
+ ]) : [];
1037
1170
  const asyncSharedModuleIdIndex = newAllModules.indexOf(
1038
1171
  asyncSharedModuleIdNumber
1039
1172
  );
@@ -1397,11 +1530,10 @@ async function loadStaticRemoteComponent(scripts, url) {
1397
1530
  unmount: mod.unmount || mod.default?.unmount
1398
1531
  };
1399
1532
  } catch (e) {
1400
- console.error(
1401
- new RemoteComponentsError(
1402
- `Error loading remote component script from "${script.src || url.href}".`,
1403
- { cause: e }
1404
- )
1533
+ logError(
1534
+ "StaticLoader",
1535
+ `Error loading remote component script from "${script.src || url.href}".`,
1536
+ e
1405
1537
  );
1406
1538
  return {
1407
1539
  mount: void 0,
@@ -1444,11 +1576,16 @@ function remoteFetchHeaders() {
1444
1576
  }
1445
1577
 
1446
1578
  // src/shared/ssr/fetch-with-hooks.ts
1447
- async function fetchWithHooks(url, init, options = {}) {
1579
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1448
1580
  const { onRequest, onResponse } = options;
1581
+ const init = {
1582
+ method: "GET",
1583
+ headers: remoteFetchHeaders(),
1584
+ ...additionalInit
1585
+ };
1449
1586
  let res = await onRequest?.(url, init);
1450
1587
  if (!res) {
1451
- res = await fetch(url, init);
1588
+ res = await fetchWithProtectedRcFallback(url, init);
1452
1589
  }
1453
1590
  const transformedRes = await onResponse?.(url, res);
1454
1591
  if (transformedRes) {
@@ -1657,8 +1794,6 @@ function RemoteComponent({
1657
1794
  );
1658
1795
  if (!html && src) {
1659
1796
  const fetchInit = {
1660
- method: "GET",
1661
- headers: remoteFetchHeaders(),
1662
1797
  credentials
1663
1798
  };
1664
1799
  const res = await fetchWithHooks(url, fetchInit, {
@@ -2133,7 +2268,8 @@ var routerImpl = async () => {
2133
2268
  },
2134
2269
  refresh: () => Promise.resolve(router.refresh()),
2135
2270
  prefetch: async () => {
2136
- console.warn(
2271
+ logWarn(
2272
+ "NextAppRouterCompat",
2137
2273
  "You are using router.prefetch() in a remote component loaded in the Next.js App Router. prefetch() is a no-op in the App Router."
2138
2274
  );
2139
2275
  return Promise.resolve();
@@ -2150,17 +2286,20 @@ var routerImpl = async () => {
2150
2286
  },
2151
2287
  events: {
2152
2288
  on: () => {
2153
- console.warn(
2289
+ logWarn(
2290
+ "NextAppRouterCompat",
2154
2291
  "You are using router.events.on() in a remote component loaded in the Next.js App Router. events.on() is a no-op in the App Router."
2155
2292
  );
2156
2293
  },
2157
2294
  off: () => {
2158
- console.warn(
2295
+ logWarn(
2296
+ "NextAppRouterCompat",
2159
2297
  "You are using router.events.off() in a remote component loaded in the Next.js App Router. events.off() is a no-op in the App Router."
2160
2298
  );
2161
2299
  },
2162
2300
  emit: () => {
2163
- console.warn(
2301
+ logWarn(
2302
+ "NextAppRouterCompat",
2164
2303
  "You are using router.events.emit() in a remote component loaded in the Next.js App Router. events.emit() is a no-op in the App Router."
2165
2304
  );
2166
2305
  }