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
package/dist/html/host.js CHANGED
@@ -40,13 +40,24 @@ function logDebug(location2, message) {
40
40
  console.debug(`[${PREFIX}:${location2}]: ${message}`);
41
41
  }
42
42
  }
43
+ function logInfo(location2, message) {
44
+ console.info(`[${PREFIX}:${location2}]: ${message}`);
45
+ }
43
46
  function logWarn(location2, message) {
44
47
  console.warn(`[${PREFIX}:${location2}]: ${message}`);
45
48
  }
49
+ function logError(location2, message, cause) {
50
+ console.error(
51
+ new RemoteComponentsError(`[${PREFIX}:${location2}]: ${message}`, {
52
+ cause
53
+ })
54
+ );
55
+ }
46
56
  var PREFIX, DEBUG;
47
57
  var init_logger = __esm({
48
58
  "src/shared/utils/logger.ts"() {
49
59
  "use strict";
60
+ init_error();
50
61
  PREFIX = "remote-components";
51
62
  DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
52
63
  }
@@ -237,6 +248,41 @@ var init_shared_modules = __esm({
237
248
  }
238
249
  });
239
250
 
251
+ // src/shared/ssr/fetch-with-protected-rc-fallback.ts
252
+ async function fetchWithProtectedRcFallback(url, init) {
253
+ try {
254
+ const res = await fetch(url, init);
255
+ return res;
256
+ } catch (error) {
257
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
258
+ logInfo(
259
+ "FetchRemoteComponent",
260
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
261
+ );
262
+ const proxiedRes = await fetch(
263
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
264
+ );
265
+ if (proxiedRes.status === 200) {
266
+ return proxiedRes;
267
+ } else {
268
+ logError(
269
+ "FetchRemoteComponent",
270
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
271
+ );
272
+ }
273
+ }
274
+ throw error;
275
+ }
276
+ }
277
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME;
278
+ var init_fetch_with_protected_rc_fallback = __esm({
279
+ "src/shared/ssr/fetch-with-protected-rc-fallback.ts"() {
280
+ "use strict";
281
+ init_logger();
282
+ RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
283
+ }
284
+ });
285
+
240
286
  // src/shared/utils/index.ts
241
287
  function escapeString(str) {
242
288
  return str.replace(/[^a-z0-9]/g, "_");
@@ -305,10 +351,19 @@ function createChunkLoader(runtime) {
305
351
  }
306
352
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
307
353
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
308
- fetch(url).then((res) => res.text()).then((code) => {
309
- if (code.includes("globalThis.TURBOPACK")) {
354
+ fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
355
+ const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
356
+ if (hasTurbopack) {
310
357
  return handleTurbopackChunk(code, bundle ?? "", url);
311
358
  }
359
+ logDebug(
360
+ "ChunkLoader",
361
+ `Chunk does not contain globalThis.TURBOPACK or self.TURBOPACK: "${url}"`
362
+ );
363
+ logDebug(
364
+ "ChunkLoader",
365
+ `First 500 chars of chunk: ${code.slice(0, 500)}`
366
+ );
312
367
  }).then(resolve).catch(reject);
313
368
  });
314
369
  return self.__remote_components_turbopack_chunk_loader_promise__[url];
@@ -330,7 +385,7 @@ async function handleTurbopackChunk(code, bundle, url) {
330
385
  const self = globalThis;
331
386
  const bundleKey = getBundleKey(bundle);
332
387
  logDebug("ChunkLoader", `Bundle key: "${bundleKey}"`);
333
- const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(
388
+ const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`).replace(
334
389
  /TURBOPACK_WORKER_LOCATION/g,
335
390
  `TURBOPACK_WORKER_LOCATION_${bundleKey}`
336
391
  ).replace(
@@ -349,6 +404,30 @@ async function handleTurbopackChunk(code, bundle, url) {
349
404
  )
350
405
  ).href}$1$2.js.map`
351
406
  );
407
+ if (!self[`TURBOPACK_${bundleKey}`]) {
408
+ const chunkData = [];
409
+ const turbopackObject = {
410
+ push: (item) => {
411
+ logDebug(
412
+ "ChunkLoader",
413
+ `TURBOPACK_${bundleKey}.push() called with item type: ${Array.isArray(item) ? "array" : typeof item}`
414
+ );
415
+ if (Array.isArray(item)) {
416
+ chunkData.push(item);
417
+ logDebug(
418
+ "ChunkLoader",
419
+ `TURBOPACK_${bundleKey} now has ${chunkData.length} chunks`
420
+ );
421
+ } else {
422
+ chunkData.push([item]);
423
+ }
424
+ return chunkData.length;
425
+ },
426
+ // Store chunks for later access
427
+ __chunks__: chunkData
428
+ };
429
+ self[`TURBOPACK_${bundleKey}`] = turbopackObject;
430
+ }
352
431
  logDebug("ChunkLoader", `Creating blob script for: "${url}"`);
353
432
  await new Promise((scriptResolve, scriptReject) => {
354
433
  const blob = new Blob([transformedCode], {
@@ -361,6 +440,21 @@ async function handleTurbopackChunk(code, bundle, url) {
361
440
  script.async = true;
362
441
  script.onload = () => {
363
442
  URL.revokeObjectURL(scriptUrl);
443
+ logDebug(
444
+ "ChunkLoader",
445
+ `Script loaded successfully for bundle "${bundle}"`
446
+ );
447
+ const turbopackBundle = self[`TURBOPACK_${bundleKey}`];
448
+ logDebug(
449
+ "ChunkLoader",
450
+ `TURBOPACK_${bundleKey} type: ${typeof turbopackBundle}, isArray: ${Array.isArray(turbopackBundle)}, keys: ${turbopackBundle ? Object.keys(turbopackBundle).slice(0, 10).join(", ") : "none"}`
451
+ );
452
+ if (turbopackBundle && typeof turbopackBundle === "object") {
453
+ logDebug(
454
+ "ChunkLoader",
455
+ `TURBOPACK_${bundleKey} length/size: ${Array.isArray(turbopackBundle) ? turbopackBundle.length : Object.keys(turbopackBundle).length}`
456
+ );
457
+ }
364
458
  scriptResolve(void 0);
365
459
  script.remove();
366
460
  };
@@ -410,19 +504,35 @@ var init_chunk_loader = __esm({
410
504
  "src/shared/client/chunk-loader.ts"() {
411
505
  "use strict";
412
506
  init_error();
507
+ init_fetch_with_protected_rc_fallback();
413
508
  init_logger();
414
509
  init_const();
415
510
  }
416
511
  });
417
512
 
513
+ // src/shared/client/turbopack-patterns.ts
514
+ 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;
515
+ var init_turbopack_patterns = __esm({
516
+ "src/shared/client/turbopack-patterns.ts"() {
517
+ "use strict";
518
+ REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
519
+ REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
520
+ ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
521
+ ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
522
+ 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]+)\)\)\)\}/;
523
+ NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
524
+ }
525
+ });
526
+
418
527
  // src/shared/client/turbopack-module.ts
419
528
  function handleTurbopackModule(bundle, moduleId, id) {
420
529
  const self = globalThis;
421
530
  const bundleKey = getBundleKey(bundle);
422
- const modules = self[`TURBOPACK_${bundleKey}`];
423
- const moduleInit = findModuleInit(modules, moduleId);
424
- const exports = {};
425
- const moduleExports = { exports };
531
+ let modules = self[`TURBOPACK_${bundleKey}`];
532
+ if (modules && typeof modules === "object" && "__chunks__" in modules) {
533
+ const chunks = modules.__chunks__;
534
+ modules = chunks.flat();
535
+ }
426
536
  if (!self.__remote_components_turbopack_modules__) {
427
537
  self.__remote_components_turbopack_modules__ = {};
428
538
  }
@@ -432,6 +542,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
432
542
  if (self.__remote_components_turbopack_modules__[bundle][moduleId]) {
433
543
  return self.__remote_components_turbopack_modules__[bundle][moduleId];
434
544
  }
545
+ if (!modules) {
546
+ logError("TurbopackModule", `TURBOPACK_${bundleKey} is undefined`);
547
+ }
548
+ const moduleInit = findModuleInit(modules, moduleId);
549
+ const exports = {};
550
+ const moduleExports = { exports };
435
551
  if (typeof moduleInit !== "function") {
436
552
  throw new Error(
437
553
  `Module ${id} not found in bundle ${bundle} with id ${moduleId}`
@@ -444,7 +560,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
444
560
  if (!self.__remote_components_turbopack_global__[bundle]) {
445
561
  self.__remote_components_turbopack_global__[bundle] = {};
446
562
  }
447
- const allModules = modules?.flat() ?? [];
563
+ const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
448
564
  moduleInit(
449
565
  createTurbopackContext(
450
566
  bundle,
@@ -464,9 +580,26 @@ function handleTurbopackModule(bundle, moduleId, id) {
464
580
  return moduleExports.exports;
465
581
  }
466
582
  function findModuleInit(modules, moduleId) {
583
+ if (modules && !Array.isArray(modules) && typeof modules === "object") {
584
+ const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
585
+ if (normalizedId in modules) {
586
+ return modules[normalizedId];
587
+ }
588
+ if (typeof normalizedId === "number" && String(normalizedId) in modules) {
589
+ return modules[String(normalizedId)];
590
+ }
591
+ const matchingKey = Object.keys(modules).find(
592
+ (key) => typeof key === "string" && key.includes(String(moduleId))
593
+ );
594
+ if (matchingKey) {
595
+ return modules[matchingKey];
596
+ }
597
+ logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
598
+ return void 0;
599
+ }
467
600
  const allModules = modules?.flat() ?? [];
468
601
  if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
469
- const normalizedId = /^[0-9]+$/.test(moduleId) ? Number(moduleId) : moduleId;
602
+ const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
470
603
  let moduleIdIndex = allModules.indexOf(normalizedId);
471
604
  if (moduleIdIndex === -1) {
472
605
  moduleIdIndex = allModules.findIndex(
@@ -634,20 +767,9 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
634
767
  var init_turbopack_module = __esm({
635
768
  "src/shared/client/turbopack-module.ts"() {
636
769
  "use strict";
770
+ init_logger();
637
771
  init_const();
638
- }
639
- });
640
-
641
- // src/shared/client/turbopack-patterns.ts
642
- var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE;
643
- var init_turbopack_patterns = __esm({
644
- "src/shared/client/turbopack-patterns.ts"() {
645
- "use strict";
646
- REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
647
- REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
648
- ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
649
- ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
650
- 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]+)\)\)\)\}/;
772
+ init_turbopack_patterns();
651
773
  }
652
774
  });
653
775
 
@@ -659,10 +781,14 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
659
781
  self.__remote_shared_modules__[bundle] = {};
660
782
  }
661
783
  const bundleKey = getBundleKey(bundle);
662
- const modules = self[`TURBOPACK_${bundleKey}`];
784
+ let modules = self[`TURBOPACK_${bundleKey}`];
785
+ if (modules && typeof modules === "object" && "__chunks__" in modules) {
786
+ const chunks = modules.__chunks__;
787
+ modules = chunks.flat();
788
+ }
663
789
  let sharedModuleInitializer = null;
664
- if (modules && Array.isArray(modules)) {
665
- const allModules = modules.flat();
790
+ if (modules) {
791
+ const allModules = Array.isArray(modules) ? modules.flat() : Object.entries(modules).flat();
666
792
  const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {
667
793
  if (typeof idOrFunc !== "function") {
668
794
  return false;
@@ -695,6 +821,11 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
695
821
  if (self.__remote_shared_modules__?.[bundle]) {
696
822
  if (hostShared[module]) {
697
823
  self.__remote_shared_modules__[bundle][id] = await hostShared[module](bundle);
824
+ } else {
825
+ logError(
826
+ "SharedModules",
827
+ `Host shared module "${module}" not found for ID ${id}`
828
+ );
698
829
  }
699
830
  }
700
831
  })
@@ -705,9 +836,13 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
705
836
  Object.entries(remoteShared).map(async ([id, module]) => {
706
837
  if (self.__remote_shared_modules__?.[bundle]) {
707
838
  if (hostShared[module]) {
708
- self.__remote_shared_modules__[bundle][id.replace("[app-ssr]", "[app-client]")] = await hostShared[module](bundle);
839
+ const normalizedId = id.replace("[app-ssr]", "[app-client]");
840
+ self.__remote_shared_modules__[bundle][normalizedId] = await hostShared[module](bundle);
709
841
  } else {
710
- console.error(`Shared module "${module}" not found for "${bundle}".`);
842
+ logError(
843
+ "SharedModules",
844
+ `Shared module "${module}" not found for "${bundle}"`
845
+ );
711
846
  }
712
847
  }
713
848
  })
@@ -719,7 +854,15 @@ function extractSharedModuleIds(shared, bundleKey, self) {
719
854
  if (asyncSharedModuleId) {
720
855
  const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
721
856
  let asyncSharedModule;
722
- const newAllModules = self[`TURBOPACK_${bundleKey}`]?.flat() ?? [];
857
+ let turbopackModules = self[`TURBOPACK_${bundleKey}`];
858
+ if (turbopackModules && typeof turbopackModules === "object" && "__chunks__" in turbopackModules) {
859
+ const chunks = turbopackModules.__chunks__;
860
+ turbopackModules = chunks.flat();
861
+ }
862
+ const newAllModules = Array.isArray(turbopackModules) ? turbopackModules.flat() : turbopackModules ? Object.entries(turbopackModules).flatMap(([key2, value2]) => [
863
+ key2,
864
+ value2
865
+ ]) : [];
723
866
  const asyncSharedModuleIdIndex = newAllModules.indexOf(
724
867
  asyncSharedModuleIdNumber
725
868
  );
@@ -752,6 +895,7 @@ function getSharedModule(bundle, id) {
752
895
  var init_shared_modules2 = __esm({
753
896
  "src/shared/client/shared-modules.ts"() {
754
897
  "use strict";
898
+ init_logger();
755
899
  init_const();
756
900
  init_turbopack_module();
757
901
  init_turbopack_patterns();
@@ -928,11 +1072,10 @@ async function loadStaticRemoteComponent(scripts, url) {
928
1072
  unmount: mod.unmount || mod.default?.unmount
929
1073
  };
930
1074
  } catch (e) {
931
- console.error(
932
- new RemoteComponentsError(
933
- `Error loading remote component script from "${script.src || url.href}".`,
934
- { cause: e }
935
- )
1075
+ logError(
1076
+ "StaticLoader",
1077
+ `Error loading remote component script from "${script.src || url.href}".`,
1078
+ e
936
1079
  );
937
1080
  return {
938
1081
  mount: void 0,
@@ -960,7 +1103,7 @@ async function loadStaticRemoteComponent(scripts, url) {
960
1103
  var init_static_loader = __esm({
961
1104
  "src/shared/client/static-loader.ts"() {
962
1105
  "use strict";
963
- init_error();
1106
+ init_logger();
964
1107
  }
965
1108
  });
966
1109
 
@@ -1028,7 +1171,8 @@ function sharedPolyfills(shared) {
1028
1171
  ...props
1029
1172
  }) => {
1030
1173
  if (prefetch) {
1031
- console.warn(
1174
+ logWarn(
1175
+ "Polyfill",
1032
1176
  "Next.js Link prefetch is not supported in remote components"
1033
1177
  );
1034
1178
  }
@@ -1131,6 +1275,7 @@ var imageImpl;
1131
1275
  var init_polyfill = __esm({
1132
1276
  "src/shared/client/polyfill.tsx"() {
1133
1277
  "use strict";
1278
+ init_logger();
1134
1279
  imageImpl = (bundle) => function RemoteImage({
1135
1280
  fill: _fill,
1136
1281
  loader: _loader,
@@ -1531,11 +1676,17 @@ function remoteFetchHeaders() {
1531
1676
  }
1532
1677
 
1533
1678
  // src/shared/ssr/fetch-with-hooks.ts
1534
- async function fetchWithHooks(url, init, options = {}) {
1679
+ init_fetch_with_protected_rc_fallback();
1680
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1535
1681
  const { onRequest, onResponse } = options;
1682
+ const init = {
1683
+ method: "GET",
1684
+ headers: remoteFetchHeaders(),
1685
+ ...additionalInit
1686
+ };
1536
1687
  let res = await onRequest?.(url, init);
1537
1688
  if (!res) {
1538
- res = await fetch(url, init);
1689
+ res = await fetchWithProtectedRcFallback(url, init);
1539
1690
  }
1540
1691
  const transformedRes = await onResponse?.(url, res);
1541
1692
  if (transformedRes) {
@@ -1546,6 +1697,7 @@ async function fetchWithHooks(url, init, options = {}) {
1546
1697
 
1547
1698
  // src/html/host/index.tsx
1548
1699
  init_utils();
1700
+ init_logger();
1549
1701
 
1550
1702
  // src/html/host/runtime/index.ts
1551
1703
  init_error();
@@ -1598,7 +1750,7 @@ if (typeof HTMLElement !== "undefined") {
1598
1750
  if ((name === "src" || name === "name") && oldValue !== newValue) {
1599
1751
  if (this.getAttribute("src")) {
1600
1752
  this.load().catch((e) => {
1601
- console.error(e);
1753
+ logError("HtmlHost", "Error loading remote component.", e);
1602
1754
  const errorEvent = new Event("error", {
1603
1755
  bubbles: true,
1604
1756
  composed: true
@@ -1620,7 +1772,7 @@ if (typeof HTMLElement !== "undefined") {
1620
1772
  });
1621
1773
  this.root = newRoot;
1622
1774
  this.load().catch((e) => {
1623
- console.error(e);
1775
+ logError("HtmlHost", "Error reloading remote component.", e);
1624
1776
  const errorEvent = new Event("error", {
1625
1777
  bubbles: true,
1626
1778
  composed: true
@@ -1653,7 +1805,7 @@ if (typeof HTMLElement !== "undefined") {
1653
1805
  this.bundle = "default";
1654
1806
  if (this.hasAttribute("src") || this.querySelector("div#__REMOTE_COMPONENT__") || this.hasAttribute("data-ssr")) {
1655
1807
  this.load().catch((e) => {
1656
- console.error(e);
1808
+ logError("HtmlHost", "Error loading remote component.", e);
1657
1809
  const errorEvent = new Event("error", {
1658
1810
  bubbles: true,
1659
1811
  composed: true
@@ -1687,8 +1839,6 @@ if (typeof HTMLElement !== "undefined") {
1687
1839
  }
1688
1840
  if (!remoteComponentChild && url) {
1689
1841
  const fetchInit = {
1690
- method: "GET",
1691
- headers: remoteFetchHeaders(),
1692
1842
  credentials: this.getAttribute("credentials") || "same-origin"
1693
1843
  };
1694
1844
  const res = await fetchWithHooks(url, fetchInit, {
@@ -1795,11 +1945,10 @@ if (typeof HTMLElement !== "undefined") {
1795
1945
  try {
1796
1946
  await unmount(this.root);
1797
1947
  } catch (e) {
1798
- console.error(
1799
- new RemoteComponentsError(
1800
- `Error while calling unmount() for Remote Component from ${prevUrl.href}.`,
1801
- { cause: e }
1802
- )
1948
+ logError(
1949
+ "HtmlHost",
1950
+ `Error while calling unmount() for Remote Component from ${prevUrl.href}.`,
1951
+ e
1803
1952
  );
1804
1953
  }
1805
1954
  })
@@ -2041,7 +2190,7 @@ if (typeof HTMLElement !== "undefined") {
2041
2190
  applyReset();
2042
2191
  if (!initial) {
2043
2192
  attachLinks().catch((e) => {
2044
- console.error(e);
2193
+ logError("HtmlHost", "Error attaching links.", e);
2045
2194
  });
2046
2195
  }
2047
2196
  this.isLoading = false;
@@ -2094,7 +2243,7 @@ if (typeof HTMLElement !== "undefined") {
2094
2243
  if (!initial) {
2095
2244
  applyReset();
2096
2245
  attachLinks().catch((e) => {
2097
- console.error(e);
2246
+ logError("HtmlHost", "Error attaching links.", e);
2098
2247
  });
2099
2248
  }
2100
2249
  remoteComponent.isLoading = false;
@@ -2136,11 +2285,10 @@ if (typeof HTMLElement !== "undefined") {
2136
2285
  try {
2137
2286
  await mount(this.root);
2138
2287
  } catch (e) {
2139
- console.error(
2140
- new RemoteComponentsError(
2141
- `Error while calling mount() for Remote Component from ${url.href}.`,
2142
- { cause: e }
2143
- )
2288
+ logError(
2289
+ "HtmlHost",
2290
+ `Error while calling mount() for Remote Component from ${url.href}.`,
2291
+ e
2144
2292
  );
2145
2293
  }
2146
2294
  })