remote-components 0.0.50 → 0.1.0
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/{component-loader-1838f572.d.ts → component-loader-76eb1b8b.d.ts} +3 -1
- package/dist/html/host.cjs +486 -242
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.d.ts +2 -0
- package/dist/html/host.js +485 -242
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs +123 -21
- package/dist/html/remote.cjs.map +1 -1
- package/dist/html/remote.js +123 -21
- package/dist/html/remote.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +12 -3
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +11 -2
- package/dist/internal/next/host/app-router-client.js +12 -3
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/react/context.cjs +43 -0
- package/dist/internal/react/context.cjs.map +1 -0
- package/dist/internal/react/context.d.ts +20 -0
- package/dist/internal/react/context.js +18 -0
- package/dist/internal/react/context.js.map +1 -0
- package/dist/internal/react/hooks/use-resolve-client-url.cjs +39 -0
- package/dist/internal/react/hooks/use-resolve-client-url.cjs.map +1 -0
- package/dist/internal/react/hooks/use-resolve-client-url.d.ts +5 -0
- package/dist/internal/react/hooks/use-resolve-client-url.js +15 -0
- package/dist/internal/react/hooks/use-resolve-client-url.js.map +1 -0
- package/dist/internal/shared/client/apply-origin.cjs +10 -5
- package/dist/internal/shared/client/apply-origin.cjs.map +1 -1
- package/dist/internal/shared/client/apply-origin.d.ts +3 -1
- package/dist/internal/shared/client/apply-origin.js +10 -5
- package/dist/internal/shared/client/apply-origin.js.map +1 -1
- package/dist/internal/shared/client/default-resolve-client-url.cjs +32 -0
- package/dist/internal/shared/client/default-resolve-client-url.cjs.map +1 -0
- package/dist/internal/shared/client/default-resolve-client-url.d.ts +5 -0
- package/dist/internal/shared/client/default-resolve-client-url.js +10 -0
- package/dist/internal/shared/client/default-resolve-client-url.js.map +1 -0
- package/dist/internal/shared/client/protected-rc-fallback.cjs +41 -0
- package/dist/internal/shared/client/protected-rc-fallback.cjs.map +1 -0
- package/dist/internal/shared/client/protected-rc-fallback.d.ts +7 -0
- package/dist/internal/shared/client/protected-rc-fallback.js +16 -0
- package/dist/internal/shared/client/protected-rc-fallback.js.map +1 -0
- package/dist/internal/shared/client/proxy-through-host.cjs +51 -0
- package/dist/internal/shared/client/proxy-through-host.cjs.map +1 -0
- package/dist/internal/shared/client/proxy-through-host.d.ts +57 -0
- package/dist/internal/shared/client/proxy-through-host.js +26 -0
- package/dist/internal/shared/client/proxy-through-host.js.map +1 -0
- package/dist/internal/shared/client/remote-component.cjs +208 -134
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +7 -5
- package/dist/internal/shared/client/remote-component.js +207 -134
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/constants.cjs +32 -0
- package/dist/internal/shared/constants.cjs.map +1 -0
- package/dist/internal/shared/constants.d.ts +4 -0
- package/dist/internal/shared/constants.js +7 -0
- package/dist/internal/shared/constants.js.map +1 -0
- package/dist/internal/shared/error.cjs +70 -0
- package/dist/internal/shared/error.cjs.map +1 -1
- package/dist/internal/shared/error.d.ts +3 -1
- package/dist/internal/shared/error.js +71 -0
- package/dist/internal/shared/error.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +1 -2
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.js +1 -2
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs +7 -2
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.js +7 -2
- package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
- package/dist/internal/shared/utils/logger.cjs +26 -10
- package/dist/internal/shared/utils/logger.cjs.map +1 -1
- package/dist/internal/shared/utils/logger.d.ts +7 -2
- package/dist/internal/shared/utils/logger.js +24 -9
- package/dist/internal/shared/utils/logger.js.map +1 -1
- package/dist/next/config.cjs +2 -2
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +2 -2
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/client/index.cjs +363 -207
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.d.ts +3 -1
- package/dist/next/host/client/index.js +336 -181
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-client.cjs +15 -2
- package/dist/next/host/pages-router-client.cjs.map +1 -1
- package/dist/next/host/pages-router-client.d.ts +12 -1
- package/dist/next/host/pages-router-client.js +15 -2
- package/dist/next/host/pages-router-client.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +3 -2
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +16 -0
- package/dist/next/host/pages-router-server.js +3 -2
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/proxy.cjs +66 -27
- package/dist/next/proxy.cjs.map +1 -1
- package/dist/next/proxy.d.ts +0 -1
- package/dist/next/proxy.js +66 -27
- package/dist/next/proxy.js.map +1 -1
- package/dist/proxy-through-host-a676a522.d.ts +52 -0
- package/dist/react/index.cjs +381 -206
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +28 -4
- package/dist/react/index.js +354 -181
- package/dist/react/index.js.map +1 -1
- package/dist/shared/host/proxy.cjs +52 -23
- package/dist/shared/host/proxy.cjs.map +1 -1
- package/dist/shared/host/proxy.d.ts +0 -3
- package/dist/shared/host/proxy.js +55 -22
- package/dist/shared/host/proxy.js.map +1 -1
- package/dist/shared/remote/proxy.cjs +9 -1
- package/dist/shared/remote/proxy.cjs.map +1 -1
- package/dist/shared/remote/proxy.d.ts +7 -1
- package/dist/shared/remote/proxy.js +8 -1
- package/dist/shared/remote/proxy.js.map +1 -1
- package/package.json +1 -1
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +0 -62
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +0 -1
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +0 -14
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +0 -37
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +0 -1
package/dist/html/remote.cjs
CHANGED
|
@@ -9,11 +9,38 @@ var __export = (target, all) => {
|
|
|
9
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
// src/shared/constants.ts
|
|
13
|
+
var CORS_DOCS_URL;
|
|
14
|
+
var init_constants = __esm({
|
|
15
|
+
"src/shared/constants.ts"() {
|
|
16
|
+
"use strict";
|
|
17
|
+
CORS_DOCS_URL = "https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components";
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// src/shared/client/protected-rc-fallback.ts
|
|
22
|
+
var init_protected_rc_fallback = __esm({
|
|
23
|
+
"src/shared/client/protected-rc-fallback.ts"() {
|
|
24
|
+
"use strict";
|
|
25
|
+
init_constants();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// src/shared/utils/abort.ts
|
|
30
|
+
var init_abort = __esm({
|
|
31
|
+
"src/shared/utils/abort.ts"() {
|
|
32
|
+
"use strict";
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
12
36
|
// src/shared/error.ts
|
|
13
37
|
var RemoteComponentsError;
|
|
14
38
|
var init_error = __esm({
|
|
15
39
|
"src/shared/error.ts"() {
|
|
16
40
|
"use strict";
|
|
41
|
+
init_protected_rc_fallback();
|
|
42
|
+
init_constants();
|
|
43
|
+
init_abort();
|
|
17
44
|
RemoteComponentsError = class extends Error {
|
|
18
45
|
code = "REMOTE_COMPONENTS_ERROR";
|
|
19
46
|
constructor(message, options) {
|
|
@@ -25,6 +52,9 @@ var init_error = __esm({
|
|
|
25
52
|
});
|
|
26
53
|
|
|
27
54
|
// src/shared/utils/logger.ts
|
|
55
|
+
function logWarn(location2, message) {
|
|
56
|
+
console.warn(`[${PREFIX}:${location2}]: ${message}`);
|
|
57
|
+
}
|
|
28
58
|
function logError(location2, message, cause) {
|
|
29
59
|
console.error(
|
|
30
60
|
new RemoteComponentsError(`[${PREFIX}:${location2}]: ${message}`, {
|
|
@@ -32,10 +62,24 @@ function logError(location2, message, cause) {
|
|
|
32
62
|
})
|
|
33
63
|
);
|
|
34
64
|
}
|
|
65
|
+
function warnCrossOriginFetchError(logLocation, url) {
|
|
66
|
+
try {
|
|
67
|
+
const parsed = typeof url === "string" ? new URL(url) : url;
|
|
68
|
+
if (typeof location === "undefined" || parsed.origin === location.origin) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
logWarn(
|
|
72
|
+
logLocation,
|
|
73
|
+
`Failed to fetch cross-origin resource "${parsed.href}". If this is a protected deployment, ensure withRemoteComponentsHost middleware is configured in your host and that the remote URL is included in allowedProxyUrls. See: ${CORS_DOCS_URL}`
|
|
74
|
+
);
|
|
75
|
+
} catch {
|
|
76
|
+
}
|
|
77
|
+
}
|
|
35
78
|
var PREFIX, DEBUG;
|
|
36
79
|
var init_logger = __esm({
|
|
37
80
|
"src/shared/utils/logger.ts"() {
|
|
38
81
|
"use strict";
|
|
82
|
+
init_constants();
|
|
39
83
|
init_error();
|
|
40
84
|
PREFIX = "remote-components";
|
|
41
85
|
DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
|
|
@@ -47,7 +91,81 @@ var static_loader_exports = {};
|
|
|
47
91
|
__export(static_loader_exports, {
|
|
48
92
|
loadStaticRemoteComponent: () => loadStaticRemoteComponent
|
|
49
93
|
});
|
|
50
|
-
async function
|
|
94
|
+
async function importViaCallback(absoluteSrc, resolveClientUrl) {
|
|
95
|
+
const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
|
|
96
|
+
const fetchUrl = new URL(resolvedUrl, location.href).href;
|
|
97
|
+
const response = await fetch(fetchUrl);
|
|
98
|
+
if (!response.ok)
|
|
99
|
+
throw new Error(`Proxied fetch failed: ${response.status}`);
|
|
100
|
+
const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
|
|
101
|
+
/\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
|
|
102
|
+
(_, keyword, quote, relativePath) => {
|
|
103
|
+
const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
|
|
104
|
+
const resolvedImportUrl = new URL(
|
|
105
|
+
resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
|
|
106
|
+
location.href
|
|
107
|
+
).href;
|
|
108
|
+
return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
const moduleBlobUrl = URL.createObjectURL(
|
|
112
|
+
new Blob([content], { type: "text/javascript" })
|
|
113
|
+
);
|
|
114
|
+
const wrapperContent = [
|
|
115
|
+
`import*as m from${JSON.stringify(moduleBlobUrl)};`,
|
|
116
|
+
`globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
|
|
117
|
+
`globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
|
|
118
|
+
].join("");
|
|
119
|
+
const wrapperBlobUrl = URL.createObjectURL(
|
|
120
|
+
new Blob([wrapperContent], { type: "text/javascript" })
|
|
121
|
+
);
|
|
122
|
+
const scriptEl = document.createElement("script");
|
|
123
|
+
scriptEl.type = "module";
|
|
124
|
+
scriptEl.src = wrapperBlobUrl;
|
|
125
|
+
try {
|
|
126
|
+
await new Promise((resolve, reject) => {
|
|
127
|
+
scriptEl.onload = () => resolve();
|
|
128
|
+
scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
|
|
129
|
+
document.head.appendChild(scriptEl);
|
|
130
|
+
});
|
|
131
|
+
} finally {
|
|
132
|
+
scriptEl.remove();
|
|
133
|
+
URL.revokeObjectURL(moduleBlobUrl);
|
|
134
|
+
URL.revokeObjectURL(wrapperBlobUrl);
|
|
135
|
+
}
|
|
136
|
+
const registry = globalThis.__rc_module_registry__;
|
|
137
|
+
const mod = registry?.[absoluteSrc] ?? {};
|
|
138
|
+
if (registry)
|
|
139
|
+
delete registry[absoluteSrc];
|
|
140
|
+
return mod;
|
|
141
|
+
}
|
|
142
|
+
async function importDirectly(absoluteSrc) {
|
|
143
|
+
try {
|
|
144
|
+
return await import(
|
|
145
|
+
/* @vite-ignore */
|
|
146
|
+
/* webpackIgnore: true */
|
|
147
|
+
absoluteSrc
|
|
148
|
+
);
|
|
149
|
+
} catch (importError) {
|
|
150
|
+
if (!absoluteSrc.startsWith("blob:")) {
|
|
151
|
+
warnCrossOriginFetchError("StaticLoader", absoluteSrc);
|
|
152
|
+
}
|
|
153
|
+
throw importError;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function resolveScriptSrc(script, url) {
|
|
157
|
+
const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
158
|
+
if (!rawSrc && script.textContent) {
|
|
159
|
+
return URL.createObjectURL(
|
|
160
|
+
new Blob(
|
|
161
|
+
[script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
|
|
162
|
+
{ type: "text/javascript" }
|
|
163
|
+
)
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return rawSrc;
|
|
167
|
+
}
|
|
168
|
+
async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
51
169
|
const self = globalThis;
|
|
52
170
|
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
53
171
|
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
@@ -58,26 +176,9 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
58
176
|
const mountUnmountSets = await Promise.all(
|
|
59
177
|
scripts.map(async (script) => {
|
|
60
178
|
try {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
[
|
|
65
|
-
script.textContent.replace(
|
|
66
|
-
/import\.meta\.url/g,
|
|
67
|
-
JSON.stringify(url)
|
|
68
|
-
)
|
|
69
|
-
],
|
|
70
|
-
{
|
|
71
|
-
type: "text/javascript"
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
src = URL.createObjectURL(blob);
|
|
75
|
-
}
|
|
76
|
-
const mod = await import(
|
|
77
|
-
/* @vite-ignore */
|
|
78
|
-
/* webpackIgnore: true */
|
|
79
|
-
new URL(src, url).href
|
|
80
|
-
);
|
|
179
|
+
const src = resolveScriptSrc(script, url);
|
|
180
|
+
const absoluteSrc = new URL(src, url).href;
|
|
181
|
+
const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
|
|
81
182
|
if (src.startsWith("blob:")) {
|
|
82
183
|
URL.revokeObjectURL(src);
|
|
83
184
|
}
|
|
@@ -159,6 +260,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
159
260
|
mode: this.getAttribute("mode") === "closed" ? "closed" : "open"
|
|
160
261
|
});
|
|
161
262
|
this.root.innerHTML = html;
|
|
263
|
+
this.replaceChildren();
|
|
162
264
|
(async () => {
|
|
163
265
|
const { loadStaticRemoteComponent: loadStaticRemoteComponent2 } = await Promise.resolve().then(() => (init_static_loader(), static_loader_exports));
|
|
164
266
|
loadStaticRemoteComponent2(
|
package/dist/html/remote.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/shared/error.ts","../../src/shared/utils/logger.ts","../../src/shared/client/static-loader.ts","../../src/html/remote/index.tsx"],"sourcesContent":["export class RemoteComponentsError extends Error {\n code = 'REMOTE_COMPONENTS_ERROR';\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = 'RemoteComponentsError';\n }\n}\n\nexport function multipleRemoteComponentsError(url: string | undefined) {\n return new RemoteComponentsError(\n `Multiple Remote Components found at \"${url}\". When a page exposes multiple Remote Components you must specify the \"name\" prop to select which one to load.`,\n );\n}\n\nexport function failedToFetchRemoteComponentError(\n url: string,\n { status, statusText }: { status: number; statusText: string },\n help: string = 'Is the URL correct and accessible?',\n) {\n return new RemoteComponentsError(\n `Failed to fetch Remote Component from \"${url}\". ${help}`,\n { cause: new Error(`${status} ${statusText}`) },\n );\n}\n","import { RemoteComponentsError } from '#internal/shared/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ComponentLoader'\n | 'SharedModules'\n | 'WebpackAdapter'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n","import { logError } from '../utils/logger';\nimport type {\n MountOrUnmountFunction,\n RemoteComponentMountUnmount,\n} from './types';\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n) {\n const self = globalThis as typeof globalThis & RemoteComponentMountUnmount;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n let src =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n // if there's no src attribute but there is inline script content, create a blob URL for it\n if (!src && script.textContent) {\n const blob = new Blob(\n [\n script.textContent.replace(\n /import\\.meta\\.url/g,\n JSON.stringify(url),\n ),\n ],\n {\n type: 'text/javascript',\n },\n );\n src = URL.createObjectURL(blob);\n }\n const mod = (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ new URL(src, url).href\n )) as {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n };\n // revoke the object URL if we created one\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n","import type { MountOrUnmountFunction } from '../../shared/client/types';\nimport { logError } from '../../shared/utils/logger';\n\nif (typeof HTMLElement !== 'undefined') {\n class RemoteComponent extends HTMLElement {\n name?: string;\n root?: ShadowRoot | null = null;\n unmount?: Set<MountOrUnmountFunction> | null = null;\n\n constructor() {\n super();\n\n const html = this.innerHTML;\n this.root = this.attachShadow({\n mode: this.getAttribute('mode') === 'closed' ? 'closed' : 'open',\n });\n this.root.innerHTML = html;\n\n // run the mount functions for any scripts inside the shadow root asynchronously\n (async () => {\n const { loadStaticRemoteComponent } = await import(\n '../../shared/client/static-loader'\n );\n loadStaticRemoteComponent(\n Array.from(this.root?.querySelectorAll('script') ?? []),\n new URL(location.href),\n )\n .then(({ mount, unmount }) => {\n this.unmount = unmount;\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(this.root)),\n );\n })\n .catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n })().catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n }\n\n disconnectedCallback() {\n // run the unmount functions for any scripts inside the shadow root asynchronously\n (async () => {\n if (this.unmount) {\n await Promise.all(\n Array.from(this.unmount).map(async (unmount) => {\n try {\n await unmount(this.root);\n } catch (e) {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n }\n }),\n );\n }\n })().catch((e) => {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n });\n }\n }\n\n // register the custom element\n customElements.define('remote-component', RemoteComponent);\n}\n"],"mappings":";;;;;;;;;;;;AAAA,IAAa;AAAb;AAAA;AAAA;AAAO,IAAM,wBAAN,cAAoC,MAAM;AAAA,MAC/C,OAAO;AAAA,MAEP,YAAY,SAAiB,SAA+B;AAC1D,cAAM,SAAS,OAAO;AACtB,aAAK,OAAO;AAAA,MACd;AAAA,IACF;AAAA;AAAA;;;AC+BO,SAAS,SACdA,WACA,SACA,OACA;AAEA,UAAQ;AAAA,IACN,IAAI,sBAAsB,IAAI,UAAUA,eAAc,WAAW;AAAA,MAC/D;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAjDA,IAiBM,QACA;AAlBN;AAAA;AAAA;AAAA;AAiBA,IAAM,SAAS;AACf,IAAM,QACJ,OAAO,WAAW,eAAe,aAAa,QAAQ,UAAU,MAAM;AAAA;AAAA;;;ACnBxE;AAAA;AAAA;AAAA;AAMA,eAAsB,0BACpB,SACA,KACA;AACA,QAAM,OAAO;AACb,MAAI,KAAK,qCAAqC,IAAI,IAAI,GAAG;AACvD,SAAK,mCAAmC,IAAI,IAAI,IAAI,oBAAI,IAAI;AAAA,EAC9D;AACA,MAAI,KAAK,uCAAuC,IAAI,IAAI,GAAG;AACzD,SAAK,qCAAqC,IAAI,IAAI,IAAI,oBAAI,IAAI;AAAA,EAChE;AACA,QAAM,mBAAmB,MAAM,QAAQ;AAAA,IACrC,QAAQ,IAAI,OAAO,WAAW;AAC5B,UAAI;AACF,YAAI,MACF,OAAO,OAAO,iBAAiB,aAC1B,OAAO,aAAa,KAAK,KAAK,OAAO,MACtC,OAAO;AAEb,YAAI,CAAC,OAAO,OAAO,aAAa;AAC9B,gBAAM,OAAO,IAAI;AAAA,YACf;AAAA,cACE,OAAO,YAAY;AAAA,gBACjB;AAAA,gBACA,KAAK,UAAU,GAAG;AAAA,cACpB;AAAA,YACF;AAAA,YACA;AAAA,cACE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S,cAAc,oCAAoC,CAAC;AAAA,MAC9D,CAAC;AAAA,IACH;AAAA,IAEA,uBAAuB;AAErB,OAAC,YAAY;AACX,YAAI,KAAK,SAAS;AAChB,gBAAM,QAAQ;AAAA,YACZ,MAAM,KAAK,KAAK,OAAO,EAAE,IAAI,OAAO,YAAY;AAC9C,kBAAI;AACF,sBAAM,QAAQ,KAAK,IAAI;AAAA,cACzB,SAAS,GAAP;AACA,yBAAS,cAAc,sCAAsC,CAAC;AAAA,cAChE;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,GAAG,EAAE,MAAM,CAAC,MAAM;AAChB,iBAAS,cAAc,sCAAsC,CAAC;AAAA,MAChE,CAAC;AAAA,IACH;AAAA,EACF;AAGA,iBAAe,OAAO,oBAAoB,eAAe;AAC3D;","names":["location","loadStaticRemoteComponent"]}
|
|
1
|
+
{"version":3,"sources":["../../src/shared/constants.ts","../../src/shared/client/protected-rc-fallback.ts","../../src/shared/utils/abort.ts","../../src/shared/error.ts","../../src/shared/utils/logger.ts","../../src/shared/client/static-loader.ts","../../src/html/remote/index.tsx"],"sourcesContent":["export const RC_PROTECTED_REMOTE_FETCH_PATHNAME = '/rc-fetch-protected-remote';\n\nexport const CORS_DOCS_URL =\n 'https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components';\n","import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from '#internal/shared/constants';\n\n/**\n * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint\n */\nexport function generateProtectedRcFallbackSrc(url: string): string {\n return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;\n}\n\nexport function isProxiedUrl(url: string): boolean {\n try {\n return (\n new URL(url, location.href).pathname ===\n RC_PROTECTED_REMOTE_FETCH_PATHNAME\n );\n } catch {\n return false;\n }\n}\n","/**\n * Type guard to check if an error is an AbortError.\n * Handles cross-environment differences (Node.js, browsers, JSDOM).\n */\nexport function isAbortError(error: unknown): error is DOMException {\n if (error instanceof DOMException && error.name === 'AbortError') {\n return true;\n }\n\n // Handle Node.js native AbortError which may not be instanceof global DOMException\n if (\n error !== null &&\n typeof error === 'object' &&\n 'name' in error &&\n error.name === 'AbortError' &&\n 'message' in error &&\n typeof (error as { message: unknown }).message === 'string'\n ) {\n // Additional check: verify it has DOMException-like structure\n const e = error as { code?: unknown; constructor?: { name?: string } };\n return typeof e.code === 'number' || e.constructor?.name === 'DOMException';\n }\n\n return false;\n}\n","import { isProxiedUrl } from '#internal/shared/client/protected-rc-fallback';\nimport {\n CORS_DOCS_URL,\n RC_PROTECTED_REMOTE_FETCH_PATHNAME,\n} from '#internal/shared/constants';\nimport { isAbortError } from '#internal/shared/utils/abort';\n\nexport class RemoteComponentsError extends Error {\n code = 'REMOTE_COMPONENTS_ERROR';\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = 'RemoteComponentsError';\n }\n}\n\nexport function multipleRemoteComponentsError(url: string | undefined) {\n return new RemoteComponentsError(\n `Multiple Remote Components found at \"${url}\". When a page exposes multiple Remote Components you must specify the \"name\" prop to select which one to load.`,\n );\n}\n\nexport function failedToFetchRemoteComponentError(\n url: string,\n { status, statusText }: { status: number; statusText: string },\n help: string = 'Is the URL correct and accessible?',\n) {\n return new RemoteComponentsError(\n `Failed to fetch Remote Component from \"${url}\". ${help}`,\n { cause: new Error(`${status} ${statusText}`) },\n );\n}\n\nexport async function errorFromFailedFetch(\n originalUrl: string,\n resolvedUrl: URL,\n res: Response | null | undefined,\n): Promise<RemoteComponentsError> {\n const isProxied = isProxiedUrl(resolvedUrl.href);\n\n if (isProxied && res) {\n const body = await res.text().catch(() => '');\n return failedProxyFetchError(\n originalUrl,\n resolvedUrl.href,\n res.status,\n body,\n );\n }\n\n const fallback = failedToFetchRemoteComponentError(\n originalUrl,\n res ?? { status: 0, statusText: 'No Response' },\n );\n\n if (!res) return fallback;\n\n try {\n const body = await res.text();\n const parser = new DOMParser();\n const doc = parser.parseFromString(body, 'text/html');\n const errorTemplate = doc.querySelector(\n 'template[data-next-error-message]',\n );\n const errorMessage = errorTemplate?.getAttribute('data-next-error-message');\n if (errorMessage) {\n const error = new RemoteComponentsError(errorMessage);\n const errorStack = errorTemplate?.getAttribute('data-next-error-stack');\n if (errorStack) {\n error.stack = errorStack;\n }\n return error;\n }\n } catch (parseError) {\n // Re-throw abort errors, ignore parse errors\n if (isAbortError(parseError)) throw parseError;\n }\n\n return fallback;\n}\n\nexport function failedProxyFetchError(\n originalUrl: string,\n proxyUrl: string,\n status: number,\n responseBody?: string,\n): RemoteComponentsError {\n if (status === 404) {\n return new RemoteComponentsError(\n `Could not proxy the request to \"${originalUrl}\" — the proxy endpoint \"${RC_PROTECTED_REMOTE_FETCH_PATHNAME}\" returned 404.\\n\\n` +\n `The host server needs middleware or a route that handles \"${RC_PROTECTED_REMOTE_FETCH_PATHNAME}\".\\n\\n` +\n `Proxying requires two pieces:\\n` +\n ` 1. resolveClientUrl={proxyClientRequestsThroughHost} on <RemoteComponent>\\n` +\n ` 2. Middleware or a route for \"${RC_PROTECTED_REMOTE_FETCH_PATHNAME}\" on the host server\\n\\n` +\n `Docs: ${CORS_DOCS_URL}`,\n );\n }\n if (status === 403) {\n const detail = responseBody ? ` ${responseBody}` : '';\n return new RemoteComponentsError(\n `Proxied request to \"${proxyUrl}\" was forbidden.${detail} ` +\n `See: ${CORS_DOCS_URL}`,\n );\n }\n return new RemoteComponentsError(\n `Proxied request for \"${originalUrl}\" via \"${proxyUrl}\" failed with status ${status}. ` +\n `See: ${CORS_DOCS_URL}`,\n );\n}\n","import { CORS_DOCS_URL } from '#internal/shared/constants';\nimport { RemoteComponentsError } from '#internal/shared/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ComponentLoader'\n | 'SharedModules'\n | 'WebpackAdapter'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'ScriptLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n\n/**\n * Logs a warning when a cross-origin asset request fails, guiding users\n * to configure the withRemoteComponentsHost middleware on their host.\n */\nexport function warnCrossOriginFetchError(\n logLocation: LogLocation,\n url: string | URL,\n): void {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n if (typeof location === 'undefined' || parsed.origin === location.origin) {\n return;\n }\n logWarn(\n logLocation,\n `Failed to fetch cross-origin resource \"${parsed.href}\". ` +\n 'If this is a protected deployment, ensure withRemoteComponentsHost middleware ' +\n 'is configured in your host and that the remote URL is included in allowedProxyUrls. ' +\n `See: ${CORS_DOCS_URL}`,\n );\n } catch {\n // URL parsing failed — skip the warning\n }\n}\n","import type { InternalResolveClientUrl } from '#internal/shared/ssr/types';\nimport { logError, warnCrossOriginFetchError } from '../utils/logger';\nimport type {\n MountOrUnmountFunction,\n RemoteComponentMountUnmount,\n} from './types';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = (\n globalThis as unknown as { __rc_module_registry__?: Record<string, T> }\n ).__rc_module_registry__;\n const mod = registry?.[absoluteSrc] ?? ({} as T);\n if (registry) delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const self = globalThis as typeof globalThis & RemoteComponentMountUnmount;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n","import type { MountOrUnmountFunction } from '../../shared/client/types';\nimport { logError } from '../../shared/utils/logger';\n\nif (typeof HTMLElement !== 'undefined') {\n class RemoteComponent extends HTMLElement {\n name?: string;\n root?: ShadowRoot | null = null;\n unmount?: Set<MountOrUnmountFunction> | null = null;\n\n constructor() {\n super();\n\n const html = this.innerHTML;\n this.root = this.attachShadow({\n mode: this.getAttribute('mode') === 'closed' ? 'closed' : 'open',\n });\n this.root.innerHTML = html;\n // Clear light DOM — content was copied into the shadow root above.\n // Without this the original children render twice (once in light DOM,\n // once in shadow DOM).\n this.replaceChildren();\n\n // run the mount functions for any scripts inside the shadow root asynchronously\n (async () => {\n const { loadStaticRemoteComponent } = await import(\n '../../shared/client/static-loader'\n );\n loadStaticRemoteComponent(\n Array.from(this.root?.querySelectorAll('script') ?? []),\n new URL(location.href),\n )\n .then(({ mount, unmount }) => {\n this.unmount = unmount;\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(this.root)),\n );\n })\n .catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n })().catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n }\n\n disconnectedCallback() {\n // run the unmount functions for any scripts inside the shadow root asynchronously\n (async () => {\n if (this.unmount) {\n await Promise.all(\n Array.from(this.unmount).map(async (unmount) => {\n try {\n await unmount(this.root);\n } catch (e) {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n }\n }),\n );\n }\n })().catch((e) => {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n });\n }\n }\n\n // register the custom element\n customElements.define('remote-component', RemoteComponent);\n}\n"],"mappings":";;;;;;;;;;;;AAAA,IAEa;AAFb;AAAA;AAAA;AAEO,IAAM,gBACX;AAAA;AAAA;;;ACHF;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAOa;AAPb;AAAA;AAAA;AAAA;AACA;AAIA;AAEO,IAAM,wBAAN,cAAoC,MAAM;AAAA,MAC/C,OAAO;AAAA,MAEP,YAAY,SAAiB,SAA+B;AAC1D,cAAM,SAAS,OAAO;AACtB,aAAK,OAAO;AAAA,MACd;AAAA,IACF;AAAA;AAAA;;;ACqBO,SAAS,QAAQA,WAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAUA,eAAc,SAAS;AACpD;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,EAAE,2BAAAC,2BAA0B,IAAI,MAAM;AAG5C,QAAAA;AAAA,UACE,MAAM,KAAK,KAAK,MAAM,iBAAiB,QAAQ,KAAK,CAAC,CAAC;AAAA,UACtD,IAAI,IAAI,SAAS,IAAI;AAAA,QACvB,EACG,KAAK,CAAC,EAAE,OAAO,QAAQ,MAAM;AAC5B,eAAK,UAAU;AACf,iBAAO,QAAQ;AAAA,YACb,MAAM,KAAK,KAAK,EAAE,IAAI,CAAC,YAAY,QAAQ,KAAK,IAAI,CAAC;AAAA,UACvD;AAAA,QACF,CAAC,EACA,MAAM,CAAC,MAAM;AACZ,mBAAS,cAAc,oCAAoC,CAAC;AAAA,QAC9D,CAAC;AAAA,MACL,GAAG,EAAE,MAAM,CAAC,MAAM;AAChB,iBAAS,cAAc,oCAAoC,CAAC;AAAA,MAC9D,CAAC;AAAA,IACH;AAAA,IAEA,uBAAuB;AAErB,OAAC,YAAY;AACX,YAAI,KAAK,SAAS;AAChB,gBAAM,QAAQ;AAAA,YACZ,MAAM,KAAK,KAAK,OAAO,EAAE,IAAI,OAAO,YAAY;AAC9C,kBAAI;AACF,sBAAM,QAAQ,KAAK,IAAI;AAAA,cACzB,SAAS,GAAP;AACA,yBAAS,cAAc,sCAAsC,CAAC;AAAA,cAChE;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,GAAG,EAAE,MAAM,CAAC,MAAM;AAChB,iBAAS,cAAc,sCAAsC,CAAC;AAAA,MAChE,CAAC;AAAA,IACH;AAAA,EACF;AAGA,iBAAe,OAAO,oBAAoB,eAAe;AAC3D;","names":["location","loadStaticRemoteComponent"]}
|
package/dist/html/remote.js
CHANGED
|
@@ -8,11 +8,38 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
// src/shared/constants.ts
|
|
12
|
+
var CORS_DOCS_URL;
|
|
13
|
+
var init_constants = __esm({
|
|
14
|
+
"src/shared/constants.ts"() {
|
|
15
|
+
"use strict";
|
|
16
|
+
CORS_DOCS_URL = "https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components";
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// src/shared/client/protected-rc-fallback.ts
|
|
21
|
+
var init_protected_rc_fallback = __esm({
|
|
22
|
+
"src/shared/client/protected-rc-fallback.ts"() {
|
|
23
|
+
"use strict";
|
|
24
|
+
init_constants();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// src/shared/utils/abort.ts
|
|
29
|
+
var init_abort = __esm({
|
|
30
|
+
"src/shared/utils/abort.ts"() {
|
|
31
|
+
"use strict";
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
11
35
|
// src/shared/error.ts
|
|
12
36
|
var RemoteComponentsError;
|
|
13
37
|
var init_error = __esm({
|
|
14
38
|
"src/shared/error.ts"() {
|
|
15
39
|
"use strict";
|
|
40
|
+
init_protected_rc_fallback();
|
|
41
|
+
init_constants();
|
|
42
|
+
init_abort();
|
|
16
43
|
RemoteComponentsError = class extends Error {
|
|
17
44
|
code = "REMOTE_COMPONENTS_ERROR";
|
|
18
45
|
constructor(message, options) {
|
|
@@ -24,6 +51,9 @@ var init_error = __esm({
|
|
|
24
51
|
});
|
|
25
52
|
|
|
26
53
|
// src/shared/utils/logger.ts
|
|
54
|
+
function logWarn(location2, message) {
|
|
55
|
+
console.warn(`[${PREFIX}:${location2}]: ${message}`);
|
|
56
|
+
}
|
|
27
57
|
function logError(location2, message, cause) {
|
|
28
58
|
console.error(
|
|
29
59
|
new RemoteComponentsError(`[${PREFIX}:${location2}]: ${message}`, {
|
|
@@ -31,10 +61,24 @@ function logError(location2, message, cause) {
|
|
|
31
61
|
})
|
|
32
62
|
);
|
|
33
63
|
}
|
|
64
|
+
function warnCrossOriginFetchError(logLocation, url) {
|
|
65
|
+
try {
|
|
66
|
+
const parsed = typeof url === "string" ? new URL(url) : url;
|
|
67
|
+
if (typeof location === "undefined" || parsed.origin === location.origin) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
logWarn(
|
|
71
|
+
logLocation,
|
|
72
|
+
`Failed to fetch cross-origin resource "${parsed.href}". If this is a protected deployment, ensure withRemoteComponentsHost middleware is configured in your host and that the remote URL is included in allowedProxyUrls. See: ${CORS_DOCS_URL}`
|
|
73
|
+
);
|
|
74
|
+
} catch {
|
|
75
|
+
}
|
|
76
|
+
}
|
|
34
77
|
var PREFIX, DEBUG;
|
|
35
78
|
var init_logger = __esm({
|
|
36
79
|
"src/shared/utils/logger.ts"() {
|
|
37
80
|
"use strict";
|
|
81
|
+
init_constants();
|
|
38
82
|
init_error();
|
|
39
83
|
PREFIX = "remote-components";
|
|
40
84
|
DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
|
|
@@ -46,7 +90,81 @@ var static_loader_exports = {};
|
|
|
46
90
|
__export(static_loader_exports, {
|
|
47
91
|
loadStaticRemoteComponent: () => loadStaticRemoteComponent
|
|
48
92
|
});
|
|
49
|
-
async function
|
|
93
|
+
async function importViaCallback(absoluteSrc, resolveClientUrl) {
|
|
94
|
+
const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
|
|
95
|
+
const fetchUrl = new URL(resolvedUrl, location.href).href;
|
|
96
|
+
const response = await fetch(fetchUrl);
|
|
97
|
+
if (!response.ok)
|
|
98
|
+
throw new Error(`Proxied fetch failed: ${response.status}`);
|
|
99
|
+
const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
|
|
100
|
+
/\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
|
|
101
|
+
(_, keyword, quote, relativePath) => {
|
|
102
|
+
const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
|
|
103
|
+
const resolvedImportUrl = new URL(
|
|
104
|
+
resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
|
|
105
|
+
location.href
|
|
106
|
+
).href;
|
|
107
|
+
return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
const moduleBlobUrl = URL.createObjectURL(
|
|
111
|
+
new Blob([content], { type: "text/javascript" })
|
|
112
|
+
);
|
|
113
|
+
const wrapperContent = [
|
|
114
|
+
`import*as m from${JSON.stringify(moduleBlobUrl)};`,
|
|
115
|
+
`globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
|
|
116
|
+
`globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
|
|
117
|
+
].join("");
|
|
118
|
+
const wrapperBlobUrl = URL.createObjectURL(
|
|
119
|
+
new Blob([wrapperContent], { type: "text/javascript" })
|
|
120
|
+
);
|
|
121
|
+
const scriptEl = document.createElement("script");
|
|
122
|
+
scriptEl.type = "module";
|
|
123
|
+
scriptEl.src = wrapperBlobUrl;
|
|
124
|
+
try {
|
|
125
|
+
await new Promise((resolve, reject) => {
|
|
126
|
+
scriptEl.onload = () => resolve();
|
|
127
|
+
scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
|
|
128
|
+
document.head.appendChild(scriptEl);
|
|
129
|
+
});
|
|
130
|
+
} finally {
|
|
131
|
+
scriptEl.remove();
|
|
132
|
+
URL.revokeObjectURL(moduleBlobUrl);
|
|
133
|
+
URL.revokeObjectURL(wrapperBlobUrl);
|
|
134
|
+
}
|
|
135
|
+
const registry = globalThis.__rc_module_registry__;
|
|
136
|
+
const mod = registry?.[absoluteSrc] ?? {};
|
|
137
|
+
if (registry)
|
|
138
|
+
delete registry[absoluteSrc];
|
|
139
|
+
return mod;
|
|
140
|
+
}
|
|
141
|
+
async function importDirectly(absoluteSrc) {
|
|
142
|
+
try {
|
|
143
|
+
return await import(
|
|
144
|
+
/* @vite-ignore */
|
|
145
|
+
/* webpackIgnore: true */
|
|
146
|
+
absoluteSrc
|
|
147
|
+
);
|
|
148
|
+
} catch (importError) {
|
|
149
|
+
if (!absoluteSrc.startsWith("blob:")) {
|
|
150
|
+
warnCrossOriginFetchError("StaticLoader", absoluteSrc);
|
|
151
|
+
}
|
|
152
|
+
throw importError;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function resolveScriptSrc(script, url) {
|
|
156
|
+
const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
157
|
+
if (!rawSrc && script.textContent) {
|
|
158
|
+
return URL.createObjectURL(
|
|
159
|
+
new Blob(
|
|
160
|
+
[script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
|
|
161
|
+
{ type: "text/javascript" }
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return rawSrc;
|
|
166
|
+
}
|
|
167
|
+
async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
50
168
|
const self = globalThis;
|
|
51
169
|
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
52
170
|
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
@@ -57,26 +175,9 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
57
175
|
const mountUnmountSets = await Promise.all(
|
|
58
176
|
scripts.map(async (script) => {
|
|
59
177
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
[
|
|
64
|
-
script.textContent.replace(
|
|
65
|
-
/import\.meta\.url/g,
|
|
66
|
-
JSON.stringify(url)
|
|
67
|
-
)
|
|
68
|
-
],
|
|
69
|
-
{
|
|
70
|
-
type: "text/javascript"
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
src = URL.createObjectURL(blob);
|
|
74
|
-
}
|
|
75
|
-
const mod = await import(
|
|
76
|
-
/* @vite-ignore */
|
|
77
|
-
/* webpackIgnore: true */
|
|
78
|
-
new URL(src, url).href
|
|
79
|
-
);
|
|
178
|
+
const src = resolveScriptSrc(script, url);
|
|
179
|
+
const absoluteSrc = new URL(src, url).href;
|
|
180
|
+
const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
|
|
80
181
|
if (src.startsWith("blob:")) {
|
|
81
182
|
URL.revokeObjectURL(src);
|
|
82
183
|
}
|
|
@@ -158,6 +259,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
158
259
|
mode: this.getAttribute("mode") === "closed" ? "closed" : "open"
|
|
159
260
|
});
|
|
160
261
|
this.root.innerHTML = html;
|
|
262
|
+
this.replaceChildren();
|
|
161
263
|
(async () => {
|
|
162
264
|
const { loadStaticRemoteComponent: loadStaticRemoteComponent2 } = await Promise.resolve().then(() => (init_static_loader(), static_loader_exports));
|
|
163
265
|
loadStaticRemoteComponent2(
|
package/dist/html/remote.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/shared/error.ts","../../src/shared/utils/logger.ts","../../src/shared/client/static-loader.ts","../../src/html/remote/index.tsx"],"sourcesContent":["export class RemoteComponentsError extends Error {\n code = 'REMOTE_COMPONENTS_ERROR';\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = 'RemoteComponentsError';\n }\n}\n\nexport function multipleRemoteComponentsError(url: string | undefined) {\n return new RemoteComponentsError(\n `Multiple Remote Components found at \"${url}\". When a page exposes multiple Remote Components you must specify the \"name\" prop to select which one to load.`,\n );\n}\n\nexport function failedToFetchRemoteComponentError(\n url: string,\n { status, statusText }: { status: number; statusText: string },\n help: string = 'Is the URL correct and accessible?',\n) {\n return new RemoteComponentsError(\n `Failed to fetch Remote Component from \"${url}\". ${help}`,\n { cause: new Error(`${status} ${statusText}`) },\n );\n}\n","import { RemoteComponentsError } from '#internal/shared/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ComponentLoader'\n | 'SharedModules'\n | 'WebpackAdapter'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n","import { logError } from '../utils/logger';\nimport type {\n MountOrUnmountFunction,\n RemoteComponentMountUnmount,\n} from './types';\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n) {\n const self = globalThis as typeof globalThis & RemoteComponentMountUnmount;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n let src =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n // if there's no src attribute but there is inline script content, create a blob URL for it\n if (!src && script.textContent) {\n const blob = new Blob(\n [\n script.textContent.replace(\n /import\\.meta\\.url/g,\n JSON.stringify(url),\n ),\n ],\n {\n type: 'text/javascript',\n },\n );\n src = URL.createObjectURL(blob);\n }\n const mod = (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ new URL(src, url).href\n )) as {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n };\n // revoke the object URL if we created one\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n","import type { MountOrUnmountFunction } from '../../shared/client/types';\nimport { logError } from '../../shared/utils/logger';\n\nif (typeof HTMLElement !== 'undefined') {\n class RemoteComponent extends HTMLElement {\n name?: string;\n root?: ShadowRoot | null = null;\n unmount?: Set<MountOrUnmountFunction> | null = null;\n\n constructor() {\n super();\n\n const html = this.innerHTML;\n this.root = this.attachShadow({\n mode: this.getAttribute('mode') === 'closed' ? 'closed' : 'open',\n });\n this.root.innerHTML = html;\n\n // run the mount functions for any scripts inside the shadow root asynchronously\n (async () => {\n const { loadStaticRemoteComponent } = await import(\n '../../shared/client/static-loader'\n );\n loadStaticRemoteComponent(\n Array.from(this.root?.querySelectorAll('script') ?? []),\n new URL(location.href),\n )\n .then(({ mount, unmount }) => {\n this.unmount = unmount;\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(this.root)),\n );\n })\n .catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n })().catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n }\n\n disconnectedCallback() {\n // run the unmount functions for any scripts inside the shadow root asynchronously\n (async () => {\n if (this.unmount) {\n await Promise.all(\n Array.from(this.unmount).map(async (unmount) => {\n try {\n await unmount(this.root);\n } catch (e) {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n }\n }),\n );\n }\n })().catch((e) => {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n });\n }\n }\n\n // register the custom element\n customElements.define('remote-component', RemoteComponent);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAa;AAAb;AAAA;AAAA;AAAO,IAAM,wBAAN,cAAoC,MAAM;AAAA,MAC/C,OAAO;AAAA,MAEP,YAAY,SAAiB,SAA+B;AAC1D,cAAM,SAAS,OAAO;AACtB,aAAK,OAAO;AAAA,MACd;AAAA,IACF;AAAA;AAAA;;;AC+BO,SAAS,SACdA,WACA,SACA,OACA;AAEA,UAAQ;AAAA,IACN,IAAI,sBAAsB,IAAI,UAAUA,eAAc,WAAW;AAAA,MAC/D;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAjDA,IAiBM,QACA;AAlBN;AAAA;AAAA;AAAA;AAiBA,I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["location","loadStaticRemoteComponent"]}
|
|
1
|
+
{"version":3,"sources":["../../src/shared/constants.ts","../../src/shared/client/protected-rc-fallback.ts","../../src/shared/utils/abort.ts","../../src/shared/error.ts","../../src/shared/utils/logger.ts","../../src/shared/client/static-loader.ts","../../src/html/remote/index.tsx"],"sourcesContent":["export const RC_PROTECTED_REMOTE_FETCH_PATHNAME = '/rc-fetch-protected-remote';\n\nexport const CORS_DOCS_URL =\n 'https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components';\n","import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from '#internal/shared/constants';\n\n/**\n * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint\n */\nexport function generateProtectedRcFallbackSrc(url: string): string {\n return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;\n}\n\nexport function isProxiedUrl(url: string): boolean {\n try {\n return (\n new URL(url, location.href).pathname ===\n RC_PROTECTED_REMOTE_FETCH_PATHNAME\n );\n } catch {\n return false;\n }\n}\n","/**\n * Type guard to check if an error is an AbortError.\n * Handles cross-environment differences (Node.js, browsers, JSDOM).\n */\nexport function isAbortError(error: unknown): error is DOMException {\n if (error instanceof DOMException && error.name === 'AbortError') {\n return true;\n }\n\n // Handle Node.js native AbortError which may not be instanceof global DOMException\n if (\n error !== null &&\n typeof error === 'object' &&\n 'name' in error &&\n error.name === 'AbortError' &&\n 'message' in error &&\n typeof (error as { message: unknown }).message === 'string'\n ) {\n // Additional check: verify it has DOMException-like structure\n const e = error as { code?: unknown; constructor?: { name?: string } };\n return typeof e.code === 'number' || e.constructor?.name === 'DOMException';\n }\n\n return false;\n}\n","import { isProxiedUrl } from '#internal/shared/client/protected-rc-fallback';\nimport {\n CORS_DOCS_URL,\n RC_PROTECTED_REMOTE_FETCH_PATHNAME,\n} from '#internal/shared/constants';\nimport { isAbortError } from '#internal/shared/utils/abort';\n\nexport class RemoteComponentsError extends Error {\n code = 'REMOTE_COMPONENTS_ERROR';\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = 'RemoteComponentsError';\n }\n}\n\nexport function multipleRemoteComponentsError(url: string | undefined) {\n return new RemoteComponentsError(\n `Multiple Remote Components found at \"${url}\". When a page exposes multiple Remote Components you must specify the \"name\" prop to select which one to load.`,\n );\n}\n\nexport function failedToFetchRemoteComponentError(\n url: string,\n { status, statusText }: { status: number; statusText: string },\n help: string = 'Is the URL correct and accessible?',\n) {\n return new RemoteComponentsError(\n `Failed to fetch Remote Component from \"${url}\". ${help}`,\n { cause: new Error(`${status} ${statusText}`) },\n );\n}\n\nexport async function errorFromFailedFetch(\n originalUrl: string,\n resolvedUrl: URL,\n res: Response | null | undefined,\n): Promise<RemoteComponentsError> {\n const isProxied = isProxiedUrl(resolvedUrl.href);\n\n if (isProxied && res) {\n const body = await res.text().catch(() => '');\n return failedProxyFetchError(\n originalUrl,\n resolvedUrl.href,\n res.status,\n body,\n );\n }\n\n const fallback = failedToFetchRemoteComponentError(\n originalUrl,\n res ?? { status: 0, statusText: 'No Response' },\n );\n\n if (!res) return fallback;\n\n try {\n const body = await res.text();\n const parser = new DOMParser();\n const doc = parser.parseFromString(body, 'text/html');\n const errorTemplate = doc.querySelector(\n 'template[data-next-error-message]',\n );\n const errorMessage = errorTemplate?.getAttribute('data-next-error-message');\n if (errorMessage) {\n const error = new RemoteComponentsError(errorMessage);\n const errorStack = errorTemplate?.getAttribute('data-next-error-stack');\n if (errorStack) {\n error.stack = errorStack;\n }\n return error;\n }\n } catch (parseError) {\n // Re-throw abort errors, ignore parse errors\n if (isAbortError(parseError)) throw parseError;\n }\n\n return fallback;\n}\n\nexport function failedProxyFetchError(\n originalUrl: string,\n proxyUrl: string,\n status: number,\n responseBody?: string,\n): RemoteComponentsError {\n if (status === 404) {\n return new RemoteComponentsError(\n `Could not proxy the request to \"${originalUrl}\" — the proxy endpoint \"${RC_PROTECTED_REMOTE_FETCH_PATHNAME}\" returned 404.\\n\\n` +\n `The host server needs middleware or a route that handles \"${RC_PROTECTED_REMOTE_FETCH_PATHNAME}\".\\n\\n` +\n `Proxying requires two pieces:\\n` +\n ` 1. resolveClientUrl={proxyClientRequestsThroughHost} on <RemoteComponent>\\n` +\n ` 2. Middleware or a route for \"${RC_PROTECTED_REMOTE_FETCH_PATHNAME}\" on the host server\\n\\n` +\n `Docs: ${CORS_DOCS_URL}`,\n );\n }\n if (status === 403) {\n const detail = responseBody ? ` ${responseBody}` : '';\n return new RemoteComponentsError(\n `Proxied request to \"${proxyUrl}\" was forbidden.${detail} ` +\n `See: ${CORS_DOCS_URL}`,\n );\n }\n return new RemoteComponentsError(\n `Proxied request for \"${originalUrl}\" via \"${proxyUrl}\" failed with status ${status}. ` +\n `See: ${CORS_DOCS_URL}`,\n );\n}\n","import { CORS_DOCS_URL } from '#internal/shared/constants';\nimport { RemoteComponentsError } from '#internal/shared/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ComponentLoader'\n | 'SharedModules'\n | 'WebpackAdapter'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'ScriptLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n\n/**\n * Logs a warning when a cross-origin asset request fails, guiding users\n * to configure the withRemoteComponentsHost middleware on their host.\n */\nexport function warnCrossOriginFetchError(\n logLocation: LogLocation,\n url: string | URL,\n): void {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n if (typeof location === 'undefined' || parsed.origin === location.origin) {\n return;\n }\n logWarn(\n logLocation,\n `Failed to fetch cross-origin resource \"${parsed.href}\". ` +\n 'If this is a protected deployment, ensure withRemoteComponentsHost middleware ' +\n 'is configured in your host and that the remote URL is included in allowedProxyUrls. ' +\n `See: ${CORS_DOCS_URL}`,\n );\n } catch {\n // URL parsing failed — skip the warning\n }\n}\n","import type { InternalResolveClientUrl } from '#internal/shared/ssr/types';\nimport { logError, warnCrossOriginFetchError } from '../utils/logger';\nimport type {\n MountOrUnmountFunction,\n RemoteComponentMountUnmount,\n} from './types';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = (\n globalThis as unknown as { __rc_module_registry__?: Record<string, T> }\n ).__rc_module_registry__;\n const mod = registry?.[absoluteSrc] ?? ({} as T);\n if (registry) delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const self = globalThis as typeof globalThis & RemoteComponentMountUnmount;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n","import type { MountOrUnmountFunction } from '../../shared/client/types';\nimport { logError } from '../../shared/utils/logger';\n\nif (typeof HTMLElement !== 'undefined') {\n class RemoteComponent extends HTMLElement {\n name?: string;\n root?: ShadowRoot | null = null;\n unmount?: Set<MountOrUnmountFunction> | null = null;\n\n constructor() {\n super();\n\n const html = this.innerHTML;\n this.root = this.attachShadow({\n mode: this.getAttribute('mode') === 'closed' ? 'closed' : 'open',\n });\n this.root.innerHTML = html;\n // Clear light DOM — content was copied into the shadow root above.\n // Without this the original children render twice (once in light DOM,\n // once in shadow DOM).\n this.replaceChildren();\n\n // run the mount functions for any scripts inside the shadow root asynchronously\n (async () => {\n const { loadStaticRemoteComponent } = await import(\n '../../shared/client/static-loader'\n );\n loadStaticRemoteComponent(\n Array.from(this.root?.querySelectorAll('script') ?? []),\n new URL(location.href),\n )\n .then(({ mount, unmount }) => {\n this.unmount = unmount;\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(this.root)),\n );\n })\n .catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n })().catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n }\n\n disconnectedCallback() {\n // run the unmount functions for any scripts inside the shadow root asynchronously\n (async () => {\n if (this.unmount) {\n await Promise.all(\n Array.from(this.unmount).map(async (unmount) => {\n try {\n await unmount(this.root);\n } catch (e) {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n }\n }),\n );\n }\n })().catch((e) => {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n });\n }\n }\n\n // register the custom element\n customElements.define('remote-component', RemoteComponent);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAEa;AAFb;AAAA;AAAA;AAEO,IAAM,gBACX;AAAA;AAAA;;;ACHF;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAOa;AAPb;AAAA;AAAA;AAAA;AACA;AAIA;AAEO,IAAM,wBAAN,cAAoC,MAAM;AAAA,MAC/C,OAAO;AAAA,MAEP,YAAY,SAAiB,SAA+B;AAC1D,cAAM,SAAS,OAAO;AACtB,aAAK,OAAO;AAAA,MACd;AAAA,IACF;AAAA;AAAA;;;ACqBO,SAAS,QAAQA,WAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAUA,eAAc,SAAS;AACpD;AAEO,SAAS,SACdA,WACA,SACA,OACA;AAEA,UAAQ;AAAA,IACN,IAAI,sBAAsB,IAAI,UAAUA,eAAc,WAAW;AAAA,MAC/D;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAMO,SAAS,0BACd,aACA,KACM;AACN,MAAI;AACF,UAAM,SAAS,OAAO,QAAQ,WAAW,IAAI,IAAI,GAAG,IAAI;AACxD,QAAI,OAAO,aAAa,eAAe,OAAO,WAAW,SAAS,QAAQ;AACxE;AAAA,IACF;AACA;AAAA,MACE;AAAA,MACA,0CAA0C,OAAO,iLAGvC;AAAA,IACZ;AAAA,EACF,QAAE;AAAA,EAEF;AACF;AA5EA,IAmBM,QACA;AApBN;AAAA;AAAA;AAAA;AACA;AAkBA,IAAM,SAAS;AACf,IAAM,QACJ,OAAO,WAAW,eAA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AA,MAC9D,CAAC;AAAA,IACH;AAAA,IAEA,uBAAuB;AAErB,OAAC,YAAY;AACX,YAAI,KAAK,SAAS;AAChB,gBAAM,QAAQ;AAAA,YACZ,MAAM,KAAK,KAAK,OAAO,EAAE,IAAI,OAAO,YAAY;AAC9C,kBAAI;AACF,sBAAM,QAAQ,KAAK,IAAI;AAAA,cACzB,SAAS,GAAP;AACA,yBAAS,cAAc,sCAAsC,CAAC;AAAA,cAChE;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,GAAG,EAAE,MAAM,CAAC,MAAM;AAChB,iBAAS,cAAc,sCAAsC,CAAC;AAAA,MAChE,CAAC;AAAA,IACH;AAAA,EACF;AAGA,iBAAe,OAAO,oBAAoB,eAAe;AAC3D;","names":["location","loadStaticRemoteComponent"]}
|
|
@@ -38,6 +38,7 @@ var import_react = require("react");
|
|
|
38
38
|
var import_react_dom = require("react-dom");
|
|
39
39
|
var import_app_router_compat = require("#internal/next/host/app-router-compat");
|
|
40
40
|
var import_remote_component_links = require("#internal/next/host/remote-component-links");
|
|
41
|
+
var import_use_resolve_client_url = require("#internal/react/hooks/use-resolve-client-url");
|
|
41
42
|
var import_remote_component = require("#internal/shared/client/remote-component");
|
|
42
43
|
var import_get_client_or_server_url = require("#internal/shared/ssr/get-client-or-server-url");
|
|
43
44
|
var import_utils = require("#internal/shared/utils");
|
|
@@ -64,6 +65,7 @@ function RemoteComponentClient({
|
|
|
64
65
|
remoteShared = {},
|
|
65
66
|
isolate,
|
|
66
67
|
mode = "open",
|
|
68
|
+
resolveClientUrl: resolveClientUrlProp,
|
|
67
69
|
reset,
|
|
68
70
|
type,
|
|
69
71
|
children
|
|
@@ -71,6 +73,7 @@ function RemoteComponentClient({
|
|
|
71
73
|
const remoteComponentId = (0, import_react.useId)();
|
|
72
74
|
const [component, setComponent] = (0, import_react.useState)(null);
|
|
73
75
|
const url = (0, import_get_client_or_server_url.getClientOrServerUrl)(src, serverUrl);
|
|
76
|
+
const resolveClientUrl = (0, import_use_resolve_client_url.useResolveClientUrl)(resolveClientUrlProp, url.href);
|
|
74
77
|
const metadataRef = (0, import_react.useRef)({
|
|
75
78
|
name,
|
|
76
79
|
bundle,
|
|
@@ -193,7 +196,11 @@ function RemoteComponentClient({
|
|
|
193
196
|
};
|
|
194
197
|
if (type === "remote-component") {
|
|
195
198
|
setComponent(children);
|
|
196
|
-
(0, import_remote_component.loadStaticRemoteComponent)(
|
|
199
|
+
(0, import_remote_component.loadStaticRemoteComponent)(
|
|
200
|
+
scripts,
|
|
201
|
+
url,
|
|
202
|
+
resolveClientUrl
|
|
203
|
+
).then(({ mount, unmount }) => {
|
|
197
204
|
if (mount.size > 0) {
|
|
198
205
|
let root = shadowRootRef.current;
|
|
199
206
|
try {
|
|
@@ -246,7 +253,8 @@ function RemoteComponentClient({
|
|
|
246
253
|
};
|
|
247
254
|
})(),
|
|
248
255
|
remoteShared,
|
|
249
|
-
container: shadowRootRef.current
|
|
256
|
+
container: shadowRootRef.current,
|
|
257
|
+
resolveClientUrl
|
|
250
258
|
});
|
|
251
259
|
metadataRef.current.loading = false;
|
|
252
260
|
if (result.error) {
|
|
@@ -274,7 +282,8 @@ function RemoteComponentClient({
|
|
|
274
282
|
isolate,
|
|
275
283
|
type,
|
|
276
284
|
keySuffix,
|
|
277
|
-
url
|
|
285
|
+
url,
|
|
286
|
+
resolveClientUrl
|
|
278
287
|
]);
|
|
279
288
|
if (nextData?.buildId === "development" && shadowRootRef.current && isolate !== false && reset && !shadowRootRef.current.querySelector("[data-remote-components-reset]")) {
|
|
280
289
|
const style = document.createElement("style");
|