remote-components 0.0.49 → 0.0.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/html/host.cjs +348 -176
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +348 -176
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs +114 -20
- package/dist/html/remote.cjs.map +1 -1
- package/dist/html/remote.js +114 -20
- package/dist/html/remote.js.map +1 -1
- package/dist/internal/shared/{ssr → client}/fetch-with-protected-rc-fallback.cjs +9 -6
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs.map +1 -0
- package/dist/internal/shared/{ssr → client}/fetch-with-protected-rc-fallback.d.ts +1 -2
- package/dist/internal/shared/{ssr → client}/fetch-with-protected-rc-fallback.js +10 -6
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js.map +1 -0
- package/dist/internal/shared/client/protected-rc-fallback.cjs +32 -0
- package/dist/internal/shared/client/protected-rc-fallback.cjs.map +1 -0
- package/dist/internal/shared/client/protected-rc-fallback.d.ts +6 -0
- package/dist/internal/shared/client/protected-rc-fallback.js +8 -0
- package/dist/internal/shared/client/protected-rc-fallback.js.map +1 -0
- package/dist/internal/shared/client/remote-component.cjs +205 -108
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.js +205 -108
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/constants.cjs +29 -0
- package/dist/internal/shared/constants.cjs.map +1 -0
- package/dist/internal/shared/constants.d.ts +3 -0
- package/dist/internal/shared/constants.js +5 -0
- package/dist/internal/shared/constants.js.map +1 -0
- 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 +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.js +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
- package/dist/internal/shared/utils/logger.cjs.map +1 -1
- package/dist/internal/shared/utils/logger.d.ts +1 -1
- package/dist/internal/shared/utils/logger.js.map +1 -1
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/client/index.cjs +217 -115
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.js +217 -115
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +1 -2
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +5 -0
- package/dist/next/host/pages-router-server.js +1 -2
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/proxy.cjs +36 -24
- package/dist/next/proxy.cjs.map +1 -1
- package/dist/next/proxy.d.ts +0 -1
- package/dist/next/proxy.js +36 -24
- package/dist/next/proxy.js.map +1 -1
- package/dist/react/index.cjs +217 -115
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +217 -115
- package/dist/react/index.js.map +1 -1
- package/dist/shared/host/proxy.cjs +23 -20
- package/dist/shared/host/proxy.cjs.map +1 -1
- package/dist/shared/host/proxy.d.ts +0 -3
- package/dist/shared/host/proxy.js +23 -19
- 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.map +0 -1
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var protected_rc_fallback_exports = {};
|
|
20
|
+
__export(protected_rc_fallback_exports, {
|
|
21
|
+
generateProtectedRcFallbackSrc: () => generateProtectedRcFallbackSrc
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(protected_rc_fallback_exports);
|
|
24
|
+
var import_constants = require("#internal/shared/constants");
|
|
25
|
+
function generateProtectedRcFallbackSrc(url) {
|
|
26
|
+
return `${import_constants.RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
generateProtectedRcFallbackSrc
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=protected-rc-fallback.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/shared/client/protected-rc-fallback.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmD;AAK5C,SAAS,+BAA+B,KAAqB;AAClE,SAAO,GAAG,2DAA0C,mBAAmB,GAAG;AAC5E;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from "#internal/shared/constants";
|
|
2
|
+
function generateProtectedRcFallbackSrc(url) {
|
|
3
|
+
return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
4
|
+
}
|
|
5
|
+
export {
|
|
6
|
+
generateProtectedRcFallbackSrc
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=protected-rc-fallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/shared/client/protected-rc-fallback.ts"],"sourcesContent":["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"],"mappings":"AAAA,SAAS,0CAA0C;AAK5C,SAAS,+BAA+B,KAAqB;AAClE,SAAO,GAAG,0CAA0C,mBAAmB,GAAG;AAC5E;","names":[]}
|
|
@@ -324,6 +324,17 @@ function createRSCStream(rscName, data) {
|
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
// src/shared/constants.ts
|
|
328
|
+
var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
329
|
+
|
|
330
|
+
// src/shared/client/protected-rc-fallback.ts
|
|
331
|
+
function generateProtectedRcFallbackSrc(url) {
|
|
332
|
+
return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/shared/client/webpack-patterns.ts
|
|
336
|
+
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
337
|
+
|
|
327
338
|
// src/shared/client/script-loader.ts
|
|
328
339
|
async function loadScripts(scripts) {
|
|
329
340
|
await Promise.all(
|
|
@@ -331,28 +342,65 @@ async function loadScripts(scripts) {
|
|
|
331
342
|
return new Promise((resolve, reject) => {
|
|
332
343
|
const newSrc = new URL(
|
|
333
344
|
// remove the remote component bundle name identifier from the script src
|
|
334
|
-
script.src.replace(
|
|
345
|
+
script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
|
|
335
346
|
location.origin
|
|
336
347
|
).href;
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
348
|
+
const loadScriptWithProtectedRcFallback = (src, isFallback = false) => {
|
|
349
|
+
const newScript = document.createElement("script");
|
|
350
|
+
newScript.onload = () => {
|
|
351
|
+
if (isFallback) {
|
|
352
|
+
logInfo(
|
|
353
|
+
"ScriptLoader",
|
|
354
|
+
`Successfully loaded <script src="${newSrc}"> using fallback.`
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
resolve();
|
|
358
|
+
};
|
|
359
|
+
newScript.onerror = () => {
|
|
360
|
+
if (!isFallback) {
|
|
361
|
+
const fallbackSrc = generateProtectedRcFallbackSrc(newSrc);
|
|
362
|
+
logWarn(
|
|
363
|
+
"ScriptLoader",
|
|
364
|
+
`Failed to load <script src="${newSrc}"> for Remote Component. Trying fallback with ${RC_PROTECTED_REMOTE_FETCH_PATHNAME} (withRemoteComponentsHost)...`
|
|
365
|
+
);
|
|
366
|
+
loadScriptWithProtectedRcFallback(fallbackSrc, true);
|
|
367
|
+
} else {
|
|
368
|
+
logError(
|
|
369
|
+
"ScriptLoader",
|
|
370
|
+
`Failed to load fallback for <script src="${newSrc}"> for Remote Component.`
|
|
371
|
+
);
|
|
372
|
+
reject(
|
|
373
|
+
new RemoteComponentsError(
|
|
374
|
+
`Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
|
|
375
|
+
)
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
newScript.src = src;
|
|
380
|
+
newScript.async = true;
|
|
381
|
+
document.head.appendChild(newScript);
|
|
347
382
|
};
|
|
348
|
-
|
|
349
|
-
newScript.async = true;
|
|
350
|
-
document.head.appendChild(newScript);
|
|
383
|
+
loadScriptWithProtectedRcFallback(newSrc);
|
|
351
384
|
});
|
|
352
385
|
})
|
|
353
386
|
);
|
|
354
387
|
}
|
|
355
388
|
|
|
389
|
+
// src/shared/utils/index.ts
|
|
390
|
+
function escapeString(str) {
|
|
391
|
+
return str.replace(/[^a-z0-9]/g, "_");
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/shared/client/const.ts
|
|
395
|
+
var DEFAULT_ROUTE = "/";
|
|
396
|
+
var RUNTIME_WEBPACK = "webpack";
|
|
397
|
+
var RUNTIME_TURBOPACK = "turbopack";
|
|
398
|
+
var RUNTIME_SCRIPT = "script";
|
|
399
|
+
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
400
|
+
function getBundleKey(bundle) {
|
|
401
|
+
return escapeString(bundle);
|
|
402
|
+
}
|
|
403
|
+
|
|
356
404
|
// src/shared/utils/abort.ts
|
|
357
405
|
function isAbortError(error) {
|
|
358
406
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
@@ -365,8 +413,7 @@ function isAbortError(error) {
|
|
|
365
413
|
return false;
|
|
366
414
|
}
|
|
367
415
|
|
|
368
|
-
// src/shared/
|
|
369
|
-
var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
416
|
+
// src/shared/client/fetch-with-protected-rc-fallback.ts
|
|
370
417
|
async function fetchWithProtectedRcFallback(url, init) {
|
|
371
418
|
try {
|
|
372
419
|
const res = await fetch(url, init);
|
|
@@ -375,16 +422,21 @@ async function fetchWithProtectedRcFallback(url, init) {
|
|
|
375
422
|
if (isAbortError(error)) {
|
|
376
423
|
throw error;
|
|
377
424
|
}
|
|
378
|
-
|
|
379
|
-
|
|
425
|
+
const parsedUrl = new URL(url);
|
|
426
|
+
if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== parsedUrl.origin) {
|
|
427
|
+
logWarn(
|
|
380
428
|
"FetchRemoteComponent",
|
|
381
429
|
"Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
|
|
382
430
|
);
|
|
383
431
|
const proxiedRes = await fetch(
|
|
384
|
-
|
|
432
|
+
generateProtectedRcFallbackSrc(parsedUrl.href),
|
|
385
433
|
init?.signal ? { signal: init.signal } : void 0
|
|
386
434
|
);
|
|
387
435
|
if (proxiedRes.status === 200) {
|
|
436
|
+
logInfo(
|
|
437
|
+
"FetchRemoteComponent",
|
|
438
|
+
`Successfully fetched ${parsedUrl.href} with fallback withRemoteComponentsHost proxy`
|
|
439
|
+
);
|
|
388
440
|
return proxiedRes;
|
|
389
441
|
} else {
|
|
390
442
|
logError(
|
|
@@ -397,20 +449,13 @@ async function fetchWithProtectedRcFallback(url, init) {
|
|
|
397
449
|
}
|
|
398
450
|
}
|
|
399
451
|
|
|
400
|
-
// src/shared/
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
var
|
|
407
|
-
var RUNTIME_WEBPACK = "webpack";
|
|
408
|
-
var RUNTIME_TURBOPACK = "turbopack";
|
|
409
|
-
var RUNTIME_SCRIPT = "script";
|
|
410
|
-
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
411
|
-
function getBundleKey(bundle) {
|
|
412
|
-
return escapeString(bundle);
|
|
413
|
-
}
|
|
452
|
+
// src/shared/client/turbopack-patterns.ts
|
|
453
|
+
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
454
|
+
var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
|
|
455
|
+
var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
|
|
456
|
+
var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
|
|
457
|
+
var ASYNC_MODULE_ALL_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<vCb>parentImport|t)=>Promise\.all\(\["[^"]+"\]\.map\((?<mapCb>chunk|t)=>\k<ctx>\.l\(\k<mapCb>\)\)\)\.then\(\(\)=>\k<vCb>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
|
|
458
|
+
var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
|
|
414
459
|
|
|
415
460
|
// src/shared/client/chunk-loader.ts
|
|
416
461
|
function createChunkLoader(runtime) {
|
|
@@ -456,7 +501,7 @@ function createChunkLoader(runtime) {
|
|
|
456
501
|
logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
|
|
457
502
|
self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
|
|
458
503
|
fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
|
|
459
|
-
const hasTurbopack =
|
|
504
|
+
const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
|
|
460
505
|
if (hasTurbopack) {
|
|
461
506
|
return handleTurbopackChunk(code, bundle ?? "", url);
|
|
462
507
|
}
|
|
@@ -489,7 +534,13 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
489
534
|
const self = globalThis;
|
|
490
535
|
const bundleKey = getBundleKey(bundle);
|
|
491
536
|
logDebug("ChunkLoader", `Bundle key: "${bundleKey}"`);
|
|
492
|
-
const transformedCode = code.replace(
|
|
537
|
+
const transformedCode = code.replace(
|
|
538
|
+
/globalThis\[\s*["']TURBOPACK["']\s*\]/g,
|
|
539
|
+
`globalThis["TURBOPACK_${bundleKey}"]`
|
|
540
|
+
).replace(
|
|
541
|
+
/self\[\s*["']TURBOPACK["']\s*\]/g,
|
|
542
|
+
`self["TURBOPACK_${bundleKey}"]`
|
|
543
|
+
).replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`).replace(
|
|
493
544
|
/TURBOPACK_WORKER_LOCATION/g,
|
|
494
545
|
`TURBOPACK_WORKER_LOCATION_${bundleKey}`
|
|
495
546
|
).replace(
|
|
@@ -605,22 +656,18 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
605
656
|
}
|
|
606
657
|
}
|
|
607
658
|
|
|
608
|
-
// src/shared/client/turbopack-patterns.ts
|
|
609
|
-
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
610
|
-
var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
|
|
611
|
-
var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
|
|
612
|
-
var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
|
|
613
|
-
var ASYNC_MODULE_ALL_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<vCb>parentImport|t)=>Promise\.all\(\["[^"]+"\]\.map\((?<mapCb>chunk|t)=>\k<ctx>\.l\(\k<mapCb>\)\)\)\.then\(\(\)=>\k<vCb>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
|
|
614
|
-
var NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
|
|
615
|
-
|
|
616
659
|
// src/shared/client/turbopack-module.ts
|
|
617
660
|
function handleTurbopackModule(bundle, moduleId, id) {
|
|
618
661
|
const self = globalThis;
|
|
619
662
|
const bundleKey = getBundleKey(bundle);
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
modules =
|
|
663
|
+
const raw = self[`TURBOPACK_${bundleKey}`];
|
|
664
|
+
let modules;
|
|
665
|
+
if (raw && typeof raw === "object" && "__chunks__" in raw) {
|
|
666
|
+
modules = raw.__chunks__.flat();
|
|
667
|
+
} else if (Array.isArray(raw)) {
|
|
668
|
+
modules = raw.flat();
|
|
669
|
+
} else {
|
|
670
|
+
modules = raw;
|
|
624
671
|
}
|
|
625
672
|
if (!self.__remote_components_turbopack_modules__) {
|
|
626
673
|
self.__remote_components_turbopack_modules__ = {};
|
|
@@ -649,13 +696,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
649
696
|
if (!self.__remote_components_turbopack_global__[bundle]) {
|
|
650
697
|
self.__remote_components_turbopack_global__[bundle] = {};
|
|
651
698
|
}
|
|
652
|
-
const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
|
|
653
699
|
moduleInit(
|
|
654
700
|
createTurbopackContext(
|
|
655
701
|
bundle,
|
|
656
702
|
exports,
|
|
657
703
|
moduleExports,
|
|
658
|
-
|
|
704
|
+
modules,
|
|
659
705
|
moduleInit,
|
|
660
706
|
id,
|
|
661
707
|
self
|
|
@@ -669,46 +715,27 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
669
715
|
return moduleExports.exports;
|
|
670
716
|
}
|
|
671
717
|
function findModuleInit(modules, moduleId) {
|
|
672
|
-
if (
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
718
|
+
if (!modules || typeof modules !== "object")
|
|
719
|
+
return;
|
|
720
|
+
if (!Array.isArray(modules)) {
|
|
721
|
+
const key = moduleId in modules ? moduleId : Object.keys(modules).find((k) => k.startsWith(moduleId));
|
|
722
|
+
return key !== void 0 ? modules[key] : void 0;
|
|
723
|
+
}
|
|
724
|
+
const flat = modules.flat();
|
|
725
|
+
let idx = flat.findIndex((e) => String(e) === String(moduleId));
|
|
726
|
+
if (idx < 0) {
|
|
727
|
+
idx = flat.findIndex(
|
|
728
|
+
(e) => typeof e === "string" && e.startsWith(moduleId)
|
|
682
729
|
);
|
|
683
|
-
if (matchingKey) {
|
|
684
|
-
return modules[matchingKey];
|
|
685
|
-
}
|
|
686
|
-
logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
|
|
687
|
-
return void 0;
|
|
688
730
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
|
|
692
|
-
let moduleIdIndex = allModules.indexOf(normalizedId);
|
|
693
|
-
if (moduleIdIndex === -1) {
|
|
694
|
-
moduleIdIndex = allModules.findIndex(
|
|
695
|
-
(bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
|
|
696
|
-
);
|
|
697
|
-
}
|
|
698
|
-
if (moduleIdIndex !== -1) {
|
|
699
|
-
while (typeof allModules[moduleIdIndex] !== "function" && moduleIdIndex < allModules.length) {
|
|
700
|
-
moduleIdIndex++;
|
|
701
|
-
}
|
|
702
|
-
return allModules[moduleIdIndex];
|
|
703
|
-
}
|
|
704
|
-
} else {
|
|
705
|
-
return allModules.find(
|
|
706
|
-
(bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
|
|
707
|
-
)?.[moduleId];
|
|
731
|
+
if (idx >= 0) {
|
|
732
|
+
return flat.slice(idx + 1).find((e) => typeof e === "function");
|
|
708
733
|
}
|
|
709
|
-
return
|
|
734
|
+
return flat.find(
|
|
735
|
+
(e) => Boolean(e && typeof e === "object" && moduleId in e)
|
|
736
|
+
)?.[moduleId];
|
|
710
737
|
}
|
|
711
|
-
function createTurbopackContext(bundle, exports, moduleExports,
|
|
738
|
+
function createTurbopackContext(bundle, exports, moduleExports, modules, moduleInit, id, self) {
|
|
712
739
|
return {
|
|
713
740
|
// HMR not implemented for Remote Components
|
|
714
741
|
k: {
|
|
@@ -829,13 +856,17 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
|
|
|
829
856
|
(parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
|
|
830
857
|
);
|
|
831
858
|
},
|
|
859
|
+
// dynamic import tracking — no-op for remote components
|
|
860
|
+
j() {
|
|
861
|
+
},
|
|
832
862
|
// chunk loader
|
|
833
863
|
l(url) {
|
|
834
|
-
const
|
|
864
|
+
const flatModules = Array.isArray(modules) ? modules : [];
|
|
865
|
+
const moduleInitIndex = flatModules.indexOf(moduleInit);
|
|
835
866
|
if (moduleInitIndex !== -1) {
|
|
836
|
-
const scriptIndex =
|
|
867
|
+
const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
|
|
837
868
|
if (scriptIndex !== -1) {
|
|
838
|
-
const script =
|
|
869
|
+
const script = flatModules[scriptIndex];
|
|
839
870
|
const scriptSrc = script.getAttribute("data-turbopack-src") || "";
|
|
840
871
|
const nextIndex = scriptSrc.indexOf("/_next");
|
|
841
872
|
const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
|
|
@@ -1244,6 +1275,89 @@ function setAttributesFromProps(el, props) {
|
|
|
1244
1275
|
}
|
|
1245
1276
|
|
|
1246
1277
|
// src/shared/client/static-loader.ts
|
|
1278
|
+
async function importViaProxy(absoluteSrc) {
|
|
1279
|
+
const proxyUrl = new URL(
|
|
1280
|
+
generateProtectedRcFallbackSrc(absoluteSrc),
|
|
1281
|
+
location.href
|
|
1282
|
+
).href;
|
|
1283
|
+
const response = await fetch(proxyUrl);
|
|
1284
|
+
if (!response.ok)
|
|
1285
|
+
throw new Error(`Proxy fetch failed: ${response.status}`);
|
|
1286
|
+
logInfo(
|
|
1287
|
+
"StaticLoader",
|
|
1288
|
+
`Successfully loaded ${absoluteSrc} via protected RC proxy fallback.`
|
|
1289
|
+
);
|
|
1290
|
+
const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
|
|
1291
|
+
/\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
|
|
1292
|
+
(_, keyword, quote, relativePath) => {
|
|
1293
|
+
const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
|
|
1294
|
+
const absoluteProxyUrl = new URL(
|
|
1295
|
+
generateProtectedRcFallbackSrc(absoluteImportUrl),
|
|
1296
|
+
location.href
|
|
1297
|
+
).href;
|
|
1298
|
+
return `${keyword} ${quote}${absoluteProxyUrl}${quote}`;
|
|
1299
|
+
}
|
|
1300
|
+
);
|
|
1301
|
+
const moduleBlobUrl = URL.createObjectURL(
|
|
1302
|
+
new Blob([content], { type: "text/javascript" })
|
|
1303
|
+
);
|
|
1304
|
+
const wrapperContent = [
|
|
1305
|
+
`import*as m from${JSON.stringify(moduleBlobUrl)};`,
|
|
1306
|
+
`globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
|
|
1307
|
+
`globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
|
|
1308
|
+
].join("");
|
|
1309
|
+
const wrapperBlobUrl = URL.createObjectURL(
|
|
1310
|
+
new Blob([wrapperContent], { type: "text/javascript" })
|
|
1311
|
+
);
|
|
1312
|
+
const scriptEl = document.createElement("script");
|
|
1313
|
+
scriptEl.type = "module";
|
|
1314
|
+
scriptEl.src = wrapperBlobUrl;
|
|
1315
|
+
try {
|
|
1316
|
+
await new Promise((resolve, reject) => {
|
|
1317
|
+
scriptEl.onload = () => resolve();
|
|
1318
|
+
scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
|
|
1319
|
+
document.head.appendChild(scriptEl);
|
|
1320
|
+
});
|
|
1321
|
+
} finally {
|
|
1322
|
+
scriptEl.remove();
|
|
1323
|
+
URL.revokeObjectURL(moduleBlobUrl);
|
|
1324
|
+
URL.revokeObjectURL(wrapperBlobUrl);
|
|
1325
|
+
}
|
|
1326
|
+
const registry = globalThis.__rc_module_registry__;
|
|
1327
|
+
const mod = registry?.[absoluteSrc] ?? {};
|
|
1328
|
+
if (registry)
|
|
1329
|
+
delete registry[absoluteSrc];
|
|
1330
|
+
return mod;
|
|
1331
|
+
}
|
|
1332
|
+
function resolveScriptSrc(script, url) {
|
|
1333
|
+
const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
1334
|
+
if (!rawSrc && script.textContent) {
|
|
1335
|
+
return URL.createObjectURL(
|
|
1336
|
+
new Blob(
|
|
1337
|
+
[script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
|
|
1338
|
+
{ type: "text/javascript" }
|
|
1339
|
+
)
|
|
1340
|
+
);
|
|
1341
|
+
}
|
|
1342
|
+
return rawSrc;
|
|
1343
|
+
}
|
|
1344
|
+
async function importScriptMod(absoluteSrc) {
|
|
1345
|
+
try {
|
|
1346
|
+
return await import(
|
|
1347
|
+
/* @vite-ignore */
|
|
1348
|
+
/* webpackIgnore: true */
|
|
1349
|
+
absoluteSrc
|
|
1350
|
+
);
|
|
1351
|
+
} catch (importError) {
|
|
1352
|
+
if (absoluteSrc.startsWith("blob:"))
|
|
1353
|
+
throw importError;
|
|
1354
|
+
logWarn(
|
|
1355
|
+
"StaticLoader",
|
|
1356
|
+
`Direct import of ${absoluteSrc} failed, attempting via protected RC proxy fallback.`
|
|
1357
|
+
);
|
|
1358
|
+
return importViaProxy(absoluteSrc);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1247
1361
|
async function loadStaticRemoteComponent(scripts, url) {
|
|
1248
1362
|
const self = globalThis;
|
|
1249
1363
|
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
@@ -1255,26 +1369,9 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
1255
1369
|
const mountUnmountSets = await Promise.all(
|
|
1256
1370
|
scripts.map(async (script) => {
|
|
1257
1371
|
try {
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
[
|
|
1262
|
-
script.textContent.replace(
|
|
1263
|
-
/import\.meta\.url/g,
|
|
1264
|
-
JSON.stringify(url)
|
|
1265
|
-
)
|
|
1266
|
-
],
|
|
1267
|
-
{
|
|
1268
|
-
type: "text/javascript"
|
|
1269
|
-
}
|
|
1270
|
-
);
|
|
1271
|
-
src = URL.createObjectURL(blob);
|
|
1272
|
-
}
|
|
1273
|
-
const mod = await import(
|
|
1274
|
-
/* @vite-ignore */
|
|
1275
|
-
/* webpackIgnore: true */
|
|
1276
|
-
new URL(src, url).href
|
|
1277
|
-
);
|
|
1372
|
+
const src = resolveScriptSrc(script, url);
|
|
1373
|
+
const absoluteSrc = new URL(src, url).href;
|
|
1374
|
+
const mod = await importScriptMod(absoluteSrc);
|
|
1278
1375
|
if (src.startsWith("blob:")) {
|
|
1279
1376
|
URL.revokeObjectURL(src);
|
|
1280
1377
|
}
|