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/react/index.js
CHANGED
|
@@ -551,6 +551,17 @@ function createRSCStream(rscName, data) {
|
|
|
551
551
|
});
|
|
552
552
|
}
|
|
553
553
|
|
|
554
|
+
// src/shared/constants.ts
|
|
555
|
+
var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
556
|
+
|
|
557
|
+
// src/shared/client/protected-rc-fallback.ts
|
|
558
|
+
function generateProtectedRcFallbackSrc(url) {
|
|
559
|
+
return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// src/shared/client/webpack-patterns.ts
|
|
563
|
+
var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
|
|
564
|
+
|
|
554
565
|
// src/shared/client/script-loader.ts
|
|
555
566
|
async function loadScripts(scripts) {
|
|
556
567
|
await Promise.all(
|
|
@@ -558,28 +569,72 @@ async function loadScripts(scripts) {
|
|
|
558
569
|
return new Promise((resolve, reject) => {
|
|
559
570
|
const newSrc = new URL(
|
|
560
571
|
// remove the remote component bundle name identifier from the script src
|
|
561
|
-
script.src.replace(
|
|
572
|
+
script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
|
|
562
573
|
location.origin
|
|
563
574
|
).href;
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
575
|
+
const loadScriptWithProtectedRcFallback = (src, isFallback = false) => {
|
|
576
|
+
const newScript = document.createElement("script");
|
|
577
|
+
newScript.onload = () => {
|
|
578
|
+
if (isFallback) {
|
|
579
|
+
logInfo(
|
|
580
|
+
"ScriptLoader",
|
|
581
|
+
`Successfully loaded <script src="${newSrc}"> using fallback.`
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
resolve();
|
|
585
|
+
};
|
|
586
|
+
newScript.onerror = () => {
|
|
587
|
+
if (!isFallback) {
|
|
588
|
+
const fallbackSrc = generateProtectedRcFallbackSrc(newSrc);
|
|
589
|
+
logWarn(
|
|
590
|
+
"ScriptLoader",
|
|
591
|
+
`Failed to load <script src="${newSrc}"> for Remote Component. Trying fallback with ${RC_PROTECTED_REMOTE_FETCH_PATHNAME} (withRemoteComponentsHost)...`
|
|
592
|
+
);
|
|
593
|
+
loadScriptWithProtectedRcFallback(fallbackSrc, true);
|
|
594
|
+
} else {
|
|
595
|
+
logError(
|
|
596
|
+
"ScriptLoader",
|
|
597
|
+
`Failed to load fallback for <script src="${newSrc}"> for Remote Component.`
|
|
598
|
+
);
|
|
599
|
+
reject(
|
|
600
|
+
new RemoteComponentsError(
|
|
601
|
+
`Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
|
|
602
|
+
)
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
newScript.src = src;
|
|
607
|
+
newScript.async = true;
|
|
608
|
+
document.head.appendChild(newScript);
|
|
574
609
|
};
|
|
575
|
-
|
|
576
|
-
newScript.async = true;
|
|
577
|
-
document.head.appendChild(newScript);
|
|
610
|
+
loadScriptWithProtectedRcFallback(newSrc);
|
|
578
611
|
});
|
|
579
612
|
})
|
|
580
613
|
);
|
|
581
614
|
}
|
|
582
615
|
|
|
616
|
+
// src/shared/utils/index.ts
|
|
617
|
+
function escapeString(str) {
|
|
618
|
+
return str.replace(/[^a-z0-9]/g, "_");
|
|
619
|
+
}
|
|
620
|
+
var attrToProp = {
|
|
621
|
+
fetchpriority: "fetchPriority",
|
|
622
|
+
crossorigin: "crossOrigin",
|
|
623
|
+
imagesrcset: "imageSrcSet",
|
|
624
|
+
imagesizes: "imageSizes",
|
|
625
|
+
srcset: "srcSet"
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
// src/shared/client/const.ts
|
|
629
|
+
var DEFAULT_ROUTE = "/";
|
|
630
|
+
var RUNTIME_WEBPACK = "webpack";
|
|
631
|
+
var RUNTIME_TURBOPACK = "turbopack";
|
|
632
|
+
var RUNTIME_SCRIPT = "script";
|
|
633
|
+
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
634
|
+
function getBundleKey(bundle) {
|
|
635
|
+
return escapeString(bundle);
|
|
636
|
+
}
|
|
637
|
+
|
|
583
638
|
// src/shared/utils/abort.ts
|
|
584
639
|
function isAbortError(error) {
|
|
585
640
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
@@ -592,8 +647,7 @@ function isAbortError(error) {
|
|
|
592
647
|
return false;
|
|
593
648
|
}
|
|
594
649
|
|
|
595
|
-
// src/shared/
|
|
596
|
-
var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
650
|
+
// src/shared/client/fetch-with-protected-rc-fallback.ts
|
|
597
651
|
async function fetchWithProtectedRcFallback(url, init) {
|
|
598
652
|
try {
|
|
599
653
|
const res = await fetch(url, init);
|
|
@@ -602,16 +656,21 @@ async function fetchWithProtectedRcFallback(url, init) {
|
|
|
602
656
|
if (isAbortError(error)) {
|
|
603
657
|
throw error;
|
|
604
658
|
}
|
|
605
|
-
|
|
606
|
-
|
|
659
|
+
const parsedUrl = new URL(url);
|
|
660
|
+
if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== parsedUrl.origin) {
|
|
661
|
+
logWarn(
|
|
607
662
|
"FetchRemoteComponent",
|
|
608
663
|
"Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
|
|
609
664
|
);
|
|
610
665
|
const proxiedRes = await fetch(
|
|
611
|
-
|
|
666
|
+
generateProtectedRcFallbackSrc(parsedUrl.href),
|
|
612
667
|
init?.signal ? { signal: init.signal } : void 0
|
|
613
668
|
);
|
|
614
669
|
if (proxiedRes.status === 200) {
|
|
670
|
+
logInfo(
|
|
671
|
+
"FetchRemoteComponent",
|
|
672
|
+
`Successfully fetched ${parsedUrl.href} with fallback withRemoteComponentsHost proxy`
|
|
673
|
+
);
|
|
615
674
|
return proxiedRes;
|
|
616
675
|
} else {
|
|
617
676
|
logError(
|
|
@@ -624,35 +683,12 @@ async function fetchWithProtectedRcFallback(url, init) {
|
|
|
624
683
|
}
|
|
625
684
|
}
|
|
626
685
|
|
|
627
|
-
// src/shared/utils/index.ts
|
|
628
|
-
function escapeString(str) {
|
|
629
|
-
return str.replace(/[^a-z0-9]/g, "_");
|
|
630
|
-
}
|
|
631
|
-
var attrToProp = {
|
|
632
|
-
fetchpriority: "fetchPriority",
|
|
633
|
-
crossorigin: "crossOrigin",
|
|
634
|
-
imagesrcset: "imageSrcSet",
|
|
635
|
-
imagesizes: "imageSizes",
|
|
636
|
-
srcset: "srcSet"
|
|
637
|
-
};
|
|
638
|
-
|
|
639
|
-
// src/shared/client/const.ts
|
|
640
|
-
var DEFAULT_ROUTE = "/";
|
|
641
|
-
var RUNTIME_WEBPACK = "webpack";
|
|
642
|
-
var RUNTIME_TURBOPACK = "turbopack";
|
|
643
|
-
var RUNTIME_SCRIPT = "script";
|
|
644
|
-
var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
645
|
-
function getBundleKey(bundle) {
|
|
646
|
-
return escapeString(bundle);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
686
|
// src/shared/client/turbopack-patterns.ts
|
|
650
687
|
var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
|
|
651
688
|
var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
|
|
652
689
|
var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
|
|
653
690
|
var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
|
|
654
691
|
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]+)\)\)\)\}/;
|
|
655
|
-
var NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
|
|
656
692
|
var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
|
|
657
693
|
|
|
658
694
|
// src/shared/client/chunk-loader.ts
|
|
@@ -858,10 +894,14 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
858
894
|
function handleTurbopackModule(bundle, moduleId, id) {
|
|
859
895
|
const self = globalThis;
|
|
860
896
|
const bundleKey = getBundleKey(bundle);
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
modules =
|
|
897
|
+
const raw = self[`TURBOPACK_${bundleKey}`];
|
|
898
|
+
let modules;
|
|
899
|
+
if (raw && typeof raw === "object" && "__chunks__" in raw) {
|
|
900
|
+
modules = raw.__chunks__.flat();
|
|
901
|
+
} else if (Array.isArray(raw)) {
|
|
902
|
+
modules = raw.flat();
|
|
903
|
+
} else {
|
|
904
|
+
modules = raw;
|
|
865
905
|
}
|
|
866
906
|
if (!self.__remote_components_turbopack_modules__) {
|
|
867
907
|
self.__remote_components_turbopack_modules__ = {};
|
|
@@ -890,13 +930,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
890
930
|
if (!self.__remote_components_turbopack_global__[bundle]) {
|
|
891
931
|
self.__remote_components_turbopack_global__[bundle] = {};
|
|
892
932
|
}
|
|
893
|
-
const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
|
|
894
933
|
moduleInit(
|
|
895
934
|
createTurbopackContext(
|
|
896
935
|
bundle,
|
|
897
936
|
exports,
|
|
898
937
|
moduleExports,
|
|
899
|
-
|
|
938
|
+
modules,
|
|
900
939
|
moduleInit,
|
|
901
940
|
id,
|
|
902
941
|
self
|
|
@@ -910,46 +949,27 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
910
949
|
return moduleExports.exports;
|
|
911
950
|
}
|
|
912
951
|
function findModuleInit(modules, moduleId) {
|
|
913
|
-
if (
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
952
|
+
if (!modules || typeof modules !== "object")
|
|
953
|
+
return;
|
|
954
|
+
if (!Array.isArray(modules)) {
|
|
955
|
+
const key = moduleId in modules ? moduleId : Object.keys(modules).find((k) => k.startsWith(moduleId));
|
|
956
|
+
return key !== void 0 ? modules[key] : void 0;
|
|
957
|
+
}
|
|
958
|
+
const flat = modules.flat();
|
|
959
|
+
let idx = flat.findIndex((e) => String(e) === String(moduleId));
|
|
960
|
+
if (idx < 0) {
|
|
961
|
+
idx = flat.findIndex(
|
|
962
|
+
(e) => typeof e === "string" && e.startsWith(moduleId)
|
|
923
963
|
);
|
|
924
|
-
if (matchingKey) {
|
|
925
|
-
return modules[matchingKey];
|
|
926
|
-
}
|
|
927
|
-
logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
|
|
928
|
-
return void 0;
|
|
929
964
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
|
|
933
|
-
let moduleIdIndex = allModules.indexOf(normalizedId);
|
|
934
|
-
if (moduleIdIndex === -1) {
|
|
935
|
-
moduleIdIndex = allModules.findIndex(
|
|
936
|
-
(bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
|
|
937
|
-
);
|
|
938
|
-
}
|
|
939
|
-
if (moduleIdIndex !== -1) {
|
|
940
|
-
while (typeof allModules[moduleIdIndex] !== "function" && moduleIdIndex < allModules.length) {
|
|
941
|
-
moduleIdIndex++;
|
|
942
|
-
}
|
|
943
|
-
return allModules[moduleIdIndex];
|
|
944
|
-
}
|
|
945
|
-
} else {
|
|
946
|
-
return allModules.find(
|
|
947
|
-
(bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
|
|
948
|
-
)?.[moduleId];
|
|
965
|
+
if (idx >= 0) {
|
|
966
|
+
return flat.slice(idx + 1).find((e) => typeof e === "function");
|
|
949
967
|
}
|
|
950
|
-
return
|
|
968
|
+
return flat.find(
|
|
969
|
+
(e) => Boolean(e && typeof e === "object" && moduleId in e)
|
|
970
|
+
)?.[moduleId];
|
|
951
971
|
}
|
|
952
|
-
function createTurbopackContext(bundle, exports, moduleExports,
|
|
972
|
+
function createTurbopackContext(bundle, exports, moduleExports, modules, moduleInit, id, self) {
|
|
953
973
|
return {
|
|
954
974
|
// HMR not implemented for Remote Components
|
|
955
975
|
k: {
|
|
@@ -1070,13 +1090,17 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
|
|
|
1070
1090
|
(parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
|
|
1071
1091
|
);
|
|
1072
1092
|
},
|
|
1093
|
+
// dynamic import tracking — no-op for remote components
|
|
1094
|
+
j() {
|
|
1095
|
+
},
|
|
1073
1096
|
// chunk loader
|
|
1074
1097
|
l(url) {
|
|
1075
|
-
const
|
|
1098
|
+
const flatModules = Array.isArray(modules) ? modules : [];
|
|
1099
|
+
const moduleInitIndex = flatModules.indexOf(moduleInit);
|
|
1076
1100
|
if (moduleInitIndex !== -1) {
|
|
1077
|
-
const scriptIndex =
|
|
1101
|
+
const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
|
|
1078
1102
|
if (scriptIndex !== -1) {
|
|
1079
|
-
const script =
|
|
1103
|
+
const script = flatModules[scriptIndex];
|
|
1080
1104
|
const scriptSrc = script.getAttribute("data-turbopack-src") || "";
|
|
1081
1105
|
const nextIndex = scriptSrc.indexOf("/_next");
|
|
1082
1106
|
const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
|
|
@@ -1485,6 +1509,89 @@ function setAttributesFromProps(el, props) {
|
|
|
1485
1509
|
}
|
|
1486
1510
|
|
|
1487
1511
|
// src/shared/client/static-loader.ts
|
|
1512
|
+
async function importViaProxy(absoluteSrc) {
|
|
1513
|
+
const proxyUrl = new URL(
|
|
1514
|
+
generateProtectedRcFallbackSrc(absoluteSrc),
|
|
1515
|
+
location.href
|
|
1516
|
+
).href;
|
|
1517
|
+
const response = await fetch(proxyUrl);
|
|
1518
|
+
if (!response.ok)
|
|
1519
|
+
throw new Error(`Proxy fetch failed: ${response.status}`);
|
|
1520
|
+
logInfo(
|
|
1521
|
+
"StaticLoader",
|
|
1522
|
+
`Successfully loaded ${absoluteSrc} via protected RC proxy fallback.`
|
|
1523
|
+
);
|
|
1524
|
+
const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
|
|
1525
|
+
/\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
|
|
1526
|
+
(_, keyword, quote, relativePath) => {
|
|
1527
|
+
const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
|
|
1528
|
+
const absoluteProxyUrl = new URL(
|
|
1529
|
+
generateProtectedRcFallbackSrc(absoluteImportUrl),
|
|
1530
|
+
location.href
|
|
1531
|
+
).href;
|
|
1532
|
+
return `${keyword} ${quote}${absoluteProxyUrl}${quote}`;
|
|
1533
|
+
}
|
|
1534
|
+
);
|
|
1535
|
+
const moduleBlobUrl = URL.createObjectURL(
|
|
1536
|
+
new Blob([content], { type: "text/javascript" })
|
|
1537
|
+
);
|
|
1538
|
+
const wrapperContent = [
|
|
1539
|
+
`import*as m from${JSON.stringify(moduleBlobUrl)};`,
|
|
1540
|
+
`globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
|
|
1541
|
+
`globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
|
|
1542
|
+
].join("");
|
|
1543
|
+
const wrapperBlobUrl = URL.createObjectURL(
|
|
1544
|
+
new Blob([wrapperContent], { type: "text/javascript" })
|
|
1545
|
+
);
|
|
1546
|
+
const scriptEl = document.createElement("script");
|
|
1547
|
+
scriptEl.type = "module";
|
|
1548
|
+
scriptEl.src = wrapperBlobUrl;
|
|
1549
|
+
try {
|
|
1550
|
+
await new Promise((resolve, reject) => {
|
|
1551
|
+
scriptEl.onload = () => resolve();
|
|
1552
|
+
scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
|
|
1553
|
+
document.head.appendChild(scriptEl);
|
|
1554
|
+
});
|
|
1555
|
+
} finally {
|
|
1556
|
+
scriptEl.remove();
|
|
1557
|
+
URL.revokeObjectURL(moduleBlobUrl);
|
|
1558
|
+
URL.revokeObjectURL(wrapperBlobUrl);
|
|
1559
|
+
}
|
|
1560
|
+
const registry = globalThis.__rc_module_registry__;
|
|
1561
|
+
const mod = registry?.[absoluteSrc] ?? {};
|
|
1562
|
+
if (registry)
|
|
1563
|
+
delete registry[absoluteSrc];
|
|
1564
|
+
return mod;
|
|
1565
|
+
}
|
|
1566
|
+
function resolveScriptSrc(script, url) {
|
|
1567
|
+
const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
1568
|
+
if (!rawSrc && script.textContent) {
|
|
1569
|
+
return URL.createObjectURL(
|
|
1570
|
+
new Blob(
|
|
1571
|
+
[script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
|
|
1572
|
+
{ type: "text/javascript" }
|
|
1573
|
+
)
|
|
1574
|
+
);
|
|
1575
|
+
}
|
|
1576
|
+
return rawSrc;
|
|
1577
|
+
}
|
|
1578
|
+
async function importScriptMod(absoluteSrc) {
|
|
1579
|
+
try {
|
|
1580
|
+
return await import(
|
|
1581
|
+
/* @vite-ignore */
|
|
1582
|
+
/* webpackIgnore: true */
|
|
1583
|
+
absoluteSrc
|
|
1584
|
+
);
|
|
1585
|
+
} catch (importError) {
|
|
1586
|
+
if (absoluteSrc.startsWith("blob:"))
|
|
1587
|
+
throw importError;
|
|
1588
|
+
logWarn(
|
|
1589
|
+
"StaticLoader",
|
|
1590
|
+
`Direct import of ${absoluteSrc} failed, attempting via protected RC proxy fallback.`
|
|
1591
|
+
);
|
|
1592
|
+
return importViaProxy(absoluteSrc);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1488
1595
|
async function loadStaticRemoteComponent(scripts, url) {
|
|
1489
1596
|
const self = globalThis;
|
|
1490
1597
|
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
@@ -1496,26 +1603,9 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
1496
1603
|
const mountUnmountSets = await Promise.all(
|
|
1497
1604
|
scripts.map(async (script) => {
|
|
1498
1605
|
try {
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
[
|
|
1503
|
-
script.textContent.replace(
|
|
1504
|
-
/import\.meta\.url/g,
|
|
1505
|
-
JSON.stringify(url)
|
|
1506
|
-
)
|
|
1507
|
-
],
|
|
1508
|
-
{
|
|
1509
|
-
type: "text/javascript"
|
|
1510
|
-
}
|
|
1511
|
-
);
|
|
1512
|
-
src = URL.createObjectURL(blob);
|
|
1513
|
-
}
|
|
1514
|
-
const mod = await import(
|
|
1515
|
-
/* @vite-ignore */
|
|
1516
|
-
/* webpackIgnore: true */
|
|
1517
|
-
new URL(src, url).href
|
|
1518
|
-
);
|
|
1606
|
+
const src = resolveScriptSrc(script, url);
|
|
1607
|
+
const absoluteSrc = new URL(src, url).href;
|
|
1608
|
+
const mod = await importScriptMod(absoluteSrc);
|
|
1519
1609
|
if (src.startsWith("blob:")) {
|
|
1520
1610
|
URL.revokeObjectURL(src);
|
|
1521
1611
|
}
|
|
@@ -1814,6 +1904,9 @@ function RemoteComponent({
|
|
|
1814
1904
|
const previousSrc = prevSrcRef.current;
|
|
1815
1905
|
const previousName = prevNameRef.current;
|
|
1816
1906
|
prevSrcRef.current = src;
|
|
1907
|
+
if (previousSrc !== null) {
|
|
1908
|
+
htmlRef.current = null;
|
|
1909
|
+
}
|
|
1817
1910
|
onBeforeLoad?.(src);
|
|
1818
1911
|
startTransition(async () => {
|
|
1819
1912
|
try {
|
|
@@ -2039,6 +2132,7 @@ function RemoteComponent({
|
|
|
2039
2132
|
shadowRootHtml = `<style data-remote-components-reset="">:host { all: initial; }</style>${shadowRootHtml}`;
|
|
2040
2133
|
}
|
|
2041
2134
|
shadowRoot.innerHTML = shadowRootHtml;
|
|
2135
|
+
htmlRef.current = null;
|
|
2042
2136
|
setRemoteComponent(null);
|
|
2043
2137
|
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
2044
2138
|
Array.from(shadowRoot.querySelectorAll("script")),
|
|
@@ -2060,6 +2154,7 @@ function RemoteComponent({
|
|
|
2060
2154
|
}
|
|
2061
2155
|
)
|
|
2062
2156
|
);
|
|
2157
|
+
htmlRef.current = null;
|
|
2063
2158
|
const { mount, unmount } = await loadStaticRemoteComponent(
|
|
2064
2159
|
Array.from(component.querySelectorAll("script")),
|
|
2065
2160
|
url
|