remote-components 0.0.46 → 0.0.48

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 (98) hide show
  1. package/dist/{component-loader-26b1f55e.d.ts → component-loader-1838f572.d.ts} +62 -8
  2. package/dist/html/host.cjs +214 -76
  3. package/dist/html/host.cjs.map +1 -1
  4. package/dist/html/host.js +214 -76
  5. package/dist/html/host.js.map +1 -1
  6. package/dist/html/remote.cjs.map +1 -1
  7. package/dist/html/remote.js.map +1 -1
  8. package/dist/internal/next/host/app-router-client.cjs +6 -6
  9. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  10. package/dist/internal/next/host/app-router-client.d.ts +1 -1
  11. package/dist/internal/next/host/app-router-client.js +1 -1
  12. package/dist/internal/next/host/app-router-client.js.map +1 -1
  13. package/dist/internal/next/host/app-router-compat.cjs +5 -5
  14. package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
  15. package/dist/internal/next/host/app-router-compat.js +1 -1
  16. package/dist/internal/next/host/app-router-compat.js.map +1 -1
  17. package/dist/internal/shared/client/polyfill.cjs +2 -2
  18. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  19. package/dist/internal/shared/client/polyfill.js +1 -1
  20. package/dist/internal/shared/client/polyfill.js.map +1 -1
  21. package/dist/internal/shared/client/remote-component.cjs +48 -1
  22. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  23. package/dist/internal/shared/client/remote-component.d.ts +2 -2
  24. package/dist/internal/shared/client/remote-component.js +48 -1
  25. package/dist/internal/shared/client/remote-component.js.map +1 -1
  26. package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
  27. package/dist/internal/shared/ssr/fetch-remote-component.cjs +1 -6
  28. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  29. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
  30. package/dist/internal/shared/ssr/fetch-remote-component.js +1 -6
  31. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  32. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +22 -5
  33. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  34. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +30 -14
  35. package/dist/internal/shared/ssr/fetch-with-hooks.js +22 -5
  36. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  37. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +62 -0
  38. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +1 -0
  39. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +14 -0
  40. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +37 -0
  41. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +1 -0
  42. package/dist/internal/shared/utils/abort.cjs +38 -0
  43. package/dist/internal/shared/utils/abort.cjs.map +1 -0
  44. package/dist/internal/shared/utils/abort.d.ts +7 -0
  45. package/dist/internal/shared/utils/abort.js +14 -0
  46. package/dist/internal/shared/utils/abort.js.map +1 -0
  47. package/dist/internal/shared/{logger.cjs → utils/logger.cjs} +5 -0
  48. package/dist/internal/shared/utils/logger.cjs.map +1 -0
  49. package/dist/internal/shared/{logger.d.ts → utils/logger.d.ts} +3 -2
  50. package/dist/internal/shared/{logger.js → utils/logger.js} +4 -0
  51. package/dist/internal/shared/utils/logger.js.map +1 -0
  52. package/dist/internal/shared/utils.cjs +2 -9
  53. package/dist/internal/shared/utils.cjs.map +1 -1
  54. package/dist/internal/shared/utils.d.ts +0 -2
  55. package/dist/internal/shared/utils.js +1 -5
  56. package/dist/internal/shared/utils.js.map +1 -1
  57. package/dist/next/config.cjs +4 -2
  58. package/dist/next/config.cjs.map +1 -1
  59. package/dist/next/config.js +4 -2
  60. package/dist/next/config.js.map +1 -1
  61. package/dist/next/host/app-router-server.d.ts +1 -1
  62. package/dist/next/host/client/index.cjs +91 -24
  63. package/dist/next/host/client/index.cjs.map +1 -1
  64. package/dist/next/host/client/index.d.ts +1 -1
  65. package/dist/next/host/client/index.js +91 -24
  66. package/dist/next/host/client/index.js.map +1 -1
  67. package/dist/next/host/pages-router-client.d.ts +1 -1
  68. package/dist/next/host/pages-router-server.d.ts +1 -1
  69. package/dist/next/index.d.ts +1 -1
  70. package/dist/next/proxy.cjs +128 -19
  71. package/dist/next/proxy.cjs.map +1 -1
  72. package/dist/next/proxy.d.ts +34 -6
  73. package/dist/next/proxy.js +125 -18
  74. package/dist/next/proxy.js.map +1 -1
  75. package/dist/react/index.cjs +91 -24
  76. package/dist/react/index.cjs.map +1 -1
  77. package/dist/react/index.d.ts +2 -1
  78. package/dist/react/index.js +91 -24
  79. package/dist/react/index.js.map +1 -1
  80. package/dist/shared/host/proxy.cjs +79 -0
  81. package/dist/shared/host/proxy.cjs.map +1 -0
  82. package/dist/shared/host/proxy.d.ts +29 -0
  83. package/dist/shared/host/proxy.js +54 -0
  84. package/dist/shared/host/proxy.js.map +1 -0
  85. package/dist/shared/remote/proxy.cjs +71 -0
  86. package/dist/shared/remote/proxy.cjs.map +1 -0
  87. package/dist/shared/remote/proxy.d.ts +38 -0
  88. package/dist/shared/remote/proxy.js +45 -0
  89. package/dist/shared/remote/proxy.js.map +1 -0
  90. package/dist/{types-6e4ba234.d.ts → types-cbe44b51.d.ts} +61 -7
  91. package/dist/webpack.cjs +274 -0
  92. package/dist/webpack.cjs.map +1 -0
  93. package/dist/webpack.d.ts +14 -0
  94. package/dist/webpack.js +247 -0
  95. package/dist/webpack.js.map +1 -0
  96. package/package.json +18 -1
  97. package/dist/internal/shared/logger.cjs.map +0 -1
  98. package/dist/internal/shared/logger.js.map +0 -1
@@ -121,6 +121,9 @@ function logDebug(location2, message) {
121
121
  console.debug(`[${PREFIX}:${location2}]: ${message}`);
122
122
  }
123
123
  }
124
+ function logInfo(location2, message) {
125
+ console.info(`[${PREFIX}:${location2}]: ${message}`);
126
+ }
124
127
  function logWarn(location2, message) {
125
128
  console.warn(`[${PREFIX}:${location2}]: ${message}`);
126
129
  }
@@ -132,18 +135,6 @@ function logError(location2, message, cause) {
132
135
  );
133
136
  }
134
137
 
135
- // src/shared/utils/index.ts
136
- function escapeString(str) {
137
- return str.replace(/[^a-z0-9]/g, "_");
138
- }
139
- var attrToProp = {
140
- fetchpriority: "fetchPriority",
141
- crossorigin: "crossOrigin",
142
- imagesrcset: "imageSrcSet",
143
- imagesizes: "imageSizes",
144
- srcset: "srcSet"
145
- };
146
-
147
138
  // src/shared/client/polyfill.tsx
148
139
  var import_jsx_runtime = (
149
140
  // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
@@ -615,6 +606,62 @@ async function loadScripts(scripts) {
615
606
  );
616
607
  }
617
608
 
609
+ // src/shared/utils/abort.ts
610
+ function isAbortError(error) {
611
+ if (error instanceof DOMException && error.name === "AbortError") {
612
+ return true;
613
+ }
614
+ if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
615
+ const e = error;
616
+ return typeof e.code === "number" || e.constructor?.name === "DOMException";
617
+ }
618
+ return false;
619
+ }
620
+
621
+ // src/shared/ssr/fetch-with-protected-rc-fallback.ts
622
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
623
+ async function fetchWithProtectedRcFallback(url, init) {
624
+ try {
625
+ const res = await fetch(url, init);
626
+ return res;
627
+ } catch (error) {
628
+ if (isAbortError(error)) {
629
+ throw error;
630
+ }
631
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
632
+ logInfo(
633
+ "FetchRemoteComponent",
634
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
635
+ );
636
+ const proxiedRes = await fetch(
637
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,
638
+ init?.signal ? { signal: init.signal } : void 0
639
+ );
640
+ if (proxiedRes.status === 200) {
641
+ return proxiedRes;
642
+ } else {
643
+ logError(
644
+ "FetchRemoteComponent",
645
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
646
+ );
647
+ }
648
+ }
649
+ throw error;
650
+ }
651
+ }
652
+
653
+ // src/shared/utils/index.ts
654
+ function escapeString(str) {
655
+ return str.replace(/[^a-z0-9]/g, "_");
656
+ }
657
+ var attrToProp = {
658
+ fetchpriority: "fetchPriority",
659
+ crossorigin: "crossOrigin",
660
+ imagesrcset: "imageSrcSet",
661
+ imagesizes: "imageSizes",
662
+ srcset: "srcSet"
663
+ };
664
+
618
665
  // src/shared/client/const.ts
619
666
  var DEFAULT_ROUTE = "/";
620
667
  var RUNTIME_WEBPACK = "webpack";
@@ -668,7 +715,7 @@ function createChunkLoader(runtime) {
668
715
  }
669
716
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
670
717
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
671
- fetch(url).then((res) => res.text()).then((code) => {
718
+ fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
672
719
  const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
673
720
  if (hasTurbopack) {
674
721
  return handleTurbopackChunk(code, bundle ?? "", url);
@@ -1566,13 +1613,28 @@ function remoteFetchHeaders() {
1566
1613
  }
1567
1614
 
1568
1615
  // src/shared/ssr/fetch-with-hooks.ts
1569
- async function fetchWithHooks(url, init, options = {}) {
1570
- const { onRequest, onResponse } = options;
1571
- let res = await onRequest?.(url, init);
1616
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1617
+ const {
1618
+ onRequest,
1619
+ onResponse,
1620
+ abortController = new AbortController()
1621
+ } = options;
1622
+ const signal = abortController.signal;
1623
+ const hookOptions = {
1624
+ signal,
1625
+ abort: (reason) => abortController.abort(reason)
1626
+ };
1627
+ const init = {
1628
+ method: "GET",
1629
+ headers: remoteFetchHeaders(),
1630
+ signal,
1631
+ ...additionalInit
1632
+ };
1633
+ let res = await onRequest?.(url, init, hookOptions);
1572
1634
  if (!res) {
1573
- res = await fetch(url, init);
1635
+ res = await fetchWithProtectedRcFallback(url, init);
1574
1636
  }
1575
- const transformedRes = await onResponse?.(url, res);
1637
+ const transformedRes = await onResponse?.(url, res, hookOptions);
1576
1638
  if (transformedRes) {
1577
1639
  res = transformedRes;
1578
1640
  }
@@ -1782,18 +1844,18 @@ function RemoteComponent({
1782
1844
  );
1783
1845
  if (!html && src) {
1784
1846
  const fetchInit = {
1785
- method: "GET",
1786
- headers: remoteFetchHeaders(),
1787
1847
  credentials
1788
1848
  };
1849
+ const abortController = new AbortController();
1789
1850
  const res = await fetchWithHooks(url, fetchInit, {
1790
1851
  onRequest,
1791
- onResponse
1852
+ onResponse,
1853
+ abortController
1792
1854
  });
1793
- if (!res.ok) {
1855
+ if (!res || !res.ok) {
1794
1856
  let error = failedToFetchRemoteComponentError(
1795
1857
  url.href,
1796
- res
1858
+ res ?? new Response(null, { status: 0 })
1797
1859
  );
1798
1860
  try {
1799
1861
  const body = await res.text();
@@ -1814,7 +1876,9 @@ function RemoteComponent({
1814
1876
  error.stack = errorStack;
1815
1877
  }
1816
1878
  }
1817
- } catch {
1879
+ } catch (parseError) {
1880
+ if (isAbortError(parseError))
1881
+ throw parseError;
1818
1882
  }
1819
1883
  throw error;
1820
1884
  }
@@ -2085,6 +2149,9 @@ function RemoteComponent({
2085
2149
  }
2086
2150
  }
2087
2151
  } catch (error) {
2152
+ if (isAbortError(error)) {
2153
+ return;
2154
+ }
2088
2155
  setRemoteComponent(error);
2089
2156
  onError?.(error);
2090
2157
  }