remote-components 0.0.43 → 0.0.45

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 (92) hide show
  1. package/README.md +1 -1
  2. package/dist/{component-loader-2ca91ad8.d.ts → component-loader-26b1f55e.d.ts} +63 -1
  3. package/dist/html/host.cjs +25 -19
  4. package/dist/html/host.cjs.map +1 -1
  5. package/dist/html/host.js +25 -19
  6. package/dist/html/host.js.map +1 -1
  7. package/dist/internal/next/host/app-router-client.d.ts +4 -3
  8. package/dist/internal/next/remote/render-client.cjs +1 -1
  9. package/dist/internal/next/remote/render-client.cjs.map +1 -1
  10. package/dist/internal/next/remote/render-client.js +1 -1
  11. package/dist/internal/next/remote/render-client.js.map +1 -1
  12. package/dist/internal/shared/client/remote-component.d.ts +2 -2
  13. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  14. package/dist/internal/shared/ssr/dom-flight.d.ts +2 -39
  15. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  16. package/dist/internal/shared/ssr/fetch-headers.cjs +4 -6
  17. package/dist/internal/shared/ssr/fetch-headers.cjs.map +1 -1
  18. package/dist/internal/shared/ssr/fetch-headers.d.ts +1 -1
  19. package/dist/internal/shared/ssr/fetch-headers.js +4 -6
  20. package/dist/internal/shared/ssr/fetch-headers.js.map +1 -1
  21. package/dist/internal/shared/ssr/fetch-remote-component.cjs +58 -24
  22. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  23. package/dist/internal/shared/ssr/fetch-remote-component.d.ts +9 -37
  24. package/dist/internal/shared/ssr/fetch-remote-component.js +60 -22
  25. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  26. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +40 -0
  27. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -0
  28. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +40 -0
  29. package/dist/internal/shared/ssr/fetch-with-hooks.js +16 -0
  30. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -0
  31. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs +6 -0
  32. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs.map +1 -1
  33. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.d.ts +3 -0
  34. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js +6 -0
  35. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js.map +1 -1
  36. package/dist/internal/shared/ssr/skeleton.cjs +97 -0
  37. package/dist/internal/shared/ssr/skeleton.cjs.map +1 -0
  38. package/dist/internal/shared/ssr/skeleton.d.ts +17 -0
  39. package/dist/internal/shared/ssr/skeleton.js +72 -0
  40. package/dist/internal/shared/ssr/skeleton.js.map +1 -0
  41. package/dist/internal/webpack/next-client-pages-loader.d.ts +3 -3
  42. package/dist/next/config.cjs +1 -9
  43. package/dist/next/config.cjs.map +1 -1
  44. package/dist/next/config.js +1 -9
  45. package/dist/next/config.js.map +1 -1
  46. package/dist/next/host/app-router-server.cjs +8 -8
  47. package/dist/next/host/app-router-server.cjs.map +1 -1
  48. package/dist/next/host/app-router-server.d.ts +14 -4
  49. package/dist/next/host/app-router-server.js +8 -8
  50. package/dist/next/host/app-router-server.js.map +1 -1
  51. package/dist/next/host/client/index.cjs +29 -12
  52. package/dist/next/host/client/index.cjs.map +1 -1
  53. package/dist/next/host/client/index.d.ts +1 -1
  54. package/dist/next/host/client/index.js +29 -12
  55. package/dist/next/host/client/index.js.map +1 -1
  56. package/dist/next/host/pages-router-client.cjs +62 -2
  57. package/dist/next/host/pages-router-client.cjs.map +1 -1
  58. package/dist/next/host/pages-router-client.d.ts +27 -1
  59. package/dist/next/host/pages-router-client.js +63 -3
  60. package/dist/next/host/pages-router-client.js.map +1 -1
  61. package/dist/next/host/pages-router-server.cjs +18 -22
  62. package/dist/next/host/pages-router-server.cjs.map +1 -1
  63. package/dist/next/host/pages-router-server.d.ts +37 -3
  64. package/dist/next/host/pages-router-server.js +18 -22
  65. package/dist/next/host/pages-router-server.js.map +1 -1
  66. package/dist/next/index.cjs.map +1 -1
  67. package/dist/next/index.d.ts +2 -1
  68. package/dist/next/index.js.map +1 -1
  69. package/dist/react/index.cjs +29 -12
  70. package/dist/react/index.cjs.map +1 -1
  71. package/dist/react/index.d.ts +13 -5
  72. package/dist/react/index.js +29 -12
  73. package/dist/react/index.js.map +1 -1
  74. package/dist/shared/host/app.cjs +1 -1
  75. package/dist/shared/host/app.cjs.map +1 -1
  76. package/dist/shared/host/app.js +1 -1
  77. package/dist/shared/host/app.js.map +1 -1
  78. package/dist/shared/host/pages.cjs +1 -1
  79. package/dist/shared/host/pages.cjs.map +1 -1
  80. package/dist/shared/host/pages.js +1 -1
  81. package/dist/shared/host/pages.js.map +1 -1
  82. package/dist/shared/remote/app.cjs +1 -1
  83. package/dist/shared/remote/app.cjs.map +1 -1
  84. package/dist/shared/remote/app.js +1 -1
  85. package/dist/shared/remote/app.js.map +1 -1
  86. package/dist/shared/remote/pages.cjs +1 -1
  87. package/dist/shared/remote/pages.cjs.map +1 -1
  88. package/dist/shared/remote/pages.js +1 -1
  89. package/dist/shared/remote/pages.js.map +1 -1
  90. package/dist/types-6e4ba234.d.ts +136 -0
  91. package/package.json +54 -32
  92. package/dist/types-cbf6c34f.d.ts +0 -9
package/README.md CHANGED
@@ -8,4 +8,4 @@
8
8
 
9
9
  > This is a work in progress feature and not yet ready for production use. We are actively working on it and will provide updates as we make progress.
10
10
 
11
- 📚 [Documentation](https://vercel.com/docs/microfrontends)
11
+ 📚 [Documentation](https://remote-components-docs.vercel.sh/)
@@ -7,6 +7,68 @@ interface RemoteComponentMetadata {
7
7
  id: string;
8
8
  type: 'nextjs' | 'remote-component' | 'unknown';
9
9
  }
10
+ /**
11
+ * Hook function that intercepts remote component fetch requests.
12
+ * Can be used to modify request options, provide a custom response, or inspect the request.
13
+ *
14
+ * @param url - The URL being fetched
15
+ * @param init - The fetch init options being used
16
+ * @returns Optional Response to use instead of fetching, or void/undefined to proceed with normal fetch
17
+ *
18
+ * @example
19
+ * // Log all remote component requests
20
+ * const onRequest = async (url, init) => {
21
+ * console.log('Fetching remote component from:', url.href);
22
+ * };
23
+ *
24
+ * @example
25
+ * // Add custom headers
26
+ * const onRequest = async (url, init) => {
27
+ * (init.headers as Headers).set('X-Custom-Header', 'value');
28
+ * };
29
+ *
30
+ * @example
31
+ * // Provide a cached response
32
+ * const onRequest = async (url) => {
33
+ * const cached = cache.get(url.href);
34
+ * if (cached) {
35
+ * return new Response(cached);
36
+ * }
37
+ * };
38
+ */
39
+ type OnRequestHook = (url: URL, init: RequestInit) => Promise<Response | undefined> | Response | undefined;
40
+ /**
41
+ * Hook function that is called after a remote component fetch completes.
42
+ * Can be used to inspect the response, check for redirects, or transform the response.
43
+ *
44
+ * @param url - The original URL that was requested
45
+ * @param response - The Response object from the fetch
46
+ * @returns Optional Response to use instead of the original, or void/undefined to use the original response
47
+ *
48
+ * @example
49
+ * // Check for redirects
50
+ * const onResponse = async (url, response) => {
51
+ * if (response.redirected) {
52
+ * console.log(`Redirected from ${url.href} to ${response.url}`);
53
+ * }
54
+ * };
55
+ *
56
+ * @example
57
+ * // Cache the response
58
+ * const onResponse = async (url, response) => {
59
+ * const cloned = response.clone();
60
+ * cache.set(url.href, await cloned.text());
61
+ * };
62
+ *
63
+ * @example
64
+ * // Transform the response
65
+ * const onResponse = async (url, response) => {
66
+ * const text = await response.text();
67
+ * const modified = text.replace(/foo/g, 'bar');
68
+ * return new Response(modified, response);
69
+ * };
70
+ */
71
+ type OnResponseHook = (url: URL, response: Response) => Promise<Response | undefined> | Response | undefined;
10
72
 
11
73
  interface RemoteComponentProps {
12
74
  /** The src provided to the `<RemoteComponent>` component. May be relative or absolute URL. */
@@ -79,4 +141,4 @@ type LoadRemoteComponentProps = Pick<RemoteComponentProps, 'name' | 'bundle' | '
79
141
  */
80
142
  declare function loadRemoteComponent({ url, name, rscName, bundle, route, runtime, data, nextData, scripts, shared, remoteShared, container, }: LoadRemoteComponentProps): Promise<LoaderResult>;
81
143
 
82
- export { GlobalScope as G, LoadRemoteComponentProps as L, MountOrUnmountFunction as M, RemoteComponentProps as R, LoaderResult as a, loadRemoteComponent as l };
144
+ export { GlobalScope as G, LoadRemoteComponentProps as L, MountOrUnmountFunction as M, OnRequestHook as O, RemoteComponentProps as R, OnResponseHook as a, LoaderResult as b, loadRemoteComponent as l };
@@ -1540,23 +1540,35 @@ init_webpack_adapter();
1540
1540
  init_error();
1541
1541
 
1542
1542
  // src/shared/ssr/fetch-headers.ts
1543
- function remoteFetchHeaders(additionalHeaders) {
1543
+ function remoteFetchHeaders() {
1544
1544
  return {
1545
1545
  /**
1546
1546
  * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
1547
- * Ensure the automation bypass secret is the same on the client and host.
1548
- * Otherwise, manually specify x-vercel-protection-bypass for the remote in the `additionalHeaders` parameter.
1547
+ * If the remote component uses vercel deployment protection, ensure the host and remote vercel
1548
+ * projects share a common automation bypass secret, and the shared secret is used as the
1549
+ * VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
1549
1550
  */
1550
1551
  ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
1551
1552
  "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
1552
1553
  } : {},
1553
- ...Object.fromEntries(
1554
- additionalHeaders instanceof Headers ? additionalHeaders.entries() : Object.entries(additionalHeaders ?? {})
1555
- ),
1556
1554
  Accept: "text/html"
1557
1555
  };
1558
1556
  }
1559
1557
 
1558
+ // src/shared/ssr/fetch-with-hooks.ts
1559
+ async function fetchWithHooks(url, init, options = {}) {
1560
+ const { onRequest, onResponse } = options;
1561
+ let res = await onRequest?.(url, init);
1562
+ if (!res) {
1563
+ res = await fetch(url, init);
1564
+ }
1565
+ const transformedRes = await onResponse?.(url, res);
1566
+ if (transformedRes) {
1567
+ res = transformedRes;
1568
+ }
1569
+ return res;
1570
+ }
1571
+
1560
1572
  // src/html/host/index.tsx
1561
1573
  init_utils();
1562
1574
 
@@ -1599,7 +1611,8 @@ if (typeof HTMLElement !== "undefined") {
1599
1611
  prevName;
1600
1612
  root = null;
1601
1613
  reactRoot;
1602
- additionalHeaders;
1614
+ onRequest;
1615
+ onResponse;
1603
1616
  static get observedAttributes() {
1604
1617
  return ["src", "name", "mode"];
1605
1618
  }
@@ -1663,16 +1676,6 @@ if (typeof HTMLElement !== "undefined") {
1663
1676
  }
1664
1677
  this.name = this.getAttribute("name") || "__vercel_remote_component";
1665
1678
  this.bundle = "default";
1666
- const additionalHeadersString = this.getAttribute("additional-headers");
1667
- if (additionalHeadersString) {
1668
- this.additionalHeaders = additionalHeadersString.split(";").reduce((headers, headerPair) => {
1669
- const [key, value] = headerPair.split(":");
1670
- if (key && value) {
1671
- headers.set(key.trim(), value.trim());
1672
- }
1673
- return headers;
1674
- }, new Headers());
1675
- }
1676
1679
  if (this.hasAttribute("src") || this.querySelector("div#__REMOTE_COMPONENT__") || this.hasAttribute("data-ssr")) {
1677
1680
  this.load().catch((e) => {
1678
1681
  console.error(e);
@@ -1710,10 +1713,13 @@ if (typeof HTMLElement !== "undefined") {
1710
1713
  if (!remoteComponentChild && url) {
1711
1714
  const fetchInit = {
1712
1715
  method: "GET",
1713
- headers: remoteFetchHeaders(this.additionalHeaders),
1716
+ headers: remoteFetchHeaders(),
1714
1717
  credentials: this.getAttribute("credentials") || "same-origin"
1715
1718
  };
1716
- const res = await fetch(url, fetchInit);
1719
+ const res = await fetchWithHooks(url, fetchInit, {
1720
+ onRequest: this.onRequest,
1721
+ onResponse: this.onResponse
1722
+ });
1717
1723
  if (!res.ok) {
1718
1724
  let error = failedToFetchRemoteComponentError(url.href, res);
1719
1725
  try {