remote-components 0.0.46 → 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 (74) hide show
  1. package/dist/html/host.cjs +50 -7
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +50 -7
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/html/remote.cjs.map +1 -1
  6. package/dist/html/remote.js.map +1 -1
  7. package/dist/internal/next/host/app-router-client.cjs +6 -6
  8. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  9. package/dist/internal/next/host/app-router-client.js +1 -1
  10. package/dist/internal/next/host/app-router-client.js.map +1 -1
  11. package/dist/internal/next/host/app-router-compat.cjs +5 -5
  12. package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
  13. package/dist/internal/next/host/app-router-compat.js +1 -1
  14. package/dist/internal/next/host/app-router-compat.js.map +1 -1
  15. package/dist/internal/shared/client/polyfill.cjs +2 -2
  16. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  17. package/dist/internal/shared/client/polyfill.js +1 -1
  18. package/dist/internal/shared/client/polyfill.js.map +1 -1
  19. package/dist/internal/shared/client/remote-component.cjs +32 -1
  20. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  21. package/dist/internal/shared/client/remote-component.js +32 -1
  22. package/dist/internal/shared/client/remote-component.js.map +1 -1
  23. package/dist/internal/shared/ssr/fetch-remote-component.cjs +1 -6
  24. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  25. package/dist/internal/shared/ssr/fetch-remote-component.js +1 -6
  26. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  27. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +9 -2
  28. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  29. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +6 -1
  30. package/dist/internal/shared/ssr/fetch-with-hooks.js +9 -2
  31. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  32. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +57 -0
  33. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +1 -0
  34. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +11 -0
  35. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +32 -0
  36. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +1 -0
  37. package/dist/internal/shared/{logger.cjs → utils/logger.cjs} +5 -0
  38. package/dist/internal/shared/utils/logger.cjs.map +1 -0
  39. package/dist/internal/shared/{logger.d.ts → utils/logger.d.ts} +3 -2
  40. package/dist/internal/shared/{logger.js → utils/logger.js} +4 -0
  41. package/dist/internal/shared/utils/logger.js.map +1 -0
  42. package/dist/internal/shared/utils.cjs +2 -9
  43. package/dist/internal/shared/utils.cjs.map +1 -1
  44. package/dist/internal/shared/utils.d.ts +0 -2
  45. package/dist/internal/shared/utils.js +1 -5
  46. package/dist/internal/shared/utils.js.map +1 -1
  47. package/dist/next/config.cjs.map +1 -1
  48. package/dist/next/config.js.map +1 -1
  49. package/dist/next/host/client/index.cjs +51 -17
  50. package/dist/next/host/client/index.cjs.map +1 -1
  51. package/dist/next/host/client/index.js +51 -17
  52. package/dist/next/host/client/index.js.map +1 -1
  53. package/dist/next/proxy.cjs +128 -19
  54. package/dist/next/proxy.cjs.map +1 -1
  55. package/dist/next/proxy.d.ts +34 -6
  56. package/dist/next/proxy.js +125 -18
  57. package/dist/next/proxy.js.map +1 -1
  58. package/dist/react/index.cjs +51 -17
  59. package/dist/react/index.cjs.map +1 -1
  60. package/dist/react/index.js +51 -17
  61. package/dist/react/index.js.map +1 -1
  62. package/dist/shared/host/proxy.cjs +79 -0
  63. package/dist/shared/host/proxy.cjs.map +1 -0
  64. package/dist/shared/host/proxy.d.ts +29 -0
  65. package/dist/shared/host/proxy.js +54 -0
  66. package/dist/shared/host/proxy.js.map +1 -0
  67. package/dist/shared/remote/proxy.cjs +71 -0
  68. package/dist/shared/remote/proxy.cjs.map +1 -0
  69. package/dist/shared/remote/proxy.d.ts +38 -0
  70. package/dist/shared/remote/proxy.js +45 -0
  71. package/dist/shared/remote/proxy.js.map +1 -0
  72. package/package.json +10 -1
  73. package/dist/internal/shared/logger.cjs.map +0 -1
  74. package/dist/internal/shared/logger.js.map +0 -1
@@ -95,6 +95,9 @@ function logDebug(location2, message) {
95
95
  console.debug(`[${PREFIX}:${location2}]: ${message}`);
96
96
  }
97
97
  }
98
+ function logInfo(location2, message) {
99
+ console.info(`[${PREFIX}:${location2}]: ${message}`);
100
+ }
98
101
  function logWarn(location2, message) {
99
102
  console.warn(`[${PREFIX}:${location2}]: ${message}`);
100
103
  }
@@ -106,18 +109,6 @@ function logError(location2, message, cause) {
106
109
  );
107
110
  }
108
111
 
109
- // src/shared/utils/index.ts
110
- function escapeString(str) {
111
- return str.replace(/[^a-z0-9]/g, "_");
112
- }
113
- var attrToProp = {
114
- fetchpriority: "fetchPriority",
115
- crossorigin: "crossOrigin",
116
- imagesrcset: "imageSrcSet",
117
- imagesizes: "imageSizes",
118
- srcset: "srcSet"
119
- };
120
-
121
112
  // src/shared/client/polyfill.tsx
122
113
  import { jsx } from "react/jsx-runtime";
123
114
  function applyBundleUrlToSrc(bundle, src) {
@@ -589,6 +580,46 @@ async function loadScripts(scripts) {
589
580
  );
590
581
  }
591
582
 
583
+ // src/shared/ssr/fetch-with-protected-rc-fallback.ts
584
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
585
+ async function fetchWithProtectedRcFallback(url, init) {
586
+ try {
587
+ const res = await fetch(url, init);
588
+ return res;
589
+ } catch (error) {
590
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
591
+ logInfo(
592
+ "FetchRemoteComponent",
593
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
594
+ );
595
+ const proxiedRes = await fetch(
596
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
597
+ );
598
+ if (proxiedRes.status === 200) {
599
+ return proxiedRes;
600
+ } else {
601
+ logError(
602
+ "FetchRemoteComponent",
603
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
604
+ );
605
+ }
606
+ }
607
+ throw error;
608
+ }
609
+ }
610
+
611
+ // src/shared/utils/index.ts
612
+ function escapeString(str) {
613
+ return str.replace(/[^a-z0-9]/g, "_");
614
+ }
615
+ var attrToProp = {
616
+ fetchpriority: "fetchPriority",
617
+ crossorigin: "crossOrigin",
618
+ imagesrcset: "imageSrcSet",
619
+ imagesizes: "imageSizes",
620
+ srcset: "srcSet"
621
+ };
622
+
592
623
  // src/shared/client/const.ts
593
624
  var DEFAULT_ROUTE = "/";
594
625
  var RUNTIME_WEBPACK = "webpack";
@@ -642,7 +673,7 @@ function createChunkLoader(runtime) {
642
673
  }
643
674
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
644
675
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
645
- fetch(url).then((res) => res.text()).then((code) => {
676
+ fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
646
677
  const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
647
678
  if (hasTurbopack) {
648
679
  return handleTurbopackChunk(code, bundle ?? "", url);
@@ -1540,11 +1571,16 @@ function remoteFetchHeaders() {
1540
1571
  }
1541
1572
 
1542
1573
  // src/shared/ssr/fetch-with-hooks.ts
1543
- async function fetchWithHooks(url, init, options = {}) {
1574
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1544
1575
  const { onRequest, onResponse } = options;
1576
+ const init = {
1577
+ method: "GET",
1578
+ headers: remoteFetchHeaders(),
1579
+ ...additionalInit
1580
+ };
1545
1581
  let res = await onRequest?.(url, init);
1546
1582
  if (!res) {
1547
- res = await fetch(url, init);
1583
+ res = await fetchWithProtectedRcFallback(url, init);
1548
1584
  }
1549
1585
  const transformedRes = await onResponse?.(url, res);
1550
1586
  if (transformedRes) {
@@ -1753,8 +1789,6 @@ function RemoteComponent({
1753
1789
  );
1754
1790
  if (!html && src) {
1755
1791
  const fetchInit = {
1756
- method: "GET",
1757
- headers: remoteFetchHeaders(),
1758
1792
  credentials
1759
1793
  };
1760
1794
  const res = await fetchWithHooks(url, fetchInit, {