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.
Files changed (71) hide show
  1. package/dist/html/host.cjs +330 -166
  2. package/dist/html/host.cjs.map +1 -1
  3. package/dist/html/host.js +330 -166
  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 +190 -100
  20. package/dist/internal/shared/client/remote-component.cjs.map +1 -1
  21. package/dist/internal/shared/client/remote-component.js +190 -100
  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 +202 -107
  42. package/dist/next/host/client/index.cjs.map +1 -1
  43. package/dist/next/host/client/index.js +202 -107
  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 +202 -107
  56. package/dist/react/index.cjs.map +1 -1
  57. package/dist/react/index.js +202 -107
  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
@@ -577,6 +577,17 @@ function createRSCStream(rscName, data) {
577
577
  });
578
578
  }
579
579
 
580
+ // src/shared/constants.ts
581
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
582
+
583
+ // src/shared/client/protected-rc-fallback.ts
584
+ function generateProtectedRcFallbackSrc(url) {
585
+ return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
586
+ }
587
+
588
+ // src/shared/client/webpack-patterns.ts
589
+ var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
590
+
580
591
  // src/shared/client/script-loader.ts
581
592
  async function loadScripts(scripts) {
582
593
  await Promise.all(
@@ -584,28 +595,72 @@ async function loadScripts(scripts) {
584
595
  return new Promise((resolve, reject) => {
585
596
  const newSrc = new URL(
586
597
  // remove the remote component bundle name identifier from the script src
587
- script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
598
+ script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
588
599
  location.origin
589
600
  ).href;
590
- const newScript = document.createElement("script");
591
- newScript.onload = () => {
592
- resolve();
593
- };
594
- newScript.onerror = () => {
595
- reject(
596
- new RemoteComponentsError(
597
- `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
598
- )
599
- );
601
+ const loadScriptWithProtectedRcFallback = (src, isFallback = false) => {
602
+ const newScript = document.createElement("script");
603
+ newScript.onload = () => {
604
+ if (isFallback) {
605
+ logInfo(
606
+ "ScriptLoader",
607
+ `Successfully loaded <script src="${newSrc}"> using fallback.`
608
+ );
609
+ }
610
+ resolve();
611
+ };
612
+ newScript.onerror = () => {
613
+ if (!isFallback) {
614
+ const fallbackSrc = generateProtectedRcFallbackSrc(newSrc);
615
+ logWarn(
616
+ "ScriptLoader",
617
+ `Failed to load <script src="${newSrc}"> for Remote Component. Trying fallback with ${RC_PROTECTED_REMOTE_FETCH_PATHNAME} (withRemoteComponentsHost)...`
618
+ );
619
+ loadScriptWithProtectedRcFallback(fallbackSrc, true);
620
+ } else {
621
+ logError(
622
+ "ScriptLoader",
623
+ `Failed to load fallback for <script src="${newSrc}"> for Remote Component.`
624
+ );
625
+ reject(
626
+ new RemoteComponentsError(
627
+ `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
628
+ )
629
+ );
630
+ }
631
+ };
632
+ newScript.src = src;
633
+ newScript.async = true;
634
+ document.head.appendChild(newScript);
600
635
  };
601
- newScript.src = newSrc;
602
- newScript.async = true;
603
- document.head.appendChild(newScript);
636
+ loadScriptWithProtectedRcFallback(newSrc);
604
637
  });
605
638
  })
606
639
  );
607
640
  }
608
641
 
642
+ // src/shared/utils/index.ts
643
+ function escapeString(str) {
644
+ return str.replace(/[^a-z0-9]/g, "_");
645
+ }
646
+ var attrToProp = {
647
+ fetchpriority: "fetchPriority",
648
+ crossorigin: "crossOrigin",
649
+ imagesrcset: "imageSrcSet",
650
+ imagesizes: "imageSizes",
651
+ srcset: "srcSet"
652
+ };
653
+
654
+ // src/shared/client/const.ts
655
+ var DEFAULT_ROUTE = "/";
656
+ var RUNTIME_WEBPACK = "webpack";
657
+ var RUNTIME_TURBOPACK = "turbopack";
658
+ var RUNTIME_SCRIPT = "script";
659
+ var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
660
+ function getBundleKey(bundle) {
661
+ return escapeString(bundle);
662
+ }
663
+
609
664
  // src/shared/utils/abort.ts
610
665
  function isAbortError(error) {
611
666
  if (error instanceof DOMException && error.name === "AbortError") {
@@ -618,8 +673,7 @@ function isAbortError(error) {
618
673
  return false;
619
674
  }
620
675
 
621
- // src/shared/ssr/fetch-with-protected-rc-fallback.ts
622
- var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
676
+ // src/shared/client/fetch-with-protected-rc-fallback.ts
623
677
  async function fetchWithProtectedRcFallback(url, init) {
624
678
  try {
625
679
  const res = await fetch(url, init);
@@ -628,16 +682,21 @@ async function fetchWithProtectedRcFallback(url, init) {
628
682
  if (isAbortError(error)) {
629
683
  throw error;
630
684
  }
631
- if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
632
- logInfo(
685
+ const parsedUrl = new URL(url);
686
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== parsedUrl.origin) {
687
+ logWarn(
633
688
  "FetchRemoteComponent",
634
689
  "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
635
690
  );
636
691
  const proxiedRes = await fetch(
637
- `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,
692
+ generateProtectedRcFallbackSrc(parsedUrl.href),
638
693
  init?.signal ? { signal: init.signal } : void 0
639
694
  );
640
695
  if (proxiedRes.status === 200) {
696
+ logInfo(
697
+ "FetchRemoteComponent",
698
+ `Successfully fetched ${parsedUrl.href} with fallback withRemoteComponentsHost proxy`
699
+ );
641
700
  return proxiedRes;
642
701
  } else {
643
702
  logError(
@@ -650,35 +709,12 @@ async function fetchWithProtectedRcFallback(url, init) {
650
709
  }
651
710
  }
652
711
 
653
- // src/shared/utils/index.ts
654
- function escapeString(str) {
655
- return str.replace(/[^a-z0-9]/g, "_");
656
- }
657
- var attrToProp = {
658
- fetchpriority: "fetchPriority",
659
- crossorigin: "crossOrigin",
660
- imagesrcset: "imageSrcSet",
661
- imagesizes: "imageSizes",
662
- srcset: "srcSet"
663
- };
664
-
665
- // src/shared/client/const.ts
666
- var DEFAULT_ROUTE = "/";
667
- var RUNTIME_WEBPACK = "webpack";
668
- var RUNTIME_TURBOPACK = "turbopack";
669
- var RUNTIME_SCRIPT = "script";
670
- var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
671
- function getBundleKey(bundle) {
672
- return escapeString(bundle);
673
- }
674
-
675
712
  // src/shared/client/turbopack-patterns.ts
676
713
  var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
677
714
  var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
678
715
  var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
679
716
  var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
680
717
  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]+)\)\)\)\}/;
681
- var NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
682
718
  var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
683
719
 
684
720
  // src/shared/client/chunk-loader.ts
@@ -884,10 +920,14 @@ async function handleTurbopackChunk(code, bundle, url) {
884
920
  function handleTurbopackModule(bundle, moduleId, id) {
885
921
  const self = globalThis;
886
922
  const bundleKey = getBundleKey(bundle);
887
- let modules = self[`TURBOPACK_${bundleKey}`];
888
- if (modules && typeof modules === "object" && "__chunks__" in modules) {
889
- const chunks = modules.__chunks__;
890
- modules = chunks.flat();
923
+ const raw = self[`TURBOPACK_${bundleKey}`];
924
+ let modules;
925
+ if (raw && typeof raw === "object" && "__chunks__" in raw) {
926
+ modules = raw.__chunks__.flat();
927
+ } else if (Array.isArray(raw)) {
928
+ modules = raw.flat();
929
+ } else {
930
+ modules = raw;
891
931
  }
892
932
  if (!self.__remote_components_turbopack_modules__) {
893
933
  self.__remote_components_turbopack_modules__ = {};
@@ -916,13 +956,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
916
956
  if (!self.__remote_components_turbopack_global__[bundle]) {
917
957
  self.__remote_components_turbopack_global__[bundle] = {};
918
958
  }
919
- const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
920
959
  moduleInit(
921
960
  createTurbopackContext(
922
961
  bundle,
923
962
  exports,
924
963
  moduleExports,
925
- allModules,
964
+ modules,
926
965
  moduleInit,
927
966
  id,
928
967
  self
@@ -936,46 +975,27 @@ function handleTurbopackModule(bundle, moduleId, id) {
936
975
  return moduleExports.exports;
937
976
  }
938
977
  function findModuleInit(modules, moduleId) {
939
- if (modules && !Array.isArray(modules) && typeof modules === "object") {
940
- const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
941
- if (normalizedId in modules) {
942
- return modules[normalizedId];
943
- }
944
- if (typeof normalizedId === "number" && String(normalizedId) in modules) {
945
- return modules[String(normalizedId)];
946
- }
947
- const matchingKey = Object.keys(modules).find(
948
- (key) => typeof key === "string" && key.includes(String(moduleId))
978
+ if (!modules || typeof modules !== "object")
979
+ return;
980
+ if (!Array.isArray(modules)) {
981
+ const key = moduleId in modules ? moduleId : Object.keys(modules).find((k) => k.startsWith(moduleId));
982
+ return key !== void 0 ? modules[key] : void 0;
983
+ }
984
+ const flat = modules.flat();
985
+ let idx = flat.findIndex((e) => String(e) === String(moduleId));
986
+ if (idx < 0) {
987
+ idx = flat.findIndex(
988
+ (e) => typeof e === "string" && e.startsWith(moduleId)
949
989
  );
950
- if (matchingKey) {
951
- return modules[matchingKey];
952
- }
953
- logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
954
- return void 0;
955
990
  }
956
- const allModules = modules?.flat() ?? [];
957
- if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
958
- const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
959
- let moduleIdIndex = allModules.indexOf(normalizedId);
960
- if (moduleIdIndex === -1) {
961
- moduleIdIndex = allModules.findIndex(
962
- (bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
963
- );
964
- }
965
- if (moduleIdIndex !== -1) {
966
- while (typeof allModules[moduleIdIndex] !== "function" && moduleIdIndex < allModules.length) {
967
- moduleIdIndex++;
968
- }
969
- return allModules[moduleIdIndex];
970
- }
971
- } else {
972
- return allModules.find(
973
- (bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
974
- )?.[moduleId];
991
+ if (idx >= 0) {
992
+ return flat.slice(idx + 1).find((e) => typeof e === "function");
975
993
  }
976
- return void 0;
994
+ return flat.find(
995
+ (e) => Boolean(e && typeof e === "object" && moduleId in e)
996
+ )?.[moduleId];
977
997
  }
978
- function createTurbopackContext(bundle, exports, moduleExports, allModules, moduleInit, id, self) {
998
+ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleInit, id, self) {
979
999
  return {
980
1000
  // HMR not implemented for Remote Components
981
1001
  k: {
@@ -1096,13 +1116,17 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
1096
1116
  (parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
1097
1117
  );
1098
1118
  },
1119
+ // dynamic import tracking — no-op for remote components
1120
+ j() {
1121
+ },
1099
1122
  // chunk loader
1100
1123
  l(url) {
1101
- const moduleInitIndex = allModules.indexOf(moduleInit);
1124
+ const flatModules = Array.isArray(modules) ? modules : [];
1125
+ const moduleInitIndex = flatModules.indexOf(moduleInit);
1102
1126
  if (moduleInitIndex !== -1) {
1103
- const scriptIndex = allModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
1127
+ const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
1104
1128
  if (scriptIndex !== -1) {
1105
- const script = allModules[scriptIndex];
1129
+ const script = flatModules[scriptIndex];
1106
1130
  const scriptSrc = script.getAttribute("data-turbopack-src") || "";
1107
1131
  const nextIndex = scriptSrc.indexOf("/_next");
1108
1132
  const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
@@ -1511,6 +1535,89 @@ function setAttributesFromProps(el, props) {
1511
1535
  }
1512
1536
 
1513
1537
  // src/shared/client/static-loader.ts
1538
+ async function importViaProxy(absoluteSrc) {
1539
+ const proxyUrl = new URL(
1540
+ generateProtectedRcFallbackSrc(absoluteSrc),
1541
+ location.href
1542
+ ).href;
1543
+ const response = await fetch(proxyUrl);
1544
+ if (!response.ok)
1545
+ throw new Error(`Proxy fetch failed: ${response.status}`);
1546
+ logInfo(
1547
+ "StaticLoader",
1548
+ `Successfully loaded ${absoluteSrc} via protected RC proxy fallback.`
1549
+ );
1550
+ const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
1551
+ /\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
1552
+ (_, keyword, quote, relativePath) => {
1553
+ const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
1554
+ const absoluteProxyUrl = new URL(
1555
+ generateProtectedRcFallbackSrc(absoluteImportUrl),
1556
+ location.href
1557
+ ).href;
1558
+ return `${keyword} ${quote}${absoluteProxyUrl}${quote}`;
1559
+ }
1560
+ );
1561
+ const moduleBlobUrl = URL.createObjectURL(
1562
+ new Blob([content], { type: "text/javascript" })
1563
+ );
1564
+ const wrapperContent = [
1565
+ `import*as m from${JSON.stringify(moduleBlobUrl)};`,
1566
+ `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
1567
+ `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
1568
+ ].join("");
1569
+ const wrapperBlobUrl = URL.createObjectURL(
1570
+ new Blob([wrapperContent], { type: "text/javascript" })
1571
+ );
1572
+ const scriptEl = document.createElement("script");
1573
+ scriptEl.type = "module";
1574
+ scriptEl.src = wrapperBlobUrl;
1575
+ try {
1576
+ await new Promise((resolve, reject) => {
1577
+ scriptEl.onload = () => resolve();
1578
+ scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
1579
+ document.head.appendChild(scriptEl);
1580
+ });
1581
+ } finally {
1582
+ scriptEl.remove();
1583
+ URL.revokeObjectURL(moduleBlobUrl);
1584
+ URL.revokeObjectURL(wrapperBlobUrl);
1585
+ }
1586
+ const registry = globalThis.__rc_module_registry__;
1587
+ const mod = registry?.[absoluteSrc] ?? {};
1588
+ if (registry)
1589
+ delete registry[absoluteSrc];
1590
+ return mod;
1591
+ }
1592
+ function resolveScriptSrc(script, url) {
1593
+ const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1594
+ if (!rawSrc && script.textContent) {
1595
+ return URL.createObjectURL(
1596
+ new Blob(
1597
+ [script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
1598
+ { type: "text/javascript" }
1599
+ )
1600
+ );
1601
+ }
1602
+ return rawSrc;
1603
+ }
1604
+ async function importScriptMod(absoluteSrc) {
1605
+ try {
1606
+ return await import(
1607
+ /* @vite-ignore */
1608
+ /* webpackIgnore: true */
1609
+ absoluteSrc
1610
+ );
1611
+ } catch (importError) {
1612
+ if (absoluteSrc.startsWith("blob:"))
1613
+ throw importError;
1614
+ logWarn(
1615
+ "StaticLoader",
1616
+ `Direct import of ${absoluteSrc} failed, attempting via protected RC proxy fallback.`
1617
+ );
1618
+ return importViaProxy(absoluteSrc);
1619
+ }
1620
+ }
1514
1621
  async function loadStaticRemoteComponent(scripts, url) {
1515
1622
  const self = globalThis;
1516
1623
  if (self.__remote_script_entrypoint_mount__?.[url.href]) {
@@ -1522,26 +1629,9 @@ async function loadStaticRemoteComponent(scripts, url) {
1522
1629
  const mountUnmountSets = await Promise.all(
1523
1630
  scripts.map(async (script) => {
1524
1631
  try {
1525
- let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1526
- if (!src && script.textContent) {
1527
- const blob = new Blob(
1528
- [
1529
- script.textContent.replace(
1530
- /import\.meta\.url/g,
1531
- JSON.stringify(url)
1532
- )
1533
- ],
1534
- {
1535
- type: "text/javascript"
1536
- }
1537
- );
1538
- src = URL.createObjectURL(blob);
1539
- }
1540
- const mod = await import(
1541
- /* @vite-ignore */
1542
- /* webpackIgnore: true */
1543
- new URL(src, url).href
1544
- );
1632
+ const src = resolveScriptSrc(script, url);
1633
+ const absoluteSrc = new URL(src, url).href;
1634
+ const mod = await importScriptMod(absoluteSrc);
1545
1635
  if (src.startsWith("blob:")) {
1546
1636
  URL.revokeObjectURL(src);
1547
1637
  }
@@ -1843,6 +1933,9 @@ function RemoteComponent({
1843
1933
  const previousSrc = prevSrcRef.current;
1844
1934
  const previousName = prevNameRef.current;
1845
1935
  prevSrcRef.current = src;
1936
+ if (previousSrc !== null) {
1937
+ htmlRef.current = null;
1938
+ }
1846
1939
  onBeforeLoad?.(src);
1847
1940
  (0, import_react2.startTransition)(async () => {
1848
1941
  try {
@@ -2068,6 +2161,7 @@ function RemoteComponent({
2068
2161
  shadowRootHtml = `<style data-remote-components-reset="">:host { all: initial; }</style>${shadowRootHtml}`;
2069
2162
  }
2070
2163
  shadowRoot.innerHTML = shadowRootHtml;
2164
+ htmlRef.current = null;
2071
2165
  setRemoteComponent(null);
2072
2166
  const { mount, unmount } = await loadStaticRemoteComponent(
2073
2167
  Array.from(shadowRoot.querySelectorAll("script")),
@@ -2088,6 +2182,7 @@ function RemoteComponent({
2088
2182
  }
2089
2183
  )
2090
2184
  );
2185
+ htmlRef.current = null;
2091
2186
  const { mount, unmount } = await loadStaticRemoteComponent(
2092
2187
  Array.from(component.querySelectorAll("script")),
2093
2188
  url