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
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { L as LoadRemoteComponentProps, O as OnRequestHook, a as OnResponseHook } from '../component-loader-26b1f55e.js';
2
+ import { L as LoadRemoteComponentProps, O as OnRequestHook, a as OnResponseHook } from '../component-loader-1838f572.js';
3
+ export { H as HookOptions } from '../component-loader-1838f572.js';
3
4
  import 'react';
4
5
 
5
6
  declare module 'react/jsx-runtime' {
@@ -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,62 @@ async function loadScripts(scripts) {
589
580
  );
590
581
  }
591
582
 
583
+ // src/shared/utils/abort.ts
584
+ function isAbortError(error) {
585
+ if (error instanceof DOMException && error.name === "AbortError") {
586
+ return true;
587
+ }
588
+ if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
589
+ const e = error;
590
+ return typeof e.code === "number" || e.constructor?.name === "DOMException";
591
+ }
592
+ return false;
593
+ }
594
+
595
+ // src/shared/ssr/fetch-with-protected-rc-fallback.ts
596
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
597
+ async function fetchWithProtectedRcFallback(url, init) {
598
+ try {
599
+ const res = await fetch(url, init);
600
+ return res;
601
+ } catch (error) {
602
+ if (isAbortError(error)) {
603
+ throw error;
604
+ }
605
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
606
+ logInfo(
607
+ "FetchRemoteComponent",
608
+ "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
609
+ );
610
+ const proxiedRes = await fetch(
611
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,
612
+ init?.signal ? { signal: init.signal } : void 0
613
+ );
614
+ if (proxiedRes.status === 200) {
615
+ return proxiedRes;
616
+ } else {
617
+ logError(
618
+ "FetchRemoteComponent",
619
+ `Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
620
+ );
621
+ }
622
+ }
623
+ throw error;
624
+ }
625
+ }
626
+
627
+ // src/shared/utils/index.ts
628
+ function escapeString(str) {
629
+ return str.replace(/[^a-z0-9]/g, "_");
630
+ }
631
+ var attrToProp = {
632
+ fetchpriority: "fetchPriority",
633
+ crossorigin: "crossOrigin",
634
+ imagesrcset: "imageSrcSet",
635
+ imagesizes: "imageSizes",
636
+ srcset: "srcSet"
637
+ };
638
+
592
639
  // src/shared/client/const.ts
593
640
  var DEFAULT_ROUTE = "/";
594
641
  var RUNTIME_WEBPACK = "webpack";
@@ -642,7 +689,7 @@ function createChunkLoader(runtime) {
642
689
  }
643
690
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
644
691
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
645
- fetch(url).then((res) => res.text()).then((code) => {
692
+ fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
646
693
  const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
647
694
  if (hasTurbopack) {
648
695
  return handleTurbopackChunk(code, bundle ?? "", url);
@@ -1540,13 +1587,28 @@ function remoteFetchHeaders() {
1540
1587
  }
1541
1588
 
1542
1589
  // src/shared/ssr/fetch-with-hooks.ts
1543
- async function fetchWithHooks(url, init, options = {}) {
1544
- const { onRequest, onResponse } = options;
1545
- let res = await onRequest?.(url, init);
1590
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1591
+ const {
1592
+ onRequest,
1593
+ onResponse,
1594
+ abortController = new AbortController()
1595
+ } = options;
1596
+ const signal = abortController.signal;
1597
+ const hookOptions = {
1598
+ signal,
1599
+ abort: (reason) => abortController.abort(reason)
1600
+ };
1601
+ const init = {
1602
+ method: "GET",
1603
+ headers: remoteFetchHeaders(),
1604
+ signal,
1605
+ ...additionalInit
1606
+ };
1607
+ let res = await onRequest?.(url, init, hookOptions);
1546
1608
  if (!res) {
1547
- res = await fetch(url, init);
1609
+ res = await fetchWithProtectedRcFallback(url, init);
1548
1610
  }
1549
- const transformedRes = await onResponse?.(url, res);
1611
+ const transformedRes = await onResponse?.(url, res, hookOptions);
1550
1612
  if (transformedRes) {
1551
1613
  res = transformedRes;
1552
1614
  }
@@ -1753,18 +1815,18 @@ function RemoteComponent({
1753
1815
  );
1754
1816
  if (!html && src) {
1755
1817
  const fetchInit = {
1756
- method: "GET",
1757
- headers: remoteFetchHeaders(),
1758
1818
  credentials
1759
1819
  };
1820
+ const abortController = new AbortController();
1760
1821
  const res = await fetchWithHooks(url, fetchInit, {
1761
1822
  onRequest,
1762
- onResponse
1823
+ onResponse,
1824
+ abortController
1763
1825
  });
1764
- if (!res.ok) {
1826
+ if (!res || !res.ok) {
1765
1827
  let error = failedToFetchRemoteComponentError(
1766
1828
  url.href,
1767
- res
1829
+ res ?? new Response(null, { status: 0 })
1768
1830
  );
1769
1831
  try {
1770
1832
  const body = await res.text();
@@ -1785,7 +1847,9 @@ function RemoteComponent({
1785
1847
  error.stack = errorStack;
1786
1848
  }
1787
1849
  }
1788
- } catch {
1850
+ } catch (parseError) {
1851
+ if (isAbortError(parseError))
1852
+ throw parseError;
1789
1853
  }
1790
1854
  throw error;
1791
1855
  }
@@ -2057,6 +2121,9 @@ function RemoteComponent({
2057
2121
  }
2058
2122
  }
2059
2123
  } catch (error) {
2124
+ if (isAbortError(error)) {
2125
+ return;
2126
+ }
2060
2127
  setRemoteComponent(error);
2061
2128
  onError?.(error);
2062
2129
  }