remote-components 0.2.2 → 0.3.1
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/config/nextjs.cjs +2 -4
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.d.ts +1 -1
- package/dist/config/nextjs.js +2 -4
- package/dist/config/nextjs.js.map +1 -1
- package/dist/host/html.cjs +128 -112
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +128 -115
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +233 -259
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +234 -260
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/nextjs/app.cjs +5 -6
- package/dist/host/nextjs/app.cjs.map +1 -1
- package/dist/host/nextjs/app.js +5 -6
- package/dist/host/nextjs/app.js.map +1 -1
- package/dist/host/nextjs/pages.cjs +7 -19
- package/dist/host/nextjs/pages.cjs.map +1 -1
- package/dist/host/nextjs/pages.js +11 -20
- package/dist/host/nextjs/pages.js.map +1 -1
- package/dist/host/react.cjs +101 -93
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +101 -93
- package/dist/host/react.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.cjs +3 -8
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.js +4 -9
- package/dist/internal/host/nextjs/app-client.js.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.cjs +16 -7
- package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.d.ts +2 -2
- package/dist/internal/host/nextjs/dom-flight.js +16 -7
- package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +25 -15
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.d.ts +19 -6
- package/dist/internal/host/nextjs/image-shared.js +24 -14
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/react/hooks/use-resolve-client-url.cjs +1 -5
- package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -1
- package/dist/internal/host/react/hooks/use-resolve-client-url.d.ts +1 -4
- package/dist/internal/host/react/hooks/use-resolve-client-url.js +1 -5
- package/dist/internal/host/react/hooks/use-resolve-client-url.js.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.cjs +164 -149
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +166 -149
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/polyfill.cjs +10 -65
- package/dist/internal/host/shared/polyfill.cjs.map +1 -1
- package/dist/internal/host/shared/polyfill.d.ts +1 -3
- package/dist/internal/host/shared/polyfill.js +9 -63
- package/dist/internal/host/shared/polyfill.js.map +1 -1
- package/dist/internal/host/shared/remote-image-loader.cjs +53 -0
- package/dist/internal/host/shared/remote-image-loader.cjs.map +1 -0
- package/dist/internal/host/shared/remote-image-loader.d.ts +30 -0
- package/dist/internal/host/shared/remote-image-loader.js +29 -0
- package/dist/internal/host/shared/remote-image-loader.js.map +1 -0
- package/dist/internal/runtime/constants.cjs +6 -6
- package/dist/internal/runtime/constants.cjs.map +1 -1
- package/dist/internal/runtime/constants.d.ts +3 -3
- package/dist/internal/runtime/constants.js +4 -4
- package/dist/internal/runtime/constants.js.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.cjs +11 -15
- package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.d.ts +2 -12
- package/dist/internal/runtime/html/parse-remote-html.js +17 -15
- package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.cjs +2 -2
- package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/script-loader.js +1 -1
- package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
- package/dist/internal/runtime/metadata.cjs +42 -0
- package/dist/internal/runtime/metadata.cjs.map +1 -1
- package/dist/internal/runtime/metadata.d.ts +21 -1
- package/dist/internal/runtime/metadata.js +38 -0
- package/dist/internal/runtime/metadata.js.map +1 -1
- package/dist/internal/runtime/patterns.cjs +38 -0
- package/dist/internal/runtime/patterns.cjs.map +1 -0
- package/dist/internal/runtime/patterns.d.ts +5 -0
- package/dist/internal/runtime/patterns.js +12 -0
- package/dist/internal/runtime/patterns.js.map +1 -0
- package/dist/internal/runtime/turbopack/chunk-loader.cjs +4 -3
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs +11 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.js +10 -2
- package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -1
- package/dist/remote/nextjs/app.cjs +2 -1
- package/dist/remote/nextjs/app.cjs.map +1 -1
- package/dist/remote/nextjs/app.js +2 -1
- package/dist/remote/nextjs/app.js.map +1 -1
- package/package.json +1 -1
- package/dist/internal/host/nextjs/image-impl.cjs +0 -64
- package/dist/internal/host/nextjs/image-impl.cjs.map +0 -1
- package/dist/internal/host/nextjs/image-impl.d.ts +0 -10
- package/dist/internal/host/nextjs/image-impl.js +0 -40
- package/dist/internal/host/nextjs/image-impl.js.map +0 -1
|
@@ -1,55 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createRemoteImageLoader } from "#internal/host/shared/remote-image-loader";
|
|
2
3
|
import { logWarn } from "#internal/utils/logger";
|
|
3
|
-
function applyBundleUrlToSrc(bundle, src) {
|
|
4
|
-
const self = globalThis;
|
|
5
|
-
if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
|
|
6
|
-
return src;
|
|
7
|
-
}
|
|
8
|
-
const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
|
|
9
|
-
if (!path) {
|
|
10
|
-
return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
|
|
11
|
-
}
|
|
12
|
-
return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
|
|
13
|
-
}
|
|
14
|
-
function applyBundleUrlToImagePropsSrc(bundle, src) {
|
|
15
|
-
if (typeof src === "string") {
|
|
16
|
-
return applyBundleUrlToSrc(bundle, src);
|
|
17
|
-
}
|
|
18
|
-
const propSrc = src;
|
|
19
|
-
return applyBundleUrlToSrc(bundle, propSrc.src);
|
|
20
|
-
}
|
|
21
|
-
const imageImpl = (bundle, resolveClientUrl) => function RemoteImage({
|
|
22
|
-
fill: _fill,
|
|
23
|
-
loader: _loader,
|
|
24
|
-
quality: _quality,
|
|
25
|
-
priority: _priority,
|
|
26
|
-
loading: _loading,
|
|
27
|
-
placeholder: _placeholder,
|
|
28
|
-
blurDataURL: _blurDataURL,
|
|
29
|
-
unoptimized: _unoptimized,
|
|
30
|
-
overrideSrc: _overrideSrc,
|
|
31
|
-
src,
|
|
32
|
-
...props
|
|
33
|
-
}) {
|
|
34
|
-
const newSrc = applyBundleUrlToImagePropsSrc(
|
|
35
|
-
bundle,
|
|
36
|
-
typeof src === "string" ? src : src.src
|
|
37
|
-
);
|
|
38
|
-
const proxiedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
|
|
39
|
-
return (
|
|
40
|
-
// eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
|
|
41
|
-
/* @__PURE__ */ jsx(
|
|
42
|
-
"img",
|
|
43
|
-
{
|
|
44
|
-
decoding: "async",
|
|
45
|
-
style: { color: "transparent" },
|
|
46
|
-
...props,
|
|
47
|
-
src: proxiedSrc,
|
|
48
|
-
suppressHydrationWarning: true
|
|
49
|
-
}
|
|
50
|
-
)
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
4
|
function sharedPolyfills(shared, resolveClientUrl) {
|
|
54
5
|
const self = globalThis;
|
|
55
6
|
const polyfill = {
|
|
@@ -140,17 +91,13 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
140
91
|
},
|
|
141
92
|
__esModule: true
|
|
142
93
|
})),
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
throw new Error(
|
|
151
|
-
"Next.js getImageProps() is not implemented in remote components"
|
|
152
|
-
);
|
|
153
|
-
},
|
|
94
|
+
// Instead of replacing next/image entirely, we let the real Next.js Image
|
|
95
|
+
// component load from the remote bundle and only replace its default loader.
|
|
96
|
+
// This gives us full next/image fidelity (fill, priority, srcSet, blur
|
|
97
|
+
// placeholders, error handling) while routing image optimization through the
|
|
98
|
+
// remote app's /_next/image endpoint.
|
|
99
|
+
"next/dist/shared/lib/image-loader": self.__remote_component_host_shared_modules__?.["next/dist/shared/lib/image-loader"] ?? shared?.["next/dist/shared/lib/image-loader"] ?? ((bundle) => Promise.resolve({
|
|
100
|
+
default: createRemoteImageLoader(bundle, resolveClientUrl),
|
|
154
101
|
__esModule: true
|
|
155
102
|
})),
|
|
156
103
|
"next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
|
|
@@ -190,12 +137,11 @@ function sharedPolyfills(shared, resolveClientUrl) {
|
|
|
190
137
|
polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
|
|
191
138
|
polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
|
|
192
139
|
polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
|
|
193
|
-
polyfill["next/dist/
|
|
140
|
+
polyfill["next/dist/esm/shared/lib/image-loader"] = polyfill["next/dist/shared/lib/image-loader"];
|
|
194
141
|
polyfill["next/script"] = polyfill["next/dist/client/script"];
|
|
195
142
|
return polyfill;
|
|
196
143
|
}
|
|
197
144
|
export {
|
|
198
|
-
applyBundleUrlToImagePropsSrc,
|
|
199
145
|
sharedPolyfills
|
|
200
146
|
};
|
|
201
147
|
//# sourceMappingURL=polyfill.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/host/shared/polyfill.tsx"],"sourcesContent":["import type { ImageProps, StaticImageData } from 'next/image';\nimport type { LinkProps } from 'next/link';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\nimport { logWarn } from '#internal/utils/logger';\n\nfunction applyBundleUrlToSrc(bundle: string, src: string) {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n\n if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {\n return src;\n }\n\n const { assetPrefix, path } =\n /^(?<assetPrefix>.*?)\\/_next\\/(?<path>.*)/.exec(src)?.groups ?? {};\n if (!path) {\n return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;\n }\n return `${\n self.__remote_bundle_url__?.[bundle]?.origin ?? ''\n }${assetPrefix}/_next/${path}`;\n}\n\nexport function applyBundleUrlToImagePropsSrc(\n bundle: string,\n src: ImageProps['src'],\n) {\n if (typeof src === 'string') {\n return applyBundleUrlToSrc(bundle, src);\n }\n const propSrc = src as StaticImageData;\n return applyBundleUrlToSrc(bundle, propSrc.src);\n}\n\nconst imageImpl = (\n bundle: string,\n resolveClientUrl?: InternalResolveClientUrl,\n) =>\n function RemoteImage({\n fill: _fill,\n loader: _loader,\n quality: _quality,\n priority: _priority,\n loading: _loading,\n placeholder: _placeholder,\n blurDataURL: _blurDataURL,\n unoptimized: _unoptimized,\n overrideSrc: _overrideSrc,\n src,\n ...props\n }: ImageProps) {\n const newSrc = applyBundleUrlToImagePropsSrc(\n bundle,\n typeof src === 'string' ? src : (src as StaticImageData).src,\n );\n const proxiedSrc = resolveClientUrl?.(newSrc) ?? newSrc;\n\n return (\n // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text\n <img\n decoding=\"async\"\n style={{ color: 'transparent' }}\n {...props}\n src={proxiedSrc}\n suppressHydrationWarning\n />\n );\n };\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const self = globalThis as typeof globalThis & {\n __remote_component_host_shared_modules__?: Record<\n string,\n () => Promise<unknown>\n >;\n };\n const polyfill = {\n 'next/dist/client/components/navigation':\n self.__remote_component_host_shared_modules__?.['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n usePathname() {\n return location.pathname;\n },\n useParams() {\n return {};\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n useSelectedLayoutSegment() {\n return null;\n },\n useSelectedLayoutSegments() {\n return [];\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n self.__remote_component_host_shared_modules__?.['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n scroll: _,\n replace,\n prefetch,\n onNavigate,\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => {\n if (prefetch) {\n logWarn(\n 'Polyfill',\n 'Next.js Link prefetch is not supported in remote components',\n );\n }\n return (\n <a\n {...props}\n href={props.href as string}\n onClick={(e) => {\n e.preventDefault();\n let preventDefaulted = false;\n e.preventDefault = () => {\n preventDefaulted = true;\n e.defaultPrevented = true;\n };\n if (typeof props.onClick === 'function') {\n props.onClick(e);\n }\n onNavigate?.(e);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (preventDefaulted) {\n return;\n }\n if (replace) {\n history.replaceState({}, '', props.href as string);\n } else {\n history.pushState({}, '', props.href as string);\n }\n }}\n suppressHydrationWarning\n >\n {children ?? null}\n </a>\n );\n },\n useLinkStatus() {\n return { pending: false };\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n self.__remote_component_host_shared_modules__?.['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n 'next/dist/client/image-component':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n Image: imageImpl(bundle, resolveClientUrl),\n __esModule: true,\n })),\n 'next/image':\n self.__remote_component_host_shared_modules__?.['next/image'] ??\n shared?.['next/image'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: imageImpl(bundle, resolveClientUrl),\n getImageProps: (_imgProps: ImageProps) => {\n throw new Error(\n 'Next.js getImageProps() is not implemented in remote components',\n );\n },\n __esModule: true,\n })),\n 'next/dist/client/script':\n self.__remote_component_host_shared_modules__?.['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n self.__remote_component_host_shared_modules__?.['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n 'next/dist/build/polyfills/process': () =>\n Promise.resolve({\n default: {\n env: {\n NODE_ENV: 'production',\n },\n },\n __esModule: true,\n }),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/api/image'] = polyfill[\n 'next/dist/client/image-component'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;\n\n return polyfill;\n}\n"],"mappings":"AA4DM;AAzDN,SAAS,eAAe;AAExB,SAAS,oBAAoB,QAAgB,KAAa;AACxD,QAAM,OAAO;AAIb,MAAI,KAAK,wBAAwB,MAAM,GAAG,WAAW,SAAS,QAAQ;AACpE,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,aAAa,KAAK,IACxB,2CAA2C,KAAK,GAAG,GAAG,UAAU,CAAC;AACnE,MAAI,CAAC,MAAM;AACT,WAAO,IAAI,IAAI,KAAK,KAAK,wBAAwB,MAAM,GAAG,MAAM,EAAE;AAAA,EACpE;AACA,SAAO,GACL,KAAK,wBAAwB,MAAM,GAAG,UAAU,KAC/C,qBAAqB;AAC1B;AAEO,SAAS,8BACd,QACA,KACA;AACA,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,oBAAoB,QAAQ,GAAG;AAAA,EACxC;AACA,QAAM,UAAU;AAChB,SAAO,oBAAoB,QAAQ,QAAQ,GAAG;AAChD;AAEA,MAAM,YAAY,CAChB,QACA,qBAEA,SAAS,YAAY;AAAA,EACnB,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb,aAAa;AAAA,EACb;AAAA,EACA,GAAG;AACL,GAAe;AACb,QAAM,SAAS;AAAA,IACb;AAAA,IACA,OAAO,QAAQ,WAAW,MAAO,IAAwB;AAAA,EAC3D;A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IACL,2BACE,KAAK,2CAA2C,aAAa,KAC7D,SAAS,aAAa,MACrB,MACC,QAAQ,QAAQ;AAAA;AAAA;AAAA,MAGd,SAAS,MAAM;AAAA,MACf,YAAY;AAAA,IACd,CAAC;AAAA,IACL,eACE,KAAK,2CAA2C,aAAa,KAC7D,SAAS,aAAa,MACrB;AAAA;AAAA,MAEC,QAAQ,QAAQ;AAAA,QACd,YAAY;AACV,iBAAO;AAAA,YACL,MAAM,CAAC,cAAsB;AAC3B,sBAAQ,UAAU,CAAC,GAAG,IAAI,SAAS;AAAA,YACrC;AAAA,YACA,SAAS,CAAC,cAAsB;AAC9B,sBAAQ,aAAa,CAAC,GAAG,IAAI,SAAS;AAAA,YACxC;AAAA,YACA,MAAM,MAAM;AACV,sBAAQ,KAAK;AAAA,YACf;AAAA,UACF;AAAA,QACF;AAAA,QACA,YAAY;AAAA,MACd,CAAC;AAAA;AAAA,IACL,qCAAqC,MACnC,QAAQ,QAAQ;AAAA,MACd,SAAS;AAAA,QACP,KAAK;AAAA,UACH,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,MACA,YAAY;AAAA,IACd,CAAC;AAAA,EACL;AAEA,WAAS,iBAAiB,IAAI,SAC5B,wCACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,qBAAqB,IAAI,SAChC,kCACF;AACA,WAAS,aAAa,IAAI,SACxB,yBACF;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/polyfill.tsx"],"sourcesContent":["import type { LinkProps } from 'next/link';\nimport { createRemoteImageLoader } from '#internal/host/shared/remote-image-loader';\nimport type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\nimport { logWarn } from '#internal/utils/logger';\n\n// polyfill Next.js App Router client API (minimal)\n// implementations are minimal and do not cover all use cases\n// developer can override these shared modules from configuration\nexport function sharedPolyfills(\n shared?: Record<string, () => Promise<unknown>>,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const self = globalThis as typeof globalThis & {\n __remote_component_host_shared_modules__?: Record<\n string,\n () => Promise<unknown>\n >;\n };\n const polyfill = {\n 'next/dist/client/components/navigation':\n self.__remote_component_host_shared_modules__?.['next/navigation'] ??\n shared?.['next/navigation'] ??\n (() =>\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n usePathname() {\n return location.pathname;\n },\n useParams() {\n return {};\n },\n useSearchParams() {\n return new URLSearchParams(location.search);\n },\n useSelectedLayoutSegment() {\n return null;\n },\n useSelectedLayoutSegments() {\n return [];\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/link':\n self.__remote_component_host_shared_modules__?.['next/link'] ??\n shared?.['next/link'] ??\n (() =>\n Promise.resolve({\n default: ({\n scroll: _,\n replace,\n prefetch,\n onNavigate,\n children,\n ...props\n }: React.PropsWithChildren<LinkProps>) => {\n if (prefetch) {\n logWarn(\n 'Polyfill',\n 'Next.js Link prefetch is not supported in remote components',\n );\n }\n return (\n <a\n {...props}\n href={props.href as string}\n onClick={(e) => {\n e.preventDefault();\n let preventDefaulted = false;\n e.preventDefault = () => {\n preventDefaulted = true;\n e.defaultPrevented = true;\n };\n if (typeof props.onClick === 'function') {\n props.onClick(e);\n }\n onNavigate?.(e);\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (preventDefaulted) {\n return;\n }\n if (replace) {\n history.replaceState({}, '', props.href as string);\n } else {\n history.pushState({}, '', props.href as string);\n }\n }}\n suppressHydrationWarning\n >\n {children ?? null}\n </a>\n );\n },\n useLinkStatus() {\n return { pending: false };\n },\n __esModule: true,\n })),\n 'next/dist/client/app-dir/form':\n self.__remote_component_host_shared_modules__?.['next/form'] ??\n shared?.['next/form'] ??\n (() =>\n Promise.resolve({\n default: () => {\n // TODO: implement <Form> component for non-Next.js host applications\n throw new Error('Next.js <Form> component not implemented');\n },\n __esModule: true,\n })),\n // Instead of replacing next/image entirely, we let the real Next.js Image\n // component load from the remote bundle and only replace its default loader.\n // This gives us full next/image fidelity (fill, priority, srcSet, blur\n // placeholders, error handling) while routing image optimization through the\n // remote app's /_next/image endpoint.\n 'next/dist/shared/lib/image-loader':\n self.__remote_component_host_shared_modules__?.[\n 'next/dist/shared/lib/image-loader'\n ] ??\n shared?.['next/dist/shared/lib/image-loader'] ??\n ((bundle: string) =>\n Promise.resolve({\n default: createRemoteImageLoader(bundle, resolveClientUrl),\n __esModule: true,\n })),\n 'next/dist/client/script':\n self.__remote_component_host_shared_modules__?.['next/script'] ??\n shared?.['next/script'] ??\n (() =>\n Promise.resolve({\n // TODO: implement <Script> component for non-Next.js host applications\n // do not throw an error for now\n default: () => null,\n __esModule: true,\n })),\n 'next/router':\n self.__remote_component_host_shared_modules__?.['next/router'] ??\n shared?.['next/router'] ??\n (() =>\n // TODO: incomplete implementation\n Promise.resolve({\n useRouter() {\n return {\n push: (routerUrl: string) => {\n history.pushState({}, '', routerUrl);\n },\n replace: (routerUrl: string) => {\n history.replaceState({}, '', routerUrl);\n },\n back: () => {\n history.back();\n },\n };\n },\n __esModule: true,\n })),\n 'next/dist/build/polyfills/process': () =>\n Promise.resolve({\n default: {\n env: {\n NODE_ENV: 'production',\n },\n },\n __esModule: true,\n }),\n } as Record<string, () => Promise<unknown>>;\n\n polyfill['next/navigation'] = polyfill[\n 'next/dist/client/components/navigation'\n ] as () => Promise<unknown>;\n polyfill['next/link'] = polyfill[\n 'next/dist/client/app-dir/link'\n ] as () => Promise<unknown>;\n polyfill['next/form'] = polyfill[\n 'next/dist/client/app-dir/form'\n ] as () => Promise<unknown>;\n polyfill['next/dist/esm/shared/lib/image-loader'] = polyfill[\n 'next/dist/shared/lib/image-loader'\n ] as () => Promise<unknown>;\n polyfill['next/script'] = polyfill[\n 'next/dist/client/script'\n ] as () => Promise<unknown>;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C;AAAA,YACA,SAAS,CAAC,cAAsB;AAC9B,sBAAQ,aAAa,CAAC,GAAG,IAAI,SAAS;AAAA,YACxC;AAAA,YACA,MAAM,MAAM;AACV,sBAAQ,KAAK;AAAA,YACf;AAAA,UACF;AAAA,QACF;AAAA,QACA,YAAY;AAAA,MACd,CAAC;AAAA;AAAA,IACL,qCAAqC,MACnC,QAAQ,QAAQ;AAAA,MACd,SAAS;AAAA,QACP,KAAK;AAAA,UACH,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,MACA,YAAY;AAAA,IACd,CAAC;AAAA,EACL;AAEA,WAAS,iBAAiB,IAAI,SAC5B,wCACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,WAAW,IAAI,SACtB,+BACF;AACA,WAAS,uCAAuC,IAAI,SAClD,mCACF;AACA,WAAS,aAAa,IAAI,SACxB,yBACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var remote_image_loader_exports = {};
|
|
20
|
+
__export(remote_image_loader_exports, {
|
|
21
|
+
createRemoteImageLoader: () => createRemoteImageLoader
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(remote_image_loader_exports);
|
|
24
|
+
function getRemoteBundleOrigin(bundle) {
|
|
25
|
+
const self = globalThis;
|
|
26
|
+
return self.__remote_bundle_url__?.[bundle]?.origin ?? "";
|
|
27
|
+
}
|
|
28
|
+
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
29
|
+
const loader = Object.assign(
|
|
30
|
+
({
|
|
31
|
+
config,
|
|
32
|
+
src,
|
|
33
|
+
width,
|
|
34
|
+
quality
|
|
35
|
+
}) => {
|
|
36
|
+
const q = quality ?? 75;
|
|
37
|
+
const remoteOrigin = getRemoteBundleOrigin(bundle);
|
|
38
|
+
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
39
|
+
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
40
|
+
const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
41
|
+
return resolveClientUrl?.(url) ?? url;
|
|
42
|
+
},
|
|
43
|
+
// Signals to getImgProps that this is a default loader (not a user-defined
|
|
44
|
+
// one), enabling srcSet generation with device/image sizes from the config.
|
|
45
|
+
{ __next_img_default: true }
|
|
46
|
+
);
|
|
47
|
+
return loader;
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
createRemoteImageLoader
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=remote-image-loader.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/remote-image-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\nfunction getRemoteBundleOrigin(bundle: string): string {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n return self.__remote_bundle_url__?.[bundle]?.origin ?? '';\n}\n\n/**\n * Replacement for `next/dist/shared/lib/image-loader`.\n *\n * Uses `config.path` (which includes the remote's asset prefix, e.g.\n * `/vc-ap-xxx/_next/image`) to generate URLs that match the server-rendered\n * HTML and avoid hydration mismatches. Under the microfrontends proxy these\n * relative paths are routed to the correct app.\n *\n * For cross-origin deployments (standalone host on a different domain),\n * `config.path` is a relative path that would incorrectly resolve to the host\n * origin, so we prefix it with the remote origin to produce an absolute URL\n * pointing at the remote's optimizer.\n *\n * When `resolveClientUrl` is provided (deployment protection), the final URL\n * is routed through the host's proxy.\n */\nexport function createRemoteImageLoader(\n bundle: string,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const loader = Object.assign(\n ({\n config,\n src,\n width,\n quality,\n }: {\n config: { path?: string };\n src: string;\n width: number;\n quality?: number;\n }) => {\n const q = quality ?? 75;\n const remoteOrigin = getRemoteBundleOrigin(bundle);\n const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;\n const basePath = isCrossOrigin\n ? `${remoteOrigin}${config.path ?? '/_next/image'}`\n : (config.path ?? `${remoteOrigin}/_next/image`);\n const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;\n return resolveClientUrl?.(url) ?? url;\n },\n // Signals to getImgProps that this is a default loader (not a user-defined\n // one), enabling srcSet generation with device/image sizes from the config.\n { __next_img_default: true as const },\n );\n return loader;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,SAAS,sBAAsB,QAAwB;AACrD,QAAM,OAAO;AAGb,SAAO,KAAK,wBAAwB,MAAM,GAAG,UAAU;AACzD;AAkBO,SAAS,wBACd,QACA,kBACA;AACA,QAAM,SAAS,OAAO;AAAA,IACpB,CAAC;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,MAKM;AACJ,YAAM,IAAI,WAAW;AACrB,YAAM,eAAe,sBAAsB,MAAM;AACjD,YAAM,gBAAgB,gBAAgB,iBAAiB,SAAS;AAChE,YAAM,WAAW,gBACb,GAAG,eAAe,OAAO,QAAQ,mBAChC,OAAO,QAAQ,GAAG;AACvB,YAAM,MAAM,GAAG,gBAAgB,mBAAmB,GAAG,OAAO,WAAW;AACvE,aAAO,mBAAmB,GAAG,KAAK;AAAA,IACpC;AAAA;AAAA;AAAA,IAGA,EAAE,oBAAoB,KAAc;AAAA,EACtC;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { InternalResolveClientUrl } from '../../runtime/url/resolve-client-url.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replacement for `next/dist/shared/lib/image-loader`.
|
|
5
|
+
*
|
|
6
|
+
* Uses `config.path` (which includes the remote's asset prefix, e.g.
|
|
7
|
+
* `/vc-ap-xxx/_next/image`) to generate URLs that match the server-rendered
|
|
8
|
+
* HTML and avoid hydration mismatches. Under the microfrontends proxy these
|
|
9
|
+
* relative paths are routed to the correct app.
|
|
10
|
+
*
|
|
11
|
+
* For cross-origin deployments (standalone host on a different domain),
|
|
12
|
+
* `config.path` is a relative path that would incorrectly resolve to the host
|
|
13
|
+
* origin, so we prefix it with the remote origin to produce an absolute URL
|
|
14
|
+
* pointing at the remote's optimizer.
|
|
15
|
+
*
|
|
16
|
+
* When `resolveClientUrl` is provided (deployment protection), the final URL
|
|
17
|
+
* is routed through the host's proxy.
|
|
18
|
+
*/
|
|
19
|
+
declare function createRemoteImageLoader(bundle: string, resolveClientUrl?: InternalResolveClientUrl): (({ config, src, width, quality, }: {
|
|
20
|
+
config: {
|
|
21
|
+
path?: string;
|
|
22
|
+
};
|
|
23
|
+
src: string;
|
|
24
|
+
width: number;
|
|
25
|
+
quality?: number;
|
|
26
|
+
}) => string) & {
|
|
27
|
+
__next_img_default: true;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { createRemoteImageLoader };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function getRemoteBundleOrigin(bundle) {
|
|
2
|
+
const self = globalThis;
|
|
3
|
+
return self.__remote_bundle_url__?.[bundle]?.origin ?? "";
|
|
4
|
+
}
|
|
5
|
+
function createRemoteImageLoader(bundle, resolveClientUrl) {
|
|
6
|
+
const loader = Object.assign(
|
|
7
|
+
({
|
|
8
|
+
config,
|
|
9
|
+
src,
|
|
10
|
+
width,
|
|
11
|
+
quality
|
|
12
|
+
}) => {
|
|
13
|
+
const q = quality ?? 75;
|
|
14
|
+
const remoteOrigin = getRemoteBundleOrigin(bundle);
|
|
15
|
+
const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;
|
|
16
|
+
const basePath = isCrossOrigin ? `${remoteOrigin}${config.path ?? "/_next/image"}` : config.path ?? `${remoteOrigin}/_next/image`;
|
|
17
|
+
const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;
|
|
18
|
+
return resolveClientUrl?.(url) ?? url;
|
|
19
|
+
},
|
|
20
|
+
// Signals to getImgProps that this is a default loader (not a user-defined
|
|
21
|
+
// one), enabling srcSet generation with device/image sizes from the config.
|
|
22
|
+
{ __next_img_default: true }
|
|
23
|
+
);
|
|
24
|
+
return loader;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
createRemoteImageLoader
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=remote-image-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/remote-image-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/runtime/url/resolve-client-url';\n\nfunction getRemoteBundleOrigin(bundle: string): string {\n const self = globalThis as typeof globalThis & {\n __remote_bundle_url__?: Record<string, URL>;\n };\n return self.__remote_bundle_url__?.[bundle]?.origin ?? '';\n}\n\n/**\n * Replacement for `next/dist/shared/lib/image-loader`.\n *\n * Uses `config.path` (which includes the remote's asset prefix, e.g.\n * `/vc-ap-xxx/_next/image`) to generate URLs that match the server-rendered\n * HTML and avoid hydration mismatches. Under the microfrontends proxy these\n * relative paths are routed to the correct app.\n *\n * For cross-origin deployments (standalone host on a different domain),\n * `config.path` is a relative path that would incorrectly resolve to the host\n * origin, so we prefix it with the remote origin to produce an absolute URL\n * pointing at the remote's optimizer.\n *\n * When `resolveClientUrl` is provided (deployment protection), the final URL\n * is routed through the host's proxy.\n */\nexport function createRemoteImageLoader(\n bundle: string,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const loader = Object.assign(\n ({\n config,\n src,\n width,\n quality,\n }: {\n config: { path?: string };\n src: string;\n width: number;\n quality?: number;\n }) => {\n const q = quality ?? 75;\n const remoteOrigin = getRemoteBundleOrigin(bundle);\n const isCrossOrigin = remoteOrigin && remoteOrigin !== location.origin;\n const basePath = isCrossOrigin\n ? `${remoteOrigin}${config.path ?? '/_next/image'}`\n : (config.path ?? `${remoteOrigin}/_next/image`);\n const url = `${basePath}?url=${encodeURIComponent(src)}&w=${width}&q=${q}`;\n return resolveClientUrl?.(url) ?? url;\n },\n // Signals to getImgProps that this is a default loader (not a user-defined\n // one), enabling srcSet generation with device/image sizes from the config.\n { __next_img_default: true as const },\n );\n return loader;\n}\n"],"mappings":"AAEA,SAAS,sBAAsB,QAAwB;AACrD,QAAM,OAAO;AAGb,SAAO,KAAK,wBAAwB,MAAM,GAAG,UAAU;AACzD;AAkBO,SAAS,wBACd,QACA,kBACA;AACA,QAAM,SAAS,OAAO;AAAA,IACpB,CAAC;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,MAKM;AACJ,YAAM,IAAI,WAAW;AACrB,YAAM,eAAe,sBAAsB,MAAM;AACjD,YAAM,gBAAgB,gBAAgB,iBAAiB,SAAS;AAChE,YAAM,WAAW,gBACb,GAAG,eAAe,OAAO,QAAQ,mBAChC,OAAO,QAAQ,GAAG;AACvB,YAAM,MAAM,GAAG,gBAAgB,mBAAmB,GAAG,OAAO,WAAW;AACvE,aAAO,mBAAmB,GAAG,KAAK;AAAA,IACpC;AAAA;AAAA;AAAA,IAGA,EAAE,oBAAoB,KAAc;AAAA,EACtC;AACA,SAAO;AACT;","names":[]}
|
|
@@ -18,9 +18,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var constants_exports = {};
|
|
20
20
|
__export(constants_exports, {
|
|
21
|
+
DEFAULT_BUNDLE_NAME: () => DEFAULT_BUNDLE_NAME,
|
|
22
|
+
DEFAULT_COMPONENT_NAME: () => DEFAULT_COMPONENT_NAME,
|
|
21
23
|
DEFAULT_ROUTE: () => DEFAULT_ROUTE,
|
|
22
|
-
NEXT_BUNDLE_PATH_RE: () => NEXT_BUNDLE_PATH_RE,
|
|
23
|
-
REMOTE_COMPONENT_REGEX: () => REMOTE_COMPONENT_REGEX,
|
|
24
24
|
RUNTIME_SCRIPT: () => RUNTIME_SCRIPT,
|
|
25
25
|
RUNTIME_TURBOPACK: () => RUNTIME_TURBOPACK,
|
|
26
26
|
RUNTIME_WEBPACK: () => RUNTIME_WEBPACK,
|
|
@@ -28,20 +28,20 @@ __export(constants_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(constants_exports);
|
|
30
30
|
var import_utils = require("#internal/utils");
|
|
31
|
+
const DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
|
|
32
|
+
const DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
|
|
31
33
|
const DEFAULT_ROUTE = "/";
|
|
32
34
|
const RUNTIME_WEBPACK = "webpack";
|
|
33
35
|
const RUNTIME_TURBOPACK = "turbopack";
|
|
34
36
|
const RUNTIME_SCRIPT = "script";
|
|
35
|
-
const REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
36
|
-
const NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
37
37
|
function getBundleKey(bundle) {
|
|
38
38
|
return (0, import_utils.escapeString)(bundle);
|
|
39
39
|
}
|
|
40
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
41
|
0 && (module.exports = {
|
|
42
|
+
DEFAULT_BUNDLE_NAME,
|
|
43
|
+
DEFAULT_COMPONENT_NAME,
|
|
42
44
|
DEFAULT_ROUTE,
|
|
43
|
-
NEXT_BUNDLE_PATH_RE,
|
|
44
|
-
REMOTE_COMPONENT_REGEX,
|
|
45
45
|
RUNTIME_SCRIPT,
|
|
46
46
|
RUNTIME_TURBOPACK,
|
|
47
47
|
RUNTIME_WEBPACK,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/constants.ts"],"sourcesContent":["import { escapeString } from '#internal/utils';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/constants.ts"],"sourcesContent":["import { escapeString } from '#internal/utils';\n\nexport const DEFAULT_BUNDLE_NAME = '__vercel_remote_bundle';\nexport const DEFAULT_COMPONENT_NAME = '__vercel_remote_component';\nexport const DEFAULT_ROUTE = '/';\n\nexport const RUNTIME_WEBPACK = 'webpack';\nexport const RUNTIME_TURBOPACK = 'turbopack';\nexport const RUNTIME_SCRIPT = 'script';\n\nexport function getBundleKey(bundle: string): string {\n return escapeString(bundle);\n}\n\nexport type Runtime =\n | typeof RUNTIME_WEBPACK\n | typeof RUNTIME_TURBOPACK\n | typeof RUNTIME_SCRIPT;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6B;AAEtB,MAAM,sBAAsB;AAC5B,MAAM,yBAAyB;AAC/B,MAAM,gBAAgB;AAEtB,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AAEvB,SAAS,aAAa,QAAwB;AACnD,aAAO,2BAAa,MAAM;AAC5B;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
declare const DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
|
|
2
|
+
declare const DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
|
|
1
3
|
declare const DEFAULT_ROUTE = "/";
|
|
2
4
|
declare const RUNTIME_WEBPACK = "webpack";
|
|
3
5
|
declare const RUNTIME_TURBOPACK = "turbopack";
|
|
4
6
|
declare const RUNTIME_SCRIPT = "script";
|
|
5
|
-
declare const REMOTE_COMPONENT_REGEX: RegExp;
|
|
6
|
-
declare const NEXT_BUNDLE_PATH_RE: RegExp;
|
|
7
7
|
declare function getBundleKey(bundle: string): string;
|
|
8
8
|
type Runtime = typeof RUNTIME_WEBPACK | typeof RUNTIME_TURBOPACK | typeof RUNTIME_SCRIPT;
|
|
9
9
|
|
|
10
|
-
export {
|
|
10
|
+
export { DEFAULT_BUNDLE_NAME, DEFAULT_COMPONENT_NAME, DEFAULT_ROUTE, RUNTIME_SCRIPT, RUNTIME_TURBOPACK, RUNTIME_WEBPACK, Runtime, getBundleKey };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { escapeString } from "#internal/utils";
|
|
2
|
+
const DEFAULT_BUNDLE_NAME = "__vercel_remote_bundle";
|
|
3
|
+
const DEFAULT_COMPONENT_NAME = "__vercel_remote_component";
|
|
2
4
|
const DEFAULT_ROUTE = "/";
|
|
3
5
|
const RUNTIME_WEBPACK = "webpack";
|
|
4
6
|
const RUNTIME_TURBOPACK = "turbopack";
|
|
5
7
|
const RUNTIME_SCRIPT = "script";
|
|
6
|
-
const REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
7
|
-
const NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
8
8
|
function getBundleKey(bundle) {
|
|
9
9
|
return escapeString(bundle);
|
|
10
10
|
}
|
|
11
11
|
export {
|
|
12
|
+
DEFAULT_BUNDLE_NAME,
|
|
13
|
+
DEFAULT_COMPONENT_NAME,
|
|
12
14
|
DEFAULT_ROUTE,
|
|
13
|
-
NEXT_BUNDLE_PATH_RE,
|
|
14
|
-
REMOTE_COMPONENT_REGEX,
|
|
15
15
|
RUNTIME_SCRIPT,
|
|
16
16
|
RUNTIME_TURBOPACK,
|
|
17
17
|
RUNTIME_WEBPACK,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/constants.ts"],"sourcesContent":["import { escapeString } from '#internal/utils';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/constants.ts"],"sourcesContent":["import { escapeString } from '#internal/utils';\n\nexport const DEFAULT_BUNDLE_NAME = '__vercel_remote_bundle';\nexport const DEFAULT_COMPONENT_NAME = '__vercel_remote_component';\nexport const DEFAULT_ROUTE = '/';\n\nexport const RUNTIME_WEBPACK = 'webpack';\nexport const RUNTIME_TURBOPACK = 'turbopack';\nexport const RUNTIME_SCRIPT = 'script';\n\nexport function getBundleKey(bundle: string): string {\n return escapeString(bundle);\n}\n\nexport type Runtime =\n | typeof RUNTIME_WEBPACK\n | typeof RUNTIME_TURBOPACK\n | typeof RUNTIME_SCRIPT;\n"],"mappings":"AAAA,SAAS,oBAAoB;AAEtB,MAAM,sBAAsB;AAC5B,MAAM,yBAAyB;AAC/B,MAAM,gBAAgB;AAEtB,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AAEvB,SAAS,aAAa,QAAwB;AACnD,SAAO,aAAa,MAAM;AAC5B;","names":[]}
|
|
@@ -18,7 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var parse_remote_html_exports = {};
|
|
20
20
|
__export(parse_remote_html_exports, {
|
|
21
|
-
extractComponentMetadata: () => extractComponentMetadata,
|
|
22
21
|
extractLinks: () => extractLinks,
|
|
23
22
|
extractRemoteShared: () => extractRemoteShared,
|
|
24
23
|
extractScripts: () => extractScripts,
|
|
@@ -31,6 +30,7 @@ __export(parse_remote_html_exports, {
|
|
|
31
30
|
});
|
|
32
31
|
module.exports = __toCommonJS(parse_remote_html_exports);
|
|
33
32
|
var import_constants = require("#internal/runtime/constants");
|
|
33
|
+
var import_metadata = require("#internal/runtime/metadata");
|
|
34
34
|
var import_error = require("#internal/utils/error");
|
|
35
35
|
function validateSingleComponent(doc, name, url) {
|
|
36
36
|
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
|
|
@@ -50,14 +50,6 @@ function resolveComponentName(component, nextData, fallbackName) {
|
|
|
50
50
|
const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
51
51
|
return { name, isRemoteComponent };
|
|
52
52
|
}
|
|
53
|
-
function extractComponentMetadata(component, nextData, name, url) {
|
|
54
|
-
return {
|
|
55
|
-
name,
|
|
56
|
-
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
|
|
57
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || import_constants.DEFAULT_ROUTE),
|
|
58
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || import_constants.RUNTIME_SCRIPT)
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
53
|
function extractRemoteShared(doc, name, nextData) {
|
|
62
54
|
const remoteSharedEl = doc.querySelector(
|
|
63
55
|
`#${name}_shared[data-remote-components-shared]`
|
|
@@ -69,7 +61,7 @@ function extractRemoteShared(doc, name, nextData) {
|
|
|
69
61
|
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
70
62
|
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
71
63
|
throw new import_error.RemoteComponentsError(
|
|
72
|
-
`Remote Component not found on ${url}.${name !==
|
|
64
|
+
`Remote Component not found on ${url}.${name !== import_constants.DEFAULT_COMPONENT_NAME ? ` The name for the <RemoteComponent> is "${name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
73
65
|
);
|
|
74
66
|
}
|
|
75
67
|
}
|
|
@@ -95,10 +87,15 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
95
87
|
name
|
|
96
88
|
);
|
|
97
89
|
const rsc = doc.querySelector(`#${resolvedName}_rsc`);
|
|
98
|
-
const metadata =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
const metadata = (0, import_metadata.buildMetadata)(
|
|
91
|
+
{
|
|
92
|
+
name: resolvedName,
|
|
93
|
+
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
|
|
94
|
+
route: component?.getAttribute("data-route") ?? nextData?.page,
|
|
95
|
+
runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? import_constants.RUNTIME_SCRIPT,
|
|
96
|
+
id: component?.getAttribute("id"),
|
|
97
|
+
type: component?.getAttribute("data-type")
|
|
98
|
+
},
|
|
102
99
|
url
|
|
103
100
|
);
|
|
104
101
|
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
@@ -126,7 +123,6 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
126
123
|
}
|
|
127
124
|
// Annotate the CommonJS export names for ESM import in node:
|
|
128
125
|
0 && (module.exports = {
|
|
129
|
-
extractComponentMetadata,
|
|
130
126
|
extractLinks,
|
|
131
127
|
extractRemoteShared,
|
|
132
128
|
extractScripts,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/html/parse-remote-html.ts"],"sourcesContent":["import type { NextData } from '#internal/host/server/types';\nimport { DEFAULT_ROUTE, RUNTIME_SCRIPT } from '#internal/runtime/constants';\nimport type { RemoteComponentMetadata } from '#internal/runtime/metadata';\nimport {\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\n\nexport interface ParsedRemoteComponent {\n /** The DOM element representing the remote component content. */\n component: Element;\n /** Resolved name of the remote component (with _ssr suffix stripped). */\n name: string;\n /** Whether the component is a <remote-component> custom element. */\n isRemoteComponent: boolean;\n /** Component metadata: bundle, route, runtime. */\n metadata: {\n name: string;\n bundle: string;\n route: string;\n runtime: RemoteComponentMetadata['runtime'];\n };\n /** Parsed __NEXT_DATA__ or __REMOTE_NEXT_DATA__, or null. */\n nextData: NextData | null;\n /** The RSC flight data script element, or null. */\n rsc: Element | null;\n /** Shared module map extracted from the component's shared data script. */\n remoteShared: Record<string, string>;\n /** Link elements extracted from the document (outside the component). */\n links: HTMLLinkElement[];\n /** Script elements extracted from the component or document. */\n scripts: HTMLScriptElement[];\n}\n\n/**\n * Validates that the document does not contain multiple unnamed remote components.\n * When multiple components exist, the consumer must specify a name to select one.\n */\nexport function validateSingleComponent(\n doc: Document,\n name: string,\n url: string,\n): void {\n if (\n (doc.querySelectorAll('div[data-bundle][data-route]').length > 1 &&\n !doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`)) ||\n (doc.querySelectorAll('remote-component:not([src])').length > 1 &&\n !doc.querySelector(`remote-component[name=\"${name}\"]`))\n ) {\n throw multipleRemoteComponentsError(url);\n }\n}\n\n/**\n * Finds the remote component element in the parsed HTML document using the\n * standard querySelector chain. Returns null if no component is found.\n */\nexport function findComponentElement(\n doc: Document,\n name: string,\n): Element | null {\n return (\n doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`) ??\n doc.querySelector('div[data-bundle][data-route]') ??\n doc.querySelector('div#__next') ??\n doc.querySelector(`remote-component[name=\"${name}\"]:not([src])`) ??\n doc.querySelector('remote-component:not([src])')\n );\n}\n\n/**\n * Parses the __NEXT_DATA__ or __REMOTE_NEXT_DATA__ script element from the document.\n */\nexport function parseNextData(doc: Document): NextData | null {\n return JSON.parse(\n (\n doc.querySelector('#__NEXT_DATA__') ??\n doc.querySelector('#__REMOTE_NEXT_DATA__')\n )?.textContent ?? 'null',\n ) as NextData | null;\n}\n\n/**\n * Resolves the component name from the element's id attribute, the name attribute\n * (for <remote-component> elements), nextData, or a fallback value.\n * Strips the _ssr suffix from the id if present.\n */\nexport function resolveComponentName(\n component: Element | null,\n nextData: NextData | null,\n fallbackName: string,\n): { name: string; isRemoteComponent: boolean } {\n const isRemoteComponent =\n component?.tagName.toLowerCase() === 'remote-component';\n\n const name =\n component?.getAttribute('id')?.replace(/_ssr$/, '') ||\n (isRemoteComponent && component?.getAttribute('name')) ||\n (nextData ? '__next' : fallbackName);\n\n return { name, isRemoteComponent };\n}\n\n/**\n * Extracts component metadata (bundle, route, runtime) from the component element\n * and Next.js data.\n */\nexport function extractComponentMetadata(\n component: Element | null,\n nextData: NextData | null,\n name: string,\n url: URL,\n): ParsedRemoteComponent['metadata'] {\n return {\n name,\n bundle:\n component?.getAttribute('data-bundle') ||\n nextData?.props.__REMOTE_COMPONENT__?.bundle ||\n 'default',\n route:\n component?.getAttribute('data-route') ??\n nextData?.page ??\n (url.pathname || DEFAULT_ROUTE),\n runtime: (component?.getAttribute('data-runtime') ??\n (nextData?.props.__REMOTE_COMPONENT__?.runtime ||\n RUNTIME_SCRIPT)) as RemoteComponentMetadata['runtime'],\n };\n}\n\n/**\n * Extracts the shared module map from the document and removes the element.\n * Falls back to nextData's shared modules if available.\n */\nexport function extractRemoteShared(\n doc: Document,\n name: string,\n nextData: NextData | null,\n): Record<string, string> {\n const remoteSharedEl = doc.querySelector(\n `#${name}_shared[data-remote-components-shared]`,\n );\n const remoteShared =\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n ((JSON.parse(remoteSharedEl?.textContent ?? '{}') ?? {}) as Record<\n string,\n string\n >);\n remoteSharedEl?.remove();\n return remoteShared;\n}\n\n/**\n * Validates that a remote component was found in the document and that it has\n * RSC data, Next.js data, or is a <remote-component> element.\n * Acts as a type assertion - narrows component to non-null on success.\n */\nexport function validateComponentFound(\n component: Element | null,\n rsc: Element | null,\n nextData: NextData | null,\n isRemoteComponent: boolean,\n url: string,\n name: string,\n): asserts component is Element {\n if (!component || !(rsc || nextData || isRemoteComponent)) {\n throw new RemoteComponentsError(\n `Remote Component not found on ${url}.${\n name !== '__vercel_remote_component'\n ? ` The name for the <RemoteComponent> is \"${name}\". Check <RemoteComponent> usage.`\n : ''\n } Did you forget to wrap the content in <RemoteComponent>?`,\n );\n }\n}\n\n/**\n * Extracts link elements from the document that are not inside the component.\n */\nexport function extractLinks(\n doc: Document,\n component: Element,\n): HTMLLinkElement[] {\n return Array.from(doc.querySelectorAll<HTMLLinkElement>('link[href]')).filter(\n (link) => !component.contains(link),\n );\n}\n\n/**\n * Extracts script elements from the component or document, depending on whether\n * the component is a <remote-component> custom element.\n */\nexport function extractScripts(\n doc: Document,\n component: Element,\n isRemoteComponent: boolean,\n): HTMLScriptElement[] {\n return Array.from(\n (isRemoteComponent ? component : doc).querySelectorAll<HTMLScriptElement>(\n 'script[src],script[data-src]',\n ),\n );\n}\n\n/**\n * Parses a remote component HTML document and extracts all data needed for\n * loading and hydrating the component. This is the main orchestrator that\n * calls the individual extraction functions.\n */\nexport function parseRemoteComponentDocument(\n doc: Document,\n name: string,\n url: URL,\n): ParsedRemoteComponent {\n validateSingleComponent(doc, name, url.href);\n\n const component = findComponentElement(doc, name);\n const nextData = parseNextData(doc);\n\n const { name: resolvedName, isRemoteComponent } = resolveComponentName(\n component,\n nextData,\n name,\n );\n\n const rsc = doc.querySelector(`#${resolvedName}_rsc`);\n const metadata = extractComponentMetadata(\n component,\n nextData,\n resolvedName,\n url,\n );\n const remoteShared = extractRemoteShared(doc, resolvedName, nextData);\n\n validateComponentFound(\n component,\n rsc,\n nextData,\n isRemoteComponent,\n url.href,\n resolvedName,\n );\n\n const links = extractLinks(doc, component);\n const scripts = extractScripts(doc, component, isRemoteComponent);\n\n return {\n component,\n name: resolvedName,\n isRemoteComponent,\n metadata,\n nextData,\n rsc,\n remoteShared,\n links,\n scripts,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA8C;AAE9C,mBAGO;AAgCA,SAAS,wBACd,KACA,MACA,KACM;AACN,MACG,IAAI,iBAAiB,8BAA8B,EAAE,SAAS,KAC7D,CAAC,IAAI,cAAc,qCAAqC,QAAQ,KACjE,IAAI,iBAAiB,6BAA6B,EAAE,SAAS,KAC5D,CAAC,IAAI,cAAc,0BAA0B,QAAQ,GACvD;AACA,cAAM,4CAA8B,GAAG;AAAA,EACzC;AACF;AAMO,SAAS,qBACd,KACA,MACgB;AAChB,SACE,IAAI,cAAc,qCAAqC,QAAQ,KAC/D,IAAI,cAAc,8BAA8B,KAChD,IAAI,cAAc,YAAY,KAC9B,IAAI,cAAc,0BAA0B,mBAAmB,KAC/D,IAAI,cAAc,6BAA6B;AAEnD;AAKO,SAAS,cAAc,KAAgC;AAC5D,SAAO,KAAK;AAAA,KAER,IAAI,cAAc,gBAAgB,KAClC,IAAI,cAAc,uBAAuB,IACxC,eAAe;AAAA,EACpB;AACF;AAOO,SAAS,qBACd,WACA,UACA,cAC8C;AAC9C,QAAM,oBACJ,WAAW,QAAQ,YAAY,MAAM;AAEvC,QAAM,OACJ,WAAW,aAAa,IAAI,GAAG,QAAQ,SAAS,EAAE,KACjD,qBAAqB,WAAW,aAAa,MAAM,MACnD,WAAW,WAAW;AAEzB,SAAO,EAAE,MAAM,kBAAkB;AACnC;AAMO,SAAS,yBACd,WACA,UACA,MACA,KACmC;AACnC,SAAO;AAAA,IACL;AAAA,IACA,QACE,WAAW,aAAa,aAAa,KACrC,UAAU,MAAM,sBAA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AAQ;AAEpE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,IAAI;AAAA,IACJ;AAAA,EACF;AAEA,QAAM,QAAQ,aAAa,KAAK,SAAS;AACzC,QAAM,UAAU,eAAe,KAAK,WAAW,iBAAiB;AAEhE,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/html/parse-remote-html.ts"],"sourcesContent":["import type { NextData } from '#internal/host/server/types';\nimport {\n DEFAULT_COMPONENT_NAME,\n RUNTIME_SCRIPT,\n} from '#internal/runtime/constants';\nimport {\n buildMetadata,\n type RemoteComponentMetadata,\n} from '#internal/runtime/metadata';\nimport {\n multipleRemoteComponentsError,\n RemoteComponentsError,\n} from '#internal/utils/error';\n\nexport interface ParsedRemoteComponent {\n /** The DOM element representing the remote component content. */\n component: Element;\n /** Resolved name of the remote component (with _ssr suffix stripped). */\n name: string;\n /** Whether the component is a <remote-component> custom element. */\n isRemoteComponent: boolean;\n /** Component metadata: bundle, route, runtime. */\n metadata: RemoteComponentMetadata;\n /** Parsed __NEXT_DATA__ or __REMOTE_NEXT_DATA__, or null. */\n nextData: NextData | null;\n /** The RSC flight data script element, or null. */\n rsc: Element | null;\n /** Shared module map extracted from the component's shared data script. */\n remoteShared: Record<string, string>;\n /** Link elements extracted from the document (outside the component). */\n links: HTMLLinkElement[];\n /** Script elements extracted from the component or document. */\n scripts: HTMLScriptElement[];\n}\n\n/**\n * Validates that the document does not contain multiple unnamed remote components.\n * When multiple components exist, the consumer must specify a name to select one.\n */\nexport function validateSingleComponent(\n doc: Document,\n name: string,\n url: string,\n): void {\n if (\n (doc.querySelectorAll('div[data-bundle][data-route]').length > 1 &&\n !doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`)) ||\n (doc.querySelectorAll('remote-component:not([src])').length > 1 &&\n !doc.querySelector(`remote-component[name=\"${name}\"]`))\n ) {\n throw multipleRemoteComponentsError(url);\n }\n}\n\n/**\n * Finds the remote component element in the parsed HTML document using the\n * standard querySelector chain. Returns null if no component is found.\n */\nexport function findComponentElement(\n doc: Document,\n name: string,\n): Element | null {\n return (\n doc.querySelector(`div[data-bundle][data-route][id^=\"${name}\"]`) ??\n doc.querySelector('div[data-bundle][data-route]') ??\n doc.querySelector('div#__next') ??\n doc.querySelector(`remote-component[name=\"${name}\"]:not([src])`) ??\n doc.querySelector('remote-component:not([src])')\n );\n}\n\n/**\n * Parses the __NEXT_DATA__ or __REMOTE_NEXT_DATA__ script element from the document.\n */\nexport function parseNextData(doc: Document): NextData | null {\n return JSON.parse(\n (\n doc.querySelector('#__NEXT_DATA__') ??\n doc.querySelector('#__REMOTE_NEXT_DATA__')\n )?.textContent ?? 'null',\n ) as NextData | null;\n}\n\n/**\n * Resolves the component name from the element's id attribute, the name attribute\n * (for <remote-component> elements), nextData, or a fallback value.\n * Strips the _ssr suffix from the id if present.\n */\nexport function resolveComponentName(\n component: Element | null,\n nextData: NextData | null,\n fallbackName: string,\n): { name: string; isRemoteComponent: boolean } {\n const isRemoteComponent =\n component?.tagName.toLowerCase() === 'remote-component';\n\n const name =\n component?.getAttribute('id')?.replace(/_ssr$/, '') ||\n (isRemoteComponent && component?.getAttribute('name')) ||\n (nextData ? '__next' : fallbackName);\n\n return { name, isRemoteComponent };\n}\n\n/**\n * Extracts the shared module map from the document and removes the element.\n * Falls back to nextData's shared modules if available.\n */\nexport function extractRemoteShared(\n doc: Document,\n name: string,\n nextData: NextData | null,\n): Record<string, string> {\n const remoteSharedEl = doc.querySelector(\n `#${name}_shared[data-remote-components-shared]`,\n );\n const remoteShared =\n nextData?.props.__REMOTE_COMPONENT__?.shared ??\n ((JSON.parse(remoteSharedEl?.textContent ?? '{}') ?? {}) as Record<\n string,\n string\n >);\n remoteSharedEl?.remove();\n return remoteShared;\n}\n\n/**\n * Validates that a remote component was found in the document and that it has\n * RSC data, Next.js data, or is a <remote-component> element.\n * Acts as a type assertion - narrows component to non-null on success.\n */\nexport function validateComponentFound(\n component: Element | null,\n rsc: Element | null,\n nextData: NextData | null,\n isRemoteComponent: boolean,\n url: string,\n name: string,\n): asserts component is Element {\n if (!component || !(rsc || nextData || isRemoteComponent)) {\n throw new RemoteComponentsError(\n `Remote Component not found on ${url}.${\n name !== DEFAULT_COMPONENT_NAME\n ? ` The name for the <RemoteComponent> is \"${name}\". Check <RemoteComponent> usage.`\n : ''\n } Did you forget to wrap the content in <RemoteComponent>?`,\n );\n }\n}\n\n/**\n * Extracts link elements from the document that are not inside the component.\n */\nexport function extractLinks(\n doc: Document,\n component: Element,\n): HTMLLinkElement[] {\n return Array.from(doc.querySelectorAll<HTMLLinkElement>('link[href]')).filter(\n (link) => !component.contains(link),\n );\n}\n\n/**\n * Extracts script elements from the component or document, depending on whether\n * the component is a <remote-component> custom element.\n */\nexport function extractScripts(\n doc: Document,\n component: Element,\n isRemoteComponent: boolean,\n): HTMLScriptElement[] {\n return Array.from(\n (isRemoteComponent ? component : doc).querySelectorAll<HTMLScriptElement>(\n 'script[src],script[data-src]',\n ),\n );\n}\n\n/**\n * Parses a remote component HTML document and extracts all data needed for\n * loading and hydrating the component. This is the main orchestrator that\n * calls the individual extraction functions.\n */\nexport function parseRemoteComponentDocument(\n doc: Document,\n name: string,\n url: URL,\n): ParsedRemoteComponent {\n validateSingleComponent(doc, name, url.href);\n\n const component = findComponentElement(doc, name);\n const nextData = parseNextData(doc);\n\n const { name: resolvedName, isRemoteComponent } = resolveComponentName(\n component,\n nextData,\n name,\n );\n\n const rsc = doc.querySelector(`#${resolvedName}_rsc`);\n const metadata = buildMetadata(\n {\n name: resolvedName,\n bundle:\n component?.getAttribute('data-bundle') ||\n nextData?.props.__REMOTE_COMPONENT__?.bundle,\n route: component?.getAttribute('data-route') ?? nextData?.page,\n runtime:\n component?.getAttribute('data-runtime') ??\n nextData?.props.__REMOTE_COMPONENT__?.runtime ??\n RUNTIME_SCRIPT,\n id: component?.getAttribute('id'),\n type: component?.getAttribute('data-type'),\n },\n url,\n );\n const remoteShared = extractRemoteShared(doc, resolvedName, nextData);\n\n validateComponentFound(\n component,\n rsc,\n nextData,\n isRemoteComponent,\n url.href,\n resolvedName,\n );\n\n const links = extractLinks(doc, component);\n const scripts = extractScripts(doc, component, isRemoteComponent);\n\n return {\n component,\n name: resolvedName,\n isRemoteComponent,\n metadata,\n nextData,\n rsc,\n remoteShared,\n links,\n scripts,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAGO;AACP,sBAGO;AACP,mBAGO;AA2BA,SAAS,wBACd,KACA,MACA,KACM;AACN,MACG,IAAI,iBAAiB,8BAA8B,EAAE,SAAS,KAC7D,CAAC,IAAI,cAAc,qCAAqC,QAAQ,KACjE,IAAI,iBAAiB,6BAA6B,EAAE,SAAS,KAC5D,CAAC,IAAI,cAAc,0BAA0B,QAAQ,GACvD;AACA,cAAM,4CAA8B,GAAG;AAAA,EACzC;AACF;AAMO,SAAS,qBACd,KACA,MACgB;AAChB,SACE,IAAI,cAAc,qCAAqC,QAAQ,KAC/D,IAAI,cAAc,8BAA8B,KAChD,IAAI,cAAc,YAAY,KAC9B,IAAI,cAAc,0BAA0B,mBAAmB,KAC/D,IAAI,cAAc,6BAA6B;AAEnD;AAKO,SAAS,cAAc,KAAgC;AAC5D,SAAO,KAAK;AAAA,KAER,IAAI,cAAc,gBAAgB,KAClC,IAAI,cAAc,uBAAuB,IACxC,eAAe;AAAA,EACpB;AACF;AAOO,SAAS,qBACd,WACA,UACA,cAC8C;AAC9C,QAAM,oBACJ,WAAW,QAAQ,YAAY,MAAM;AAEvC,QAAM,OACJ,WAAW,aAAa,IAAI,GAAG,QAAQ,SAAS,EAAE,KACjD,qBAAqB,WAAW,aAA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MAAM,sBAAsB,WACtC;AAAA,MACF,IAAI,WAAW,aAAa,IAAI;AAAA,MAChC,MAAM,WAAW,aAAa,WAAW;AAAA,IAC3C;AAAA,IACA;AAAA,EACF;AACA,QAAM,eAAe,oBAAoB,KAAK,cAAc,QAAQ;AAEpE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,IAAI;AAAA,IACJ;AAAA,EACF;AAEA,QAAM,QAAQ,aAAa,KAAK,SAAS;AACzC,QAAM,UAAU,eAAe,KAAK,WAAW,iBAAiB;AAEhE,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -13,12 +13,7 @@ interface ParsedRemoteComponent {
|
|
|
13
13
|
/** Whether the component is a <remote-component> custom element. */
|
|
14
14
|
isRemoteComponent: boolean;
|
|
15
15
|
/** Component metadata: bundle, route, runtime. */
|
|
16
|
-
metadata:
|
|
17
|
-
name: string;
|
|
18
|
-
bundle: string;
|
|
19
|
-
route: string;
|
|
20
|
-
runtime: RemoteComponentMetadata['runtime'];
|
|
21
|
-
};
|
|
16
|
+
metadata: RemoteComponentMetadata;
|
|
22
17
|
/** Parsed __NEXT_DATA__ or __REMOTE_NEXT_DATA__, or null. */
|
|
23
18
|
nextData: NextData | null;
|
|
24
19
|
/** The RSC flight data script element, or null. */
|
|
@@ -53,11 +48,6 @@ declare function resolveComponentName(component: Element | null, nextData: NextD
|
|
|
53
48
|
name: string;
|
|
54
49
|
isRemoteComponent: boolean;
|
|
55
50
|
};
|
|
56
|
-
/**
|
|
57
|
-
* Extracts component metadata (bundle, route, runtime) from the component element
|
|
58
|
-
* and Next.js data.
|
|
59
|
-
*/
|
|
60
|
-
declare function extractComponentMetadata(component: Element | null, nextData: NextData | null, name: string, url: URL): ParsedRemoteComponent['metadata'];
|
|
61
51
|
/**
|
|
62
52
|
* Extracts the shared module map from the document and removes the element.
|
|
63
53
|
* Falls back to nextData's shared modules if available.
|
|
@@ -85,4 +75,4 @@ declare function extractScripts(doc: Document, component: Element, isRemoteCompo
|
|
|
85
75
|
*/
|
|
86
76
|
declare function parseRemoteComponentDocument(doc: Document, name: string, url: URL): ParsedRemoteComponent;
|
|
87
77
|
|
|
88
|
-
export { ParsedRemoteComponent,
|
|
78
|
+
export { ParsedRemoteComponent, extractLinks, extractRemoteShared, extractScripts, findComponentElement, parseNextData, parseRemoteComponentDocument, resolveComponentName, validateComponentFound, validateSingleComponent };
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_COMPONENT_NAME,
|
|
3
|
+
RUNTIME_SCRIPT
|
|
4
|
+
} from "#internal/runtime/constants";
|
|
5
|
+
import {
|
|
6
|
+
buildMetadata
|
|
7
|
+
} from "#internal/runtime/metadata";
|
|
2
8
|
import {
|
|
3
9
|
multipleRemoteComponentsError,
|
|
4
10
|
RemoteComponentsError
|
|
@@ -21,14 +27,6 @@ function resolveComponentName(component, nextData, fallbackName) {
|
|
|
21
27
|
const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
22
28
|
return { name, isRemoteComponent };
|
|
23
29
|
}
|
|
24
|
-
function extractComponentMetadata(component, nextData, name, url) {
|
|
25
|
-
return {
|
|
26
|
-
name,
|
|
27
|
-
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
|
|
28
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
29
|
-
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
30
|
function extractRemoteShared(doc, name, nextData) {
|
|
33
31
|
const remoteSharedEl = doc.querySelector(
|
|
34
32
|
`#${name}_shared[data-remote-components-shared]`
|
|
@@ -40,7 +38,7 @@ function extractRemoteShared(doc, name, nextData) {
|
|
|
40
38
|
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
41
39
|
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
42
40
|
throw new RemoteComponentsError(
|
|
43
|
-
`Remote Component not found on ${url}.${name !==
|
|
41
|
+
`Remote Component not found on ${url}.${name !== DEFAULT_COMPONENT_NAME ? ` The name for the <RemoteComponent> is "${name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
44
42
|
);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
@@ -66,10 +64,15 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
66
64
|
name
|
|
67
65
|
);
|
|
68
66
|
const rsc = doc.querySelector(`#${resolvedName}_rsc`);
|
|
69
|
-
const metadata =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
const metadata = buildMetadata(
|
|
68
|
+
{
|
|
69
|
+
name: resolvedName,
|
|
70
|
+
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
|
|
71
|
+
route: component?.getAttribute("data-route") ?? nextData?.page,
|
|
72
|
+
runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
|
|
73
|
+
id: component?.getAttribute("id"),
|
|
74
|
+
type: component?.getAttribute("data-type")
|
|
75
|
+
},
|
|
73
76
|
url
|
|
74
77
|
);
|
|
75
78
|
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
@@ -96,7 +99,6 @@ function parseRemoteComponentDocument(doc, name, url) {
|
|
|
96
99
|
};
|
|
97
100
|
}
|
|
98
101
|
export {
|
|
99
|
-
extractComponentMetadata,
|
|
100
102
|
extractLinks,
|
|
101
103
|
extractRemoteShared,
|
|
102
104
|
extractScripts,
|