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