remote-components 0.0.47 → 0.0.49

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 (64) hide show
  1. package/dist/{component-loader-26b1f55e.d.ts → component-loader-1838f572.d.ts} +62 -8
  2. package/dist/html/host.cjs +165 -70
  3. package/dist/html/host.cjs.map +1 -1
  4. package/dist/html/host.js +165 -70
  5. package/dist/html/host.js.map +1 -1
  6. package/dist/internal/next/host/app-router-client.cjs +13 -50
  7. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  8. package/dist/internal/next/host/app-router-client.d.ts +1 -1
  9. package/dist/internal/next/host/app-router-client.js +14 -51
  10. package/dist/internal/next/host/app-router-client.js.map +1 -1
  11. package/dist/internal/next/host/remote-component-links.cjs +96 -0
  12. package/dist/internal/next/host/remote-component-links.cjs.map +1 -0
  13. package/dist/internal/next/host/remote-component-links.d.ts +25 -0
  14. package/dist/internal/next/host/remote-component-links.js +72 -0
  15. package/dist/internal/next/host/remote-component-links.js.map +1 -0
  16. package/dist/internal/shared/client/remote-component.cjs +17 -1
  17. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  18. package/dist/internal/shared/client/remote-component.d.ts +2 -2
  19. package/dist/internal/shared/client/remote-component.js +17 -1
  20. package/dist/internal/shared/client/remote-component.js.map +1 -1
  21. package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
  22. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
  23. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +13 -3
  24. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  25. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +24 -13
  26. package/dist/internal/shared/ssr/fetch-with-hooks.js +13 -3
  27. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  28. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +6 -1
  29. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +1 -1
  30. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +3 -0
  31. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +6 -1
  32. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +1 -1
  33. package/dist/internal/shared/utils/abort.cjs +38 -0
  34. package/dist/internal/shared/utils/abort.cjs.map +1 -0
  35. package/dist/internal/shared/utils/abort.d.ts +7 -0
  36. package/dist/internal/shared/utils/abort.js +14 -0
  37. package/dist/internal/shared/utils/abort.js.map +1 -0
  38. package/dist/next/config.cjs +4 -2
  39. package/dist/next/config.cjs.map +1 -1
  40. package/dist/next/config.js +4 -2
  41. package/dist/next/config.js.map +1 -1
  42. package/dist/next/host/app-router-server.d.ts +1 -1
  43. package/dist/next/host/client/index.cjs +41 -8
  44. package/dist/next/host/client/index.cjs.map +1 -1
  45. package/dist/next/host/client/index.d.ts +1 -1
  46. package/dist/next/host/client/index.js +41 -8
  47. package/dist/next/host/client/index.js.map +1 -1
  48. package/dist/next/host/pages-router-client.d.ts +1 -1
  49. package/dist/next/host/pages-router-server.d.ts +1 -1
  50. package/dist/next/index.d.ts +1 -1
  51. package/dist/next/proxy.cjs.map +1 -1
  52. package/dist/next/proxy.js.map +1 -1
  53. package/dist/react/index.cjs +41 -8
  54. package/dist/react/index.cjs.map +1 -1
  55. package/dist/react/index.d.ts +2 -1
  56. package/dist/react/index.js +41 -8
  57. package/dist/react/index.js.map +1 -1
  58. package/dist/{types-6e4ba234.d.ts → types-cbe44b51.d.ts} +61 -7
  59. package/dist/webpack.cjs +274 -0
  60. package/dist/webpack.cjs.map +1 -0
  61. package/dist/webpack.d.ts +14 -0
  62. package/dist/webpack.js +247 -0
  63. package/dist/webpack.js.map +1 -0
  64. package/package.json +9 -1
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { RemoteComponentProps } from '../../../react/index.js';
4
- import '../../../component-loader-26b1f55e.js';
4
+ import '../../../component-loader-1838f572.js';
5
5
 
6
6
  /**
7
7
  * RemoteComponent - Client-side component for rendering remote components
@@ -585,6 +585,18 @@ async function loadScripts(scripts) {
585
585
  );
586
586
  }
587
587
 
588
+ // src/shared/utils/abort.ts
589
+ function isAbortError(error) {
590
+ if (error instanceof DOMException && error.name === "AbortError") {
591
+ return true;
592
+ }
593
+ if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
594
+ const e = error;
595
+ return typeof e.code === "number" || e.constructor?.name === "DOMException";
596
+ }
597
+ return false;
598
+ }
599
+
588
600
  // src/shared/ssr/fetch-with-protected-rc-fallback.ts
589
601
  var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
590
602
  async function fetchWithProtectedRcFallback(url, init) {
@@ -592,13 +604,17 @@ async function fetchWithProtectedRcFallback(url, init) {
592
604
  const res = await fetch(url, init);
593
605
  return res;
594
606
  } catch (error) {
607
+ if (isAbortError(error)) {
608
+ throw error;
609
+ }
595
610
  if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
596
611
  logInfo(
597
612
  "FetchRemoteComponent",
598
613
  "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
599
614
  );
600
615
  const proxiedRes = await fetch(
601
- `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`
616
+ `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,
617
+ init?.signal ? { signal: init.signal } : void 0
602
618
  );
603
619
  if (proxiedRes.status === 200) {
604
620
  return proxiedRes;
@@ -1577,17 +1593,27 @@ function remoteFetchHeaders() {
1577
1593
 
1578
1594
  // src/shared/ssr/fetch-with-hooks.ts
1579
1595
  async function fetchWithHooks(url, additionalInit, options = {}) {
1580
- const { onRequest, onResponse } = options;
1596
+ const {
1597
+ onRequest,
1598
+ onResponse,
1599
+ abortController = new AbortController()
1600
+ } = options;
1601
+ const signal = abortController.signal;
1602
+ const hookOptions = {
1603
+ signal,
1604
+ abort: (reason) => abortController.abort(reason)
1605
+ };
1581
1606
  const init = {
1582
1607
  method: "GET",
1583
1608
  headers: remoteFetchHeaders(),
1609
+ signal,
1584
1610
  ...additionalInit
1585
1611
  };
1586
- let res = await onRequest?.(url, init);
1612
+ let res = await onRequest?.(url, init, hookOptions);
1587
1613
  if (!res) {
1588
1614
  res = await fetchWithProtectedRcFallback(url, init);
1589
1615
  }
1590
- const transformedRes = await onResponse?.(url, res);
1616
+ const transformedRes = await onResponse?.(url, res, hookOptions);
1591
1617
  if (transformedRes) {
1592
1618
  res = transformedRes;
1593
1619
  }
@@ -1796,14 +1822,16 @@ function RemoteComponent({
1796
1822
  const fetchInit = {
1797
1823
  credentials
1798
1824
  };
1825
+ const abortController = new AbortController();
1799
1826
  const res = await fetchWithHooks(url, fetchInit, {
1800
1827
  onRequest,
1801
- onResponse
1828
+ onResponse,
1829
+ abortController
1802
1830
  });
1803
- if (!res.ok) {
1831
+ if (!res || !res.ok) {
1804
1832
  let error = failedToFetchRemoteComponentError(
1805
1833
  url.href,
1806
- res
1834
+ res ?? new Response(null, { status: 0 })
1807
1835
  );
1808
1836
  try {
1809
1837
  const body = await res.text();
@@ -1824,7 +1852,9 @@ function RemoteComponent({
1824
1852
  error.stack = errorStack;
1825
1853
  }
1826
1854
  }
1827
- } catch {
1855
+ } catch (parseError) {
1856
+ if (isAbortError(parseError))
1857
+ throw parseError;
1828
1858
  }
1829
1859
  throw error;
1830
1860
  }
@@ -2096,6 +2126,9 @@ function RemoteComponent({
2096
2126
  }
2097
2127
  }
2098
2128
  } catch (error) {
2129
+ if (isAbortError(error)) {
2130
+ return;
2131
+ }
2099
2132
  setRemoteComponent(error);
2100
2133
  onError?.(error);
2101
2134
  }