remote-components 0.0.51 → 0.1.2
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-21865da3.d.ts} +142 -16
- package/dist/host-config-58cdccea.d.ts +87 -0
- package/dist/html/host.cjs +589 -377
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.d.ts +2 -0
- package/dist/html/host.js +588 -377
- 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 +21 -10
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +36 -14
- package/dist/internal/next/host/app-router-client.js +21 -10
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/remote/render-server.cjs.map +1 -1
- package/dist/internal/next/remote/render-server.d.ts +13 -14
- package/dist/internal/next/remote/render-server.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 +65 -0
- package/dist/internal/shared/client/proxy-through-host.cjs.map +1 -0
- package/dist/internal/shared/client/proxy-through-host.d.ts +62 -0
- package/dist/internal/shared/client/proxy-through-host.js +40 -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/contract/host-state.cjs +38 -0
- package/dist/internal/shared/contract/host-state.cjs.map +1 -0
- package/dist/internal/shared/contract/host-state.d.ts +53 -0
- package/dist/internal/shared/contract/host-state.js +14 -0
- package/dist/internal/shared/contract/host-state.js.map +1 -0
- package/dist/internal/shared/contract/resolve-name-from-src.cjs +40 -0
- package/dist/internal/shared/contract/resolve-name-from-src.cjs.map +1 -0
- package/dist/internal/shared/contract/resolve-name-from-src.d.ts +13 -0
- package/dist/internal/shared/contract/resolve-name-from-src.js +16 -0
- package/dist/internal/shared/contract/resolve-name-from-src.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/dom-flight.d.ts +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
- 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.d.ts +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/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.d.ts +11 -41
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +467 -298
- 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 +445 -277
- 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 +14 -26
- 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 +17 -31
- package/dist/next/host/pages-router-server.js +2 -0
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.ts +13 -39
- package/dist/next/index.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/next/remote/server.d.ts +4 -0
- package/dist/proxy-through-host-a676a522.d.ts +52 -0
- package/dist/react/index.cjs +486 -298
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +27 -40
- package/dist/react/index.js +463 -277
- 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/dist/{types-cbe44b51.d.ts → types-2b26a246.d.ts} +23 -6
- 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
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { M as MountOrUnmountFunction } from '../../../component-loader-
|
|
2
|
-
export { G as GlobalScope, L as LoadRemoteComponentProps,
|
|
1
|
+
import { M as MountOrUnmountFunction } from '../../../component-loader-21865da3.js';
|
|
2
|
+
export { G as GlobalScope, L as LoadRemoteComponentProps, d as LoaderResult, R as RemoteComponentPayload, e as ResolvedRemoteComponentData, l as loadRemoteComponent } from '../../../component-loader-21865da3.js';
|
|
3
|
+
import { I as InternalResolveClientUrl } from '../../../proxy-through-host-a676a522.js';
|
|
4
|
+
export { p as proxyClientRequestsThroughHost } from '../../../proxy-through-host-a676a522.js';
|
|
3
5
|
import { ReadableStream } from 'web-streams-polyfill';
|
|
4
6
|
import 'react';
|
|
5
7
|
|
|
@@ -32,11 +34,11 @@ declare function createRSCStream(rscName: string, data: string[]): ReadableStrea
|
|
|
32
34
|
*/
|
|
33
35
|
declare function loadScripts(scripts: {
|
|
34
36
|
src: string;
|
|
35
|
-
}[]): Promise<void>;
|
|
37
|
+
}[], resolveClientUrl?: InternalResolveClientUrl): Promise<void>;
|
|
36
38
|
|
|
37
39
|
declare function setAttributesFromProps(el: HTMLElement, props: object): void;
|
|
38
40
|
|
|
39
|
-
declare function loadStaticRemoteComponent(scripts: HTMLScriptElement[], url: URL): Promise<{
|
|
41
|
+
declare function loadStaticRemoteComponent(scripts: HTMLScriptElement[], url: URL, resolveClientUrl?: InternalResolveClientUrl): Promise<{
|
|
40
42
|
mount: Set<MountOrUnmountFunction>;
|
|
41
43
|
unmount: Set<MountOrUnmountFunction>;
|
|
42
44
|
}>;
|
|
@@ -55,6 +57,6 @@ declare function loadStaticRemoteComponent(scripts: HTMLScriptElement[], url: UR
|
|
|
55
57
|
*/
|
|
56
58
|
declare function setupWebpackRuntime(runtime: Runtime, scripts?: {
|
|
57
59
|
src: string | null;
|
|
58
|
-
}[], url?: URL, bundle?: string, shared?: Record<string, () => Promise<unknown>>, remoteShared?: Record<string, string
|
|
60
|
+
}[], url?: URL, bundle?: string, shared?: Record<string, () => Promise<unknown>>, remoteShared?: Record<string, string>, resolveClientUrl?: InternalResolveClientUrl): Promise<void>;
|
|
59
61
|
|
|
60
62
|
export { DEFAULT_ROUTE, REMOTE_COMPONENT_REGEX, RUNTIME_SCRIPT, RUNTIME_TURBOPACK, RUNTIME_WEBPACK, RemoteComponentsError, Runtime, createRSCStream, fixPayload, getBundleKey, loadScripts, loadStaticRemoteComponent, setAttributesFromProps, setupWebpackRuntime };
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
// src/shared/constants.ts
|
|
2
|
+
var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
3
|
+
var CORS_DOCS_URL = "https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components";
|
|
4
|
+
|
|
5
|
+
// src/shared/client/protected-rc-fallback.ts
|
|
6
|
+
function generateProtectedRcFallbackSrc(url) {
|
|
7
|
+
return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
8
|
+
}
|
|
9
|
+
function isProxiedUrl(url) {
|
|
10
|
+
try {
|
|
11
|
+
return new URL(url, location.href).pathname === RC_PROTECTED_REMOTE_FETCH_PATHNAME;
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
// src/shared/error.ts
|
|
2
18
|
var RemoteComponentsError = class extends Error {
|
|
3
19
|
code = "REMOTE_COMPONENTS_ERROR";
|
|
@@ -22,9 +38,6 @@ function logDebug(location2, message) {
|
|
|
22
38
|
console.debug(`[${PREFIX}:${location2}]: ${message}`);
|
|
23
39
|
}
|
|
24
40
|
}
|
|
25
|
-
function logInfo(location2, message) {
|
|
26
|
-
console.info(`[${PREFIX}:${location2}]: ${message}`);
|
|
27
|
-
}
|
|
28
41
|
function logWarn(location2, message) {
|
|
29
42
|
console.warn(`[${PREFIX}:${location2}]: ${message}`);
|
|
30
43
|
}
|
|
@@ -35,6 +48,19 @@ function logError(location2, message, cause) {
|
|
|
35
48
|
})
|
|
36
49
|
);
|
|
37
50
|
}
|
|
51
|
+
function warnCrossOriginFetchError(logLocation, url) {
|
|
52
|
+
try {
|
|
53
|
+
const parsed = typeof url === "string" ? new URL(url) : url;
|
|
54
|
+
if (typeof location === "undefined" || parsed.origin === location.origin) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
logWarn(
|
|
58
|
+
logLocation,
|
|
59
|
+
`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}`
|
|
60
|
+
);
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
38
64
|
|
|
39
65
|
// src/shared/webpack/next-client-pages-loader.ts
|
|
40
66
|
function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
@@ -275,19 +301,11 @@ function createRSCStream(rscName, data) {
|
|
|
275
301
|
});
|
|
276
302
|
}
|
|
277
303
|
|
|
278
|
-
// src/shared/constants.ts
|
|
279
|
-
var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
280
|
-
|
|
281
|
-
// src/shared/client/protected-rc-fallback.ts
|
|
282
|
-
function generateProtectedRcFallbackSrc(url) {
|
|
283
|
-
return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
304
|
// src/shared/client/webpack-patterns.ts
|
|
287
305
|
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
288
306
|
|
|
289
307
|
// src/shared/client/script-loader.ts
|
|
290
|
-
async function loadScripts(scripts) {
|
|
308
|
+
async function loadScripts(scripts, resolveClientUrl) {
|
|
291
309
|
await Promise.all(
|
|
292
310
|
scripts.map((script) => {
|
|
293
311
|
return new Promise((resolve, reject) => {
|
|
@@ -296,42 +314,29 @@ async function loadScripts(scripts) {
|
|
|
296
314
|
script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
|
|
297
315
|
location.origin
|
|
298
316
|
).href;
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
"
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
} else {
|
|
319
|
-
logError(
|
|
320
|
-
"ScriptLoader",
|
|
321
|
-
`Failed to load fallback for <script src="${newSrc}"> for Remote Component.`
|
|
322
|
-
);
|
|
323
|
-
reject(
|
|
324
|
-
new RemoteComponentsError(
|
|
325
|
-
`Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
|
|
326
|
-
)
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
newScript.src = src;
|
|
331
|
-
newScript.async = true;
|
|
332
|
-
document.head.appendChild(newScript);
|
|
317
|
+
const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
|
|
318
|
+
const newScript = document.createElement("script");
|
|
319
|
+
newScript.onload = () => resolve();
|
|
320
|
+
newScript.onerror = () => {
|
|
321
|
+
const isProxied = isProxiedUrl(resolvedSrc);
|
|
322
|
+
if (isProxied) {
|
|
323
|
+
reject(
|
|
324
|
+
new RemoteComponentsError(
|
|
325
|
+
`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}`
|
|
326
|
+
)
|
|
327
|
+
);
|
|
328
|
+
} else {
|
|
329
|
+
warnCrossOriginFetchError("ScriptLoader", newSrc);
|
|
330
|
+
reject(
|
|
331
|
+
new RemoteComponentsError(
|
|
332
|
+
`Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
|
|
333
|
+
)
|
|
334
|
+
);
|
|
335
|
+
}
|
|
333
336
|
};
|
|
334
|
-
|
|
337
|
+
newScript.src = resolvedSrc;
|
|
338
|
+
newScript.async = true;
|
|
339
|
+
document.head.appendChild(newScript);
|
|
335
340
|
});
|
|
336
341
|
})
|
|
337
342
|
);
|
|
@@ -352,54 +357,6 @@ function getBundleKey(bundle) {
|
|
|
352
357
|
return escapeString(bundle);
|
|
353
358
|
}
|
|
354
359
|
|
|
355
|
-
// src/shared/utils/abort.ts
|
|
356
|
-
function isAbortError(error) {
|
|
357
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
358
|
-
return true;
|
|
359
|
-
}
|
|
360
|
-
if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
|
|
361
|
-
const e = error;
|
|
362
|
-
return typeof e.code === "number" || e.constructor?.name === "DOMException";
|
|
363
|
-
}
|
|
364
|
-
return false;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// src/shared/client/fetch-with-protected-rc-fallback.ts
|
|
368
|
-
async function fetchWithProtectedRcFallback(url, init) {
|
|
369
|
-
try {
|
|
370
|
-
const res = await fetch(url, init);
|
|
371
|
-
return res;
|
|
372
|
-
} catch (error) {
|
|
373
|
-
if (isAbortError(error)) {
|
|
374
|
-
throw error;
|
|
375
|
-
}
|
|
376
|
-
const parsedUrl = new URL(url);
|
|
377
|
-
if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== parsedUrl.origin) {
|
|
378
|
-
logWarn(
|
|
379
|
-
"FetchRemoteComponent",
|
|
380
|
-
"Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
|
|
381
|
-
);
|
|
382
|
-
const proxiedRes = await fetch(
|
|
383
|
-
generateProtectedRcFallbackSrc(parsedUrl.href),
|
|
384
|
-
init?.signal ? { signal: init.signal } : void 0
|
|
385
|
-
);
|
|
386
|
-
if (proxiedRes.status === 200) {
|
|
387
|
-
logInfo(
|
|
388
|
-
"FetchRemoteComponent",
|
|
389
|
-
`Successfully fetched ${parsedUrl.href} with fallback withRemoteComponentsHost proxy`
|
|
390
|
-
);
|
|
391
|
-
return proxiedRes;
|
|
392
|
-
} else {
|
|
393
|
-
logError(
|
|
394
|
-
"FetchRemoteComponent",
|
|
395
|
-
`Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
throw error;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
360
|
// src/shared/client/turbopack-patterns.ts
|
|
404
361
|
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
405
362
|
var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
|
|
@@ -409,7 +366,7 @@ var ASYNC_MODULE_ALL_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<vCb
|
|
|
409
366
|
var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
|
|
410
367
|
|
|
411
368
|
// src/shared/client/chunk-loader.ts
|
|
412
|
-
function createChunkLoader(runtime) {
|
|
369
|
+
function createChunkLoader(runtime, resolveClientUrl) {
|
|
413
370
|
return function __turbopack_chunk_load__(chunkId, scriptBundle) {
|
|
414
371
|
logDebug("ChunkLoader", `Loading chunk: "${chunkId}"`);
|
|
415
372
|
const self = globalThis;
|
|
@@ -449,9 +406,10 @@ function createChunkLoader(runtime) {
|
|
|
449
406
|
logDebug("ChunkLoader", `Returning cached promise for: "${url}"`);
|
|
450
407
|
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
451
408
|
}
|
|
452
|
-
|
|
409
|
+
const resolvedUrl = resolveClientUrl?.(url) ?? url;
|
|
410
|
+
logDebug("ChunkLoader", `Fetching chunk from: "${resolvedUrl}"`);
|
|
453
411
|
self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
|
|
454
|
-
|
|
412
|
+
fetch(resolvedUrl).then((res) => res.text()).then((code) => {
|
|
455
413
|
const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
|
|
456
414
|
if (hasTurbopack) {
|
|
457
415
|
return handleTurbopackChunk(code, bundle ?? "", url);
|
|
@@ -464,7 +422,19 @@ function createChunkLoader(runtime) {
|
|
|
464
422
|
"ChunkLoader",
|
|
465
423
|
`First 500 chars of chunk: ${code.slice(0, 500)}`
|
|
466
424
|
);
|
|
467
|
-
}).then(resolve).catch(
|
|
425
|
+
}).then(resolve).catch((error) => {
|
|
426
|
+
const isProxied = isProxiedUrl(resolvedUrl);
|
|
427
|
+
if (isProxied) {
|
|
428
|
+
reject(
|
|
429
|
+
new RemoteComponentsError(
|
|
430
|
+
`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}`
|
|
431
|
+
)
|
|
432
|
+
);
|
|
433
|
+
} else {
|
|
434
|
+
warnCrossOriginFetchError("ChunkLoader", url);
|
|
435
|
+
reject(error);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
468
438
|
});
|
|
469
439
|
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
470
440
|
};
|
|
@@ -957,7 +927,7 @@ function getSharedModule(bundle, id) {
|
|
|
957
927
|
}
|
|
958
928
|
|
|
959
929
|
// src/shared/client/webpack-adapter.ts
|
|
960
|
-
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}) {
|
|
930
|
+
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
|
|
961
931
|
const self = globalThis;
|
|
962
932
|
if (!self.__remote_bundle_url__) {
|
|
963
933
|
self.__remote_bundle_url__ = {};
|
|
@@ -969,7 +939,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
969
939
|
self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
|
|
970
940
|
self.__original_webpack_require__ = self.__webpack_require__;
|
|
971
941
|
}
|
|
972
|
-
self.__webpack_chunk_load__ = createChunkLoader(runtime);
|
|
942
|
+
self.__webpack_chunk_load__ = createChunkLoader(runtime, resolveClientUrl);
|
|
973
943
|
self.__webpack_require__ = createModuleRequire(runtime);
|
|
974
944
|
self.__webpack_require_type__ = runtime;
|
|
975
945
|
if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
|
|
@@ -1064,7 +1034,8 @@ async function loadRemoteComponent({
|
|
|
1064
1034
|
scripts = [],
|
|
1065
1035
|
shared = Promise.resolve({}),
|
|
1066
1036
|
remoteShared = {},
|
|
1067
|
-
container
|
|
1037
|
+
container,
|
|
1038
|
+
resolveClientUrl
|
|
1068
1039
|
}) {
|
|
1069
1040
|
try {
|
|
1070
1041
|
if (runtime === "webpack") {
|
|
@@ -1073,7 +1044,7 @@ async function loadRemoteComponent({
|
|
|
1073
1044
|
self.__DISABLE_WEBPACK_EXEC__ = {};
|
|
1074
1045
|
}
|
|
1075
1046
|
self.__DISABLE_WEBPACK_EXEC__[bundle] = true;
|
|
1076
|
-
await loadScripts(scripts);
|
|
1047
|
+
await loadScripts(scripts, resolveClientUrl);
|
|
1077
1048
|
}
|
|
1078
1049
|
const hostShared = await shared;
|
|
1079
1050
|
logDebug(
|
|
@@ -1094,7 +1065,8 @@ async function loadRemoteComponent({
|
|
|
1094
1065
|
url,
|
|
1095
1066
|
bundle,
|
|
1096
1067
|
hostShared,
|
|
1097
|
-
remoteShared
|
|
1068
|
+
remoteShared,
|
|
1069
|
+
resolveClientUrl
|
|
1098
1070
|
);
|
|
1099
1071
|
if (bundle) {
|
|
1100
1072
|
const resolve = {
|
|
@@ -1183,6 +1155,25 @@ function loadNextPagesComponent(bundle, route, nextData, name, container) {
|
|
|
1183
1155
|
return { component };
|
|
1184
1156
|
}
|
|
1185
1157
|
|
|
1158
|
+
// src/shared/client/proxy-through-host.ts
|
|
1159
|
+
var proxyClientRequestsThroughHost = (remoteSrc, url) => {
|
|
1160
|
+
if (typeof location === "undefined") {
|
|
1161
|
+
return void 0;
|
|
1162
|
+
}
|
|
1163
|
+
const remoteOrigin = new URL(remoteSrc, location.href).origin;
|
|
1164
|
+
if (remoteOrigin === location.origin) {
|
|
1165
|
+
return void 0;
|
|
1166
|
+
}
|
|
1167
|
+
try {
|
|
1168
|
+
const parsed = new URL(url, location.href);
|
|
1169
|
+
if (parsed.origin === remoteOrigin) {
|
|
1170
|
+
return generateProtectedRcFallbackSrc(url);
|
|
1171
|
+
}
|
|
1172
|
+
} catch {
|
|
1173
|
+
}
|
|
1174
|
+
return void 0;
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1186
1177
|
// src/shared/client/set-attributes-from-props.ts
|
|
1187
1178
|
var DOMAttributeNames = {
|
|
1188
1179
|
acceptCharset: "accept-charset",
|
|
@@ -1226,27 +1217,21 @@ function setAttributesFromProps(el, props) {
|
|
|
1226
1217
|
}
|
|
1227
1218
|
|
|
1228
1219
|
// src/shared/client/static-loader.ts
|
|
1229
|
-
async function
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
).href;
|
|
1234
|
-
const response = await fetch(proxyUrl);
|
|
1220
|
+
async function importViaCallback(absoluteSrc, resolveClientUrl) {
|
|
1221
|
+
const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
|
|
1222
|
+
const fetchUrl = new URL(resolvedUrl, location.href).href;
|
|
1223
|
+
const response = await fetch(fetchUrl);
|
|
1235
1224
|
if (!response.ok)
|
|
1236
|
-
throw new Error(`
|
|
1237
|
-
logInfo(
|
|
1238
|
-
"StaticLoader",
|
|
1239
|
-
`Successfully loaded ${absoluteSrc} via protected RC proxy fallback.`
|
|
1240
|
-
);
|
|
1225
|
+
throw new Error(`Proxied fetch failed: ${response.status}`);
|
|
1241
1226
|
const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
|
|
1242
1227
|
/\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
|
|
1243
1228
|
(_, keyword, quote, relativePath) => {
|
|
1244
1229
|
const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1230
|
+
const resolvedImportUrl = new URL(
|
|
1231
|
+
resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
|
|
1247
1232
|
location.href
|
|
1248
1233
|
).href;
|
|
1249
|
-
return `${keyword} ${quote}${
|
|
1234
|
+
return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
|
|
1250
1235
|
}
|
|
1251
1236
|
);
|
|
1252
1237
|
const moduleBlobUrl = URL.createObjectURL(
|
|
@@ -1280,6 +1265,20 @@ async function importViaProxy(absoluteSrc) {
|
|
|
1280
1265
|
delete registry[absoluteSrc];
|
|
1281
1266
|
return mod;
|
|
1282
1267
|
}
|
|
1268
|
+
async function importDirectly(absoluteSrc) {
|
|
1269
|
+
try {
|
|
1270
|
+
return await import(
|
|
1271
|
+
/* @vite-ignore */
|
|
1272
|
+
/* webpackIgnore: true */
|
|
1273
|
+
absoluteSrc
|
|
1274
|
+
);
|
|
1275
|
+
} catch (importError) {
|
|
1276
|
+
if (!absoluteSrc.startsWith("blob:")) {
|
|
1277
|
+
warnCrossOriginFetchError("StaticLoader", absoluteSrc);
|
|
1278
|
+
}
|
|
1279
|
+
throw importError;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1283
1282
|
function resolveScriptSrc(script, url) {
|
|
1284
1283
|
const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
1285
1284
|
if (!rawSrc && script.textContent) {
|
|
@@ -1292,24 +1291,7 @@ function resolveScriptSrc(script, url) {
|
|
|
1292
1291
|
}
|
|
1293
1292
|
return rawSrc;
|
|
1294
1293
|
}
|
|
1295
|
-
async function
|
|
1296
|
-
try {
|
|
1297
|
-
return await import(
|
|
1298
|
-
/* @vite-ignore */
|
|
1299
|
-
/* webpackIgnore: true */
|
|
1300
|
-
absoluteSrc
|
|
1301
|
-
);
|
|
1302
|
-
} catch (importError) {
|
|
1303
|
-
if (absoluteSrc.startsWith("blob:"))
|
|
1304
|
-
throw importError;
|
|
1305
|
-
logWarn(
|
|
1306
|
-
"StaticLoader",
|
|
1307
|
-
`Direct import of ${absoluteSrc} failed, attempting via protected RC proxy fallback.`
|
|
1308
|
-
);
|
|
1309
|
-
return importViaProxy(absoluteSrc);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
async function loadStaticRemoteComponent(scripts, url) {
|
|
1294
|
+
async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
1313
1295
|
const self = globalThis;
|
|
1314
1296
|
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
1315
1297
|
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
@@ -1322,7 +1304,7 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
1322
1304
|
try {
|
|
1323
1305
|
const src = resolveScriptSrc(script, url);
|
|
1324
1306
|
const absoluteSrc = new URL(src, url).href;
|
|
1325
|
-
const mod = await
|
|
1307
|
+
const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
|
|
1326
1308
|
if (src.startsWith("blob:")) {
|
|
1327
1309
|
URL.revokeObjectURL(src);
|
|
1328
1310
|
}
|
|
@@ -1396,6 +1378,7 @@ export {
|
|
|
1396
1378
|
loadRemoteComponent,
|
|
1397
1379
|
loadScripts,
|
|
1398
1380
|
loadStaticRemoteComponent,
|
|
1381
|
+
proxyClientRequestsThroughHost,
|
|
1399
1382
|
setAttributesFromProps,
|
|
1400
1383
|
setupWebpackRuntime
|
|
1401
1384
|
};
|