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.
Files changed (71) hide show
  1. package/dist/html/host.cjs +348 -176
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +348 -176
  4. package/dist/html/host.js.map +1 -1
  5. package/dist/html/remote.cjs +114 -20
  6. package/dist/html/remote.cjs.map +1 -1
  7. package/dist/html/remote.js +114 -20
  8. package/dist/html/remote.js.map +1 -1
  9. package/dist/internal/shared/{ssr → client}/fetch-with-protected-rc-fallback.cjs +9 -6
  10. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs.map +1 -0
  11. package/dist/internal/shared/{ssr → client}/fetch-with-protected-rc-fallback.d.ts +1 -2
  12. package/dist/internal/shared/{ssr → client}/fetch-with-protected-rc-fallback.js +10 -6
  13. package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js.map +1 -0
  14. package/dist/internal/shared/client/protected-rc-fallback.cjs +32 -0
  15. package/dist/internal/shared/client/protected-rc-fallback.cjs.map +1 -0
  16. package/dist/internal/shared/client/protected-rc-fallback.d.ts +6 -0
  17. package/dist/internal/shared/client/protected-rc-fallback.js +8 -0
  18. package/dist/internal/shared/client/protected-rc-fallback.js.map +1 -0
  19. package/dist/internal/shared/client/remote-component.cjs +205 -108
  20. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  21. package/dist/internal/shared/client/remote-component.js +205 -108
  22. package/dist/internal/shared/client/remote-component.js.map +1 -1
  23. package/dist/internal/shared/constants.cjs +29 -0
  24. package/dist/internal/shared/constants.cjs.map +1 -0
  25. package/dist/internal/shared/constants.d.ts +3 -0
  26. package/dist/internal/shared/constants.js +5 -0
  27. package/dist/internal/shared/constants.js.map +1 -0
  28. package/dist/internal/shared/ssr/fetch-remote-component.cjs +1 -2
  29. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
  30. package/dist/internal/shared/ssr/fetch-remote-component.js +1 -2
  31. package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
  32. package/dist/internal/shared/ssr/fetch-with-hooks.cjs +1 -1
  33. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
  34. package/dist/internal/shared/ssr/fetch-with-hooks.js +1 -1
  35. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
  36. package/dist/internal/shared/utils/logger.cjs.map +1 -1
  37. package/dist/internal/shared/utils/logger.d.ts +1 -1
  38. package/dist/internal/shared/utils/logger.js.map +1 -1
  39. package/dist/next/config.cjs.map +1 -1
  40. package/dist/next/config.js.map +1 -1
  41. package/dist/next/host/client/index.cjs +217 -115
  42. package/dist/next/host/client/index.cjs.map +1 -1
  43. package/dist/next/host/client/index.js +217 -115
  44. package/dist/next/host/client/index.js.map +1 -1
  45. package/dist/next/host/pages-router-server.cjs +1 -2
  46. package/dist/next/host/pages-router-server.cjs.map +1 -1
  47. package/dist/next/host/pages-router-server.d.ts +5 -0
  48. package/dist/next/host/pages-router-server.js +1 -2
  49. package/dist/next/host/pages-router-server.js.map +1 -1
  50. package/dist/next/proxy.cjs +36 -24
  51. package/dist/next/proxy.cjs.map +1 -1
  52. package/dist/next/proxy.d.ts +0 -1
  53. package/dist/next/proxy.js +36 -24
  54. package/dist/next/proxy.js.map +1 -1
  55. package/dist/react/index.cjs +217 -115
  56. package/dist/react/index.cjs.map +1 -1
  57. package/dist/react/index.js +217 -115
  58. package/dist/react/index.js.map +1 -1
  59. package/dist/shared/host/proxy.cjs +23 -20
  60. package/dist/shared/host/proxy.cjs.map +1 -1
  61. package/dist/shared/host/proxy.d.ts +0 -3
  62. package/dist/shared/host/proxy.js +23 -19
  63. package/dist/shared/host/proxy.js.map +1 -1
  64. package/dist/shared/remote/proxy.cjs +9 -1
  65. package/dist/shared/remote/proxy.cjs.map +1 -1
  66. package/dist/shared/remote/proxy.d.ts +7 -1
  67. package/dist/shared/remote/proxy.js +8 -1
  68. package/dist/shared/remote/proxy.js.map +1 -1
  69. package/package.json +1 -1
  70. package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +0 -1
  71. 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(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
577
+ script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
567
578
  location.origin
568
579
  ).href;
569
- const newScript = document.createElement("script");
570
- newScript.onload = () => {
571
- resolve();
572
- };
573
- newScript.onerror = () => {
574
- reject(
575
- new RemoteComponentsError(
576
- `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
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
- newScript.src = newSrc;
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/ssr/fetch-with-protected-rc-fallback.ts
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
- if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
611
- logInfo(
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
- `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,
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,27 +688,13 @@ 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
- }
691
+ // src/shared/client/turbopack-patterns.ts
692
+ var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
693
+ var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
694
+ var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
695
+ var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
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]+)\)\)\)\}/;
697
+ var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
653
698
 
654
699
  // src/shared/client/chunk-loader.ts
655
700
  function createChunkLoader(runtime) {
@@ -695,7 +740,7 @@ function createChunkLoader(runtime) {
695
740
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
696
741
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
697
742
  fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
698
- const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
743
+ const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
699
744
  if (hasTurbopack) {
700
745
  return handleTurbopackChunk(code, bundle ?? "", url);
701
746
  }
@@ -728,7 +773,13 @@ async function handleTurbopackChunk(code, bundle, url) {
728
773
  const self = globalThis;
729
774
  const bundleKey = getBundleKey(bundle);
730
775
  logDebug("ChunkLoader", `Bundle key: "${bundleKey}"`);
731
- const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`).replace(
776
+ const transformedCode = code.replace(
777
+ /globalThis\[\s*["']TURBOPACK["']\s*\]/g,
778
+ `globalThis["TURBOPACK_${bundleKey}"]`
779
+ ).replace(
780
+ /self\[\s*["']TURBOPACK["']\s*\]/g,
781
+ `self["TURBOPACK_${bundleKey}"]`
782
+ ).replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`).replace(
732
783
  /TURBOPACK_WORKER_LOCATION/g,
733
784
  `TURBOPACK_WORKER_LOCATION_${bundleKey}`
734
785
  ).replace(
@@ -844,22 +895,18 @@ async function handleTurbopackChunk(code, bundle, url) {
844
895
  }
845
896
  }
846
897
 
847
- // src/shared/client/turbopack-patterns.ts
848
- var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
849
- var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
850
- var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
851
- var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
852
- 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]+)\)\)\)\}/;
853
- var NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
854
-
855
898
  // src/shared/client/turbopack-module.ts
856
899
  function handleTurbopackModule(bundle, moduleId, id) {
857
900
  const self = globalThis;
858
901
  const bundleKey = getBundleKey(bundle);
859
- let modules = self[`TURBOPACK_${bundleKey}`];
860
- if (modules && typeof modules === "object" && "__chunks__" in modules) {
861
- const chunks = modules.__chunks__;
862
- modules = chunks.flat();
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;
863
910
  }
864
911
  if (!self.__remote_components_turbopack_modules__) {
865
912
  self.__remote_components_turbopack_modules__ = {};
@@ -888,13 +935,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
888
935
  if (!self.__remote_components_turbopack_global__[bundle]) {
889
936
  self.__remote_components_turbopack_global__[bundle] = {};
890
937
  }
891
- const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
892
938
  moduleInit(
893
939
  createTurbopackContext(
894
940
  bundle,
895
941
  exports,
896
942
  moduleExports,
897
- allModules,
943
+ modules,
898
944
  moduleInit,
899
945
  id,
900
946
  self
@@ -908,46 +954,27 @@ function handleTurbopackModule(bundle, moduleId, id) {
908
954
  return moduleExports.exports;
909
955
  }
910
956
  function findModuleInit(modules, moduleId) {
911
- if (modules && !Array.isArray(modules) && typeof modules === "object") {
912
- const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
913
- if (normalizedId in modules) {
914
- return modules[normalizedId];
915
- }
916
- if (typeof normalizedId === "number" && String(normalizedId) in modules) {
917
- return modules[String(normalizedId)];
918
- }
919
- const matchingKey = Object.keys(modules).find(
920
- (key) => typeof key === "string" && key.includes(String(moduleId))
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)
921
968
  );
922
- if (matchingKey) {
923
- return modules[matchingKey];
924
- }
925
- logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
926
- return void 0;
927
969
  }
928
- const allModules = modules?.flat() ?? [];
929
- if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
930
- const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
931
- let moduleIdIndex = allModules.indexOf(normalizedId);
932
- if (moduleIdIndex === -1) {
933
- moduleIdIndex = allModules.findIndex(
934
- (bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
935
- );
936
- }
937
- if (moduleIdIndex !== -1) {
938
- while (typeof allModules[moduleIdIndex] !== "function" && moduleIdIndex < allModules.length) {
939
- moduleIdIndex++;
940
- }
941
- return allModules[moduleIdIndex];
942
- }
943
- } else {
944
- return allModules.find(
945
- (bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
946
- )?.[moduleId];
970
+ if (idx >= 0) {
971
+ return flat.slice(idx + 1).find((e) => typeof e === "function");
947
972
  }
948
- return void 0;
973
+ return flat.find(
974
+ (e) => Boolean(e && typeof e === "object" && moduleId in e)
975
+ )?.[moduleId];
949
976
  }
950
- function createTurbopackContext(bundle, exports, moduleExports, allModules, moduleInit, id, self) {
977
+ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleInit, id, self) {
951
978
  return {
952
979
  // HMR not implemented for Remote Components
953
980
  k: {
@@ -1068,13 +1095,17 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
1068
1095
  (parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
1069
1096
  );
1070
1097
  },
1098
+ // dynamic import tracking — no-op for remote components
1099
+ j() {
1100
+ },
1071
1101
  // chunk loader
1072
1102
  l(url) {
1073
- const moduleInitIndex = allModules.indexOf(moduleInit);
1103
+ const flatModules = Array.isArray(modules) ? modules : [];
1104
+ const moduleInitIndex = flatModules.indexOf(moduleInit);
1074
1105
  if (moduleInitIndex !== -1) {
1075
- const scriptIndex = allModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
1106
+ const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
1076
1107
  if (scriptIndex !== -1) {
1077
- const script = allModules[scriptIndex];
1108
+ const script = flatModules[scriptIndex];
1078
1109
  const scriptSrc = script.getAttribute("data-turbopack-src") || "";
1079
1110
  const nextIndex = scriptSrc.indexOf("/_next");
1080
1111
  const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
@@ -1483,6 +1514,89 @@ function setAttributesFromProps(el, props) {
1483
1514
  }
1484
1515
 
1485
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
+ }
1486
1600
  async function loadStaticRemoteComponent(scripts, url) {
1487
1601
  const self = globalThis;
1488
1602
  if (self.__remote_script_entrypoint_mount__?.[url.href]) {
@@ -1494,26 +1608,9 @@ async function loadStaticRemoteComponent(scripts, url) {
1494
1608
  const mountUnmountSets = await Promise.all(
1495
1609
  scripts.map(async (script) => {
1496
1610
  try {
1497
- let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1498
- if (!src && script.textContent) {
1499
- const blob = new Blob(
1500
- [
1501
- script.textContent.replace(
1502
- /import\.meta\.url/g,
1503
- JSON.stringify(url)
1504
- )
1505
- ],
1506
- {
1507
- type: "text/javascript"
1508
- }
1509
- );
1510
- src = URL.createObjectURL(blob);
1511
- }
1512
- const mod = await import(
1513
- /* @vite-ignore */
1514
- /* webpackIgnore: true */
1515
- new URL(src, url).href
1516
- );
1611
+ const src = resolveScriptSrc(script, url);
1612
+ const absoluteSrc = new URL(src, url).href;
1613
+ const mod = await importScriptMod(absoluteSrc);
1517
1614
  if (src.startsWith("blob:")) {
1518
1615
  URL.revokeObjectURL(src);
1519
1616
  }
@@ -1812,6 +1909,9 @@ function RemoteComponent({
1812
1909
  const previousSrc = prevSrcRef.current;
1813
1910
  const previousName = prevNameRef.current;
1814
1911
  prevSrcRef.current = src;
1912
+ if (previousSrc !== null) {
1913
+ htmlRef.current = null;
1914
+ }
1815
1915
  onBeforeLoad?.(src);
1816
1916
  startTransition(async () => {
1817
1917
  try {
@@ -2037,6 +2137,7 @@ function RemoteComponent({
2037
2137
  shadowRootHtml = `<style data-remote-components-reset="">:host { all: initial; }</style>${shadowRootHtml}`;
2038
2138
  }
2039
2139
  shadowRoot.innerHTML = shadowRootHtml;
2140
+ htmlRef.current = null;
2040
2141
  setRemoteComponent(null);
2041
2142
  const { mount, unmount } = await loadStaticRemoteComponent(
2042
2143
  Array.from(shadowRoot.querySelectorAll("script")),
@@ -2058,6 +2159,7 @@ function RemoteComponent({
2058
2159
  }
2059
2160
  )
2060
2161
  );
2162
+ htmlRef.current = null;
2061
2163
  const { mount, unmount } = await loadStaticRemoteComponent(
2062
2164
  Array.from(component.querySelectorAll("script")),
2063
2165
  url