remote-components 0.0.50 → 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 +330 -166
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +330 -166
- 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 +190 -100
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.js +190 -100
- 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 +202 -107
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.js +202 -107
- 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 +202 -107
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +202 -107
- 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
package/dist/html/host.cjs
CHANGED
|
@@ -270,6 +270,121 @@ var init_shared_modules = __esm({
|
|
|
270
270
|
}
|
|
271
271
|
});
|
|
272
272
|
|
|
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
|
+
// src/shared/client/webpack-patterns.ts
|
|
294
|
+
var NEXT_BUNDLE_PATH_RE;
|
|
295
|
+
var init_webpack_patterns = __esm({
|
|
296
|
+
"src/shared/client/webpack-patterns.ts"() {
|
|
297
|
+
"use strict";
|
|
298
|
+
NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// src/shared/client/script-loader.ts
|
|
303
|
+
async function loadScripts(scripts) {
|
|
304
|
+
await Promise.all(
|
|
305
|
+
scripts.map((script) => {
|
|
306
|
+
return new Promise((resolve, reject) => {
|
|
307
|
+
const newSrc = new URL(
|
|
308
|
+
// remove the remote component bundle name identifier from the script src
|
|
309
|
+
script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
|
|
310
|
+
location.origin
|
|
311
|
+
).href;
|
|
312
|
+
const loadScriptWithProtectedRcFallback = (src, isFallback = false) => {
|
|
313
|
+
const newScript = document.createElement("script");
|
|
314
|
+
newScript.onload = () => {
|
|
315
|
+
if (isFallback) {
|
|
316
|
+
logInfo(
|
|
317
|
+
"ScriptLoader",
|
|
318
|
+
`Successfully loaded <script src="${newSrc}"> using fallback.`
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
resolve();
|
|
322
|
+
};
|
|
323
|
+
newScript.onerror = () => {
|
|
324
|
+
if (!isFallback) {
|
|
325
|
+
const fallbackSrc = generateProtectedRcFallbackSrc(newSrc);
|
|
326
|
+
logWarn(
|
|
327
|
+
"ScriptLoader",
|
|
328
|
+
`Failed to load <script src="${newSrc}"> for Remote Component. Trying fallback with ${RC_PROTECTED_REMOTE_FETCH_PATHNAME} (withRemoteComponentsHost)...`
|
|
329
|
+
);
|
|
330
|
+
loadScriptWithProtectedRcFallback(fallbackSrc, true);
|
|
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);
|
|
346
|
+
};
|
|
347
|
+
loadScriptWithProtectedRcFallback(newSrc);
|
|
348
|
+
});
|
|
349
|
+
})
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
var init_script_loader = __esm({
|
|
353
|
+
"src/shared/client/script-loader.ts"() {
|
|
354
|
+
"use strict";
|
|
355
|
+
init_constants();
|
|
356
|
+
init_error();
|
|
357
|
+
init_logger();
|
|
358
|
+
init_protected_rc_fallback();
|
|
359
|
+
init_webpack_patterns();
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
// src/shared/utils/index.ts
|
|
364
|
+
function escapeString(str) {
|
|
365
|
+
return str.replace(/[^a-z0-9]/g, "_");
|
|
366
|
+
}
|
|
367
|
+
var init_utils = __esm({
|
|
368
|
+
"src/shared/utils/index.ts"() {
|
|
369
|
+
"use strict";
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// src/shared/client/const.ts
|
|
374
|
+
function getBundleKey(bundle) {
|
|
375
|
+
return escapeString(bundle);
|
|
376
|
+
}
|
|
377
|
+
var RUNTIME_WEBPACK, RUNTIME_TURBOPACK, REMOTE_COMPONENT_REGEX;
|
|
378
|
+
var init_const = __esm({
|
|
379
|
+
"src/shared/client/const.ts"() {
|
|
380
|
+
"use strict";
|
|
381
|
+
init_utils();
|
|
382
|
+
RUNTIME_WEBPACK = "webpack";
|
|
383
|
+
RUNTIME_TURBOPACK = "turbopack";
|
|
384
|
+
REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
273
388
|
// src/shared/utils/abort.ts
|
|
274
389
|
function isAbortError(error) {
|
|
275
390
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
@@ -287,7 +402,7 @@ var init_abort = __esm({
|
|
|
287
402
|
}
|
|
288
403
|
});
|
|
289
404
|
|
|
290
|
-
// src/shared/
|
|
405
|
+
// src/shared/client/fetch-with-protected-rc-fallback.ts
|
|
291
406
|
async function fetchWithProtectedRcFallback(url, init) {
|
|
292
407
|
try {
|
|
293
408
|
const res = await fetch(url, init);
|
|
@@ -296,16 +411,21 @@ async function fetchWithProtectedRcFallback(url, init) {
|
|
|
296
411
|
if (isAbortError(error)) {
|
|
297
412
|
throw error;
|
|
298
413
|
}
|
|
299
|
-
|
|
300
|
-
|
|
414
|
+
const parsedUrl = new URL(url);
|
|
415
|
+
if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== parsedUrl.origin) {
|
|
416
|
+
logWarn(
|
|
301
417
|
"FetchRemoteComponent",
|
|
302
418
|
"Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
|
|
303
419
|
);
|
|
304
420
|
const proxiedRes = await fetch(
|
|
305
|
-
|
|
421
|
+
generateProtectedRcFallbackSrc(parsedUrl.href),
|
|
306
422
|
init?.signal ? { signal: init.signal } : void 0
|
|
307
423
|
);
|
|
308
424
|
if (proxiedRes.status === 200) {
|
|
425
|
+
logInfo(
|
|
426
|
+
"FetchRemoteComponent",
|
|
427
|
+
`Successfully fetched ${parsedUrl.href} with fallback withRemoteComponentsHost proxy`
|
|
428
|
+
);
|
|
309
429
|
return proxiedRes;
|
|
310
430
|
} else {
|
|
311
431
|
logError(
|
|
@@ -317,43 +437,17 @@ async function fetchWithProtectedRcFallback(url, init) {
|
|
|
317
437
|
throw error;
|
|
318
438
|
}
|
|
319
439
|
}
|
|
320
|
-
var RC_PROTECTED_REMOTE_FETCH_PATHNAME;
|
|
321
440
|
var init_fetch_with_protected_rc_fallback = __esm({
|
|
322
|
-
"src/shared/
|
|
441
|
+
"src/shared/client/fetch-with-protected-rc-fallback.ts"() {
|
|
323
442
|
"use strict";
|
|
443
|
+
init_protected_rc_fallback();
|
|
324
444
|
init_abort();
|
|
325
445
|
init_logger();
|
|
326
|
-
RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
// src/shared/utils/index.ts
|
|
331
|
-
function escapeString(str) {
|
|
332
|
-
return str.replace(/[^a-z0-9]/g, "_");
|
|
333
|
-
}
|
|
334
|
-
var init_utils = __esm({
|
|
335
|
-
"src/shared/utils/index.ts"() {
|
|
336
|
-
"use strict";
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
// src/shared/client/const.ts
|
|
341
|
-
function getBundleKey(bundle) {
|
|
342
|
-
return escapeString(bundle);
|
|
343
|
-
}
|
|
344
|
-
var RUNTIME_WEBPACK, RUNTIME_TURBOPACK, REMOTE_COMPONENT_REGEX;
|
|
345
|
-
var init_const = __esm({
|
|
346
|
-
"src/shared/client/const.ts"() {
|
|
347
|
-
"use strict";
|
|
348
|
-
init_utils();
|
|
349
|
-
RUNTIME_WEBPACK = "webpack";
|
|
350
|
-
RUNTIME_TURBOPACK = "turbopack";
|
|
351
|
-
REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
352
446
|
}
|
|
353
447
|
});
|
|
354
448
|
|
|
355
449
|
// src/shared/client/turbopack-patterns.ts
|
|
356
|
-
var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE,
|
|
450
|
+
var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, TURBOPACK_GLOBAL_RE;
|
|
357
451
|
var init_turbopack_patterns = __esm({
|
|
358
452
|
"src/shared/client/turbopack-patterns.ts"() {
|
|
359
453
|
"use strict";
|
|
@@ -362,7 +456,6 @@ var init_turbopack_patterns = __esm({
|
|
|
362
456
|
ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
|
|
363
457
|
ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
|
|
364
458
|
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]+)\)\)\)\}/;
|
|
365
|
-
NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
|
|
366
459
|
TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
|
|
367
460
|
}
|
|
368
461
|
});
|
|
@@ -569,9 +662,9 @@ var init_chunk_loader = __esm({
|
|
|
569
662
|
"src/shared/client/chunk-loader.ts"() {
|
|
570
663
|
"use strict";
|
|
571
664
|
init_error();
|
|
572
|
-
init_fetch_with_protected_rc_fallback();
|
|
573
665
|
init_logger();
|
|
574
666
|
init_const();
|
|
667
|
+
init_fetch_with_protected_rc_fallback();
|
|
575
668
|
init_turbopack_patterns();
|
|
576
669
|
}
|
|
577
670
|
});
|
|
@@ -580,10 +673,14 @@ var init_chunk_loader = __esm({
|
|
|
580
673
|
function handleTurbopackModule(bundle, moduleId, id) {
|
|
581
674
|
const self = globalThis;
|
|
582
675
|
const bundleKey = getBundleKey(bundle);
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
modules =
|
|
676
|
+
const raw = self[`TURBOPACK_${bundleKey}`];
|
|
677
|
+
let modules;
|
|
678
|
+
if (raw && typeof raw === "object" && "__chunks__" in raw) {
|
|
679
|
+
modules = raw.__chunks__.flat();
|
|
680
|
+
} else if (Array.isArray(raw)) {
|
|
681
|
+
modules = raw.flat();
|
|
682
|
+
} else {
|
|
683
|
+
modules = raw;
|
|
587
684
|
}
|
|
588
685
|
if (!self.__remote_components_turbopack_modules__) {
|
|
589
686
|
self.__remote_components_turbopack_modules__ = {};
|
|
@@ -612,13 +709,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
612
709
|
if (!self.__remote_components_turbopack_global__[bundle]) {
|
|
613
710
|
self.__remote_components_turbopack_global__[bundle] = {};
|
|
614
711
|
}
|
|
615
|
-
const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
|
|
616
712
|
moduleInit(
|
|
617
713
|
createTurbopackContext(
|
|
618
714
|
bundle,
|
|
619
715
|
exports,
|
|
620
716
|
moduleExports,
|
|
621
|
-
|
|
717
|
+
modules,
|
|
622
718
|
moduleInit,
|
|
623
719
|
id,
|
|
624
720
|
self
|
|
@@ -632,46 +728,27 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
632
728
|
return moduleExports.exports;
|
|
633
729
|
}
|
|
634
730
|
function findModuleInit(modules, moduleId) {
|
|
635
|
-
if (
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
731
|
+
if (!modules || typeof modules !== "object")
|
|
732
|
+
return;
|
|
733
|
+
if (!Array.isArray(modules)) {
|
|
734
|
+
const key = moduleId in modules ? moduleId : Object.keys(modules).find((k) => k.startsWith(moduleId));
|
|
735
|
+
return key !== void 0 ? modules[key] : void 0;
|
|
736
|
+
}
|
|
737
|
+
const flat = modules.flat();
|
|
738
|
+
let idx = flat.findIndex((e) => String(e) === String(moduleId));
|
|
739
|
+
if (idx < 0) {
|
|
740
|
+
idx = flat.findIndex(
|
|
741
|
+
(e) => typeof e === "string" && e.startsWith(moduleId)
|
|
645
742
|
);
|
|
646
|
-
if (matchingKey) {
|
|
647
|
-
return modules[matchingKey];
|
|
648
|
-
}
|
|
649
|
-
logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
|
|
650
|
-
return void 0;
|
|
651
|
-
}
|
|
652
|
-
const allModules = modules?.flat() ?? [];
|
|
653
|
-
if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
|
|
654
|
-
const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
|
|
655
|
-
let moduleIdIndex = allModules.indexOf(normalizedId);
|
|
656
|
-
if (moduleIdIndex === -1) {
|
|
657
|
-
moduleIdIndex = allModules.findIndex(
|
|
658
|
-
(bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
if (moduleIdIndex !== -1) {
|
|
662
|
-
while (typeof allModules[moduleIdIndex] !== "function" && moduleIdIndex < allModules.length) {
|
|
663
|
-
moduleIdIndex++;
|
|
664
|
-
}
|
|
665
|
-
return allModules[moduleIdIndex];
|
|
666
|
-
}
|
|
667
|
-
} else {
|
|
668
|
-
return allModules.find(
|
|
669
|
-
(bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
|
|
670
|
-
)?.[moduleId];
|
|
671
743
|
}
|
|
672
|
-
|
|
744
|
+
if (idx >= 0) {
|
|
745
|
+
return flat.slice(idx + 1).find((e) => typeof e === "function");
|
|
746
|
+
}
|
|
747
|
+
return flat.find(
|
|
748
|
+
(e) => Boolean(e && typeof e === "object" && moduleId in e)
|
|
749
|
+
)?.[moduleId];
|
|
673
750
|
}
|
|
674
|
-
function createTurbopackContext(bundle, exports, moduleExports,
|
|
751
|
+
function createTurbopackContext(bundle, exports, moduleExports, modules, moduleInit, id, self) {
|
|
675
752
|
return {
|
|
676
753
|
// HMR not implemented for Remote Components
|
|
677
754
|
k: {
|
|
@@ -792,13 +869,17 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
|
|
|
792
869
|
(parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
|
|
793
870
|
);
|
|
794
871
|
},
|
|
872
|
+
// dynamic import tracking — no-op for remote components
|
|
873
|
+
j() {
|
|
874
|
+
},
|
|
795
875
|
// chunk loader
|
|
796
876
|
l(url) {
|
|
797
|
-
const
|
|
877
|
+
const flatModules = Array.isArray(modules) ? modules : [];
|
|
878
|
+
const moduleInitIndex = flatModules.indexOf(moduleInit);
|
|
798
879
|
if (moduleInitIndex !== -1) {
|
|
799
|
-
const scriptIndex =
|
|
880
|
+
const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
|
|
800
881
|
if (scriptIndex !== -1) {
|
|
801
|
-
const script =
|
|
882
|
+
const script = flatModules[scriptIndex];
|
|
802
883
|
const scriptSrc = script.getAttribute("data-turbopack-src") || "";
|
|
803
884
|
const nextIndex = scriptSrc.indexOf("/_next");
|
|
804
885
|
const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
|
|
@@ -821,7 +902,6 @@ var init_turbopack_module = __esm({
|
|
|
821
902
|
"use strict";
|
|
822
903
|
init_logger();
|
|
823
904
|
init_const();
|
|
824
|
-
init_turbopack_patterns();
|
|
825
905
|
}
|
|
826
906
|
});
|
|
827
907
|
|
|
@@ -1061,6 +1141,89 @@ var init_webpack_adapter = __esm({
|
|
|
1061
1141
|
});
|
|
1062
1142
|
|
|
1063
1143
|
// src/shared/client/static-loader.ts
|
|
1144
|
+
async function importViaProxy(absoluteSrc) {
|
|
1145
|
+
const proxyUrl = new URL(
|
|
1146
|
+
generateProtectedRcFallbackSrc(absoluteSrc),
|
|
1147
|
+
location.href
|
|
1148
|
+
).href;
|
|
1149
|
+
const response = await fetch(proxyUrl);
|
|
1150
|
+
if (!response.ok)
|
|
1151
|
+
throw new Error(`Proxy fetch failed: ${response.status}`);
|
|
1152
|
+
logInfo(
|
|
1153
|
+
"StaticLoader",
|
|
1154
|
+
`Successfully loaded ${absoluteSrc} via protected RC proxy fallback.`
|
|
1155
|
+
);
|
|
1156
|
+
const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
|
|
1157
|
+
/\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
|
|
1158
|
+
(_, keyword, quote, relativePath) => {
|
|
1159
|
+
const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
|
|
1160
|
+
const absoluteProxyUrl = new URL(
|
|
1161
|
+
generateProtectedRcFallbackSrc(absoluteImportUrl),
|
|
1162
|
+
location.href
|
|
1163
|
+
).href;
|
|
1164
|
+
return `${keyword} ${quote}${absoluteProxyUrl}${quote}`;
|
|
1165
|
+
}
|
|
1166
|
+
);
|
|
1167
|
+
const moduleBlobUrl = URL.createObjectURL(
|
|
1168
|
+
new Blob([content], { type: "text/javascript" })
|
|
1169
|
+
);
|
|
1170
|
+
const wrapperContent = [
|
|
1171
|
+
`import*as m from${JSON.stringify(moduleBlobUrl)};`,
|
|
1172
|
+
`globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
|
|
1173
|
+
`globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
|
|
1174
|
+
].join("");
|
|
1175
|
+
const wrapperBlobUrl = URL.createObjectURL(
|
|
1176
|
+
new Blob([wrapperContent], { type: "text/javascript" })
|
|
1177
|
+
);
|
|
1178
|
+
const scriptEl = document.createElement("script");
|
|
1179
|
+
scriptEl.type = "module";
|
|
1180
|
+
scriptEl.src = wrapperBlobUrl;
|
|
1181
|
+
try {
|
|
1182
|
+
await new Promise((resolve, reject) => {
|
|
1183
|
+
scriptEl.onload = () => resolve();
|
|
1184
|
+
scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
|
|
1185
|
+
document.head.appendChild(scriptEl);
|
|
1186
|
+
});
|
|
1187
|
+
} finally {
|
|
1188
|
+
scriptEl.remove();
|
|
1189
|
+
URL.revokeObjectURL(moduleBlobUrl);
|
|
1190
|
+
URL.revokeObjectURL(wrapperBlobUrl);
|
|
1191
|
+
}
|
|
1192
|
+
const registry = globalThis.__rc_module_registry__;
|
|
1193
|
+
const mod = registry?.[absoluteSrc] ?? {};
|
|
1194
|
+
if (registry)
|
|
1195
|
+
delete registry[absoluteSrc];
|
|
1196
|
+
return mod;
|
|
1197
|
+
}
|
|
1198
|
+
function resolveScriptSrc(script, url) {
|
|
1199
|
+
const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
1200
|
+
if (!rawSrc && script.textContent) {
|
|
1201
|
+
return URL.createObjectURL(
|
|
1202
|
+
new Blob(
|
|
1203
|
+
[script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
|
|
1204
|
+
{ type: "text/javascript" }
|
|
1205
|
+
)
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
return rawSrc;
|
|
1209
|
+
}
|
|
1210
|
+
async function importScriptMod(absoluteSrc) {
|
|
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
|
+
}
|
|
1064
1227
|
async function loadStaticRemoteComponent(scripts, url) {
|
|
1065
1228
|
const self = globalThis;
|
|
1066
1229
|
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
@@ -1072,26 +1235,9 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
1072
1235
|
const mountUnmountSets = await Promise.all(
|
|
1073
1236
|
scripts.map(async (script) => {
|
|
1074
1237
|
try {
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
[
|
|
1079
|
-
script.textContent.replace(
|
|
1080
|
-
/import\.meta\.url/g,
|
|
1081
|
-
JSON.stringify(url)
|
|
1082
|
-
)
|
|
1083
|
-
],
|
|
1084
|
-
{
|
|
1085
|
-
type: "text/javascript"
|
|
1086
|
-
}
|
|
1087
|
-
);
|
|
1088
|
-
src = URL.createObjectURL(blob);
|
|
1089
|
-
}
|
|
1090
|
-
const mod = await import(
|
|
1091
|
-
/* @vite-ignore */
|
|
1092
|
-
/* webpackIgnore: true */
|
|
1093
|
-
new URL(src, url).href
|
|
1094
|
-
);
|
|
1238
|
+
const src = resolveScriptSrc(script, url);
|
|
1239
|
+
const absoluteSrc = new URL(src, url).href;
|
|
1240
|
+
const mod = await importScriptMod(absoluteSrc);
|
|
1095
1241
|
if (src.startsWith("blob:")) {
|
|
1096
1242
|
URL.revokeObjectURL(src);
|
|
1097
1243
|
}
|
|
@@ -1156,6 +1302,7 @@ var init_static_loader = __esm({
|
|
|
1156
1302
|
"src/shared/client/static-loader.ts"() {
|
|
1157
1303
|
"use strict";
|
|
1158
1304
|
init_logger();
|
|
1305
|
+
init_protected_rc_fallback();
|
|
1159
1306
|
}
|
|
1160
1307
|
});
|
|
1161
1308
|
|
|
@@ -1397,35 +1544,18 @@ async function webpackRuntime(bundle, shared, remoteShared) {
|
|
|
1397
1544
|
default: { createFromReadableStream }
|
|
1398
1545
|
} = await import("react-server-dom-webpack/client.browser");
|
|
1399
1546
|
async function preloadScripts(scripts, url, remoteBundle, _) {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
)
|
|
1413
|
-
);
|
|
1414
|
-
newScript.remove();
|
|
1415
|
-
};
|
|
1416
|
-
const scriptSrc = script.getAttribute("src") || script.getAttribute("data-src");
|
|
1417
|
-
if (scriptSrc) {
|
|
1418
|
-
newScript.src = new URL(
|
|
1419
|
-
scriptSrc.replace(/\/_next\/\[(?:.+)\](?:%20| )/, "/_next/"),
|
|
1420
|
-
url
|
|
1421
|
-
).href;
|
|
1422
|
-
}
|
|
1423
|
-
newScript.async = true;
|
|
1424
|
-
document.body.appendChild(newScript);
|
|
1425
|
-
script.parentElement?.removeChild(script);
|
|
1426
|
-
});
|
|
1427
|
-
})
|
|
1428
|
-
);
|
|
1547
|
+
const scriptSrcs = scripts.flatMap((script) => {
|
|
1548
|
+
const scriptSrc = script.getAttribute("src") || script.getAttribute("data-src");
|
|
1549
|
+
script.parentElement?.removeChild(script);
|
|
1550
|
+
if (!scriptSrc)
|
|
1551
|
+
return [];
|
|
1552
|
+
return [
|
|
1553
|
+
{
|
|
1554
|
+
src: new URL(scriptSrc.replace(NEXT_BUNDLE_PATH_RE, "/_next/"), url).href
|
|
1555
|
+
}
|
|
1556
|
+
];
|
|
1557
|
+
});
|
|
1558
|
+
await loadScripts(scriptSrcs);
|
|
1429
1559
|
const hostShared = {
|
|
1430
1560
|
...sharedPolyfills(shared),
|
|
1431
1561
|
...self.__remote_component_host_shared_modules__,
|
|
@@ -1469,6 +1599,8 @@ var init_webpack = __esm({
|
|
|
1469
1599
|
"src/html/host/runtime/webpack.ts"() {
|
|
1470
1600
|
"use strict";
|
|
1471
1601
|
init_polyfill();
|
|
1602
|
+
init_script_loader();
|
|
1603
|
+
init_webpack_patterns();
|
|
1472
1604
|
init_error();
|
|
1473
1605
|
init_next_client_pages_loader();
|
|
1474
1606
|
init_shared_modules();
|
|
@@ -1700,20 +1832,22 @@ function createRSCStream(rscName, data) {
|
|
|
1700
1832
|
});
|
|
1701
1833
|
}
|
|
1702
1834
|
|
|
1703
|
-
// src/shared/client/script-loader.ts
|
|
1704
|
-
init_error();
|
|
1705
|
-
|
|
1706
1835
|
// src/shared/client/component-loader.ts
|
|
1836
|
+
init_script_loader();
|
|
1707
1837
|
init_webpack_adapter();
|
|
1708
1838
|
|
|
1709
1839
|
// src/shared/client/remote-component.ts
|
|
1710
1840
|
init_const();
|
|
1841
|
+
init_script_loader();
|
|
1711
1842
|
init_static_loader();
|
|
1712
1843
|
init_webpack_adapter();
|
|
1713
1844
|
|
|
1714
1845
|
// src/html/host/index.tsx
|
|
1715
1846
|
init_error();
|
|
1716
1847
|
|
|
1848
|
+
// src/shared/ssr/fetch-with-hooks.ts
|
|
1849
|
+
init_fetch_with_protected_rc_fallback();
|
|
1850
|
+
|
|
1717
1851
|
// src/shared/ssr/fetch-headers.ts
|
|
1718
1852
|
function remoteFetchHeaders() {
|
|
1719
1853
|
return {
|
|
@@ -1731,7 +1865,6 @@ function remoteFetchHeaders() {
|
|
|
1731
1865
|
}
|
|
1732
1866
|
|
|
1733
1867
|
// src/shared/ssr/fetch-with-hooks.ts
|
|
1734
|
-
init_fetch_with_protected_rc_fallback();
|
|
1735
1868
|
async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
1736
1869
|
const {
|
|
1737
1870
|
onRequest,
|
|
@@ -1897,7 +2030,6 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1897
2030
|
if (this.getAttribute("src")) {
|
|
1898
2031
|
this.load().catch((e) => {
|
|
1899
2032
|
if (isAbortError(e)) {
|
|
1900
|
-
this.isLoading = false;
|
|
1901
2033
|
return;
|
|
1902
2034
|
}
|
|
1903
2035
|
logError("HtmlHost", "Error loading remote component.", e);
|
|
@@ -1923,7 +2055,6 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1923
2055
|
this.root = newRoot;
|
|
1924
2056
|
this.load().catch((e) => {
|
|
1925
2057
|
if (isAbortError(e)) {
|
|
1926
|
-
this.isLoading = false;
|
|
1927
2058
|
return;
|
|
1928
2059
|
}
|
|
1929
2060
|
logError("HtmlHost", "Error reloading remote component.", e);
|
|
@@ -1946,7 +2077,14 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1946
2077
|
});
|
|
1947
2078
|
});
|
|
1948
2079
|
if (this.isLoading) {
|
|
1949
|
-
|
|
2080
|
+
this.abortController?.abort();
|
|
2081
|
+
this.isLoading = false;
|
|
2082
|
+
if (this.root && !this.reactRoot) {
|
|
2083
|
+
this.root.innerHTML = "";
|
|
2084
|
+
this.fouc = null;
|
|
2085
|
+
this.fallbackSlot = document.createElement("slot");
|
|
2086
|
+
this.root.appendChild(this.fallbackSlot);
|
|
2087
|
+
}
|
|
1950
2088
|
}
|
|
1951
2089
|
if (!this.root) {
|
|
1952
2090
|
this.root = this.attachShadow({
|
|
@@ -1957,28 +2095,16 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1957
2095
|
}
|
|
1958
2096
|
this.name = this.getAttribute("name") || "__vercel_remote_component";
|
|
1959
2097
|
this.bundle = "default";
|
|
1960
|
-
if (this.hasAttribute("src") || this.querySelector("div#__REMOTE_COMPONENT__") || this.hasAttribute("data-ssr")) {
|
|
1961
|
-
this.load().catch((e) => {
|
|
1962
|
-
if (isAbortError(e)) {
|
|
1963
|
-
this.isLoading = false;
|
|
1964
|
-
return;
|
|
1965
|
-
}
|
|
1966
|
-
logError("HtmlHost", "Error loading remote component.", e);
|
|
1967
|
-
const errorEvent = new Event("error", {
|
|
1968
|
-
bubbles: true,
|
|
1969
|
-
composed: true
|
|
1970
|
-
});
|
|
1971
|
-
Object.assign(errorEvent, {
|
|
1972
|
-
error: e,
|
|
1973
|
-
src: this.getAttribute("src")
|
|
1974
|
-
});
|
|
1975
|
-
this.dispatchEvent(errorEvent);
|
|
1976
|
-
});
|
|
1977
|
-
}
|
|
1978
2098
|
this.isLoading = true;
|
|
1979
2099
|
const src = this.getAttribute("src");
|
|
1980
2100
|
this.abortController = new AbortController();
|
|
1981
2101
|
const signal = this.abortController.signal;
|
|
2102
|
+
const isCurrentLoad = () => !signal.aborted && this.getAttribute("src") === src;
|
|
2103
|
+
const abandonLoad = () => {
|
|
2104
|
+
if (this.abortController?.signal === signal && this.isLoading) {
|
|
2105
|
+
this.isLoading = false;
|
|
2106
|
+
}
|
|
2107
|
+
};
|
|
1982
2108
|
const beforeLoadEvent = new Event("beforeload", {
|
|
1983
2109
|
bubbles: true,
|
|
1984
2110
|
composed: true
|
|
@@ -2001,11 +2127,19 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2001
2127
|
const fetchInit = {
|
|
2002
2128
|
credentials: this.getAttribute("credentials") || "same-origin"
|
|
2003
2129
|
};
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2130
|
+
let res;
|
|
2131
|
+
try {
|
|
2132
|
+
res = await fetchWithHooks(url, fetchInit, {
|
|
2133
|
+
onRequest: this.onRequest,
|
|
2134
|
+
onResponse: this.onResponse,
|
|
2135
|
+
abortController: this.abortController
|
|
2136
|
+
});
|
|
2137
|
+
} catch (e) {
|
|
2138
|
+
if (isAbortError(e)) {
|
|
2139
|
+
return abandonLoad();
|
|
2140
|
+
}
|
|
2141
|
+
throw e;
|
|
2142
|
+
}
|
|
2009
2143
|
if (!res || !res.ok) {
|
|
2010
2144
|
let error = failedToFetchRemoteComponentError(
|
|
2011
2145
|
url.href,
|
|
@@ -2036,7 +2170,17 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2036
2170
|
}
|
|
2037
2171
|
throw error;
|
|
2038
2172
|
}
|
|
2039
|
-
|
|
2173
|
+
try {
|
|
2174
|
+
html = await res.text();
|
|
2175
|
+
} catch (e) {
|
|
2176
|
+
if (isAbortError(e)) {
|
|
2177
|
+
return abandonLoad();
|
|
2178
|
+
}
|
|
2179
|
+
throw e;
|
|
2180
|
+
}
|
|
2181
|
+
if (!isCurrentLoad()) {
|
|
2182
|
+
return abandonLoad();
|
|
2183
|
+
}
|
|
2040
2184
|
}
|
|
2041
2185
|
const parser = new DOMParser();
|
|
2042
2186
|
const doc = parser.parseFromString(html, "text/html");
|
|
@@ -2119,6 +2263,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2119
2263
|
}
|
|
2120
2264
|
})
|
|
2121
2265
|
);
|
|
2266
|
+
if (!isCurrentLoad()) {
|
|
2267
|
+
return abandonLoad();
|
|
2268
|
+
}
|
|
2122
2269
|
}
|
|
2123
2270
|
}
|
|
2124
2271
|
this.root.innerHTML = "";
|
|
@@ -2163,6 +2310,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2163
2310
|
remoteComponentSrc,
|
|
2164
2311
|
root: this.root
|
|
2165
2312
|
});
|
|
2313
|
+
if (!isCurrentLoad()) {
|
|
2314
|
+
return abandonLoad();
|
|
2315
|
+
}
|
|
2166
2316
|
}
|
|
2167
2317
|
applyOriginToNodes(doc, url ?? new URL(location.href));
|
|
2168
2318
|
if (!this.reactRoot) {
|
|
@@ -2246,6 +2396,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2246
2396
|
},
|
|
2247
2397
|
remoteShared
|
|
2248
2398
|
);
|
|
2399
|
+
if (!isCurrentLoad()) {
|
|
2400
|
+
return abandonLoad();
|
|
2401
|
+
}
|
|
2249
2402
|
const scripts = isRemoteComponent ? component.querySelectorAll("script") : doc.querySelectorAll(
|
|
2250
2403
|
"script[src],script[data-src],script[data-remote-component-entrypoint]"
|
|
2251
2404
|
);
|
|
@@ -2261,6 +2414,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2261
2414
|
this.bundle ?? "default",
|
|
2262
2415
|
this.name ?? "__vercel_remote_component"
|
|
2263
2416
|
);
|
|
2417
|
+
if (!isCurrentLoad()) {
|
|
2418
|
+
return abandonLoad();
|
|
2419
|
+
}
|
|
2264
2420
|
if (isRemoteComponent) {
|
|
2265
2421
|
Array.from(component.children).forEach((child) => {
|
|
2266
2422
|
if (child.tagName === "SCRIPT") {
|
|
@@ -2321,7 +2477,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2321
2477
|
logError("HtmlHost", "Error attaching styles.", e);
|
|
2322
2478
|
});
|
|
2323
2479
|
}
|
|
2324
|
-
|
|
2480
|
+
if (isCurrentLoad()) {
|
|
2481
|
+
this.isLoading = false;
|
|
2482
|
+
}
|
|
2325
2483
|
const loadEvent = new Event("load", {
|
|
2326
2484
|
bubbles: true,
|
|
2327
2485
|
composed: true
|
|
@@ -2374,7 +2532,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2374
2532
|
logError("HtmlHost", "Error attaching styles.", e);
|
|
2375
2533
|
});
|
|
2376
2534
|
}
|
|
2377
|
-
|
|
2535
|
+
if (isCurrentLoad()) {
|
|
2536
|
+
remoteComponent.isLoading = false;
|
|
2537
|
+
}
|
|
2378
2538
|
const loadEvent = new Event("load", {
|
|
2379
2539
|
bubbles: true,
|
|
2380
2540
|
composed: true
|
|
@@ -2391,7 +2551,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2391
2551
|
(0, import_react.startTransition)(() => {
|
|
2392
2552
|
root.render(/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RemoteComponentFromNext, { initial: false }));
|
|
2393
2553
|
doCleanup();
|
|
2394
|
-
|
|
2554
|
+
if (isCurrentLoad()) {
|
|
2555
|
+
this.isLoading = false;
|
|
2556
|
+
}
|
|
2395
2557
|
});
|
|
2396
2558
|
return;
|
|
2397
2559
|
}
|
|
@@ -2435,7 +2597,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2435
2597
|
Object.assign(loadEvent, { src: this.getAttribute("src") });
|
|
2436
2598
|
this.dispatchEvent(loadEvent);
|
|
2437
2599
|
}
|
|
2438
|
-
|
|
2600
|
+
if (isCurrentLoad()) {
|
|
2601
|
+
this.isLoading = false;
|
|
2602
|
+
}
|
|
2439
2603
|
}
|
|
2440
2604
|
}
|
|
2441
2605
|
customElements.define("remote-component", RemoteComponent);
|