remote-components 0.0.43 → 0.0.44

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 (80) hide show
  1. package/dist/{component-loader-2ca91ad8.d.ts → component-loader-26b1f55e.d.ts} +63 -1
  2. package/dist/html/host.cjs +25 -19
  3. package/dist/html/host.cjs.map +1 -1
  4. package/dist/html/host.js +25 -19
  5. package/dist/html/host.js.map +1 -1
  6. package/dist/internal/next/host/app-router-client.d.ts +1 -1
  7. package/dist/internal/next/remote/render-client.cjs +1 -1
  8. package/dist/internal/next/remote/render-client.cjs.map +1 -1
  9. package/dist/internal/next/remote/render-client.js +1 -1
  10. package/dist/internal/next/remote/render-client.js.map +1 -1
  11. package/dist/internal/shared/client/remote-component.d.ts +2 -2
  12. package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
  13. package/dist/internal/shared/ssr/fetch-headers.cjs +4 -6
  14. package/dist/internal/shared/ssr/fetch-headers.cjs.map +1 -1
  15. package/dist/internal/shared/ssr/fetch-headers.d.ts +1 -1
  16. package/dist/internal/shared/ssr/fetch-headers.js +4 -6
  17. package/dist/internal/shared/ssr/fetch-headers.js.map +1 -1
  18. package/dist/internal/shared/ssr/fetch-remote-component.cjs +14 -23
  19. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  20. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +5 -9
  21. package/dist/internal/shared/ssr/fetch-remote-component.js +13 -21
  22. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  23. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +40 -0
  24. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -0
  25. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +39 -0
  26. package/dist/internal/shared/ssr/fetch-with-hooks.js +16 -0
  27. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -0
  28. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs.map +1 -1
  29. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js.map +1 -1
  30. package/dist/next/config.cjs +1 -9
  31. package/dist/next/config.cjs.map +1 -1
  32. package/dist/next/config.js +1 -9
  33. package/dist/next/config.js.map +1 -1
  34. package/dist/next/host/app-router-server.cjs +7 -8
  35. package/dist/next/host/app-router-server.cjs.map +1 -1
  36. package/dist/next/host/app-router-server.d.ts +13 -4
  37. package/dist/next/host/app-router-server.js +7 -8
  38. package/dist/next/host/app-router-server.js.map +1 -1
  39. package/dist/next/host/client/index.cjs +29 -12
  40. package/dist/next/host/client/index.cjs.map +1 -1
  41. package/dist/next/host/client/index.d.ts +1 -1
  42. package/dist/next/host/client/index.js +29 -12
  43. package/dist/next/host/client/index.js.map +1 -1
  44. package/dist/next/host/pages-router-client.cjs +62 -2
  45. package/dist/next/host/pages-router-client.cjs.map +1 -1
  46. package/dist/next/host/pages-router-client.d.ts +26 -1
  47. package/dist/next/host/pages-router-client.js +63 -3
  48. package/dist/next/host/pages-router-client.js.map +1 -1
  49. package/dist/next/host/pages-router-server.cjs +18 -22
  50. package/dist/next/host/pages-router-server.cjs.map +1 -1
  51. package/dist/next/host/pages-router-server.d.ts +36 -3
  52. package/dist/next/host/pages-router-server.js +18 -22
  53. package/dist/next/host/pages-router-server.js.map +1 -1
  54. package/dist/next/index.cjs.map +1 -1
  55. package/dist/next/index.d.ts +1 -1
  56. package/dist/next/index.js.map +1 -1
  57. package/dist/react/index.cjs +29 -12
  58. package/dist/react/index.cjs.map +1 -1
  59. package/dist/react/index.d.ts +13 -5
  60. package/dist/react/index.js +29 -12
  61. package/dist/react/index.js.map +1 -1
  62. package/dist/shared/host/app.cjs +1 -1
  63. package/dist/shared/host/app.cjs.map +1 -1
  64. package/dist/shared/host/app.js +1 -1
  65. package/dist/shared/host/app.js.map +1 -1
  66. package/dist/shared/host/pages.cjs +1 -1
  67. package/dist/shared/host/pages.cjs.map +1 -1
  68. package/dist/shared/host/pages.js +1 -1
  69. package/dist/shared/host/pages.js.map +1 -1
  70. package/dist/shared/remote/app.cjs +1 -1
  71. package/dist/shared/remote/app.cjs.map +1 -1
  72. package/dist/shared/remote/app.js +1 -1
  73. package/dist/shared/remote/app.js.map +1 -1
  74. package/dist/shared/remote/pages.cjs +1 -1
  75. package/dist/shared/remote/pages.cjs.map +1 -1
  76. package/dist/shared/remote/pages.js +1 -1
  77. package/dist/shared/remote/pages.js.map +1 -1
  78. package/dist/types-2ab78f67.d.ts +71 -0
  79. package/package.json +54 -32
  80. package/dist/types-cbf6c34f.d.ts +0 -9
@@ -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-2ca91ad8.js';
4
+ import '../../../component-loader-26b1f55e.js';
5
5
 
6
6
  /**
7
7
  * RemoteComponent - Client-side component for rendering remote components
@@ -1428,23 +1428,35 @@ async function loadStaticRemoteComponent(scripts, url) {
1428
1428
  }
1429
1429
 
1430
1430
  // src/shared/ssr/fetch-headers.ts
1431
- function remoteFetchHeaders(additionalHeaders) {
1431
+ function remoteFetchHeaders() {
1432
1432
  return {
1433
1433
  /**
1434
1434
  * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
1435
- * Ensure the automation bypass secret is the same on the client and host.
1436
- * Otherwise, manually specify x-vercel-protection-bypass for the remote in the `additionalHeaders` parameter.
1435
+ * If the remote component uses vercel deployment protection, ensure the host and remote vercel
1436
+ * projects share a common automation bypass secret, and the shared secret is used as the
1437
+ * VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
1437
1438
  */
1438
1439
  ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
1439
1440
  "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
1440
1441
  } : {},
1441
- ...Object.fromEntries(
1442
- additionalHeaders instanceof Headers ? additionalHeaders.entries() : Object.entries(additionalHeaders ?? {})
1443
- ),
1444
1442
  Accept: "text/html"
1445
1443
  };
1446
1444
  }
1447
1445
 
1446
+ // src/shared/ssr/fetch-with-hooks.ts
1447
+ async function fetchWithHooks(url, init, options = {}) {
1448
+ const { onRequest, onResponse } = options;
1449
+ let res = await onRequest?.(url, init);
1450
+ if (!res) {
1451
+ res = await fetch(url, init);
1452
+ }
1453
+ const transformedRes = await onResponse?.(url, res);
1454
+ if (transformedRes) {
1455
+ res = transformedRes;
1456
+ }
1457
+ return res;
1458
+ }
1459
+
1448
1460
  // src/shared/ssr/get-client-or-server-url.ts
1449
1461
  function getClientOrServerUrl(src, serverFallback) {
1450
1462
  const fallback = typeof location !== "undefined" ? location.href : serverFallback;
@@ -1536,12 +1548,13 @@ function RemoteComponent({
1536
1548
  credentials = "same-origin",
1537
1549
  name: nameProp = "__vercel_remote_component",
1538
1550
  shared = {},
1539
- additionalHeaders,
1540
1551
  children,
1541
1552
  onBeforeLoad,
1542
1553
  onLoad,
1543
1554
  onError,
1544
- onChange
1555
+ onChange,
1556
+ onRequest,
1557
+ onResponse
1545
1558
  }) {
1546
1559
  const instanceId = useId();
1547
1560
  const name = useMemo(() => {
@@ -1645,10 +1658,13 @@ function RemoteComponent({
1645
1658
  if (!html && src) {
1646
1659
  const fetchInit = {
1647
1660
  method: "GET",
1648
- headers: remoteFetchHeaders(additionalHeaders),
1661
+ headers: remoteFetchHeaders(),
1649
1662
  credentials
1650
1663
  };
1651
- const res = await fetch(url, fetchInit);
1664
+ const res = await fetchWithHooks(url, fetchInit, {
1665
+ onRequest,
1666
+ onResponse
1667
+ });
1652
1668
  if (!res.ok) {
1653
1669
  let error = failedToFetchRemoteComponentError(
1654
1670
  url.href,
@@ -1958,13 +1974,14 @@ function RemoteComponent({
1958
1974
  name,
1959
1975
  shared,
1960
1976
  shadowRoot,
1961
- additionalHeaders,
1962
1977
  reset,
1963
1978
  id,
1964
1979
  onBeforeLoad,
1965
1980
  onLoad,
1966
1981
  onError,
1967
- onChange
1982
+ onChange,
1983
+ onRequest,
1984
+ onResponse
1968
1985
  ]);
1969
1986
  if (remoteComponent instanceof Error) {
1970
1987
  throw remoteComponent;