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
@@ -97,6 +97,48 @@ function applyOriginToNodes(doc, url) {
97
97
  }
98
98
  }
99
99
 
100
+ // src/shared/error.ts
101
+ var RemoteComponentsError = class extends Error {
102
+ code = "REMOTE_COMPONENTS_ERROR";
103
+ constructor(message, options) {
104
+ super(message, options);
105
+ this.name = "RemoteComponentsError";
106
+ }
107
+ };
108
+ function multipleRemoteComponentsError(url) {
109
+ return new RemoteComponentsError(
110
+ `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.`
111
+ );
112
+ }
113
+ function failedToFetchRemoteComponentError(url, { status, statusText }, help = "Is the URL correct and accessible?") {
114
+ return new RemoteComponentsError(
115
+ `Failed to fetch Remote Component from "${url}". ${help}`,
116
+ { cause: new Error(`${status} ${statusText}`) }
117
+ );
118
+ }
119
+
120
+ // src/shared/utils/logger.ts
121
+ var PREFIX = "remote-components";
122
+ var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
123
+ function logDebug(location2, message) {
124
+ if (DEBUG) {
125
+ console.debug(`[${PREFIX}:${location2}]: ${message}`);
126
+ }
127
+ }
128
+ function logInfo(location2, message) {
129
+ console.info(`[${PREFIX}:${location2}]: ${message}`);
130
+ }
131
+ function logWarn(location2, message) {
132
+ console.warn(`[${PREFIX}:${location2}]: ${message}`);
133
+ }
134
+ function logError(location2, message, cause) {
135
+ console.error(
136
+ new RemoteComponentsError(`[${PREFIX}:${location2}]: ${message}`, {
137
+ cause
138
+ })
139
+ );
140
+ }
141
+
100
142
  // src/shared/client/polyfill.tsx
101
143
  var import_jsx_runtime = (
102
144
  // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
@@ -192,7 +234,8 @@ function sharedPolyfills(shared) {
192
234
  ...props
193
235
  }) => {
194
236
  if (prefetch) {
195
- console.warn(
237
+ logWarn(
238
+ "Polyfill",
196
239
  "Next.js Link prefetch is not supported in remote components"
197
240
  );
198
241
  }
@@ -292,26 +335,6 @@ function sharedPolyfills(shared) {
292
335
  return polyfill;
293
336
  }
294
337
 
295
- // src/shared/error.ts
296
- var RemoteComponentsError = class extends Error {
297
- code = "REMOTE_COMPONENTS_ERROR";
298
- constructor(message, options) {
299
- super(message, options);
300
- this.name = "RemoteComponentsError";
301
- }
302
- };
303
- function multipleRemoteComponentsError(url) {
304
- return new RemoteComponentsError(
305
- `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.`
306
- );
307
- }
308
- function failedToFetchRemoteComponentError(url, { status, statusText }, help = "Is the URL correct and accessible?") {
309
- return new RemoteComponentsError(
310
- `Failed to fetch Remote Component from "${url}". ${help}`,
311
- { cause: new Error(`${status} ${statusText}`) }
312
- );
313
- }
314
-
315
338
  // src/shared/client/component-loader.ts
316
339
  var React = __toESM(require("react"), 1);
317
340
  var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
@@ -319,18 +342,6 @@ var JSXRuntime = __toESM(require("react/jsx-runtime"), 1);
319
342
  var ReactDOM = __toESM(require("react-dom"), 1);
320
343
  var ReactDOMClient = __toESM(require("react-dom/client"), 1);
321
344
 
322
- // src/shared/utils/logger.ts
323
- var PREFIX = "remote-components";
324
- var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
325
- function logDebug(location2, message) {
326
- if (DEBUG) {
327
- console.debug(`[${PREFIX}:${location2}]: ${message}`);
328
- }
329
- }
330
- function logWarn(location2, message) {
331
- console.warn(`[${PREFIX}:${location2}]: ${message}`);
332
- }
333
-
334
345
  // src/shared/webpack/next-client-pages-loader.ts
335
346
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
336
347
  const self = globalThis;
@@ -599,6 +610,34 @@ async function loadScripts(scripts) {
599
610
  );
600
611
  }
601
612
 
613
+ // src/shared/ssr/fetch-with-protected-rc-fallback.ts
614
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
615
+ async function fetchWithProtectedRcFallback(url, init) {
616
+ try {
617
+ const res = await fetch(url, init);
618
+ return res;
619
+ } catch (error) {
620
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
621
+ logInfo(
622
+ "FetchRemoteComponent",
623
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
624
+ );
625
+ const proxiedRes = await fetch(
626
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
627
+ );
628
+ if (proxiedRes.status === 200) {
629
+ return proxiedRes;
630
+ } else {
631
+ logError(
632
+ "FetchRemoteComponent",
633
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
634
+ );
635
+ }
636
+ }
637
+ throw error;
638
+ }
639
+ }
640
+
602
641
  // src/shared/utils/index.ts
603
642
  function escapeString(str) {
604
643
  return str.replace(/[^a-z0-9]/g, "_");
@@ -664,10 +703,19 @@ function createChunkLoader(runtime) {
664
703
  }
665
704
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
666
705
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
667
- fetch(url).then((res) => res.text()).then((code) => {
668
- if (code.includes("globalThis.TURBOPACK")) {
706
+ fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
707
+ const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
708
+ if (hasTurbopack) {
669
709
  return handleTurbopackChunk(code, bundle ?? "", url);
670
710
  }
711
+ logDebug(
712
+ "ChunkLoader",
713
+ `Chunk does not contain globalThis.TURBOPACK or self.TURBOPACK: "${url}"`
714
+ );
715
+ logDebug(
716
+ "ChunkLoader",
717
+ `First 500 chars of chunk: ${code.slice(0, 500)}`
718
+ );
671
719
  }).then(resolve).catch(reject);
672
720
  });
673
721
  return self.__remote_components_turbopack_chunk_loader_promise__[url];
@@ -689,7 +737,7 @@ async function handleTurbopackChunk(code, bundle, url) {
689
737
  const self = globalThis;
690
738
  const bundleKey = getBundleKey(bundle);
691
739
  logDebug("ChunkLoader", `Bundle key: "${bundleKey}"`);
692
- const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(
740
+ const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`).replace(
693
741
  /TURBOPACK_WORKER_LOCATION/g,
694
742
  `TURBOPACK_WORKER_LOCATION_${bundleKey}`
695
743
  ).replace(
@@ -708,6 +756,30 @@ async function handleTurbopackChunk(code, bundle, url) {
708
756
  )
709
757
  ).href}$1$2.js.map`
710
758
  );
759
+ if (!self[`TURBOPACK_${bundleKey}`]) {
760
+ const chunkData = [];
761
+ const turbopackObject = {
762
+ push: (item) => {
763
+ logDebug(
764
+ "ChunkLoader",
765
+ `TURBOPACK_${bundleKey}.push() called with item type: ${Array.isArray(item) ? "array" : typeof item}`
766
+ );
767
+ if (Array.isArray(item)) {
768
+ chunkData.push(item);
769
+ logDebug(
770
+ "ChunkLoader",
771
+ `TURBOPACK_${bundleKey} now has ${chunkData.length} chunks`
772
+ );
773
+ } else {
774
+ chunkData.push([item]);
775
+ }
776
+ return chunkData.length;
777
+ },
778
+ // Store chunks for later access
779
+ __chunks__: chunkData
780
+ };
781
+ self[`TURBOPACK_${bundleKey}`] = turbopackObject;
782
+ }
711
783
  logDebug("ChunkLoader", `Creating blob script for: "${url}"`);
712
784
  await new Promise((scriptResolve, scriptReject) => {
713
785
  const blob = new Blob([transformedCode], {
@@ -720,6 +792,21 @@ async function handleTurbopackChunk(code, bundle, url) {
720
792
  script.async = true;
721
793
  script.onload = () => {
722
794
  URL.revokeObjectURL(scriptUrl);
795
+ logDebug(
796
+ "ChunkLoader",
797
+ `Script loaded successfully for bundle "${bundle}"`
798
+ );
799
+ const turbopackBundle = self[`TURBOPACK_${bundleKey}`];
800
+ logDebug(
801
+ "ChunkLoader",
802
+ `TURBOPACK_${bundleKey} type: ${typeof turbopackBundle}, isArray: ${Array.isArray(turbopackBundle)}, keys: ${turbopackBundle ? Object.keys(turbopackBundle).slice(0, 10).join(", ") : "none"}`
803
+ );
804
+ if (turbopackBundle && typeof turbopackBundle === "object") {
805
+ logDebug(
806
+ "ChunkLoader",
807
+ `TURBOPACK_${bundleKey} length/size: ${Array.isArray(turbopackBundle) ? turbopackBundle.length : Object.keys(turbopackBundle).length}`
808
+ );
809
+ }
723
810
  scriptResolve(void 0);
724
811
  script.remove();
725
812
  };
@@ -766,14 +853,23 @@ async function handleTurbopackChunk(code, bundle, url) {
766
853
  }
767
854
  }
768
855
 
856
+ // src/shared/client/turbopack-patterns.ts
857
+ var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
858
+ var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
859
+ var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
860
+ var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
861
+ 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]+)\)\)\)\}/;
862
+ var NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
863
+
769
864
  // src/shared/client/turbopack-module.ts
770
865
  function handleTurbopackModule(bundle, moduleId, id) {
771
866
  const self = globalThis;
772
867
  const bundleKey = getBundleKey(bundle);
773
- const modules = self[`TURBOPACK_${bundleKey}`];
774
- const moduleInit = findModuleInit(modules, moduleId);
775
- const exports = {};
776
- const moduleExports = { exports };
868
+ let modules = self[`TURBOPACK_${bundleKey}`];
869
+ if (modules && typeof modules === "object" && "__chunks__" in modules) {
870
+ const chunks = modules.__chunks__;
871
+ modules = chunks.flat();
872
+ }
777
873
  if (!self.__remote_components_turbopack_modules__) {
778
874
  self.__remote_components_turbopack_modules__ = {};
779
875
  }
@@ -783,6 +879,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
783
879
  if (self.__remote_components_turbopack_modules__[bundle][moduleId]) {
784
880
  return self.__remote_components_turbopack_modules__[bundle][moduleId];
785
881
  }
882
+ if (!modules) {
883
+ logError("TurbopackModule", `TURBOPACK_${bundleKey} is undefined`);
884
+ }
885
+ const moduleInit = findModuleInit(modules, moduleId);
886
+ const exports = {};
887
+ const moduleExports = { exports };
786
888
  if (typeof moduleInit !== "function") {
787
889
  throw new Error(
788
890
  `Module ${id} not found in bundle ${bundle} with id ${moduleId}`
@@ -795,7 +897,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
795
897
  if (!self.__remote_components_turbopack_global__[bundle]) {
796
898
  self.__remote_components_turbopack_global__[bundle] = {};
797
899
  }
798
- const allModules = modules?.flat() ?? [];
900
+ const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
799
901
  moduleInit(
800
902
  createTurbopackContext(
801
903
  bundle,
@@ -815,9 +917,26 @@ function handleTurbopackModule(bundle, moduleId, id) {
815
917
  return moduleExports.exports;
816
918
  }
817
919
  function findModuleInit(modules, moduleId) {
920
+ if (modules && !Array.isArray(modules) && typeof modules === "object") {
921
+ const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
922
+ if (normalizedId in modules) {
923
+ return modules[normalizedId];
924
+ }
925
+ if (typeof normalizedId === "number" && String(normalizedId) in modules) {
926
+ return modules[String(normalizedId)];
927
+ }
928
+ const matchingKey = Object.keys(modules).find(
929
+ (key) => typeof key === "string" && key.includes(String(moduleId))
930
+ );
931
+ if (matchingKey) {
932
+ return modules[matchingKey];
933
+ }
934
+ logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
935
+ return void 0;
936
+ }
818
937
  const allModules = modules?.flat() ?? [];
819
938
  if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
820
- const normalizedId = /^[0-9]+$/.test(moduleId) ? Number(moduleId) : moduleId;
939
+ const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
821
940
  let moduleIdIndex = allModules.indexOf(normalizedId);
822
941
  if (moduleIdIndex === -1) {
823
942
  moduleIdIndex = allModules.findIndex(
@@ -983,13 +1102,6 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
983
1102
  };
984
1103
  }
985
1104
 
986
- // src/shared/client/turbopack-patterns.ts
987
- var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
988
- var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
989
- var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
990
- var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
991
- 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]+)\)\)\)\}/;
992
-
993
1105
  // src/shared/client/shared-modules.ts
994
1106
  async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {}) {
995
1107
  const self = globalThis;
@@ -998,10 +1110,14 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
998
1110
  self.__remote_shared_modules__[bundle] = {};
999
1111
  }
1000
1112
  const bundleKey = getBundleKey(bundle);
1001
- const modules = self[`TURBOPACK_${bundleKey}`];
1113
+ let modules = self[`TURBOPACK_${bundleKey}`];
1114
+ if (modules && typeof modules === "object" && "__chunks__" in modules) {
1115
+ const chunks = modules.__chunks__;
1116
+ modules = chunks.flat();
1117
+ }
1002
1118
  let sharedModuleInitializer = null;
1003
- if (modules && Array.isArray(modules)) {
1004
- const allModules = modules.flat();
1119
+ if (modules) {
1120
+ const allModules = Array.isArray(modules) ? modules.flat() : Object.entries(modules).flat();
1005
1121
  const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {
1006
1122
  if (typeof idOrFunc !== "function") {
1007
1123
  return false;
@@ -1034,6 +1150,11 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
1034
1150
  if (self.__remote_shared_modules__?.[bundle]) {
1035
1151
  if (hostShared[module2]) {
1036
1152
  self.__remote_shared_modules__[bundle][id] = await hostShared[module2](bundle);
1153
+ } else {
1154
+ logError(
1155
+ "SharedModules",
1156
+ `Host shared module "${module2}" not found for ID ${id}`
1157
+ );
1037
1158
  }
1038
1159
  }
1039
1160
  })
@@ -1044,9 +1165,13 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
1044
1165
  Object.entries(remoteShared).map(async ([id, module2]) => {
1045
1166
  if (self.__remote_shared_modules__?.[bundle]) {
1046
1167
  if (hostShared[module2]) {
1047
- self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await hostShared[module2](bundle);
1168
+ const normalizedId = id.replace("[app-ssr]", "[app-client]");
1169
+ self.__remote_shared_modules__[bundle][normalizedId] = await hostShared[module2](bundle);
1048
1170
  } else {
1049
- console.error(`Shared module "${module2}" not found for "${bundle}".`);
1171
+ logError(
1172
+ "SharedModules",
1173
+ `Shared module "${module2}" not found for "${bundle}"`
1174
+ );
1050
1175
  }
1051
1176
  }
1052
1177
  })
@@ -1058,7 +1183,15 @@ function extractSharedModuleIds(shared, bundleKey, self) {
1058
1183
  if (asyncSharedModuleId) {
1059
1184
  const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
1060
1185
  let asyncSharedModule;
1061
- const newAllModules = self[`TURBOPACK_${bundleKey}`]?.flat() ?? [];
1186
+ let turbopackModules = self[`TURBOPACK_${bundleKey}`];
1187
+ if (turbopackModules && typeof turbopackModules === "object" && "__chunks__" in turbopackModules) {
1188
+ const chunks = turbopackModules.__chunks__;
1189
+ turbopackModules = chunks.flat();
1190
+ }
1191
+ const newAllModules = Array.isArray(turbopackModules) ? turbopackModules.flat() : turbopackModules ? Object.entries(turbopackModules).flatMap(([key2, value2]) => [
1192
+ key2,
1193
+ value2
1194
+ ]) : [];
1062
1195
  const asyncSharedModuleIdIndex = newAllModules.indexOf(
1063
1196
  asyncSharedModuleIdNumber
1064
1197
  );
@@ -1422,11 +1555,10 @@ async function loadStaticRemoteComponent(scripts, url) {
1422
1555
  unmount: mod.unmount || mod.default?.unmount
1423
1556
  };
1424
1557
  } catch (e) {
1425
- console.error(
1426
- new RemoteComponentsError(
1427
- `Error loading remote component script from "${script.src || url.href}".`,
1428
- { cause: e }
1429
- )
1558
+ logError(
1559
+ "StaticLoader",
1560
+ `Error loading remote component script from "${script.src || url.href}".`,
1561
+ e
1430
1562
  );
1431
1563
  return {
1432
1564
  mount: void 0,
@@ -1469,11 +1601,16 @@ function remoteFetchHeaders() {
1469
1601
  }
1470
1602
 
1471
1603
  // src/shared/ssr/fetch-with-hooks.ts
1472
- async function fetchWithHooks(url, init, options = {}) {
1604
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1473
1605
  const { onRequest, onResponse } = options;
1606
+ const init = {
1607
+ method: "GET",
1608
+ headers: remoteFetchHeaders(),
1609
+ ...additionalInit
1610
+ };
1474
1611
  let res = await onRequest?.(url, init);
1475
1612
  if (!res) {
1476
- res = await fetch(url, init);
1613
+ res = await fetchWithProtectedRcFallback(url, init);
1477
1614
  }
1478
1615
  const transformedRes = await onResponse?.(url, res);
1479
1616
  if (transformedRes) {
@@ -1685,8 +1822,6 @@ function RemoteComponent({
1685
1822
  );
1686
1823
  if (!html && src) {
1687
1824
  const fetchInit = {
1688
- method: "GET",
1689
- headers: remoteFetchHeaders(),
1690
1825
  credentials
1691
1826
  };
1692
1827
  const res = await fetchWithHooks(url, fetchInit, {
@@ -2160,7 +2295,8 @@ var routerImpl = async () => {
2160
2295
  },
2161
2296
  refresh: () => Promise.resolve(router.refresh()),
2162
2297
  prefetch: async () => {
2163
- console.warn(
2298
+ logWarn(
2299
+ "NextAppRouterCompat",
2164
2300
  "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."
2165
2301
  );
2166
2302
  return Promise.resolve();
@@ -2177,17 +2313,20 @@ var routerImpl = async () => {
2177
2313
  },
2178
2314
  events: {
2179
2315
  on: () => {
2180
- console.warn(
2316
+ logWarn(
2317
+ "NextAppRouterCompat",
2181
2318
  "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."
2182
2319
  );
2183
2320
  },
2184
2321
  off: () => {
2185
- console.warn(
2322
+ logWarn(
2323
+ "NextAppRouterCompat",
2186
2324
  "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."
2187
2325
  );
2188
2326
  },
2189
2327
  emit: () => {
2190
- console.warn(
2328
+ logWarn(
2329
+ "NextAppRouterCompat",
2191
2330
  "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."
2192
2331
  );
2193
2332
  }