remote-components 0.0.51 → 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 +297 -217
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.d.ts +2 -0
- package/dist/html/host.js +296 -217
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs +65 -57
- package/dist/html/remote.cjs.map +1 -1
- package/dist/html/remote.js +65 -57
- 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 +11 -2
- package/dist/internal/shared/client/protected-rc-fallback.cjs.map +1 -1
- package/dist/internal/shared/client/protected-rc-fallback.d.ts +2 -1
- package/dist/internal/shared/client/protected-rc-fallback.js +9 -1
- package/dist/internal/shared/client/protected-rc-fallback.js.map +1 -1
- 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 +121 -137
- 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 +120 -137
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/constants.cjs +3 -0
- package/dist/internal/shared/constants.cjs.map +1 -1
- package/dist/internal/shared/constants.d.ts +2 -1
- package/dist/internal/shared/constants.js +2 -0
- package/dist/internal/shared/constants.js.map +1 -1
- 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-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 +6 -1
- 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 +270 -209
- 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 +244 -184
- 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 +2 -0
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +11 -0
- package/dist/next/host/pages-router-server.js +2 -0
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/proxy.cjs +33 -6
- package/dist/next/proxy.cjs.map +1 -1
- package/dist/next/proxy.js +33 -6
- package/dist/next/proxy.js.map +1 -1
- package/dist/proxy-through-host-a676a522.d.ts +52 -0
- package/dist/react/index.cjs +289 -209
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +28 -4
- package/dist/react/index.js +262 -184
- package/dist/react/index.js.map +1 -1
- package/dist/shared/host/proxy.cjs +32 -6
- package/dist/shared/host/proxy.cjs.map +1 -1
- package/dist/shared/host/proxy.js +36 -7
- package/dist/shared/host/proxy.js.map +1 -1
- package/package.json +1 -1
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs +0 -65
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs.map +0 -1
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.d.ts +0 -13
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js +0 -41
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js.map +0 -1
package/dist/html/host.cjs
CHANGED
|
@@ -30,6 +30,51 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
+
// src/shared/constants.ts
|
|
34
|
+
var RC_PROTECTED_REMOTE_FETCH_PATHNAME, CORS_DOCS_URL;
|
|
35
|
+
var init_constants = __esm({
|
|
36
|
+
"src/shared/constants.ts"() {
|
|
37
|
+
"use strict";
|
|
38
|
+
RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
39
|
+
CORS_DOCS_URL = "https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components";
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// src/shared/client/protected-rc-fallback.ts
|
|
44
|
+
function generateProtectedRcFallbackSrc(url) {
|
|
45
|
+
return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
46
|
+
}
|
|
47
|
+
function isProxiedUrl(url) {
|
|
48
|
+
try {
|
|
49
|
+
return new URL(url, location.href).pathname === RC_PROTECTED_REMOTE_FETCH_PATHNAME;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var init_protected_rc_fallback = __esm({
|
|
55
|
+
"src/shared/client/protected-rc-fallback.ts"() {
|
|
56
|
+
"use strict";
|
|
57
|
+
init_constants();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// src/shared/utils/abort.ts
|
|
62
|
+
function isAbortError(error) {
|
|
63
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
|
|
67
|
+
const e = error;
|
|
68
|
+
return typeof e.code === "number" || e.constructor?.name === "DOMException";
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
var init_abort = __esm({
|
|
73
|
+
"src/shared/utils/abort.ts"() {
|
|
74
|
+
"use strict";
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
33
78
|
// src/shared/error.ts
|
|
34
79
|
function multipleRemoteComponentsError(url) {
|
|
35
80
|
return new RemoteComponentsError(
|
|
@@ -42,10 +87,76 @@ function failedToFetchRemoteComponentError(url, { status, statusText }, help = "
|
|
|
42
87
|
{ cause: new Error(`${status} ${statusText}`) }
|
|
43
88
|
);
|
|
44
89
|
}
|
|
90
|
+
async function errorFromFailedFetch(originalUrl, resolvedUrl, res) {
|
|
91
|
+
const isProxied = isProxiedUrl(resolvedUrl.href);
|
|
92
|
+
if (isProxied && res) {
|
|
93
|
+
const body = await res.text().catch(() => "");
|
|
94
|
+
return failedProxyFetchError(
|
|
95
|
+
originalUrl,
|
|
96
|
+
resolvedUrl.href,
|
|
97
|
+
res.status,
|
|
98
|
+
body
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const fallback = failedToFetchRemoteComponentError(
|
|
102
|
+
originalUrl,
|
|
103
|
+
res ?? { status: 0, statusText: "No Response" }
|
|
104
|
+
);
|
|
105
|
+
if (!res)
|
|
106
|
+
return fallback;
|
|
107
|
+
try {
|
|
108
|
+
const body = await res.text();
|
|
109
|
+
const parser = new DOMParser();
|
|
110
|
+
const doc = parser.parseFromString(body, "text/html");
|
|
111
|
+
const errorTemplate = doc.querySelector(
|
|
112
|
+
"template[data-next-error-message]"
|
|
113
|
+
);
|
|
114
|
+
const errorMessage = errorTemplate?.getAttribute("data-next-error-message");
|
|
115
|
+
if (errorMessage) {
|
|
116
|
+
const error = new RemoteComponentsError(errorMessage);
|
|
117
|
+
const errorStack = errorTemplate?.getAttribute("data-next-error-stack");
|
|
118
|
+
if (errorStack) {
|
|
119
|
+
error.stack = errorStack;
|
|
120
|
+
}
|
|
121
|
+
return error;
|
|
122
|
+
}
|
|
123
|
+
} catch (parseError) {
|
|
124
|
+
if (isAbortError(parseError))
|
|
125
|
+
throw parseError;
|
|
126
|
+
}
|
|
127
|
+
return fallback;
|
|
128
|
+
}
|
|
129
|
+
function failedProxyFetchError(originalUrl, proxyUrl, status, responseBody) {
|
|
130
|
+
if (status === 404) {
|
|
131
|
+
return new RemoteComponentsError(
|
|
132
|
+
`Could not proxy the request to "${originalUrl}" \u2014 the proxy endpoint "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" returned 404.
|
|
133
|
+
|
|
134
|
+
The host server needs middleware or a route that handles "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}".
|
|
135
|
+
|
|
136
|
+
Proxying requires two pieces:
|
|
137
|
+
1. resolveClientUrl={proxyClientRequestsThroughHost} on <RemoteComponent>
|
|
138
|
+
2. Middleware or a route for "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" on the host server
|
|
139
|
+
|
|
140
|
+
Docs: ${CORS_DOCS_URL}`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (status === 403) {
|
|
144
|
+
const detail = responseBody ? ` ${responseBody}` : "";
|
|
145
|
+
return new RemoteComponentsError(
|
|
146
|
+
`Proxied request to "${proxyUrl}" was forbidden.${detail} See: ${CORS_DOCS_URL}`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return new RemoteComponentsError(
|
|
150
|
+
`Proxied request for "${originalUrl}" via "${proxyUrl}" failed with status ${status}. See: ${CORS_DOCS_URL}`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
45
153
|
var RemoteComponentsError;
|
|
46
154
|
var init_error = __esm({
|
|
47
155
|
"src/shared/error.ts"() {
|
|
48
156
|
"use strict";
|
|
157
|
+
init_protected_rc_fallback();
|
|
158
|
+
init_constants();
|
|
159
|
+
init_abort();
|
|
49
160
|
RemoteComponentsError = class extends Error {
|
|
50
161
|
code = "REMOTE_COMPONENTS_ERROR";
|
|
51
162
|
constructor(message, options) {
|
|
@@ -62,9 +173,6 @@ function logDebug(location2, message) {
|
|
|
62
173
|
console.debug(`[${PREFIX}:${location2}]: ${message}`);
|
|
63
174
|
}
|
|
64
175
|
}
|
|
65
|
-
function logInfo(location2, message) {
|
|
66
|
-
console.info(`[${PREFIX}:${location2}]: ${message}`);
|
|
67
|
-
}
|
|
68
176
|
function logWarn(location2, message) {
|
|
69
177
|
console.warn(`[${PREFIX}:${location2}]: ${message}`);
|
|
70
178
|
}
|
|
@@ -75,10 +183,24 @@ function logError(location2, message, cause) {
|
|
|
75
183
|
})
|
|
76
184
|
);
|
|
77
185
|
}
|
|
186
|
+
function warnCrossOriginFetchError(logLocation, url) {
|
|
187
|
+
try {
|
|
188
|
+
const parsed = typeof url === "string" ? new URL(url) : url;
|
|
189
|
+
if (typeof location === "undefined" || parsed.origin === location.origin) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
logWarn(
|
|
193
|
+
logLocation,
|
|
194
|
+
`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}`
|
|
195
|
+
);
|
|
196
|
+
} catch {
|
|
197
|
+
}
|
|
198
|
+
}
|
|
78
199
|
var PREFIX, DEBUG;
|
|
79
200
|
var init_logger = __esm({
|
|
80
201
|
"src/shared/utils/logger.ts"() {
|
|
81
202
|
"use strict";
|
|
203
|
+
init_constants();
|
|
82
204
|
init_error();
|
|
83
205
|
PREFIX = "remote-components";
|
|
84
206
|
DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
|
|
@@ -270,26 +392,6 @@ var init_shared_modules = __esm({
|
|
|
270
392
|
}
|
|
271
393
|
});
|
|
272
394
|
|
|
273
|
-
// src/shared/constants.ts
|
|
274
|
-
var RC_PROTECTED_REMOTE_FETCH_PATHNAME;
|
|
275
|
-
var init_constants = __esm({
|
|
276
|
-
"src/shared/constants.ts"() {
|
|
277
|
-
"use strict";
|
|
278
|
-
RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
// src/shared/client/protected-rc-fallback.ts
|
|
283
|
-
function generateProtectedRcFallbackSrc(url) {
|
|
284
|
-
return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
285
|
-
}
|
|
286
|
-
var init_protected_rc_fallback = __esm({
|
|
287
|
-
"src/shared/client/protected-rc-fallback.ts"() {
|
|
288
|
-
"use strict";
|
|
289
|
-
init_constants();
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
|
|
293
395
|
// src/shared/client/webpack-patterns.ts
|
|
294
396
|
var NEXT_BUNDLE_PATH_RE;
|
|
295
397
|
var init_webpack_patterns = __esm({
|
|
@@ -300,7 +402,7 @@ var init_webpack_patterns = __esm({
|
|
|
300
402
|
});
|
|
301
403
|
|
|
302
404
|
// src/shared/client/script-loader.ts
|
|
303
|
-
async function loadScripts(scripts) {
|
|
405
|
+
async function loadScripts(scripts, resolveClientUrl) {
|
|
304
406
|
await Promise.all(
|
|
305
407
|
scripts.map((script) => {
|
|
306
408
|
return new Promise((resolve, reject) => {
|
|
@@ -309,42 +411,29 @@ async function loadScripts(scripts) {
|
|
|
309
411
|
script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
|
|
310
412
|
location.origin
|
|
311
413
|
).href;
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
"
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
} else {
|
|
332
|
-
logError(
|
|
333
|
-
"ScriptLoader",
|
|
334
|
-
`Failed to load fallback for <script src="${newSrc}"> for Remote Component.`
|
|
335
|
-
);
|
|
336
|
-
reject(
|
|
337
|
-
new RemoteComponentsError(
|
|
338
|
-
`Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
|
|
339
|
-
)
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
newScript.src = src;
|
|
344
|
-
newScript.async = true;
|
|
345
|
-
document.head.appendChild(newScript);
|
|
414
|
+
const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
|
|
415
|
+
const newScript = document.createElement("script");
|
|
416
|
+
newScript.onload = () => resolve();
|
|
417
|
+
newScript.onerror = () => {
|
|
418
|
+
const isProxied = isProxiedUrl(resolvedSrc);
|
|
419
|
+
if (isProxied) {
|
|
420
|
+
reject(
|
|
421
|
+
new RemoteComponentsError(
|
|
422
|
+
`Failed to load script "${newSrc}" via proxy "${resolvedSrc}". Ensure withRemoteComponentsHost middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
|
|
423
|
+
)
|
|
424
|
+
);
|
|
425
|
+
} else {
|
|
426
|
+
warnCrossOriginFetchError("ScriptLoader", newSrc);
|
|
427
|
+
reject(
|
|
428
|
+
new RemoteComponentsError(
|
|
429
|
+
`Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
|
|
430
|
+
)
|
|
431
|
+
);
|
|
432
|
+
}
|
|
346
433
|
};
|
|
347
|
-
|
|
434
|
+
newScript.src = resolvedSrc;
|
|
435
|
+
newScript.async = true;
|
|
436
|
+
document.head.appendChild(newScript);
|
|
348
437
|
});
|
|
349
438
|
})
|
|
350
439
|
);
|
|
@@ -385,67 +474,6 @@ var init_const = __esm({
|
|
|
385
474
|
}
|
|
386
475
|
});
|
|
387
476
|
|
|
388
|
-
// src/shared/utils/abort.ts
|
|
389
|
-
function isAbortError(error) {
|
|
390
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
391
|
-
return true;
|
|
392
|
-
}
|
|
393
|
-
if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
|
|
394
|
-
const e = error;
|
|
395
|
-
return typeof e.code === "number" || e.constructor?.name === "DOMException";
|
|
396
|
-
}
|
|
397
|
-
return false;
|
|
398
|
-
}
|
|
399
|
-
var init_abort = __esm({
|
|
400
|
-
"src/shared/utils/abort.ts"() {
|
|
401
|
-
"use strict";
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// src/shared/client/fetch-with-protected-rc-fallback.ts
|
|
406
|
-
async function fetchWithProtectedRcFallback(url, init) {
|
|
407
|
-
try {
|
|
408
|
-
const res = await fetch(url, init);
|
|
409
|
-
return res;
|
|
410
|
-
} catch (error) {
|
|
411
|
-
if (isAbortError(error)) {
|
|
412
|
-
throw error;
|
|
413
|
-
}
|
|
414
|
-
const parsedUrl = new URL(url);
|
|
415
|
-
if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== parsedUrl.origin) {
|
|
416
|
-
logWarn(
|
|
417
|
-
"FetchRemoteComponent",
|
|
418
|
-
"Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
|
|
419
|
-
);
|
|
420
|
-
const proxiedRes = await fetch(
|
|
421
|
-
generateProtectedRcFallbackSrc(parsedUrl.href),
|
|
422
|
-
init?.signal ? { signal: init.signal } : void 0
|
|
423
|
-
);
|
|
424
|
-
if (proxiedRes.status === 200) {
|
|
425
|
-
logInfo(
|
|
426
|
-
"FetchRemoteComponent",
|
|
427
|
-
`Successfully fetched ${parsedUrl.href} with fallback withRemoteComponentsHost proxy`
|
|
428
|
-
);
|
|
429
|
-
return proxiedRes;
|
|
430
|
-
} else {
|
|
431
|
-
logError(
|
|
432
|
-
"FetchRemoteComponent",
|
|
433
|
-
`Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
throw error;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
var init_fetch_with_protected_rc_fallback = __esm({
|
|
441
|
-
"src/shared/client/fetch-with-protected-rc-fallback.ts"() {
|
|
442
|
-
"use strict";
|
|
443
|
-
init_protected_rc_fallback();
|
|
444
|
-
init_abort();
|
|
445
|
-
init_logger();
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
|
|
449
477
|
// src/shared/client/turbopack-patterns.ts
|
|
450
478
|
var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, TURBOPACK_GLOBAL_RE;
|
|
451
479
|
var init_turbopack_patterns = __esm({
|
|
@@ -461,7 +489,7 @@ var init_turbopack_patterns = __esm({
|
|
|
461
489
|
});
|
|
462
490
|
|
|
463
491
|
// src/shared/client/chunk-loader.ts
|
|
464
|
-
function createChunkLoader(runtime) {
|
|
492
|
+
function createChunkLoader(runtime, resolveClientUrl) {
|
|
465
493
|
return function __turbopack_chunk_load__(chunkId, scriptBundle) {
|
|
466
494
|
logDebug("ChunkLoader", `Loading chunk: "${chunkId}"`);
|
|
467
495
|
const self = globalThis;
|
|
@@ -501,9 +529,10 @@ function createChunkLoader(runtime) {
|
|
|
501
529
|
logDebug("ChunkLoader", `Returning cached promise for: "${url}"`);
|
|
502
530
|
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
503
531
|
}
|
|
504
|
-
|
|
532
|
+
const resolvedUrl = resolveClientUrl?.(url) ?? url;
|
|
533
|
+
logDebug("ChunkLoader", `Fetching chunk from: "${resolvedUrl}"`);
|
|
505
534
|
self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
|
|
506
|
-
|
|
535
|
+
fetch(resolvedUrl).then((res) => res.text()).then((code) => {
|
|
507
536
|
const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
|
|
508
537
|
if (hasTurbopack) {
|
|
509
538
|
return handleTurbopackChunk(code, bundle ?? "", url);
|
|
@@ -516,7 +545,19 @@ function createChunkLoader(runtime) {
|
|
|
516
545
|
"ChunkLoader",
|
|
517
546
|
`First 500 chars of chunk: ${code.slice(0, 500)}`
|
|
518
547
|
);
|
|
519
|
-
}).then(resolve).catch(
|
|
548
|
+
}).then(resolve).catch((error) => {
|
|
549
|
+
const isProxied = isProxiedUrl(resolvedUrl);
|
|
550
|
+
if (isProxied) {
|
|
551
|
+
reject(
|
|
552
|
+
new RemoteComponentsError(
|
|
553
|
+
`Failed to load chunk "${url}" via proxy "${resolvedUrl}". Ensure withRemoteComponentsHost middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
|
|
554
|
+
)
|
|
555
|
+
);
|
|
556
|
+
} else {
|
|
557
|
+
warnCrossOriginFetchError("ChunkLoader", url);
|
|
558
|
+
reject(error);
|
|
559
|
+
}
|
|
560
|
+
});
|
|
520
561
|
});
|
|
521
562
|
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
522
563
|
};
|
|
@@ -661,10 +702,11 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
661
702
|
var init_chunk_loader = __esm({
|
|
662
703
|
"src/shared/client/chunk-loader.ts"() {
|
|
663
704
|
"use strict";
|
|
705
|
+
init_constants();
|
|
664
706
|
init_error();
|
|
665
707
|
init_logger();
|
|
666
708
|
init_const();
|
|
667
|
-
|
|
709
|
+
init_protected_rc_fallback();
|
|
668
710
|
init_turbopack_patterns();
|
|
669
711
|
}
|
|
670
712
|
});
|
|
@@ -1035,7 +1077,7 @@ var init_shared_modules2 = __esm({
|
|
|
1035
1077
|
});
|
|
1036
1078
|
|
|
1037
1079
|
// src/shared/client/webpack-adapter.ts
|
|
1038
|
-
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}) {
|
|
1080
|
+
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
|
|
1039
1081
|
const self = globalThis;
|
|
1040
1082
|
if (!self.__remote_bundle_url__) {
|
|
1041
1083
|
self.__remote_bundle_url__ = {};
|
|
@@ -1047,7 +1089,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1047
1089
|
self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
|
|
1048
1090
|
self.__original_webpack_require__ = self.__webpack_require__;
|
|
1049
1091
|
}
|
|
1050
|
-
self.__webpack_chunk_load__ = createChunkLoader(runtime);
|
|
1092
|
+
self.__webpack_chunk_load__ = createChunkLoader(runtime, resolveClientUrl);
|
|
1051
1093
|
self.__webpack_require__ = createModuleRequire(runtime);
|
|
1052
1094
|
self.__webpack_require_type__ = runtime;
|
|
1053
1095
|
if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
|
|
@@ -1141,27 +1183,21 @@ var init_webpack_adapter = __esm({
|
|
|
1141
1183
|
});
|
|
1142
1184
|
|
|
1143
1185
|
// src/shared/client/static-loader.ts
|
|
1144
|
-
async function
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
).href;
|
|
1149
|
-
const response = await fetch(proxyUrl);
|
|
1186
|
+
async function importViaCallback(absoluteSrc, resolveClientUrl) {
|
|
1187
|
+
const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
|
|
1188
|
+
const fetchUrl = new URL(resolvedUrl, location.href).href;
|
|
1189
|
+
const response = await fetch(fetchUrl);
|
|
1150
1190
|
if (!response.ok)
|
|
1151
|
-
throw new Error(`
|
|
1152
|
-
logInfo(
|
|
1153
|
-
"StaticLoader",
|
|
1154
|
-
`Successfully loaded ${absoluteSrc} via protected RC proxy fallback.`
|
|
1155
|
-
);
|
|
1191
|
+
throw new Error(`Proxied fetch failed: ${response.status}`);
|
|
1156
1192
|
const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
|
|
1157
1193
|
/\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
|
|
1158
1194
|
(_, keyword, quote, relativePath) => {
|
|
1159
1195
|
const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1196
|
+
const resolvedImportUrl = new URL(
|
|
1197
|
+
resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
|
|
1162
1198
|
location.href
|
|
1163
1199
|
).href;
|
|
1164
|
-
return `${keyword} ${quote}${
|
|
1200
|
+
return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
|
|
1165
1201
|
}
|
|
1166
1202
|
);
|
|
1167
1203
|
const moduleBlobUrl = URL.createObjectURL(
|
|
@@ -1195,6 +1231,20 @@ async function importViaProxy(absoluteSrc) {
|
|
|
1195
1231
|
delete registry[absoluteSrc];
|
|
1196
1232
|
return mod;
|
|
1197
1233
|
}
|
|
1234
|
+
async function importDirectly(absoluteSrc) {
|
|
1235
|
+
try {
|
|
1236
|
+
return await import(
|
|
1237
|
+
/* @vite-ignore */
|
|
1238
|
+
/* webpackIgnore: true */
|
|
1239
|
+
absoluteSrc
|
|
1240
|
+
);
|
|
1241
|
+
} catch (importError) {
|
|
1242
|
+
if (!absoluteSrc.startsWith("blob:")) {
|
|
1243
|
+
warnCrossOriginFetchError("StaticLoader", absoluteSrc);
|
|
1244
|
+
}
|
|
1245
|
+
throw importError;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1198
1248
|
function resolveScriptSrc(script, url) {
|
|
1199
1249
|
const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
1200
1250
|
if (!rawSrc && script.textContent) {
|
|
@@ -1207,24 +1257,7 @@ function resolveScriptSrc(script, url) {
|
|
|
1207
1257
|
}
|
|
1208
1258
|
return rawSrc;
|
|
1209
1259
|
}
|
|
1210
|
-
async function
|
|
1211
|
-
try {
|
|
1212
|
-
return await import(
|
|
1213
|
-
/* @vite-ignore */
|
|
1214
|
-
/* webpackIgnore: true */
|
|
1215
|
-
absoluteSrc
|
|
1216
|
-
);
|
|
1217
|
-
} catch (importError) {
|
|
1218
|
-
if (absoluteSrc.startsWith("blob:"))
|
|
1219
|
-
throw importError;
|
|
1220
|
-
logWarn(
|
|
1221
|
-
"StaticLoader",
|
|
1222
|
-
`Direct import of ${absoluteSrc} failed, attempting via protected RC proxy fallback.`
|
|
1223
|
-
);
|
|
1224
|
-
return importViaProxy(absoluteSrc);
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
async function loadStaticRemoteComponent(scripts, url) {
|
|
1260
|
+
async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
1228
1261
|
const self = globalThis;
|
|
1229
1262
|
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
1230
1263
|
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
@@ -1237,7 +1270,7 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
1237
1270
|
try {
|
|
1238
1271
|
const src = resolveScriptSrc(script, url);
|
|
1239
1272
|
const absoluteSrc = new URL(src, url).href;
|
|
1240
|
-
const mod = await
|
|
1273
|
+
const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
|
|
1241
1274
|
if (src.startsWith("blob:")) {
|
|
1242
1275
|
URL.revokeObjectURL(src);
|
|
1243
1276
|
}
|
|
@@ -1302,7 +1335,6 @@ var init_static_loader = __esm({
|
|
|
1302
1335
|
"src/shared/client/static-loader.ts"() {
|
|
1303
1336
|
"use strict";
|
|
1304
1337
|
init_logger();
|
|
1305
|
-
init_protected_rc_fallback();
|
|
1306
1338
|
}
|
|
1307
1339
|
});
|
|
1308
1340
|
|
|
@@ -1512,7 +1544,7 @@ var webpack_exports = {};
|
|
|
1512
1544
|
__export(webpack_exports, {
|
|
1513
1545
|
webpackRuntime: () => webpackRuntime
|
|
1514
1546
|
});
|
|
1515
|
-
async function webpackRuntime(bundle, shared, remoteShared) {
|
|
1547
|
+
async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
|
|
1516
1548
|
const self = globalThis;
|
|
1517
1549
|
if (!self.__DISABLE_WEBPACK_EXEC__) {
|
|
1518
1550
|
self.__DISABLE_WEBPACK_EXEC__ = {};
|
|
@@ -1555,7 +1587,7 @@ async function webpackRuntime(bundle, shared, remoteShared) {
|
|
|
1555
1587
|
}
|
|
1556
1588
|
];
|
|
1557
1589
|
});
|
|
1558
|
-
await loadScripts(scriptSrcs);
|
|
1590
|
+
await loadScripts(scriptSrcs, resolveClientUrl);
|
|
1559
1591
|
const hostShared = {
|
|
1560
1592
|
...sharedPolyfills(shared),
|
|
1561
1593
|
...self.__remote_component_host_shared_modules__,
|
|
@@ -1612,7 +1644,7 @@ var turbopack_exports = {};
|
|
|
1612
1644
|
__export(turbopack_exports, {
|
|
1613
1645
|
turbopackRuntime: () => turbopackRuntime
|
|
1614
1646
|
});
|
|
1615
|
-
async function turbopackRuntime(url, bundle, shared, remoteShared) {
|
|
1647
|
+
async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClientUrl) {
|
|
1616
1648
|
const self = globalThis;
|
|
1617
1649
|
const hostShared = {
|
|
1618
1650
|
...sharedPolyfills(shared),
|
|
@@ -1626,7 +1658,8 @@ async function turbopackRuntime(url, bundle, shared, remoteShared) {
|
|
|
1626
1658
|
url,
|
|
1627
1659
|
bundle,
|
|
1628
1660
|
hostShared,
|
|
1629
|
-
remoteShared
|
|
1661
|
+
remoteShared,
|
|
1662
|
+
resolveClientUrl
|
|
1630
1663
|
);
|
|
1631
1664
|
const {
|
|
1632
1665
|
default: { createFromReadableStream }
|
|
@@ -1640,7 +1673,8 @@ async function turbopackRuntime(url, bundle, shared, remoteShared) {
|
|
|
1640
1673
|
url,
|
|
1641
1674
|
bundle,
|
|
1642
1675
|
hostShared,
|
|
1643
|
-
remoteShared
|
|
1676
|
+
remoteShared,
|
|
1677
|
+
resolveClientUrl
|
|
1644
1678
|
);
|
|
1645
1679
|
}
|
|
1646
1680
|
return {
|
|
@@ -1666,7 +1700,7 @@ var script_exports = {};
|
|
|
1666
1700
|
__export(script_exports, {
|
|
1667
1701
|
scriptRuntime: () => scriptRuntime
|
|
1668
1702
|
});
|
|
1669
|
-
function scriptRuntime() {
|
|
1703
|
+
function scriptRuntime(resolveClientUrl) {
|
|
1670
1704
|
const self = globalThis;
|
|
1671
1705
|
return {
|
|
1672
1706
|
self,
|
|
@@ -1676,7 +1710,7 @@ function scriptRuntime() {
|
|
|
1676
1710
|
Component: null,
|
|
1677
1711
|
App: null
|
|
1678
1712
|
}),
|
|
1679
|
-
preloadScripts: loadStaticRemoteComponent
|
|
1713
|
+
preloadScripts: (scripts, url) => loadStaticRemoteComponent(scripts, url, resolveClientUrl)
|
|
1680
1714
|
};
|
|
1681
1715
|
}
|
|
1682
1716
|
var init_script = __esm({
|
|
@@ -1689,6 +1723,7 @@ var init_script = __esm({
|
|
|
1689
1723
|
// src/html/host/index.tsx
|
|
1690
1724
|
var host_exports = {};
|
|
1691
1725
|
__export(host_exports, {
|
|
1726
|
+
proxyClientRequestsThroughHost: () => proxyClientRequestsThroughHost,
|
|
1692
1727
|
registerSharedModules: () => registerSharedModules
|
|
1693
1728
|
});
|
|
1694
1729
|
module.exports = __toCommonJS(host_exports);
|
|
@@ -1707,7 +1742,7 @@ var tagNames = [
|
|
|
1707
1742
|
"script",
|
|
1708
1743
|
"link"
|
|
1709
1744
|
];
|
|
1710
|
-
function applyOriginToNodes(doc, url) {
|
|
1745
|
+
function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
1711
1746
|
if (url.origin !== location.origin) {
|
|
1712
1747
|
const nodes = doc.querySelectorAll(
|
|
1713
1748
|
tagNames.map(
|
|
@@ -1716,12 +1751,15 @@ function applyOriginToNodes(doc, url) {
|
|
|
1716
1751
|
);
|
|
1717
1752
|
nodes.forEach((node) => {
|
|
1718
1753
|
if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
|
|
1719
|
-
|
|
1754
|
+
const absoluteSrc = new URL(node.getAttribute("src") ?? "/", url).href;
|
|
1755
|
+
const isScript = node.tagName.toLowerCase() === "script";
|
|
1756
|
+
node.src = isScript ? absoluteSrc : resolveClientUrl?.(absoluteSrc) ?? absoluteSrc;
|
|
1720
1757
|
}
|
|
1721
1758
|
if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
|
|
1759
|
+
const absoluteHref = new URL(node.getAttribute("href") ?? "/", url).href;
|
|
1722
1760
|
node.setAttribute(
|
|
1723
1761
|
"href",
|
|
1724
|
-
|
|
1762
|
+
resolveClientUrl?.(absoluteHref) ?? absoluteHref
|
|
1725
1763
|
);
|
|
1726
1764
|
}
|
|
1727
1765
|
if (node.hasAttribute("srcset")) {
|
|
@@ -1730,7 +1768,8 @@ function applyOriginToNodes(doc, url) {
|
|
|
1730
1768
|
if (!urlPart)
|
|
1731
1769
|
return entry;
|
|
1732
1770
|
const absoluteUrl = new URL(urlPart, url).href;
|
|
1733
|
-
|
|
1771
|
+
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
1772
|
+
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
1734
1773
|
}).join(", ");
|
|
1735
1774
|
if (srcSet) {
|
|
1736
1775
|
node.setAttribute("srcset", srcSet);
|
|
@@ -1742,7 +1781,8 @@ function applyOriginToNodes(doc, url) {
|
|
|
1742
1781
|
if (!urlPart)
|
|
1743
1782
|
return entry;
|
|
1744
1783
|
const absoluteUrl = new URL(urlPart, url).href;
|
|
1745
|
-
|
|
1784
|
+
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
1785
|
+
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
1746
1786
|
}).join(", ");
|
|
1747
1787
|
if (srcSet) {
|
|
1748
1788
|
node.setAttribute("imagesrcset", srcSet);
|
|
@@ -1752,6 +1792,34 @@ function applyOriginToNodes(doc, url) {
|
|
|
1752
1792
|
}
|
|
1753
1793
|
}
|
|
1754
1794
|
|
|
1795
|
+
// src/shared/client/proxy-through-host.ts
|
|
1796
|
+
init_protected_rc_fallback();
|
|
1797
|
+
function withRemoteSrc(resolveClientUrl, remoteSrc) {
|
|
1798
|
+
return (url) => resolveClientUrl(remoteSrc, url);
|
|
1799
|
+
}
|
|
1800
|
+
var proxyClientRequestsThroughHost = (remoteSrc, url) => {
|
|
1801
|
+
if (typeof location === "undefined") {
|
|
1802
|
+
return void 0;
|
|
1803
|
+
}
|
|
1804
|
+
const remoteOrigin = new URL(remoteSrc, location.href).origin;
|
|
1805
|
+
if (remoteOrigin === location.origin) {
|
|
1806
|
+
return void 0;
|
|
1807
|
+
}
|
|
1808
|
+
try {
|
|
1809
|
+
const parsed = new URL(url, location.href);
|
|
1810
|
+
if (parsed.origin === remoteOrigin) {
|
|
1811
|
+
return generateProtectedRcFallbackSrc(url);
|
|
1812
|
+
}
|
|
1813
|
+
} catch {
|
|
1814
|
+
}
|
|
1815
|
+
return void 0;
|
|
1816
|
+
};
|
|
1817
|
+
|
|
1818
|
+
// src/shared/client/default-resolve-client-url.ts
|
|
1819
|
+
function bindResolveClientUrl(prop, remoteSrc) {
|
|
1820
|
+
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1755
1823
|
// src/shared/client/remote-component.ts
|
|
1756
1824
|
init_error();
|
|
1757
1825
|
|
|
@@ -1846,7 +1914,7 @@ init_webpack_adapter();
|
|
|
1846
1914
|
init_error();
|
|
1847
1915
|
|
|
1848
1916
|
// src/shared/ssr/fetch-with-hooks.ts
|
|
1849
|
-
|
|
1917
|
+
init_logger();
|
|
1850
1918
|
|
|
1851
1919
|
// src/shared/ssr/fetch-headers.ts
|
|
1852
1920
|
function remoteFetchHeaders() {
|
|
@@ -1884,7 +1952,12 @@ async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
|
1884
1952
|
};
|
|
1885
1953
|
let res = await onRequest?.(url, init, hookOptions);
|
|
1886
1954
|
if (!res) {
|
|
1887
|
-
|
|
1955
|
+
try {
|
|
1956
|
+
res = await fetch(url, init);
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
warnCrossOriginFetchError("FetchRemoteComponent", url);
|
|
1959
|
+
throw error;
|
|
1960
|
+
}
|
|
1888
1961
|
}
|
|
1889
1962
|
const transformedRes = await onResponse?.(url, res, hookOptions);
|
|
1890
1963
|
if (transformedRes) {
|
|
@@ -1907,7 +1980,8 @@ async function attachStyles({
|
|
|
1907
1980
|
signal,
|
|
1908
1981
|
baseUrl,
|
|
1909
1982
|
remoteComponentSrc,
|
|
1910
|
-
root
|
|
1983
|
+
root,
|
|
1984
|
+
resolveClientUrl
|
|
1911
1985
|
}) {
|
|
1912
1986
|
const appendedLinks = [];
|
|
1913
1987
|
let abortReject = null;
|
|
@@ -1942,9 +2016,13 @@ async function attachStyles({
|
|
|
1942
2016
|
});
|
|
1943
2017
|
for (const attr of link.attributes) {
|
|
1944
2018
|
if (attr.name === "href") {
|
|
2019
|
+
const absoluteHref = new URL(
|
|
2020
|
+
attr.value,
|
|
2021
|
+
baseUrl ?? location.origin
|
|
2022
|
+
).href;
|
|
1945
2023
|
newLink.setAttribute(
|
|
1946
2024
|
attr.name,
|
|
1947
|
-
|
|
2025
|
+
resolveClientUrl?.(absoluteHref) ?? absoluteHref
|
|
1948
2026
|
);
|
|
1949
2027
|
} else {
|
|
1950
2028
|
newLink.setAttribute(attr.name, attr.value);
|
|
@@ -1978,7 +2056,7 @@ async function attachStyles({
|
|
|
1978
2056
|
|
|
1979
2057
|
// src/html/host/runtime/index.ts
|
|
1980
2058
|
init_error();
|
|
1981
|
-
async function getRuntime(type, url, bundle, shared, remoteShared) {
|
|
2059
|
+
async function getRuntime(type, url, bundle, shared, remoteShared, resolveClientUrl) {
|
|
1982
2060
|
if (typeof globalThis.process === "undefined") {
|
|
1983
2061
|
globalThis.process = {
|
|
1984
2062
|
env: {}
|
|
@@ -1986,13 +2064,24 @@ async function getRuntime(type, url, bundle, shared, remoteShared) {
|
|
|
1986
2064
|
}
|
|
1987
2065
|
if (type === "webpack") {
|
|
1988
2066
|
const { webpackRuntime: webpackRuntime2 } = await Promise.resolve().then(() => (init_webpack(), webpack_exports));
|
|
1989
|
-
return webpackRuntime2(
|
|
2067
|
+
return webpackRuntime2(
|
|
2068
|
+
bundle ?? "default",
|
|
2069
|
+
shared,
|
|
2070
|
+
remoteShared,
|
|
2071
|
+
resolveClientUrl
|
|
2072
|
+
);
|
|
1990
2073
|
} else if (type === "turbopack") {
|
|
1991
2074
|
const { turbopackRuntime: turbopackRuntime2 } = await Promise.resolve().then(() => (init_turbopack(), turbopack_exports));
|
|
1992
|
-
return turbopackRuntime2(
|
|
2075
|
+
return turbopackRuntime2(
|
|
2076
|
+
url,
|
|
2077
|
+
bundle,
|
|
2078
|
+
shared,
|
|
2079
|
+
remoteShared,
|
|
2080
|
+
resolveClientUrl
|
|
2081
|
+
);
|
|
1993
2082
|
} else if (type === "script") {
|
|
1994
2083
|
const { scriptRuntime: scriptRuntime2 } = await Promise.resolve().then(() => (init_script(), script_exports));
|
|
1995
|
-
return scriptRuntime2();
|
|
2084
|
+
return scriptRuntime2(resolveClientUrl);
|
|
1996
2085
|
}
|
|
1997
2086
|
throw new RemoteComponentsError(
|
|
1998
2087
|
`Remote Components runtime "${type}" is not supported. Supported runtimes are "webpack", "turbopack", and "script".`
|
|
@@ -2017,6 +2106,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2017
2106
|
reactRoot;
|
|
2018
2107
|
onRequest;
|
|
2019
2108
|
onResponse;
|
|
2109
|
+
resolveClientUrl;
|
|
2020
2110
|
/** Current AbortController for the loading operation - can be used to cancel loading via controller.abort() */
|
|
2021
2111
|
abortController;
|
|
2022
2112
|
static get observedAttributes() {
|
|
@@ -2123,13 +2213,18 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2123
2213
|
this.name = url.hash.slice(1);
|
|
2124
2214
|
}
|
|
2125
2215
|
}
|
|
2216
|
+
const resolveClientUrl = url ? bindResolveClientUrl(this.resolveClientUrl, url.href) : void 0;
|
|
2126
2217
|
if (!remoteComponentChild && url) {
|
|
2127
2218
|
const fetchInit = {
|
|
2128
2219
|
credentials: this.getAttribute("credentials") || "same-origin"
|
|
2129
2220
|
};
|
|
2221
|
+
const resolvedUrl = new URL(
|
|
2222
|
+
resolveClientUrl?.(url.href) ?? url.href,
|
|
2223
|
+
window.location.href
|
|
2224
|
+
);
|
|
2130
2225
|
let res;
|
|
2131
2226
|
try {
|
|
2132
|
-
res = await fetchWithHooks(
|
|
2227
|
+
res = await fetchWithHooks(resolvedUrl, fetchInit, {
|
|
2133
2228
|
onRequest: this.onRequest,
|
|
2134
2229
|
onResponse: this.onResponse,
|
|
2135
2230
|
abortController: this.abortController
|
|
@@ -2141,34 +2236,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2141
2236
|
throw e;
|
|
2142
2237
|
}
|
|
2143
2238
|
if (!res || !res.ok) {
|
|
2144
|
-
|
|
2145
|
-
url.href,
|
|
2146
|
-
res ?? new Response(null, { status: 0 })
|
|
2147
|
-
);
|
|
2148
|
-
try {
|
|
2149
|
-
const body = res ? await res.text() : "";
|
|
2150
|
-
const parser2 = new DOMParser();
|
|
2151
|
-
const doc2 = parser2.parseFromString(body, "text/html");
|
|
2152
|
-
const errorTemplate = doc2.querySelector(
|
|
2153
|
-
"template[data-next-error-message]"
|
|
2154
|
-
);
|
|
2155
|
-
const errorMessage = errorTemplate?.getAttribute(
|
|
2156
|
-
"data-next-error-message"
|
|
2157
|
-
);
|
|
2158
|
-
const errorStack = errorTemplate?.getAttribute(
|
|
2159
|
-
"data-next-error-stack"
|
|
2160
|
-
);
|
|
2161
|
-
if (errorMessage) {
|
|
2162
|
-
error = new RemoteComponentsError(errorMessage);
|
|
2163
|
-
if (errorStack) {
|
|
2164
|
-
error.stack = errorStack;
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
} catch (parseError) {
|
|
2168
|
-
if (isAbortError(parseError))
|
|
2169
|
-
throw parseError;
|
|
2170
|
-
}
|
|
2171
|
-
throw error;
|
|
2239
|
+
throw await errorFromFailedFetch(url.href, resolvedUrl, res);
|
|
2172
2240
|
}
|
|
2173
2241
|
try {
|
|
2174
2242
|
html = await res.text();
|
|
@@ -2283,7 +2351,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2283
2351
|
});
|
|
2284
2352
|
this.dispatchEvent(changeEvent);
|
|
2285
2353
|
}
|
|
2286
|
-
this.prevUrl = url ?? new URL(location.href);
|
|
2354
|
+
this.prevUrl = url ?? new URL(window.location.href);
|
|
2287
2355
|
this.prevIsRemoteComponent = isRemoteComponent;
|
|
2288
2356
|
this.prevSrc = src;
|
|
2289
2357
|
this.prevName = this.name;
|
|
@@ -2298,7 +2366,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2298
2366
|
// Effects run after load, no abort needed
|
|
2299
2367
|
baseUrl: url?.href,
|
|
2300
2368
|
remoteComponentSrc,
|
|
2301
|
-
root: this.root ?? null
|
|
2369
|
+
root: this.root ?? null,
|
|
2370
|
+
resolveClientUrl
|
|
2302
2371
|
});
|
|
2303
2372
|
if (!this.reactRoot) {
|
|
2304
2373
|
await attachStyles({
|
|
@@ -2308,22 +2377,31 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2308
2377
|
signal,
|
|
2309
2378
|
baseUrl: url?.href,
|
|
2310
2379
|
remoteComponentSrc,
|
|
2311
|
-
root: this.root
|
|
2380
|
+
root: this.root,
|
|
2381
|
+
resolveClientUrl
|
|
2312
2382
|
});
|
|
2313
2383
|
if (!isCurrentLoad()) {
|
|
2314
2384
|
return abandonLoad();
|
|
2315
2385
|
}
|
|
2316
2386
|
}
|
|
2317
|
-
applyOriginToNodes(
|
|
2387
|
+
applyOriginToNodes(
|
|
2388
|
+
doc,
|
|
2389
|
+
url ?? new URL(window.location.href),
|
|
2390
|
+
resolveClientUrl
|
|
2391
|
+
);
|
|
2318
2392
|
if (!this.reactRoot) {
|
|
2319
2393
|
Array.from(component.children).forEach((el) => {
|
|
2320
2394
|
if (!isRemoteComponent && el.tagName.toLowerCase() === "script") {
|
|
2321
2395
|
const newScript = document.createElement("script");
|
|
2322
2396
|
for (const attr of el.attributes) {
|
|
2323
2397
|
if (attr.name === "src") {
|
|
2398
|
+
const absoluteSrc = new URL(
|
|
2399
|
+
attr.value,
|
|
2400
|
+
url ?? window.location.origin
|
|
2401
|
+
).href;
|
|
2324
2402
|
newScript.setAttribute(
|
|
2325
2403
|
attr.name,
|
|
2326
|
-
|
|
2404
|
+
resolveClientUrl?.(absoluteSrc) ?? absoluteSrc
|
|
2327
2405
|
);
|
|
2328
2406
|
} else {
|
|
2329
2407
|
newScript.setAttribute(attr.name, attr.value);
|
|
@@ -2385,7 +2463,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2385
2463
|
preloadScripts
|
|
2386
2464
|
} = await getRuntime(
|
|
2387
2465
|
metadataObj.runtime,
|
|
2388
|
-
url ?? new URL(location.href),
|
|
2466
|
+
url ?? new URL(window.location.href),
|
|
2389
2467
|
this.bundle,
|
|
2390
2468
|
{
|
|
2391
2469
|
react: async () => (await import("react")).default,
|
|
@@ -2394,7 +2472,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2394
2472
|
"react-dom": async () => (await import("react-dom")).default,
|
|
2395
2473
|
"react-dom/client": async () => (await import("react-dom/client")).default
|
|
2396
2474
|
},
|
|
2397
|
-
remoteShared
|
|
2475
|
+
remoteShared,
|
|
2476
|
+
resolveClientUrl
|
|
2398
2477
|
);
|
|
2399
2478
|
if (!isCurrentLoad()) {
|
|
2400
2479
|
return abandonLoad();
|
|
@@ -2617,6 +2696,7 @@ function registerSharedModules(modules = {}) {
|
|
|
2617
2696
|
}
|
|
2618
2697
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2619
2698
|
0 && (module.exports = {
|
|
2699
|
+
proxyClientRequestsThroughHost,
|
|
2620
2700
|
registerSharedModules
|
|
2621
2701
|
});
|
|
2622
2702
|
//# sourceMappingURL=host.cjs.map
|