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.
- package/dist/html/host.cjs +119 -7
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +119 -7
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +4 -4
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.js +5 -5
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/shared/client/apply-origin.cjs +21 -1
- package/dist/internal/shared/client/apply-origin.cjs.map +1 -1
- package/dist/internal/shared/client/apply-origin.js +21 -1
- package/dist/internal/shared/client/apply-origin.js.map +1 -1
- package/dist/internal/shared/client/polyfill.cjs +69 -3
- package/dist/internal/shared/client/polyfill.cjs.map +1 -1
- package/dist/internal/shared/client/polyfill.js +69 -3
- package/dist/internal/shared/client/polyfill.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.cjs +20 -0
- package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.js +20 -0
- package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-headers.cjs +44 -0
- package/dist/internal/shared/ssr/fetch-headers.cjs.map +1 -0
- package/dist/internal/shared/ssr/fetch-headers.d.ts +9 -0
- package/dist/internal/shared/ssr/fetch-headers.js +20 -0
- package/dist/internal/shared/ssr/fetch-headers.js.map +1 -0
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +5 -7
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.js +5 -7
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/internal/shared/utils.cjs +9 -0
- package/dist/internal/shared/utils.cjs.map +1 -1
- package/dist/internal/shared/utils.d.ts +2 -1
- package/dist/internal/shared/utils.js +8 -0
- package/dist/internal/shared/utils.js.map +1 -1
- package/dist/next/host/app-router-server.cjs +6 -1
- package/dist/next/host/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.d.ts +8 -1
- package/dist/next/host/app-router-server.js +6 -1
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +2 -0
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +1 -0
- package/dist/next/host/pages-router-server.js +2 -0
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/index.cjs +3 -7
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.ts +8 -5
- package/dist/next/index.js +3 -7
- package/dist/next/index.js.map +1 -1
- package/dist/next/middleware.cjs +15 -22
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +15 -22
- package/dist/next/middleware.js.map +1 -1
- package/dist/react/index.cjs +20 -9
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +3 -1
- package/dist/react/index.js +20 -9
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/html/host.cjs
CHANGED
|
@@ -620,16 +620,70 @@ function sharedPolyfills(shared) {
|
|
|
620
620
|
}
|
|
621
621
|
};
|
|
622
622
|
},
|
|
623
|
+
usePathname() {
|
|
624
|
+
return location.pathname;
|
|
625
|
+
},
|
|
626
|
+
useParams() {
|
|
627
|
+
return {};
|
|
628
|
+
},
|
|
623
629
|
useSearchParams() {
|
|
624
630
|
return new URLSearchParams(location.search);
|
|
625
631
|
},
|
|
632
|
+
useSelectedLayoutSegment() {
|
|
633
|
+
return null;
|
|
634
|
+
},
|
|
635
|
+
useSelectedLayoutSegments() {
|
|
636
|
+
return [];
|
|
637
|
+
},
|
|
626
638
|
__esModule: true
|
|
627
639
|
})),
|
|
628
640
|
"next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
|
|
629
641
|
default: ({
|
|
642
|
+
scroll: _,
|
|
643
|
+
replace,
|
|
644
|
+
prefetch,
|
|
645
|
+
onNavigate,
|
|
630
646
|
children,
|
|
631
647
|
...props
|
|
632
|
-
}) =>
|
|
648
|
+
}) => {
|
|
649
|
+
if (prefetch) {
|
|
650
|
+
console.warn(
|
|
651
|
+
"Next.js Link prefetch is not supported in remote components"
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
655
|
+
"a",
|
|
656
|
+
{
|
|
657
|
+
...props,
|
|
658
|
+
href: props.href,
|
|
659
|
+
onClick: (e) => {
|
|
660
|
+
e.preventDefault();
|
|
661
|
+
let preventDefaulted = false;
|
|
662
|
+
e.preventDefault = () => {
|
|
663
|
+
preventDefaulted = true;
|
|
664
|
+
e.defaultPrevented = true;
|
|
665
|
+
};
|
|
666
|
+
if (typeof props.onClick === "function") {
|
|
667
|
+
props.onClick(e);
|
|
668
|
+
}
|
|
669
|
+
onNavigate?.(e);
|
|
670
|
+
if (preventDefaulted) {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
if (replace) {
|
|
674
|
+
history.replaceState({}, "", props.href);
|
|
675
|
+
} else {
|
|
676
|
+
history.pushState({}, "", props.href);
|
|
677
|
+
}
|
|
678
|
+
},
|
|
679
|
+
suppressHydrationWarning: true,
|
|
680
|
+
children: children ?? null
|
|
681
|
+
}
|
|
682
|
+
);
|
|
683
|
+
},
|
|
684
|
+
useLinkStatus() {
|
|
685
|
+
return { pending: false };
|
|
686
|
+
},
|
|
633
687
|
__esModule: true
|
|
634
688
|
})),
|
|
635
689
|
"next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
|
|
@@ -698,10 +752,22 @@ var init_polyfill = __esm({
|
|
|
698
752
|
"use strict";
|
|
699
753
|
// eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
|
|
700
754
|
import_jsx_runtime = require("react/jsx-runtime");
|
|
701
|
-
imageImpl = (bundle) => function RemoteImage({
|
|
755
|
+
imageImpl = (bundle) => function RemoteImage({
|
|
756
|
+
fill: _fill,
|
|
757
|
+
loader: _loader,
|
|
758
|
+
quality: _quality,
|
|
759
|
+
priority: _priority,
|
|
760
|
+
loading: _loading,
|
|
761
|
+
placeholder: _placeholder,
|
|
762
|
+
blurDataURL: _blurDataURL,
|
|
763
|
+
unoptimized: _unoptimized,
|
|
764
|
+
overrideSrc: _overrideSrc,
|
|
765
|
+
src,
|
|
766
|
+
...props
|
|
767
|
+
}) {
|
|
702
768
|
const newSrc = applyBundleUrlToImagePropsSrc(
|
|
703
769
|
bundle,
|
|
704
|
-
typeof
|
|
770
|
+
typeof src === "string" ? src : src.src
|
|
705
771
|
);
|
|
706
772
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
707
773
|
"img",
|
|
@@ -973,6 +1039,24 @@ init_const();
|
|
|
973
1039
|
// src/html/host/index.tsx
|
|
974
1040
|
init_utils();
|
|
975
1041
|
|
|
1042
|
+
// src/shared/ssr/fetch-headers.ts
|
|
1043
|
+
function remoteFetchHeaders(additionalHeaders) {
|
|
1044
|
+
return {
|
|
1045
|
+
/**
|
|
1046
|
+
* Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
|
|
1047
|
+
* Ensure the automation bypass secret is the same on the client and host.
|
|
1048
|
+
* Otherwise, manually specify x-vercel-protection-bypass for the remote in the `additionalHeaders` parameter.
|
|
1049
|
+
*/
|
|
1050
|
+
...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
|
|
1051
|
+
"x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
|
|
1052
|
+
} : {},
|
|
1053
|
+
...Object.fromEntries(
|
|
1054
|
+
additionalHeaders instanceof Headers ? additionalHeaders.entries() : Object.entries(additionalHeaders ?? {})
|
|
1055
|
+
),
|
|
1056
|
+
Accept: "text/html"
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
|
|
976
1060
|
// src/shared/client/apply-origin.ts
|
|
977
1061
|
var tagNames = [
|
|
978
1062
|
"img",
|
|
@@ -988,12 +1072,20 @@ var tagNames = [
|
|
|
988
1072
|
function applyOriginToNodes(doc, url) {
|
|
989
1073
|
if (url.origin !== location.origin) {
|
|
990
1074
|
const nodes = doc.querySelectorAll(
|
|
991
|
-
tagNames.map(
|
|
1075
|
+
tagNames.map(
|
|
1076
|
+
(type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
|
|
1077
|
+
).join(",")
|
|
992
1078
|
);
|
|
993
1079
|
nodes.forEach((node) => {
|
|
994
1080
|
if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
|
|
995
1081
|
node.src = new URL(node.getAttribute("src") ?? "/", url).href;
|
|
996
1082
|
}
|
|
1083
|
+
if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
|
|
1084
|
+
node.setAttribute(
|
|
1085
|
+
"href",
|
|
1086
|
+
new URL(node.getAttribute("href") ?? "/", url).href
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
997
1089
|
if (node.hasAttribute("srcset")) {
|
|
998
1090
|
const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
|
|
999
1091
|
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
@@ -1006,6 +1098,18 @@ function applyOriginToNodes(doc, url) {
|
|
|
1006
1098
|
node.setAttribute("srcset", srcSet);
|
|
1007
1099
|
}
|
|
1008
1100
|
}
|
|
1101
|
+
if (node.hasAttribute("imagesrcset")) {
|
|
1102
|
+
const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
|
|
1103
|
+
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
1104
|
+
if (!urlPart)
|
|
1105
|
+
return entry;
|
|
1106
|
+
const absoluteUrl = new URL(urlPart, url).href;
|
|
1107
|
+
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
1108
|
+
}).join(", ");
|
|
1109
|
+
if (srcSet) {
|
|
1110
|
+
node.setAttribute("imagesrcset", srcSet);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1009
1113
|
});
|
|
1010
1114
|
}
|
|
1011
1115
|
}
|
|
@@ -1085,6 +1189,16 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1085
1189
|
}
|
|
1086
1190
|
this.name = this.getAttribute("name") || "__vercel_remote_component";
|
|
1087
1191
|
this.bundle = "default";
|
|
1192
|
+
const additionalHeadersString = this.getAttribute("additional-headers");
|
|
1193
|
+
if (additionalHeadersString) {
|
|
1194
|
+
this.additionalHeaders = additionalHeadersString.split(";").reduce((headers, headerPair) => {
|
|
1195
|
+
const [key, value] = headerPair.split(":");
|
|
1196
|
+
if (key && value) {
|
|
1197
|
+
headers.set(key.trim(), value.trim());
|
|
1198
|
+
}
|
|
1199
|
+
return headers;
|
|
1200
|
+
}, new Headers());
|
|
1201
|
+
}
|
|
1088
1202
|
if (this.hasAttribute("src") || this.querySelector("div#__REMOTE_COMPONENT__") || this.hasAttribute("data-ssr")) {
|
|
1089
1203
|
this.load().catch((e) => {
|
|
1090
1204
|
throw new Error(`Failed to load remote component: ${e}`);
|
|
@@ -1107,9 +1221,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1107
1221
|
if (!remoteComponentChild && url) {
|
|
1108
1222
|
const fetchInit = {
|
|
1109
1223
|
method: "GET",
|
|
1110
|
-
headers:
|
|
1111
|
-
Accept: "text/html"
|
|
1112
|
-
},
|
|
1224
|
+
headers: remoteFetchHeaders(this.additionalHeaders),
|
|
1113
1225
|
credentials: this.getAttribute("credentials") || "same-origin"
|
|
1114
1226
|
};
|
|
1115
1227
|
const res = await fetch(url, fetchInit);
|