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
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var protected_rc_fallback_exports = {};
20
+ __export(protected_rc_fallback_exports, {
21
+ generateProtectedRcFallbackSrc: () => generateProtectedRcFallbackSrc
22
+ });
23
+ module.exports = __toCommonJS(protected_rc_fallback_exports);
24
+ var import_constants = require("#internal/shared/constants");
25
+ function generateProtectedRcFallbackSrc(url) {
26
+ return `${import_constants.RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
27
+ }
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ generateProtectedRcFallbackSrc
31
+ });
32
+ //# sourceMappingURL=protected-rc-fallback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/client/protected-rc-fallback.ts"],"sourcesContent":["import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from '#internal/shared/constants';\n\n/**\n * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint\n */\nexport function generateProtectedRcFallbackSrc(url: string): string {\n return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmD;AAK5C,SAAS,+BAA+B,KAAqB;AAClE,SAAO,GAAG,2DAA0C,mBAAmB,GAAG;AAC5E;","names":[]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint
3
+ */
4
+ declare function generateProtectedRcFallbackSrc(url: string): string;
5
+
6
+ export { generateProtectedRcFallbackSrc };
@@ -0,0 +1,8 @@
1
+ import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from "#internal/shared/constants";
2
+ function generateProtectedRcFallbackSrc(url) {
3
+ return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
4
+ }
5
+ export {
6
+ generateProtectedRcFallbackSrc
7
+ };
8
+ //# sourceMappingURL=protected-rc-fallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/shared/client/protected-rc-fallback.ts"],"sourcesContent":["import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from '#internal/shared/constants';\n\n/**\n * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint\n */\nexport function generateProtectedRcFallbackSrc(url: string): string {\n return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;\n}\n"],"mappings":"AAAA,SAAS,0CAA0C;AAK5C,SAAS,+BAA+B,KAAqB;AAClE,SAAO,GAAG,0CAA0C,mBAAmB,GAAG;AAC5E;","names":[]}
@@ -324,6 +324,17 @@ function createRSCStream(rscName, data) {
324
324
  });
325
325
  }
326
326
 
327
+ // src/shared/constants.ts
328
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
329
+
330
+ // src/shared/client/protected-rc-fallback.ts
331
+ function generateProtectedRcFallbackSrc(url) {
332
+ return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
333
+ }
334
+
335
+ // src/shared/client/webpack-patterns.ts
336
+ var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
337
+
327
338
  // src/shared/client/script-loader.ts
328
339
  async function loadScripts(scripts) {
329
340
  await Promise.all(
@@ -331,28 +342,65 @@ async function loadScripts(scripts) {
331
342
  return new Promise((resolve, reject) => {
332
343
  const newSrc = new URL(
333
344
  // remove the remote component bundle name identifier from the script src
334
- script.src.replace(/\/_next\/\[.+\](?<whitespace>%20| )/, "/_next/"),
345
+ script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
335
346
  location.origin
336
347
  ).href;
337
- const newScript = document.createElement("script");
338
- newScript.onload = () => {
339
- resolve();
340
- };
341
- newScript.onerror = () => {
342
- reject(
343
- new RemoteComponentsError(
344
- `Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
345
- )
346
- );
348
+ const loadScriptWithProtectedRcFallback = (src, isFallback = false) => {
349
+ const newScript = document.createElement("script");
350
+ newScript.onload = () => {
351
+ if (isFallback) {
352
+ logInfo(
353
+ "ScriptLoader",
354
+ `Successfully loaded <script src="${newSrc}"> using fallback.`
355
+ );
356
+ }
357
+ resolve();
358
+ };
359
+ newScript.onerror = () => {
360
+ if (!isFallback) {
361
+ const fallbackSrc = generateProtectedRcFallbackSrc(newSrc);
362
+ logWarn(
363
+ "ScriptLoader",
364
+ `Failed to load <script src="${newSrc}"> for Remote Component. Trying fallback with ${RC_PROTECTED_REMOTE_FETCH_PATHNAME} (withRemoteComponentsHost)...`
365
+ );
366
+ loadScriptWithProtectedRcFallback(fallbackSrc, true);
367
+ } else {
368
+ logError(
369
+ "ScriptLoader",
370
+ `Failed to load fallback for <script src="${newSrc}"> for Remote Component.`
371
+ );
372
+ reject(
373
+ new RemoteComponentsError(
374
+ `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
375
+ )
376
+ );
377
+ }
378
+ };
379
+ newScript.src = src;
380
+ newScript.async = true;
381
+ document.head.appendChild(newScript);
347
382
  };
348
- newScript.src = newSrc;
349
- newScript.async = true;
350
- document.head.appendChild(newScript);
383
+ loadScriptWithProtectedRcFallback(newSrc);
351
384
  });
352
385
  })
353
386
  );
354
387
  }
355
388
 
389
+ // src/shared/utils/index.ts
390
+ function escapeString(str) {
391
+ return str.replace(/[^a-z0-9]/g, "_");
392
+ }
393
+
394
+ // src/shared/client/const.ts
395
+ var DEFAULT_ROUTE = "/";
396
+ var RUNTIME_WEBPACK = "webpack";
397
+ var RUNTIME_TURBOPACK = "turbopack";
398
+ var RUNTIME_SCRIPT = "script";
399
+ var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
400
+ function getBundleKey(bundle) {
401
+ return escapeString(bundle);
402
+ }
403
+
356
404
  // src/shared/utils/abort.ts
357
405
  function isAbortError(error) {
358
406
  if (error instanceof DOMException && error.name === "AbortError") {
@@ -365,8 +413,7 @@ function isAbortError(error) {
365
413
  return false;
366
414
  }
367
415
 
368
- // src/shared/ssr/fetch-with-protected-rc-fallback.ts
369
- var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
416
+ // src/shared/client/fetch-with-protected-rc-fallback.ts
370
417
  async function fetchWithProtectedRcFallback(url, init) {
371
418
  try {
372
419
  const res = await fetch(url, init);
@@ -375,16 +422,21 @@ async function fetchWithProtectedRcFallback(url, init) {
375
422
  if (isAbortError(error)) {
376
423
  throw error;
377
424
  }
378
- if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
379
- logInfo(
425
+ const parsedUrl = new URL(url);
426
+ if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== parsedUrl.origin) {
427
+ logWarn(
380
428
  "FetchRemoteComponent",
381
429
  "Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
382
430
  );
383
431
  const proxiedRes = await fetch(
384
- `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,
432
+ generateProtectedRcFallbackSrc(parsedUrl.href),
385
433
  init?.signal ? { signal: init.signal } : void 0
386
434
  );
387
435
  if (proxiedRes.status === 200) {
436
+ logInfo(
437
+ "FetchRemoteComponent",
438
+ `Successfully fetched ${parsedUrl.href} with fallback withRemoteComponentsHost proxy`
439
+ );
388
440
  return proxiedRes;
389
441
  } else {
390
442
  logError(
@@ -397,28 +449,12 @@ async function fetchWithProtectedRcFallback(url, init) {
397
449
  }
398
450
  }
399
451
 
400
- // src/shared/utils/index.ts
401
- function escapeString(str) {
402
- return str.replace(/[^a-z0-9]/g, "_");
403
- }
404
-
405
- // src/shared/client/const.ts
406
- var DEFAULT_ROUTE = "/";
407
- var RUNTIME_WEBPACK = "webpack";
408
- var RUNTIME_TURBOPACK = "turbopack";
409
- var RUNTIME_SCRIPT = "script";
410
- var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
411
- function getBundleKey(bundle) {
412
- return escapeString(bundle);
413
- }
414
-
415
452
  // src/shared/client/turbopack-patterns.ts
416
453
  var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
417
454
  var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
418
455
  var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
419
456
  var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
420
457
  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]+)\)\)\)\}/;
421
- var NUMERIC_MODULE_ID_RE = /^[0-9]+$/;
422
458
  var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
423
459
 
424
460
  // src/shared/client/chunk-loader.ts
@@ -624,10 +660,14 @@ async function handleTurbopackChunk(code, bundle, url) {
624
660
  function handleTurbopackModule(bundle, moduleId, id) {
625
661
  const self = globalThis;
626
662
  const bundleKey = getBundleKey(bundle);
627
- let modules = self[`TURBOPACK_${bundleKey}`];
628
- if (modules && typeof modules === "object" && "__chunks__" in modules) {
629
- const chunks = modules.__chunks__;
630
- modules = chunks.flat();
663
+ const raw = self[`TURBOPACK_${bundleKey}`];
664
+ let modules;
665
+ if (raw && typeof raw === "object" && "__chunks__" in raw) {
666
+ modules = raw.__chunks__.flat();
667
+ } else if (Array.isArray(raw)) {
668
+ modules = raw.flat();
669
+ } else {
670
+ modules = raw;
631
671
  }
632
672
  if (!self.__remote_components_turbopack_modules__) {
633
673
  self.__remote_components_turbopack_modules__ = {};
@@ -656,13 +696,12 @@ function handleTurbopackModule(bundle, moduleId, id) {
656
696
  if (!self.__remote_components_turbopack_global__[bundle]) {
657
697
  self.__remote_components_turbopack_global__[bundle] = {};
658
698
  }
659
- const allModules = Array.isArray(modules) ? modules.flat() : modules ? Object.values(modules) : [];
660
699
  moduleInit(
661
700
  createTurbopackContext(
662
701
  bundle,
663
702
  exports,
664
703
  moduleExports,
665
- allModules,
704
+ modules,
666
705
  moduleInit,
667
706
  id,
668
707
  self
@@ -676,46 +715,27 @@ function handleTurbopackModule(bundle, moduleId, id) {
676
715
  return moduleExports.exports;
677
716
  }
678
717
  function findModuleInit(modules, moduleId) {
679
- if (modules && !Array.isArray(modules) && typeof modules === "object") {
680
- const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
681
- if (normalizedId in modules) {
682
- return modules[normalizedId];
683
- }
684
- if (typeof normalizedId === "number" && String(normalizedId) in modules) {
685
- return modules[String(normalizedId)];
686
- }
687
- const matchingKey = Object.keys(modules).find(
688
- (key) => typeof key === "string" && key.includes(String(moduleId))
718
+ if (!modules || typeof modules !== "object")
719
+ return;
720
+ if (!Array.isArray(modules)) {
721
+ const key = moduleId in modules ? moduleId : Object.keys(modules).find((k) => k.startsWith(moduleId));
722
+ return key !== void 0 ? modules[key] : void 0;
723
+ }
724
+ const flat = modules.flat();
725
+ let idx = flat.findIndex((e) => String(e) === String(moduleId));
726
+ if (idx < 0) {
727
+ idx = flat.findIndex(
728
+ (e) => typeof e === "string" && e.startsWith(moduleId)
689
729
  );
690
- if (matchingKey) {
691
- return modules[matchingKey];
692
- }
693
- logError("TurbopackModule", `No match found for module ID: ${moduleId}`);
694
- return void 0;
695
730
  }
696
- const allModules = modules?.flat() ?? [];
697
- if (typeof allModules[1] === "string" || typeof allModules[1] === "number") {
698
- const normalizedId = NUMERIC_MODULE_ID_RE.test(moduleId) ? Number(moduleId) : moduleId;
699
- let moduleIdIndex = allModules.indexOf(normalizedId);
700
- if (moduleIdIndex === -1) {
701
- moduleIdIndex = allModules.findIndex(
702
- (bundleEntry) => typeof bundleEntry === "string" && bundleEntry.startsWith(moduleId) || bundleEntry === normalizedId
703
- );
704
- }
705
- if (moduleIdIndex !== -1) {
706
- while (typeof allModules[moduleIdIndex] !== "function" && moduleIdIndex < allModules.length) {
707
- moduleIdIndex++;
708
- }
709
- return allModules[moduleIdIndex];
710
- }
711
- } else {
712
- return allModules.find(
713
- (bundleEntry) => typeof bundleEntry === "object" && bundleEntry !== null && moduleId in bundleEntry
714
- )?.[moduleId];
731
+ if (idx >= 0) {
732
+ return flat.slice(idx + 1).find((e) => typeof e === "function");
715
733
  }
716
- return void 0;
734
+ return flat.find(
735
+ (e) => Boolean(e && typeof e === "object" && moduleId in e)
736
+ )?.[moduleId];
717
737
  }
718
- function createTurbopackContext(bundle, exports, moduleExports, allModules, moduleInit, id, self) {
738
+ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleInit, id, self) {
719
739
  return {
720
740
  // HMR not implemented for Remote Components
721
741
  k: {
@@ -836,13 +856,17 @@ function createTurbopackContext(bundle, exports, moduleExports, allModules, modu
836
856
  (parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
837
857
  );
838
858
  },
859
+ // dynamic import tracking — no-op for remote components
860
+ j() {
861
+ },
839
862
  // chunk loader
840
863
  l(url) {
841
- const moduleInitIndex = allModules.indexOf(moduleInit);
864
+ const flatModules = Array.isArray(modules) ? modules : [];
865
+ const moduleInitIndex = flatModules.indexOf(moduleInit);
842
866
  if (moduleInitIndex !== -1) {
843
- const scriptIndex = allModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
867
+ const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
844
868
  if (scriptIndex !== -1) {
845
- const script = allModules[scriptIndex];
869
+ const script = flatModules[scriptIndex];
846
870
  const scriptSrc = script.getAttribute("data-turbopack-src") || "";
847
871
  const nextIndex = scriptSrc.indexOf("/_next");
848
872
  const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
@@ -1251,6 +1275,89 @@ function setAttributesFromProps(el, props) {
1251
1275
  }
1252
1276
 
1253
1277
  // src/shared/client/static-loader.ts
1278
+ async function importViaProxy(absoluteSrc) {
1279
+ const proxyUrl = new URL(
1280
+ generateProtectedRcFallbackSrc(absoluteSrc),
1281
+ location.href
1282
+ ).href;
1283
+ const response = await fetch(proxyUrl);
1284
+ if (!response.ok)
1285
+ throw new Error(`Proxy fetch failed: ${response.status}`);
1286
+ logInfo(
1287
+ "StaticLoader",
1288
+ `Successfully loaded ${absoluteSrc} via protected RC proxy fallback.`
1289
+ );
1290
+ const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
1291
+ /\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
1292
+ (_, keyword, quote, relativePath) => {
1293
+ const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
1294
+ const absoluteProxyUrl = new URL(
1295
+ generateProtectedRcFallbackSrc(absoluteImportUrl),
1296
+ location.href
1297
+ ).href;
1298
+ return `${keyword} ${quote}${absoluteProxyUrl}${quote}`;
1299
+ }
1300
+ );
1301
+ const moduleBlobUrl = URL.createObjectURL(
1302
+ new Blob([content], { type: "text/javascript" })
1303
+ );
1304
+ const wrapperContent = [
1305
+ `import*as m from${JSON.stringify(moduleBlobUrl)};`,
1306
+ `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
1307
+ `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
1308
+ ].join("");
1309
+ const wrapperBlobUrl = URL.createObjectURL(
1310
+ new Blob([wrapperContent], { type: "text/javascript" })
1311
+ );
1312
+ const scriptEl = document.createElement("script");
1313
+ scriptEl.type = "module";
1314
+ scriptEl.src = wrapperBlobUrl;
1315
+ try {
1316
+ await new Promise((resolve, reject) => {
1317
+ scriptEl.onload = () => resolve();
1318
+ scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
1319
+ document.head.appendChild(scriptEl);
1320
+ });
1321
+ } finally {
1322
+ scriptEl.remove();
1323
+ URL.revokeObjectURL(moduleBlobUrl);
1324
+ URL.revokeObjectURL(wrapperBlobUrl);
1325
+ }
1326
+ const registry = globalThis.__rc_module_registry__;
1327
+ const mod = registry?.[absoluteSrc] ?? {};
1328
+ if (registry)
1329
+ delete registry[absoluteSrc];
1330
+ return mod;
1331
+ }
1332
+ function resolveScriptSrc(script, url) {
1333
+ const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1334
+ if (!rawSrc && script.textContent) {
1335
+ return URL.createObjectURL(
1336
+ new Blob(
1337
+ [script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
1338
+ { type: "text/javascript" }
1339
+ )
1340
+ );
1341
+ }
1342
+ return rawSrc;
1343
+ }
1344
+ async function importScriptMod(absoluteSrc) {
1345
+ try {
1346
+ return await import(
1347
+ /* @vite-ignore */
1348
+ /* webpackIgnore: true */
1349
+ absoluteSrc
1350
+ );
1351
+ } catch (importError) {
1352
+ if (absoluteSrc.startsWith("blob:"))
1353
+ throw importError;
1354
+ logWarn(
1355
+ "StaticLoader",
1356
+ `Direct import of ${absoluteSrc} failed, attempting via protected RC proxy fallback.`
1357
+ );
1358
+ return importViaProxy(absoluteSrc);
1359
+ }
1360
+ }
1254
1361
  async function loadStaticRemoteComponent(scripts, url) {
1255
1362
  const self = globalThis;
1256
1363
  if (self.__remote_script_entrypoint_mount__?.[url.href]) {
@@ -1262,26 +1369,9 @@ async function loadStaticRemoteComponent(scripts, url) {
1262
1369
  const mountUnmountSets = await Promise.all(
1263
1370
  scripts.map(async (script) => {
1264
1371
  try {
1265
- let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1266
- if (!src && script.textContent) {
1267
- const blob = new Blob(
1268
- [
1269
- script.textContent.replace(
1270
- /import\.meta\.url/g,
1271
- JSON.stringify(url)
1272
- )
1273
- ],
1274
- {
1275
- type: "text/javascript"
1276
- }
1277
- );
1278
- src = URL.createObjectURL(blob);
1279
- }
1280
- const mod = await import(
1281
- /* @vite-ignore */
1282
- /* webpackIgnore: true */
1283
- new URL(src, url).href
1284
- );
1372
+ const src = resolveScriptSrc(script, url);
1373
+ const absoluteSrc = new URL(src, url).href;
1374
+ const mod = await importScriptMod(absoluteSrc);
1285
1375
  if (src.startsWith("blob:")) {
1286
1376
  URL.revokeObjectURL(src);
1287
1377
  }