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
@@ -275,6 +275,17 @@ function createRSCStream(rscName, data) {
275
275
  });
276
276
  }
277
277
 
278
+ // src/shared/constants.ts
279
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
280
+
281
+ // src/shared/client/protected-rc-fallback.ts
282
+ function generateProtectedRcFallbackSrc(url) {
283
+ return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
284
+ }
285
+
286
+ // src/shared/client/webpack-patterns.ts
287
+ var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
288
+
278
289
  // src/shared/client/script-loader.ts
279
290
  async function loadScripts(scripts) {
280
291
  await Promise.all(
@@ -282,28 +293,65 @@ async function loadScripts(scripts) {
282
293
  return new Promise((resolve, reject) => {
283
294
  const newSrc = new URL(
284
295
  // remove the remote component bundle name identifier from the script src
285
- script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
296
+ script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
286
297
  location.origin
287
298
  ).href;
288
- const newScript = document.createElement("script");
289
- newScript.onload = () => {
290
- resolve();
291
- };
292
- newScript.onerror = () => {
293
- reject(
294
- new RemoteComponentsError(
295
- `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
296
- )
297
- );
299
+ const loadScriptWithProtectedRcFallback = (src, isFallback = false) => {
300
+ const newScript = document.createElement("script");
301
+ newScript.onload = () => {
302
+ if (isFallback) {
303
+ logInfo(
304
+ "ScriptLoader",
305
+ `Successfully loaded <script src="${newSrc}"> using fallback.`
306
+ );
307
+ }
308
+ resolve();
309
+ };
310
+ newScript.onerror = () => {
311
+ if (!isFallback) {
312
+ const fallbackSrc = generateProtectedRcFallbackSrc(newSrc);
313
+ logWarn(
314
+ "ScriptLoader",
315
+ `Failed to load <script src="${newSrc}"> for Remote Component. Trying fallback with ${RC_PROTECTED_REMOTE_FETCH_PATHNAME} (withRemoteComponentsHost)...`
316
+ );
317
+ loadScriptWithProtectedRcFallback(fallbackSrc, true);
318
+ } else {
319
+ logError(
320
+ "ScriptLoader",
321
+ `Failed to load fallback for <script src="${newSrc}"> for Remote Component.`
322
+ );
323
+ reject(
324
+ new RemoteComponentsError(
325
+ `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
326
+ )
327
+ );
328
+ }
329
+ };
330
+ newScript.src = src;
331
+ newScript.async = true;
332
+ document.head.appendChild(newScript);
298
333
  };
299
- newScript.src = newSrc;
300
- newScript.async = true;
301
- document.head.appendChild(newScript);
334
+ loadScriptWithProtectedRcFallback(newSrc);
302
335
  });
303
336
  })
304
337
  );
305
338
  }
306
339
 
340
+ // src/shared/utils/index.ts
341
+ function escapeString(str) {
342
+ return str.replace(/[^a-z0-9]/g, "_");
343
+ }
344
+
345
+ // src/shared/client/const.ts
346
+ var DEFAULT_ROUTE = "/";
347
+ var RUNTIME_WEBPACK = "webpack";
348
+ var RUNTIME_TURBOPACK = "turbopack";
349
+ var RUNTIME_SCRIPT = "script";
350
+ var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
351
+ function getBundleKey(bundle) {
352
+ return escapeString(bundle);
353
+ }
354
+
307
355
  // src/shared/utils/abort.ts
308
356
  function isAbortError(error) {
309
357
  if (error instanceof DOMException && error.name === "AbortError") {
@@ -316,8 +364,7 @@ function isAbortError(error) {
316
364
  return false;
317
365
  }
318
366
 
319
- // src/shared/ssr/fetch-with-protected-rc-fallback.ts
320
- var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
367
+ // src/shared/client/fetch-with-protected-rc-fallback.ts
321
368
  async function fetchWithProtectedRcFallback(url, init) {
322
369
  try {
323
370
  const res = await fetch(url, init);
@@ -326,16 +373,21 @@ async function fetchWithProtectedRcFallback(url, init) {
326
373
  if (isAbortError(error)) {
327
374
  throw error;
328
375
  }
329
- if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
330
- logInfo(
376
+ const parsedUrl = new URL(url);
377
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== parsedUrl.origin) {
378
+ logWarn(
331
379
  "FetchRemoteComponent",
332
380
  "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
333
381
  );
334
382
  const proxiedRes = await fetch(
335
- `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,
383
+ generateProtectedRcFallbackSrc(parsedUrl.href),
336
384
  init?.signal ? { signal: init.signal } : void 0
337
385
  );
338
386
  if (proxiedRes.status === 200) {
387
+ logInfo(
388
+ "FetchRemoteComponent",
389
+ `Successfully fetched ${parsedUrl.href} with fallback withRemoteComponentsHost proxy`
390
+ );
339
391
  return proxiedRes;
340
392
  } else {
341
393
  logError(
@@ -348,20 +400,13 @@ async function fetchWithProtectedRcFallback(url, init) {
348
400
  }
349
401
  }
350
402
 
351
- // src/shared/utils/index.ts
352
- function escapeString(str) {
353
- return str.replace(/[^a-z0-9]/g, "_");
354
- }
355
-
356
- // src/shared/client/const.ts
357
- var DEFAULT_ROUTE = "/";
358
- var RUNTIME_WEBPACK = "webpack";
359
- var RUNTIME_TURBOPACK = "turbopack";
360
- var RUNTIME_SCRIPT = "script";
361
- var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
362
- function getBundleKey(bundle) {
363
- return escapeString(bundle);
364
- }
403
+ // src/shared/client/turbopack-patterns.ts
404
+ var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
405
+ var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
406
+ var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
407
+ var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
408
+ 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]+)\)\)\)\}/;
409
+ var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
365
410
 
366
411
  // src/shared/client/chunk-loader.ts
367
412
  function createChunkLoader(runtime) {
@@ -407,7 +452,7 @@ function createChunkLoader(runtime) {
407
452
  logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
408
453
  self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
409
454
  fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
410
- const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
455
+ const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
411
456
  if (hasTurbopack) {
412
457
  return handleTurbopackChunk(code, bundle ?? "", url);
413
458
  }
@@ -440,7 +485,13 @@ async function handleTurbopackChunk(code, bundle, url) {
440
485
  const self = globalThis;
441
486
  const bundleKey = getBundleKey(bundle);
442
487
  logDebug("ChunkLoader", `Bundle key: "${bundleKey}"`);
443
- const transformedCode = code.replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`).replace(
488
+ const transformedCode = code.replace(
489
+ /globalThis\[\s*["']TURBOPACK["']\s*\]/g,
490
+ `globalThis["TURBOPACK_${bundleKey}"]`
491
+ ).replace(
492
+ /self\[\s*["']TURBOPACK["']\s*\]/g,
493
+ `self["TURBOPACK_${bundleKey}"]`
494
+ ).replace(/globalThis\.TURBOPACK/g, `globalThis.TURBOPACK_${bundleKey}`).replace(/self\.TURBOPACK(?!_)/g, `self.TURBOPACK_${bundleKey}`).replace(
444
495
  /TURBOPACK_WORKER_LOCATION/g,
445
496
  `TURBOPACK_WORKER_LOCATION_${bundleKey}`
446
497
  ).replace(
@@ -556,22 +607,18 @@ async function handleTurbopackChunk(code, bundle, url) {
556
607
  }
557
608
  }
558
609
 
559
- // src/shared/client/turbopack-patterns.ts
560
- var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
561
- var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
562
- var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
563
- var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
564
- 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]+)\)\)\)\}/;
565
- var NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
566
-
567
610
  // src/shared/client/turbopack-module.ts
568
611
  function handleTurbopackModule(bundle, moduleId, id) {
569
612
  const self = globalThis;
570
613
  const bundleKey = getBundleKey(bundle);
571
- let modules = self[`TURBOPACK_${bundleKey}`];
572
- if (modules && typeof modules === "object" && "__chunks__" in modules) {
573
- const chunks = modules.__chunks__;
574
- modules = chunks.flat();
614
+ const raw = self[`TURBOPACK_${bundleKey}`];
615
+ let modules;
616
+ if (raw && typeof raw === "object" && "__chunks__" in raw) {
617
+ modules = raw.__chunks__.flat();
618
+ } else if (Array.isArray(raw)) {
619
+ modules = raw.flat();
620
+ } else {
621
+ modules = raw;
575
622
  }
576
623
  if (!self.__remote_components_turbopack_modules__) {
577
624
  self.__remote_components_turbopack_modules__ = {};
@@ -600,13 +647,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
600
647
  if (!self.__remote_components_turbopack_global__[bundle]) {
601
648
  self.__remote_components_turbopack_global__[bundle] = {};
602
649
  }
603
- const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
604
650
  moduleInit(
605
651
  createTurbopackContext(
606
652
  bundle,
607
653
  exports,
608
654
  moduleExports,
609
- allModules,
655
+ modules,
610
656
  moduleInit,
611
657
  id,
612
658
  self
@@ -620,46 +666,27 @@ function handleTurbopackModule(bundle, moduleId, id) {
620
666
  return moduleExports.exports;
621
667
  }
622
668
  function findModuleInit(modules, moduleId) {
623
- if (modules && !Array.isArray(modules) && typeof modules === "object") {
624
- const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
625
- if (normalizedId in modules) {
626
- return modules[normalizedId];
627
- }
628
- if (typeof normalizedId === "number" && String(normalizedId) in modules) {
629
- return modules[String(normalizedId)];
630
- }
631
- const matchingKey = Object.keys(modules).find(
632
- (key) => typeof key === "string" && key.includes(String(moduleId))
669
+ if (!modules || typeof modules !== "object")
670
+ return;
671
+ if (!Array.isArray(modules)) {
672
+ const key = moduleId in modules ? moduleId : Object.keys(modules).find((k) => k.startsWith(moduleId));
673
+ return key !== void 0 ? modules[key] : void 0;
674
+ }
675
+ const flat = modules.flat();
676
+ let idx = flat.findIndex((e) => String(e) === String(moduleId));
677
+ if (idx < 0) {
678
+ idx = flat.findIndex(
679
+ (e) => typeof e === "string" && e.startsWith(moduleId)
633
680
  );
634
- if (matchingKey) {
635
- return modules[matchingKey];
636
- }
637
- logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
638
- return void 0;
639
681
  }
640
- const allModules = modules?.flat() ?? [];
641
- if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
642
- const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
643
- let moduleIdIndex = allModules.indexOf(normalizedId);
644
- if (moduleIdIndex === -1) {
645
- moduleIdIndex = allModules.findIndex(
646
- (bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
647
- );
648
- }
649
- if (moduleIdIndex !== -1) {
650
- while (typeof allModules[moduleIdIndex] !== "function" && moduleIdIndex < allModules.length) {
651
- moduleIdIndex++;
652
- }
653
- return allModules[moduleIdIndex];
654
- }
655
- } else {
656
- return allModules.find(
657
- (bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
658
- )?.[moduleId];
682
+ if (idx >= 0) {
683
+ return flat.slice(idx + 1).find((e) => typeof e === "function");
659
684
  }
660
- return void 0;
685
+ return flat.find(
686
+ (e) => Boolean(e && typeof e === "object" && moduleId in e)
687
+ )?.[moduleId];
661
688
  }
662
- function createTurbopackContext(bundle, exports, moduleExports, allModules, moduleInit, id, self) {
689
+ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleInit, id, self) {
663
690
  return {
664
691
  // HMR not implemented for Remote Components
665
692
  k: {
@@ -780,13 +807,17 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
780
807
  (parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
781
808
  );
782
809
  },
810
+ // dynamic import tracking — no-op for remote components
811
+ j() {
812
+ },
783
813
  // chunk loader
784
814
  l(url) {
785
- const moduleInitIndex = allModules.indexOf(moduleInit);
815
+ const flatModules = Array.isArray(modules) ? modules : [];
816
+ const moduleInitIndex = flatModules.indexOf(moduleInit);
786
817
  if (moduleInitIndex !== -1) {
787
- const scriptIndex = allModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
818
+ const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
788
819
  if (scriptIndex !== -1) {
789
- const script = allModules[scriptIndex];
820
+ const script = flatModules[scriptIndex];
790
821
  const scriptSrc = script.getAttribute("data-turbopack-src") || "";
791
822
  const nextIndex = scriptSrc.indexOf("/_next");
792
823
  const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
@@ -1195,6 +1226,89 @@ function setAttributesFromProps(el, props) {
1195
1226
  }
1196
1227
 
1197
1228
  // src/shared/client/static-loader.ts
1229
+ async function importViaProxy(absoluteSrc) {
1230
+ const proxyUrl = new URL(
1231
+ generateProtectedRcFallbackSrc(absoluteSrc),
1232
+ location.href
1233
+ ).href;
1234
+ const response = await fetch(proxyUrl);
1235
+ if (!response.ok)
1236
+ throw new Error(`Proxy fetch failed: ${response.status}`);
1237
+ logInfo(
1238
+ "StaticLoader",
1239
+ `Successfully loaded ${absoluteSrc} via protected RC proxy fallback.`
1240
+ );
1241
+ const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
1242
+ /\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
1243
+ (_, keyword, quote, relativePath) => {
1244
+ const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
1245
+ const absoluteProxyUrl = new URL(
1246
+ generateProtectedRcFallbackSrc(absoluteImportUrl),
1247
+ location.href
1248
+ ).href;
1249
+ return `${keyword} ${quote}${absoluteProxyUrl}${quote}`;
1250
+ }
1251
+ );
1252
+ const moduleBlobUrl = URL.createObjectURL(
1253
+ new Blob([content], { type: "text/javascript" })
1254
+ );
1255
+ const wrapperContent = [
1256
+ `import*as m from${JSON.stringify(moduleBlobUrl)};`,
1257
+ `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
1258
+ `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
1259
+ ].join("");
1260
+ const wrapperBlobUrl = URL.createObjectURL(
1261
+ new Blob([wrapperContent], { type: "text/javascript" })
1262
+ );
1263
+ const scriptEl = document.createElement("script");
1264
+ scriptEl.type = "module";
1265
+ scriptEl.src = wrapperBlobUrl;
1266
+ try {
1267
+ await new Promise((resolve, reject) => {
1268
+ scriptEl.onload = () => resolve();
1269
+ scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
1270
+ document.head.appendChild(scriptEl);
1271
+ });
1272
+ } finally {
1273
+ scriptEl.remove();
1274
+ URL.revokeObjectURL(moduleBlobUrl);
1275
+ URL.revokeObjectURL(wrapperBlobUrl);
1276
+ }
1277
+ const registry = globalThis.__rc_module_registry__;
1278
+ const mod = registry?.[absoluteSrc] ?? {};
1279
+ if (registry)
1280
+ delete registry[absoluteSrc];
1281
+ return mod;
1282
+ }
1283
+ function resolveScriptSrc(script, url) {
1284
+ const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1285
+ if (!rawSrc && script.textContent) {
1286
+ return URL.createObjectURL(
1287
+ new Blob(
1288
+ [script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
1289
+ { type: "text/javascript" }
1290
+ )
1291
+ );
1292
+ }
1293
+ return rawSrc;
1294
+ }
1295
+ async function importScriptMod(absoluteSrc) {
1296
+ try {
1297
+ return await import(
1298
+ /* @vite-ignore */
1299
+ /* webpackIgnore: true */
1300
+ absoluteSrc
1301
+ );
1302
+ } catch (importError) {
1303
+ if (absoluteSrc.startsWith("blob:"))
1304
+ throw importError;
1305
+ logWarn(
1306
+ "StaticLoader",
1307
+ `Direct import of ${absoluteSrc} failed, attempting via protected RC proxy fallback.`
1308
+ );
1309
+ return importViaProxy(absoluteSrc);
1310
+ }
1311
+ }
1198
1312
  async function loadStaticRemoteComponent(scripts, url) {
1199
1313
  const self = globalThis;
1200
1314
  if (self.__remote_script_entrypoint_mount__?.[url.href]) {
@@ -1206,26 +1320,9 @@ async function loadStaticRemoteComponent(scripts, url) {
1206
1320
  const mountUnmountSets = await Promise.all(
1207
1321
  scripts.map(async (script) => {
1208
1322
  try {
1209
- let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1210
- if (!src && script.textContent) {
1211
- const blob = new Blob(
1212
- [
1213
- script.textContent.replace(
1214
- /import\.meta\.url/g,
1215
- JSON.stringify(url)
1216
- )
1217
- ],
1218
- {
1219
- type: "text/javascript"
1220
- }
1221
- );
1222
- src = URL.createObjectURL(blob);
1223
- }
1224
- const mod = await import(
1225
- /* @vite-ignore */
1226
- /* webpackIgnore: true */
1227
- new URL(src, url).href
1228
- );
1323
+ const src = resolveScriptSrc(script, url);
1324
+ const absoluteSrc = new URL(src, url).href;
1325
+ const mod = await importScriptMod(absoluteSrc);
1229
1326
  if (src.startsWith("blob:")) {
1230
1327
  URL.revokeObjectURL(src);
1231
1328
  }