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
@@ -62,13 +62,24 @@ function logDebug(location2, message) {
62
62
  console.debug(`[${PREFIX}:${location2}]: ${message}`);
63
63
  }
64
64
  }
65
+ function logInfo(location2, message) {
66
+ console.info(`[${PREFIX}:${location2}]: ${message}`);
67
+ }
65
68
  function logWarn(location2, message) {
66
69
  console.warn(`[${PREFIX}:${location2}]: ${message}`);
67
70
  }
71
+ function logError(location2, message, cause) {
72
+ console.error(
73
+ new RemoteComponentsError(`[${PREFIX}:${location2}]: ${message}`, {
74
+ cause
75
+ })
76
+ );
77
+ }
68
78
  var PREFIX, DEBUG;
69
79
  var init_logger = __esm({
70
80
  "src/shared/utils/logger.ts"() {
71
81
  "use strict";
82
+ init_error();
72
83
  PREFIX = "remote-components";
73
84
  DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
74
85
  }
@@ -259,6 +270,41 @@ var init_shared_modules = __esm({
259
270
  }
260
271
  });
261
272
 
273
+ // src/shared/ssr/fetch-with-protected-rc-fallback.ts
274
+ async function fetchWithProtectedRcFallback(url, init) {
275
+ try {
276
+ const res = await fetch(url, init);
277
+ return res;
278
+ } catch (error) {
279
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
280
+ logInfo(
281
+ "FetchRemoteComponent",
282
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
283
+ );
284
+ const proxiedRes = await fetch(
285
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
286
+ );
287
+ if (proxiedRes.status === 200) {
288
+ return proxiedRes;
289
+ } else {
290
+ logError(
291
+ "FetchRemoteComponent",
292
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
293
+ );
294
+ }
295
+ }
296
+ throw error;
297
+ }
298
+ }
299
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME;
300
+ var init_fetch_with_protected_rc_fallback = __esm({
301
+ "src/shared/ssr/fetch-with-protected-rc-fallback.ts"() {
302
+ "use strict";
303
+ init_logger();
304
+ RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
305
+ }
306
+ });
307
+
262
308
  // src/shared/utils/index.ts
263
309
  function escapeString(str) {
264
310
  return str.replace(/[^a-z0-9]/g, "_");
@@ -327,10 +373,19 @@ function createChunkLoader(runtime) {
327
373
  }
328
374
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
329
375
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
330
- fetch(url).then((res) => res.text()).then((code) => {
331
- if (code.includes("globalThis.TURBOPACK")) {
376
+ fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
377
+ const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
378
+ if (hasTurbopack) {
332
379
  return handleTurbopackChunk(code, bundle ?? "", url);
333
380
  }
381
+ logDebug(
382
+ "ChunkLoader",
383
+ `Chunk does not contain globalThis.TURBOPACK or self.TURBOPACK: "${url}"`
384
+ );
385
+ logDebug(
386
+ "ChunkLoader",
387
+ `First 500 chars of chunk: ${code.slice(0, 500)}`
388
+ );
334
389
  }).then(resolve).catch(reject);
335
390
  });
336
391
  return self.__remote_components_turbopack_chunk_loader_promise__[url];
@@ -352,7 +407,7 @@ async function handleTurbopackChunk(code, bundle, url) {
352
407
  const self = globalThis;
353
408
  const bundleKey = getBundleKey(bundle);
354
409
  logDebug("ChunkLoader", `Bundle key: "${bundleKey}"`);
355
- const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(
410
+ const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`).replace(
356
411
  /TURBOPACK_WORKER_LOCATION/g,
357
412
  `TURBOPACK_WORKER_LOCATION_${bundleKey}`
358
413
  ).replace(
@@ -371,6 +426,30 @@ async function handleTurbopackChunk(code, bundle, url) {
371
426
  )
372
427
  ).href}$1$2.js.map`
373
428
  );
429
+ if (!self[`TURBOPACK_${bundleKey}`]) {
430
+ const chunkData = [];
431
+ const turbopackObject = {
432
+ push: (item) => {
433
+ logDebug(
434
+ "ChunkLoader",
435
+ `TURBOPACK_${bundleKey}.push() called with item type: ${Array.isArray(item) ? "array" : typeof item}`
436
+ );
437
+ if (Array.isArray(item)) {
438
+ chunkData.push(item);
439
+ logDebug(
440
+ "ChunkLoader",
441
+ `TURBOPACK_${bundleKey} now has ${chunkData.length} chunks`
442
+ );
443
+ } else {
444
+ chunkData.push([item]);
445
+ }
446
+ return chunkData.length;
447
+ },
448
+ // Store chunks for later access
449
+ __chunks__: chunkData
450
+ };
451
+ self[`TURBOPACK_${bundleKey}`] = turbopackObject;
452
+ }
374
453
  logDebug("ChunkLoader", `Creating blob script for: "${url}"`);
375
454
  await new Promise((scriptResolve, scriptReject) => {
376
455
  const blob = new Blob([transformedCode], {
@@ -383,6 +462,21 @@ async function handleTurbopackChunk(code, bundle, url) {
383
462
  script.async = true;
384
463
  script.onload = () => {
385
464
  URL.revokeObjectURL(scriptUrl);
465
+ logDebug(
466
+ "ChunkLoader",
467
+ `Script loaded successfully for bundle "${bundle}"`
468
+ );
469
+ const turbopackBundle = self[`TURBOPACK_${bundleKey}`];
470
+ logDebug(
471
+ "ChunkLoader",
472
+ `TURBOPACK_${bundleKey} type: ${typeof turbopackBundle}, isArray: ${Array.isArray(turbopackBundle)}, keys: ${turbopackBundle ? Object.keys(turbopackBundle).slice(0, 10).join(", ") : "none"}`
473
+ );
474
+ if (turbopackBundle && typeof turbopackBundle === "object") {
475
+ logDebug(
476
+ "ChunkLoader",
477
+ `TURBOPACK_${bundleKey} length/size: ${Array.isArray(turbopackBundle) ? turbopackBundle.length : Object.keys(turbopackBundle).length}`
478
+ );
479
+ }
386
480
  scriptResolve(void 0);
387
481
  script.remove();
388
482
  };
@@ -432,19 +526,35 @@ var init_chunk_loader = __esm({
432
526
  "src/shared/client/chunk-loader.ts"() {
433
527
  "use strict";
434
528
  init_error();
529
+ init_fetch_with_protected_rc_fallback();
435
530
  init_logger();
436
531
  init_const();
437
532
  }
438
533
  });
439
534
 
535
+ // src/shared/client/turbopack-patterns.ts
536
+ var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, NUMERIC_MODULE_ID_RE;
537
+ var init_turbopack_patterns = __esm({
538
+ "src/shared/client/turbopack-patterns.ts"() {
539
+ "use strict";
540
+ REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
541
+ REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
542
+ ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
543
+ ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
544
+ 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]+)\)\)\)\}/;
545
+ NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
546
+ }
547
+ });
548
+
440
549
  // src/shared/client/turbopack-module.ts
441
550
  function handleTurbopackModule(bundle, moduleId, id) {
442
551
  const self = globalThis;
443
552
  const bundleKey = getBundleKey(bundle);
444
- const modules = self[`TURBOPACK_${bundleKey}`];
445
- const moduleInit = findModuleInit(modules, moduleId);
446
- const exports = {};
447
- const moduleExports = { exports };
553
+ let modules = self[`TURBOPACK_${bundleKey}`];
554
+ if (modules && typeof modules === "object" && "__chunks__" in modules) {
555
+ const chunks = modules.__chunks__;
556
+ modules = chunks.flat();
557
+ }
448
558
  if (!self.__remote_components_turbopack_modules__) {
449
559
  self.__remote_components_turbopack_modules__ = {};
450
560
  }
@@ -454,6 +564,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
454
564
  if (self.__remote_components_turbopack_modules__[bundle][moduleId]) {
455
565
  return self.__remote_components_turbopack_modules__[bundle][moduleId];
456
566
  }
567
+ if (!modules) {
568
+ logError("TurbopackModule", `TURBOPACK_${bundleKey} is undefined`);
569
+ }
570
+ const moduleInit = findModuleInit(modules, moduleId);
571
+ const exports = {};
572
+ const moduleExports = { exports };
457
573
  if (typeof moduleInit !== "function") {
458
574
  throw new Error(
459
575
  `Module ${id} not found in bundle ${bundle} with id ${moduleId}`
@@ -466,7 +582,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
466
582
  if (!self.__remote_components_turbopack_global__[bundle]) {
467
583
  self.__remote_components_turbopack_global__[bundle] = {};
468
584
  }
469
- const allModules = modules?.flat() ?? [];
585
+ const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
470
586
  moduleInit(
471
587
  createTurbopackContext(
472
588
  bundle,
@@ -486,9 +602,26 @@ function handleTurbopackModule(bundle, moduleId, id) {
486
602
  return moduleExports.exports;
487
603
  }
488
604
  function findModuleInit(modules, moduleId) {
605
+ if (modules && !Array.isArray(modules) && typeof modules === "object") {
606
+ const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
607
+ if (normalizedId in modules) {
608
+ return modules[normalizedId];
609
+ }
610
+ if (typeof normalizedId === "number" && String(normalizedId) in modules) {
611
+ return modules[String(normalizedId)];
612
+ }
613
+ const matchingKey = Object.keys(modules).find(
614
+ (key) => typeof key === "string" && key.includes(String(moduleId))
615
+ );
616
+ if (matchingKey) {
617
+ return modules[matchingKey];
618
+ }
619
+ logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
620
+ return void 0;
621
+ }
489
622
  const allModules = modules?.flat() ?? [];
490
623
  if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
491
- const normalizedId = /^[0-9]+$/.test(moduleId) ? Number(moduleId) : moduleId;
624
+ const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
492
625
  let moduleIdIndex = allModules.indexOf(normalizedId);
493
626
  if (moduleIdIndex === -1) {
494
627
  moduleIdIndex = allModules.findIndex(
@@ -656,20 +789,9 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
656
789
  var init_turbopack_module = __esm({
657
790
  "src/shared/client/turbopack-module.ts"() {
658
791
  "use strict";
792
+ init_logger();
659
793
  init_const();
660
- }
661
- });
662
-
663
- // src/shared/client/turbopack-patterns.ts
664
- var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE;
665
- var init_turbopack_patterns = __esm({
666
- "src/shared/client/turbopack-patterns.ts"() {
667
- "use strict";
668
- REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
669
- REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
670
- ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
671
- ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
672
- 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]+)\)\)\)\}/;
794
+ init_turbopack_patterns();
673
795
  }
674
796
  });
675
797
 
@@ -681,10 +803,14 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
681
803
  self.__remote_shared_modules__[bundle] = {};
682
804
  }
683
805
  const bundleKey = getBundleKey(bundle);
684
- const modules = self[`TURBOPACK_${bundleKey}`];
806
+ let modules = self[`TURBOPACK_${bundleKey}`];
807
+ if (modules && typeof modules === "object" && "__chunks__" in modules) {
808
+ const chunks = modules.__chunks__;
809
+ modules = chunks.flat();
810
+ }
685
811
  let sharedModuleInitializer = null;
686
- if (modules && Array.isArray(modules)) {
687
- const allModules = modules.flat();
812
+ if (modules) {
813
+ const allModules = Array.isArray(modules) ? modules.flat() : Object.entries(modules).flat();
688
814
  const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {
689
815
  if (typeof idOrFunc !== "function") {
690
816
  return false;
@@ -717,6 +843,11 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
717
843
  if (self.__remote_shared_modules__?.[bundle]) {
718
844
  if (hostShared[module2]) {
719
845
  self.__remote_shared_modules__[bundle][id] = await hostShared[module2](bundle);
846
+ } else {
847
+ logError(
848
+ "SharedModules",
849
+ `Host shared module "${module2}" not found for ID ${id}`
850
+ );
720
851
  }
721
852
  }
722
853
  })
@@ -727,9 +858,13 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
727
858
  Object.entries(remoteShared).map(async ([id, module2]) => {
728
859
  if (self.__remote_shared_modules__?.[bundle]) {
729
860
  if (hostShared[module2]) {
730
- self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await hostShared[module2](bundle);
861
+ const normalizedId = id.replace("[app-ssr]", "[app-client]");
862
+ self.__remote_shared_modules__[bundle][normalizedId] = await hostShared[module2](bundle);
731
863
  } else {
732
- console.error(`Shared module "${module2}" not found for "${bundle}".`);
864
+ logError(
865
+ "SharedModules",
866
+ `Shared module "${module2}" not found for "${bundle}"`
867
+ );
733
868
  }
734
869
  }
735
870
  })
@@ -741,7 +876,15 @@ function extractSharedModuleIds(shared, bundleKey, self) {
741
876
  if (asyncSharedModuleId) {
742
877
  const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
743
878
  let asyncSharedModule;
744
- const newAllModules = self[`TURBOPACK_${bundleKey}`]?.flat() ?? [];
879
+ let turbopackModules = self[`TURBOPACK_${bundleKey}`];
880
+ if (turbopackModules && typeof turbopackModules === "object" && "__chunks__" in turbopackModules) {
881
+ const chunks = turbopackModules.__chunks__;
882
+ turbopackModules = chunks.flat();
883
+ }
884
+ const newAllModules = Array.isArray(turbopackModules) ? turbopackModules.flat() : turbopackModules ? Object.entries(turbopackModules).flatMap(([key2, value2]) => [
885
+ key2,
886
+ value2
887
+ ]) : [];
745
888
  const asyncSharedModuleIdIndex = newAllModules.indexOf(
746
889
  asyncSharedModuleIdNumber
747
890
  );
@@ -774,6 +917,7 @@ function getSharedModule(bundle, id) {
774
917
  var init_shared_modules2 = __esm({
775
918
  "src/shared/client/shared-modules.ts"() {
776
919
  "use strict";
920
+ init_logger();
777
921
  init_const();
778
922
  init_turbopack_module();
779
923
  init_turbopack_patterns();
@@ -950,11 +1094,10 @@ async function loadStaticRemoteComponent(scripts, url) {
950
1094
  unmount: mod.unmount || mod.default?.unmount
951
1095
  };
952
1096
  } catch (e) {
953
- console.error(
954
- new RemoteComponentsError(
955
- `Error loading remote component script from "${script.src || url.href}".`,
956
- { cause: e }
957
- )
1097
+ logError(
1098
+ "StaticLoader",
1099
+ `Error loading remote component script from "${script.src || url.href}".`,
1100
+ e
958
1101
  );
959
1102
  return {
960
1103
  mount: void 0,
@@ -982,7 +1125,7 @@ async function loadStaticRemoteComponent(scripts, url) {
982
1125
  var init_static_loader = __esm({
983
1126
  "src/shared/client/static-loader.ts"() {
984
1127
  "use strict";
985
- init_error();
1128
+ init_logger();
986
1129
  }
987
1130
  });
988
1131
 
@@ -1049,7 +1192,8 @@ function sharedPolyfills(shared) {
1049
1192
  ...props
1050
1193
  }) => {
1051
1194
  if (prefetch) {
1052
- console.warn(
1195
+ logWarn(
1196
+ "Polyfill",
1053
1197
  "Next.js Link prefetch is not supported in remote components"
1054
1198
  );
1055
1199
  }
@@ -1152,6 +1296,7 @@ var import_jsx_runtime, imageImpl;
1152
1296
  var init_polyfill = __esm({
1153
1297
  "src/shared/client/polyfill.tsx"() {
1154
1298
  "use strict";
1299
+ init_logger();
1155
1300
  // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
1156
1301
  import_jsx_runtime = require("react/jsx-runtime");
1157
1302
  imageImpl = (bundle) => function RemoteImage({
@@ -1556,11 +1701,17 @@ function remoteFetchHeaders() {
1556
1701
  }
1557
1702
 
1558
1703
  // src/shared/ssr/fetch-with-hooks.ts
1559
- async function fetchWithHooks(url, init, options = {}) {
1704
+ init_fetch_with_protected_rc_fallback();
1705
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1560
1706
  const { onRequest, onResponse } = options;
1707
+ const init = {
1708
+ method: "GET",
1709
+ headers: remoteFetchHeaders(),
1710
+ ...additionalInit
1711
+ };
1561
1712
  let res = await onRequest?.(url, init);
1562
1713
  if (!res) {
1563
- res = await fetch(url, init);
1714
+ res = await fetchWithProtectedRcFallback(url, init);
1564
1715
  }
1565
1716
  const transformedRes = await onResponse?.(url, res);
1566
1717
  if (transformedRes) {
@@ -1571,6 +1722,7 @@ async function fetchWithHooks(url, init, options = {}) {
1571
1722
 
1572
1723
  // src/html/host/index.tsx
1573
1724
  init_utils();
1725
+ init_logger();
1574
1726
 
1575
1727
  // src/html/host/runtime/index.ts
1576
1728
  init_error();
@@ -1623,7 +1775,7 @@ if (typeof HTMLElement !== "undefined") {
1623
1775
  if ((name === "src" || name === "name") && oldValue !== newValue) {
1624
1776
  if (this.getAttribute("src")) {
1625
1777
  this.load().catch((e) => {
1626
- console.error(e);
1778
+ logError("HtmlHost", "Error loading remote component.", e);
1627
1779
  const errorEvent = new Event("error", {
1628
1780
  bubbles: true,
1629
1781
  composed: true
@@ -1645,7 +1797,7 @@ if (typeof HTMLElement !== "undefined") {
1645
1797
  });
1646
1798
  this.root = newRoot;
1647
1799
  this.load().catch((e) => {
1648
- console.error(e);
1800
+ logError("HtmlHost", "Error reloading remote component.", e);
1649
1801
  const errorEvent = new Event("error", {
1650
1802
  bubbles: true,
1651
1803
  composed: true
@@ -1678,7 +1830,7 @@ if (typeof HTMLElement !== "undefined") {
1678
1830
  this.bundle = "default";
1679
1831
  if (this.hasAttribute("src") || this.querySelector("div#__REMOTE_COMPONENT__") || this.hasAttribute("data-ssr")) {
1680
1832
  this.load().catch((e) => {
1681
- console.error(e);
1833
+ logError("HtmlHost", "Error loading remote component.", e);
1682
1834
  const errorEvent = new Event("error", {
1683
1835
  bubbles: true,
1684
1836
  composed: true
@@ -1712,8 +1864,6 @@ if (typeof HTMLElement !== "undefined") {
1712
1864
  }
1713
1865
  if (!remoteComponentChild && url) {
1714
1866
  const fetchInit = {
1715
- method: "GET",
1716
- headers: remoteFetchHeaders(),
1717
1867
  credentials: this.getAttribute("credentials") || "same-origin"
1718
1868
  };
1719
1869
  const res = await fetchWithHooks(url, fetchInit, {
@@ -1820,11 +1970,10 @@ if (typeof HTMLElement !== "undefined") {
1820
1970
  try {
1821
1971
  await unmount(this.root);
1822
1972
  } catch (e) {
1823
- console.error(
1824
- new RemoteComponentsError(
1825
- `Error while calling unmount() for Remote Component from ${prevUrl.href}.`,
1826
- { cause: e }
1827
- )
1973
+ logError(
1974
+ "HtmlHost",
1975
+ `Error while calling unmount() for Remote Component from ${prevUrl.href}.`,
1976
+ e
1828
1977
  );
1829
1978
  }
1830
1979
  })
@@ -2066,7 +2215,7 @@ if (typeof HTMLElement !== "undefined") {
2066
2215
  applyReset();
2067
2216
  if (!initial) {
2068
2217
  attachLinks().catch((e) => {
2069
- console.error(e);
2218
+ logError("HtmlHost", "Error attaching links.", e);
2070
2219
  });
2071
2220
  }
2072
2221
  this.isLoading = false;
@@ -2119,7 +2268,7 @@ if (typeof HTMLElement !== "undefined") {
2119
2268
  if (!initial) {
2120
2269
  applyReset();
2121
2270
  attachLinks().catch((e) => {
2122
- console.error(e);
2271
+ logError("HtmlHost", "Error attaching links.", e);
2123
2272
  });
2124
2273
  }
2125
2274
  remoteComponent.isLoading = false;
@@ -2161,11 +2310,10 @@ if (typeof HTMLElement !== "undefined") {
2161
2310
  try {
2162
2311
  await mount(this.root);
2163
2312
  } catch (e) {
2164
- console.error(
2165
- new RemoteComponentsError(
2166
- `Error while calling mount() for Remote Component from ${url.href}.`,
2167
- { cause: e }
2168
- )
2313
+ logError(
2314
+ "HtmlHost",
2315
+ `Error while calling mount() for Remote Component from ${url.href}.`,
2316
+ e
2169
2317
  );
2170
2318
  }
2171
2319
  })