remote-components 0.0.27 → 0.0.29

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 (61) hide show
  1. package/dist/html/host.cjs +119 -7
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +119 -7
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/internal/next/host/app-router-client.cjs +4 -4
  6. package/dist/internal/next/host/app-router-client.cjs.map +1 -1
  7. package/dist/internal/next/host/app-router-client.js +5 -5
  8. package/dist/internal/next/host/app-router-client.js.map +1 -1
  9. package/dist/internal/shared/client/apply-origin.cjs +21 -1
  10. package/dist/internal/shared/client/apply-origin.cjs.map +1 -1
  11. package/dist/internal/shared/client/apply-origin.js +21 -1
  12. package/dist/internal/shared/client/apply-origin.js.map +1 -1
  13. package/dist/internal/shared/client/polyfill.cjs +69 -3
  14. package/dist/internal/shared/client/polyfill.cjs.map +1 -1
  15. package/dist/internal/shared/client/polyfill.js +69 -3
  16. package/dist/internal/shared/client/polyfill.js.map +1 -1
  17. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  18. package/dist/internal/shared/client/remote-component.js.map +1 -1
  19. package/dist/internal/shared/ssr/dom-flight.cjs +20 -0
  20. package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
  21. package/dist/internal/shared/ssr/dom-flight.js +20 -0
  22. package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
  23. package/dist/internal/shared/ssr/fetch-headers.cjs +44 -0
  24. package/dist/internal/shared/ssr/fetch-headers.cjs.map +1 -0
  25. package/dist/internal/shared/ssr/fetch-headers.d.ts +9 -0
  26. package/dist/internal/shared/ssr/fetch-headers.js +20 -0
  27. package/dist/internal/shared/ssr/fetch-headers.js.map +1 -0
  28. package/dist/internal/shared/ssr/fetch-remote-component.cjs +5 -7
  29. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  30. package/dist/internal/shared/ssr/fetch-remote-component.js +5 -7
  31. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  32. package/dist/internal/shared/utils.cjs +9 -0
  33. package/dist/internal/shared/utils.cjs.map +1 -1
  34. package/dist/internal/shared/utils.d.ts +2 -1
  35. package/dist/internal/shared/utils.js +8 -0
  36. package/dist/internal/shared/utils.js.map +1 -1
  37. package/dist/next/host/app-router-server.cjs +6 -1
  38. package/dist/next/host/app-router-server.cjs.map +1 -1
  39. package/dist/next/host/app-router-server.d.ts +8 -1
  40. package/dist/next/host/app-router-server.js +6 -1
  41. package/dist/next/host/app-router-server.js.map +1 -1
  42. package/dist/next/host/pages-router-server.cjs +2 -0
  43. package/dist/next/host/pages-router-server.cjs.map +1 -1
  44. package/dist/next/host/pages-router-server.d.ts +1 -0
  45. package/dist/next/host/pages-router-server.js +2 -0
  46. package/dist/next/host/pages-router-server.js.map +1 -1
  47. package/dist/next/index.cjs +3 -7
  48. package/dist/next/index.cjs.map +1 -1
  49. package/dist/next/index.d.ts +8 -5
  50. package/dist/next/index.js +3 -7
  51. package/dist/next/index.js.map +1 -1
  52. package/dist/next/middleware.cjs +15 -22
  53. package/dist/next/middleware.cjs.map +1 -1
  54. package/dist/next/middleware.js +15 -22
  55. package/dist/next/middleware.js.map +1 -1
  56. package/dist/react/index.cjs +20 -9
  57. package/dist/react/index.cjs.map +1 -1
  58. package/dist/react/index.d.ts +3 -1
  59. package/dist/react/index.js +20 -9
  60. package/dist/react/index.js.map +1 -1
  61. package/package.json +1 -1
package/dist/html/host.js CHANGED
@@ -599,16 +599,70 @@ function sharedPolyfills(shared) {
599
599
  }
600
600
  };
601
601
  },
602
+ usePathname() {
603
+ return location.pathname;
604
+ },
605
+ useParams() {
606
+ return {};
607
+ },
602
608
  useSearchParams() {
603
609
  return new URLSearchParams(location.search);
604
610
  },
611
+ useSelectedLayoutSegment() {
612
+ return null;
613
+ },
614
+ useSelectedLayoutSegments() {
615
+ return [];
616
+ },
605
617
  __esModule: true
606
618
  })),
607
619
  "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
608
620
  default: ({
621
+ scroll: _,
622
+ replace,
623
+ prefetch,
624
+ onNavigate,
609
625
  children,
610
626
  ...props
611
- }) => /* @__PURE__ */ jsx("a", { ...props, href: props.href, suppressHydrationWarning: true, children: children ?? null }),
627
+ }) => {
628
+ if (prefetch) {
629
+ console.warn(
630
+ "Next.js Link prefetch is not supported in remote components"
631
+ );
632
+ }
633
+ return /* @__PURE__ */ jsx(
634
+ "a",
635
+ {
636
+ ...props,
637
+ href: props.href,
638
+ onClick: (e) => {
639
+ e.preventDefault();
640
+ let preventDefaulted = false;
641
+ e.preventDefault = () => {
642
+ preventDefaulted = true;
643
+ e.defaultPrevented = true;
644
+ };
645
+ if (typeof props.onClick === "function") {
646
+ props.onClick(e);
647
+ }
648
+ onNavigate?.(e);
649
+ if (preventDefaulted) {
650
+ return;
651
+ }
652
+ if (replace) {
653
+ history.replaceState({}, "", props.href);
654
+ } else {
655
+ history.pushState({}, "", props.href);
656
+ }
657
+ },
658
+ suppressHydrationWarning: true,
659
+ children: children ?? null
660
+ }
661
+ );
662
+ },
663
+ useLinkStatus() {
664
+ return { pending: false };
665
+ },
612
666
  __esModule: true
613
667
  })),
614
668
  "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
@@ -675,10 +729,22 @@ var imageImpl;
675
729
  var init_polyfill = __esm({
676
730
  "src/shared/client/polyfill.tsx"() {
677
731
  "use strict";
678
- imageImpl = (bundle) => function RemoteImage({ priority: _, ...props }) {
732
+ imageImpl = (bundle) => function RemoteImage({
733
+ fill: _fill,
734
+ loader: _loader,
735
+ quality: _quality,
736
+ priority: _priority,
737
+ loading: _loading,
738
+ placeholder: _placeholder,
739
+ blurDataURL: _blurDataURL,
740
+ unoptimized: _unoptimized,
741
+ overrideSrc: _overrideSrc,
742
+ src,
743
+ ...props
744
+ }) {
679
745
  const newSrc = applyBundleUrlToImagePropsSrc(
680
746
  bundle,
681
- typeof props.src === "string" ? props.src : props.src.src
747
+ typeof src === "string" ? src : src.src
682
748
  );
683
749
  return (
684
750
  // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
@@ -948,6 +1014,24 @@ init_const();
948
1014
  // src/html/host/index.tsx
949
1015
  init_utils();
950
1016
 
1017
+ // src/shared/ssr/fetch-headers.ts
1018
+ function remoteFetchHeaders(additionalHeaders) {
1019
+ return {
1020
+ /**
1021
+ * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
1022
+ * Ensure the automation bypass secret is the same on the client and host.
1023
+ * Otherwise, manually specify x-vercel-protection-bypass for the remote in the `additionalHeaders` parameter.
1024
+ */
1025
+ ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
1026
+ "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
1027
+ } : {},
1028
+ ...Object.fromEntries(
1029
+ additionalHeaders instanceof Headers ? additionalHeaders.entries() : Object.entries(additionalHeaders ?? {})
1030
+ ),
1031
+ Accept: "text/html"
1032
+ };
1033
+ }
1034
+
951
1035
  // src/shared/client/apply-origin.ts
952
1036
  var tagNames = [
953
1037
  "img",
@@ -963,12 +1047,20 @@ var tagNames = [
963
1047
  function applyOriginToNodes(doc, url) {
964
1048
  if (url.origin !== location.origin) {
965
1049
  const nodes = doc.querySelectorAll(
966
- tagNames.map((type) => `${type}[src],${type}[srcset]`).join(",")
1050
+ tagNames.map(
1051
+ (type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
1052
+ ).join(",")
967
1053
  );
968
1054
  nodes.forEach((node) => {
969
1055
  if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
970
1056
  node.src = new URL(node.getAttribute("src") ?? "/", url).href;
971
1057
  }
1058
+ if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
1059
+ node.setAttribute(
1060
+ "href",
1061
+ new URL(node.getAttribute("href") ?? "/", url).href
1062
+ );
1063
+ }
972
1064
  if (node.hasAttribute("srcset")) {
973
1065
  const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
974
1066
  const [urlPart, descriptor] = entry.trim().split(/\s+/);
@@ -981,6 +1073,18 @@ function applyOriginToNodes(doc, url) {
981
1073
  node.setAttribute("srcset", srcSet);
982
1074
  }
983
1075
  }
1076
+ if (node.hasAttribute("imagesrcset")) {
1077
+ const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
1078
+ const [urlPart, descriptor] = entry.trim().split(/\s+/);
1079
+ if (!urlPart)
1080
+ return entry;
1081
+ const absoluteUrl = new URL(urlPart, url).href;
1082
+ return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
1083
+ }).join(", ");
1084
+ if (srcSet) {
1085
+ node.setAttribute("imagesrcset", srcSet);
1086
+ }
1087
+ }
984
1088
  });
985
1089
  }
986
1090
  }
@@ -1060,6 +1164,16 @@ if (typeof HTMLElement !== "undefined") {
1060
1164
  }
1061
1165
  this.name = this.getAttribute("name") || "__vercel_remote_component";
1062
1166
  this.bundle = "default";
1167
+ const additionalHeadersString = this.getAttribute("additional-headers");
1168
+ if (additionalHeadersString) {
1169
+ this.additionalHeaders = additionalHeadersString.split(";").reduce((headers, headerPair) => {
1170
+ const [key, value] = headerPair.split(":");
1171
+ if (key && value) {
1172
+ headers.set(key.trim(), value.trim());
1173
+ }
1174
+ return headers;
1175
+ }, new Headers());
1176
+ }
1063
1177
  if (this.hasAttribute("src") || this.querySelector("div#__REMOTE_COMPONENT__") || this.hasAttribute("data-ssr")) {
1064
1178
  this.load().catch((e) => {
1065
1179
  throw new Error(`Failed to load remote component: ${e}`);
@@ -1082,9 +1196,7 @@ if (typeof HTMLElement !== "undefined") {
1082
1196
  if (!remoteComponentChild && url) {
1083
1197
  const fetchInit = {
1084
1198
  method: "GET",
1085
- headers: {
1086
- Accept: "text/html"
1087
- },
1199
+ headers: remoteFetchHeaders(this.additionalHeaders),
1088
1200
  credentials: this.getAttribute("credentials") || "same-origin"
1089
1201
  };
1090
1202
  const res = await fetch(url, fetchInit);