remote-components 0.4.2 → 0.4.3

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 (114) hide show
  1. package/dist/{chunk-KVQI55BZ.cjs → chunk-2W7JBTID.cjs} +37 -36
  2. package/dist/chunk-2W7JBTID.cjs.map +1 -0
  3. package/dist/{chunk-TZT7DLO5.cjs → chunk-3AX5WLZD.cjs} +4 -4
  4. package/dist/{chunk-4O3EOST4.cjs → chunk-4AH3KXDW.cjs} +27 -27
  5. package/dist/{chunk-MTMDXJLM.js → chunk-4NW46ZVD.js} +410 -146
  6. package/dist/chunk-4NW46ZVD.js.map +1 -0
  7. package/dist/{chunk-SAGYPGIQ.js → chunk-55TEMSB5.js} +92 -23
  8. package/dist/chunk-55TEMSB5.js.map +1 -0
  9. package/dist/{chunk-RLI4YTBJ.cjs → chunk-7XXO2DLF.cjs} +96 -27
  10. package/dist/chunk-7XXO2DLF.cjs.map +1 -0
  11. package/dist/{chunk-RUWR74XQ.cjs → chunk-BBXVML3D.cjs} +1 -1
  12. package/dist/{chunk-RUWR74XQ.cjs.map → chunk-BBXVML3D.cjs.map} +1 -1
  13. package/dist/{chunk-42TVDI3G.cjs → chunk-C5EYU7EQ.cjs} +7 -7
  14. package/dist/{chunk-CC3WOSDO.js → chunk-DGZVFKSQ.js} +10 -9
  15. package/dist/chunk-DGZVFKSQ.js.map +1 -0
  16. package/dist/{chunk-AKOMV2UF.js → chunk-HL6BL5HY.js} +3 -3
  17. package/dist/chunk-HMB3SIVJ.cjs +973 -0
  18. package/dist/chunk-HMB3SIVJ.cjs.map +1 -0
  19. package/dist/{chunk-LOYJP2V2.js → chunk-HYVNEUIK.js} +5 -5
  20. package/dist/chunk-KV5J7PNM.js +152 -0
  21. package/dist/chunk-KV5J7PNM.js.map +1 -0
  22. package/dist/{chunk-LQ7VQ74E.js → chunk-LEKG4YWI.js} +2 -2
  23. package/dist/chunk-SECN7UAL.cjs +152 -0
  24. package/dist/chunk-SECN7UAL.cjs.map +1 -0
  25. package/dist/{chunk-S2A4TFLS.js → chunk-ULXU6XWH.js} +1 -1
  26. package/dist/{chunk-S2A4TFLS.js.map → chunk-ULXU6XWH.js.map} +1 -1
  27. package/dist/config/nextjs.cjs +7 -7
  28. package/dist/config/nextjs.js +2 -2
  29. package/dist/host/html.cjs +36 -36
  30. package/dist/host/html.js +10 -10
  31. package/dist/host/nextjs/app/client-only.cjs +17 -17
  32. package/dist/host/nextjs/app/client-only.js +8 -8
  33. package/dist/host/react.cjs +9 -9
  34. package/dist/host/react.js +8 -8
  35. package/dist/internal/config/webpack/next-client-pages-loader.cjs +151 -53
  36. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  37. package/dist/internal/config/webpack/next-client-pages-loader.d.ts +8 -4
  38. package/dist/internal/config/webpack/next-client-pages-loader.js +153 -53
  39. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  40. package/dist/internal/host/shared/pipeline.d.ts +1 -1
  41. package/dist/internal/host/shared/shared-broker.cjs +106 -0
  42. package/dist/internal/host/shared/shared-broker.cjs.map +1 -0
  43. package/dist/internal/host/shared/shared-broker.d.ts +35 -0
  44. package/dist/internal/host/shared/shared-broker.js +80 -0
  45. package/dist/internal/host/shared/shared-broker.js.map +1 -0
  46. package/dist/internal/host/shared/shared-module-resolver.cjs +13 -22
  47. package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -1
  48. package/dist/internal/host/shared/shared-module-resolver.d.ts +1 -1
  49. package/dist/internal/host/shared/shared-module-resolver.js +16 -22
  50. package/dist/internal/host/shared/shared-module-resolver.js.map +1 -1
  51. package/dist/internal/runtime/loaders/component-loader.cjs +2 -1
  52. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  53. package/dist/internal/runtime/loaders/component-loader.d.ts +1 -1
  54. package/dist/internal/runtime/loaders/component-loader.js +2 -1
  55. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  56. package/dist/internal/runtime/loaders/static-loader.d.ts +1 -1
  57. package/dist/internal/runtime/namespace.d.ts +1 -1
  58. package/dist/internal/runtime/turbopack/module.cjs +26 -4
  59. package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
  60. package/dist/internal/runtime/turbopack/module.d.ts +14 -7
  61. package/dist/internal/runtime/turbopack/module.js +27 -5
  62. package/dist/internal/runtime/turbopack/module.js.map +1 -1
  63. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs +5 -4
  64. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -1
  65. package/dist/internal/runtime/turbopack/remote-scope-setup.js +5 -4
  66. package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -1
  67. package/dist/internal/runtime/turbopack/shared-modules.cjs +113 -26
  68. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
  69. package/dist/internal/runtime/turbopack/shared-modules.d.ts +3 -1
  70. package/dist/internal/runtime/turbopack/shared-modules.js +116 -26
  71. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
  72. package/dist/internal/runtime/types.cjs.map +1 -1
  73. package/dist/internal/runtime/types.d.ts +1 -1
  74. package/dist/internal/utils/logger.cjs.map +1 -1
  75. package/dist/internal/utils/logger.d.ts +1 -1
  76. package/dist/internal/utils/logger.js.map +1 -1
  77. package/dist/remote/html.cjs +6 -6
  78. package/dist/remote/html.js +2 -2
  79. package/dist/{script-VPOI7ARP.js → script-ISAHSV3X.js} +3 -3
  80. package/dist/{script-D5AD7HLV.cjs → script-YQCDUYDP.cjs} +4 -4
  81. package/dist/static-loader-EOJQHFZ6.cjs +11 -0
  82. package/dist/{static-loader-OHSAUD62.js → static-loader-Z24427MK.js} +3 -3
  83. package/dist/{turbopack-5N44NVPT.js → turbopack-7F757Z7V.js} +6 -6
  84. package/dist/{turbopack-EPXGK4EV.cjs → turbopack-DULMVTWV.cjs} +12 -12
  85. package/dist/{types-8b0edd78.d.ts → types-bd7be268.d.ts} +1 -5
  86. package/dist/{webpack-SIFRCBIN.cjs → webpack-6LXCB7WA.cjs} +14 -14
  87. package/dist/{webpack-KSDNIXMS.js → webpack-WGVTKJ3W.js} +5 -5
  88. package/package.json +1 -1
  89. package/dist/chunk-CC3WOSDO.js.map +0 -1
  90. package/dist/chunk-JJTCFQHE.cjs +0 -202
  91. package/dist/chunk-JJTCFQHE.cjs.map +0 -1
  92. package/dist/chunk-KVQI55BZ.cjs.map +0 -1
  93. package/dist/chunk-MKO52FRO.js +0 -202
  94. package/dist/chunk-MKO52FRO.js.map +0 -1
  95. package/dist/chunk-MQ2BBSL4.cjs +0 -709
  96. package/dist/chunk-MQ2BBSL4.cjs.map +0 -1
  97. package/dist/chunk-MTMDXJLM.js.map +0 -1
  98. package/dist/chunk-RLI4YTBJ.cjs.map +0 -1
  99. package/dist/chunk-SAGYPGIQ.js.map +0 -1
  100. package/dist/static-loader-UDIXK5MV.cjs +0 -11
  101. /package/dist/{chunk-TZT7DLO5.cjs.map → chunk-3AX5WLZD.cjs.map} +0 -0
  102. /package/dist/{chunk-4O3EOST4.cjs.map → chunk-4AH3KXDW.cjs.map} +0 -0
  103. /package/dist/{chunk-42TVDI3G.cjs.map → chunk-C5EYU7EQ.cjs.map} +0 -0
  104. /package/dist/{chunk-AKOMV2UF.js.map → chunk-HL6BL5HY.js.map} +0 -0
  105. /package/dist/{chunk-LOYJP2V2.js.map → chunk-HYVNEUIK.js.map} +0 -0
  106. /package/dist/{chunk-LQ7VQ74E.js.map → chunk-LEKG4YWI.js.map} +0 -0
  107. /package/dist/{script-VPOI7ARP.js.map → script-ISAHSV3X.js.map} +0 -0
  108. /package/dist/{script-D5AD7HLV.cjs.map → script-YQCDUYDP.cjs.map} +0 -0
  109. /package/dist/{static-loader-UDIXK5MV.cjs.map → static-loader-EOJQHFZ6.cjs.map} +0 -0
  110. /package/dist/{static-loader-OHSAUD62.js.map → static-loader-Z24427MK.js.map} +0 -0
  111. /package/dist/{turbopack-5N44NVPT.js.map → turbopack-7F757Z7V.js.map} +0 -0
  112. /package/dist/{turbopack-EPXGK4EV.cjs.map → turbopack-DULMVTWV.cjs.map} +0 -0
  113. /package/dist/{webpack-SIFRCBIN.cjs.map → webpack-6LXCB7WA.cjs.map} +0 -0
  114. /package/dist/{webpack-KSDNIXMS.js.map → webpack-WGVTKJ3W.js.map} +0 -0
@@ -1,14 +1,12 @@
1
1
  import {
2
- REMOTE_COMPONENT_REGEX,
3
- RUNTIME_TURBOPACK,
4
2
  RUNTIME_WEBPACK,
5
3
  collapseDoubleSlashes,
6
- createScope,
4
+ createSharedModulePlan,
7
5
  formatRemoteId,
8
6
  getScope,
9
- parseRemoteId,
10
- registerScope
11
- } from "./chunk-SAGYPGIQ.js";
7
+ installSharedModulePlan,
8
+ parseRemoteId
9
+ } from "./chunk-55TEMSB5.js";
12
10
  import {
13
11
  getNamespace
14
12
  } from "./chunk-D5GNZB6O.js";
@@ -19,11 +17,74 @@ import {
19
17
  logError,
20
18
  logWarn,
21
19
  warnCrossOriginFetchError
22
- } from "./chunk-S2A4TFLS.js";
20
+ } from "./chunk-ULXU6XWH.js";
23
21
  import {
24
22
  isProxiedUrl
25
23
  } from "./chunk-X6YKUJKH.js";
26
24
 
25
+ // src/config/webpack/apply-shared-modules.ts
26
+ var DEDUPLICATION_SKIPPED = "shared module deduplication skipped. The remote may load its own copy of shared dependencies.";
27
+ function applySharedModules(bundle, resolve) {
28
+ logDebug(
29
+ "SharedModules",
30
+ `applySharedModules called for bundle: "${bundle}"`
31
+ );
32
+ logDebug(
33
+ "SharedModules",
34
+ `Shared modules to resolve: ${Object.keys(resolve)}`
35
+ );
36
+ const self = globalThis;
37
+ const scope = getScope(bundle);
38
+ const webpackBundle = scope?.webpackRequire ?? self.__remote_webpack_require__?.[bundle];
39
+ if (webpackBundle) {
40
+ const modulePaths = Object.keys(
41
+ self.__remote_webpack_module_map__?.[bundle] ?? webpackBundle.m ?? {}
42
+ );
43
+ logDebug(
44
+ "SharedModules",
45
+ `Available module paths for bundle "${bundle}": ${modulePaths}`
46
+ );
47
+ for (const [key, value] of Object.entries(resolve)) {
48
+ const exactIds = modulePaths.filter((p) => p === key);
49
+ const ids = exactIds.length > 0 ? exactIds : modulePaths.filter((p) => p.includes(key));
50
+ if (ids.length === 0) {
51
+ logDebug(
52
+ "SharedModules",
53
+ `No matching module path found for shared module "${key}"`
54
+ );
55
+ }
56
+ for (const id of ids) {
57
+ if (webpackBundle.m) {
58
+ const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id] ? `${self.__remote_webpack_module_map__[bundle][id]}` : id;
59
+ if (resolvedId !== id) {
60
+ logDebug(
61
+ "SharedModules",
62
+ `Mapped module id: "${id}" -> "${resolvedId}"`
63
+ );
64
+ }
65
+ webpackBundle.m[resolvedId] = (module) => {
66
+ module.exports = value;
67
+ };
68
+ } else {
69
+ logWarn(
70
+ "SharedModules",
71
+ `webpackBundle.m is not available for bundle "${bundle}" \u2014 ${DEDUPLICATION_SKIPPED}`
72
+ );
73
+ }
74
+ }
75
+ }
76
+ } else {
77
+ logWarn(
78
+ "SharedModules",
79
+ `No webpack require found for bundle "${bundle}" \u2014 ${DEDUPLICATION_SKIPPED}`
80
+ );
81
+ logDebug(
82
+ "SharedModules",
83
+ `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
84
+ );
85
+ }
86
+ }
87
+
27
88
  // src/runtime/turbopack/patterns.ts
28
89
  var MODULE_ID_PATTERN = '"[^"]+"|[0-9]+';
29
90
  function stripQuotes(value) {
@@ -223,11 +284,18 @@ async function handleTurbopackChunk(code, scope, url) {
223
284
  // src/runtime/turbopack/module.ts
224
285
  function requireModule(scope, moduleId, fullId) {
225
286
  const idStr = String(moduleId);
226
- if (scope.moduleCache[idStr])
227
- return scope.moduleCache[idStr];
228
287
  const sharedModule = getSharedModule(scope, moduleId);
229
- if (sharedModule)
288
+ if (sharedModule !== null) {
289
+ if (scope.moduleCache[idStr]) {
290
+ logDebug(
291
+ "TurbopackModule",
292
+ `Shared module "${idStr}" resolved from host and overrides a cached remote copy in "${scope.scopedName}"`
293
+ );
294
+ }
230
295
  return sharedModule;
296
+ }
297
+ if (scope.moduleCache[idStr])
298
+ return scope.moduleCache[idStr];
231
299
  return handleTurbopackModule(
232
300
  scope,
233
301
  idStr,
@@ -247,7 +315,10 @@ function handleTurbopackModule(scope, moduleId, id) {
247
315
  }
248
316
  const moduleInit = findModuleInit(modules, moduleId);
249
317
  const exports = {};
250
- const moduleExports = { exports };
318
+ const moduleExports = {
319
+ exports,
320
+ hot: createNoopHotModule()
321
+ };
251
322
  if (typeof moduleInit !== "function") {
252
323
  throw new Error(
253
324
  `Module ${id} not found in bundle ${scope.name} with id ${moduleId}`
@@ -443,9 +514,22 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
443
514
  e: exports
444
515
  };
445
516
  }
517
+ function createNoopHotModule() {
518
+ return {
519
+ active: true,
520
+ data: {},
521
+ accept() {
522
+ },
523
+ dispose() {
524
+ },
525
+ invalidate() {
526
+ }
527
+ };
528
+ }
446
529
 
447
530
  // src/runtime/turbopack/shared-modules.ts
448
531
  var DEDUPLICATION_WARNING = "This module will not be deduplicated \u2014 the remote may load its own copy, which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).";
532
+ var INLINE_REMOTE_SHARED_RE = /["']?__remote_shared_module_(?<specifier>[^"':]+)["']?\s*:\s*\(\)\s*=>\s*(?:__turbopack_context__|[a-z])\.A\((?<asyncSharedModuleId>"[^"]+"|[0-9]+)\)/g;
449
533
  function getTurbopackModules(scope) {
450
534
  if (scope.turbopackModules.length > 0) {
451
535
  return scope.turbopackModules;
@@ -498,17 +582,27 @@ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}
498
582
  "SharedModules",
499
583
  `Resolved shared modules for scope="${scope.scopedName}": ${JSON.stringify(sharedModuleIds)}`
500
584
  );
501
- return Promise.all(
502
- Object.entries(sharedModuleIds).map(async ([id, module]) => {
503
- if (hostShared[module]) {
504
- scope.sharedModules[id] = await hostShared[module](scope.name);
505
- } else {
506
- logError(
507
- "SharedModules",
508
- `Host shared module "${module}" not found for ID ${id}. ${DEDUPLICATION_WARNING}`
509
- );
510
- }
511
- })
585
+ return installSharedModules(
586
+ scope,
587
+ hostShared,
588
+ sharedModuleIds,
589
+ (id, module) => `Host shared module "${module}" not found for ID ${id}. ${DEDUPLICATION_WARNING}`
590
+ );
591
+ }
592
+ const inlineSharedModuleIds = extractInlineSharedModuleIds(
593
+ allModules,
594
+ scope
595
+ );
596
+ if (Object.keys(inlineSharedModuleIds).length > 0) {
597
+ logDebug(
598
+ "SharedModules",
599
+ `Resolved inline shared modules for scope="${scope.scopedName}": ${JSON.stringify(inlineSharedModuleIds)}`
600
+ );
601
+ return installSharedModules(
602
+ scope,
603
+ hostShared,
604
+ inlineSharedModuleIds,
605
+ (id, module) => `Host shared module "${module}" not found for inline ID ${id}. ${DEDUPLICATION_WARNING}`
512
606
  );
513
607
  }
514
608
  logWarn(
@@ -521,20 +615,17 @@ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}
521
615
  `No TURBOPACK modules found for scope="${scope.scopedName}" (TURBOPACK_${scope.globalKey} is empty)`
522
616
  );
523
617
  }
524
- return Promise.all(
525
- Object.entries(remoteShared).map(async ([id, module]) => {
526
- if (hostShared[module]) {
527
- const normalizedId = id.replace("[app-ssr]", "[app-client]");
528
- scope.sharedModules[normalizedId] = await hostShared[module](
529
- scope.name
530
- );
531
- } else {
532
- logError(
533
- "SharedModules",
534
- `Shared module "${module}" not found for "${scope.name}". ${DEDUPLICATION_WARNING}`
535
- );
536
- }
537
- })
618
+ const normalizedRemoteShared = Object.fromEntries(
619
+ Object.entries(remoteShared).map(([id, module]) => [
620
+ id.replace("[app-ssr]", "[app-client]"),
621
+ module
622
+ ])
623
+ );
624
+ return installSharedModules(
625
+ scope,
626
+ hostShared,
627
+ normalizedRemoteShared,
628
+ (_id, module) => `Shared module "${module}" not found for "${scope.name}". ${DEDUPLICATION_WARNING}`
538
629
  );
539
630
  }
540
631
  function extractSharedModuleIds(shared, scope) {
@@ -564,146 +655,319 @@ function extractSharedModuleIds(shared, scope) {
564
655
  return acc;
565
656
  }, {});
566
657
  }
658
+ function extractInlineSharedModuleIds(allModules, scope) {
659
+ const sharedModuleIds = {};
660
+ for (const idOrFunc of allModules) {
661
+ if (typeof idOrFunc !== "function")
662
+ continue;
663
+ const funcCode = idOrFunc.toString();
664
+ if (!funcCode.includes("__remote_shared_module_"))
665
+ continue;
666
+ INLINE_REMOTE_SHARED_RE.lastIndex = 0;
667
+ for (const match of funcCode.matchAll(INLINE_REMOTE_SHARED_RE)) {
668
+ const specifier = match.groups?.specifier;
669
+ const asyncSharedModuleId = stripQuotes2(
670
+ match.groups?.asyncSharedModuleId
671
+ );
672
+ if (!specifier || !asyncSharedModuleId)
673
+ continue;
674
+ const asyncSharedModule = findModuleInit(
675
+ getTurbopackModules(scope),
676
+ asyncSharedModuleId
677
+ );
678
+ if (!asyncSharedModule)
679
+ continue;
680
+ const sharedModuleId = extractGroup(
681
+ ASYNC_MODULE_CALLBACK_RE,
682
+ asyncSharedModule.toString(),
683
+ "sharedModuleId"
684
+ );
685
+ sharedModuleIds[sharedModuleId ?? asyncSharedModuleId] = specifier;
686
+ }
687
+ }
688
+ return sharedModuleIds;
689
+ }
690
+ function stripQuotes2(value) {
691
+ if (value?.startsWith('"') && value.endsWith('"')) {
692
+ return value.slice(1, -1);
693
+ }
694
+ return value;
695
+ }
696
+ function installSharedModules(scope, hostShared, sharedModuleIds, missingMessage) {
697
+ const plan = createSharedModulePlan({
698
+ bundle: scope.name,
699
+ hostShared,
700
+ remoteShared: sharedModuleIds,
701
+ scope: `remote:${scope.scopedName}`,
702
+ callerTag: "SharedModules"
703
+ });
704
+ for (const entry of plan.entries) {
705
+ if (entry.status === "resolved") {
706
+ delete scope.moduleCache[entry.id];
707
+ }
708
+ }
709
+ return installSharedModulePlan({
710
+ plan,
711
+ target: scope.sharedModules,
712
+ callerTag: "SharedModules",
713
+ onMissing: (entry) => {
714
+ logError("SharedModules", missingMessage(entry.id, entry.specifier));
715
+ }
716
+ }).then((results) => {
717
+ for (const entry of plan.entries) {
718
+ if (entry.status === "resolved") {
719
+ delete scope.moduleCache[entry.id];
720
+ }
721
+ }
722
+ return results;
723
+ });
724
+ }
567
725
  function getSharedModule(scope, id) {
568
726
  const idStr = String(id);
569
727
  if (scope.sharedModules[idStr] !== void 0) {
570
728
  return scope.sharedModules[idStr];
571
729
  }
572
730
  for (const [key, value] of Object.entries(scope.sharedModules)) {
573
- if (typeof value !== "undefined" && idStr !== key && idStr.endsWith(key)) {
731
+ if (typeof value !== "undefined" && idStr !== key && matchesSharedModuleKey(idStr, key)) {
574
732
  return value;
575
733
  }
576
734
  }
577
735
  return null;
578
736
  }
737
+ function matchesSharedModuleKey(id, key) {
738
+ if (id.endsWith(key))
739
+ return true;
740
+ if (!key.includes("/") && !key.endsWith(".js"))
741
+ return false;
742
+ const index = id.lastIndexOf(key);
743
+ if (index < 0)
744
+ return false;
745
+ const afterKey = id.slice(index + key.length);
746
+ return /^\s+(?:\[[^\]]+\]\s*)?(?:\([^)]*\))?$/.test(afterKey);
747
+ }
579
748
 
580
- // src/runtime/turbopack/remote-scope-setup.ts
581
- async function setupRemoteScope(runtime, scripts = [], url = new URL(location.href), bundle, resolveClientUrl) {
749
+ // src/config/webpack/next-client-pages-loader.ts
750
+ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
582
751
  const self = globalThis;
583
752
  const ns = getNamespace();
584
- const bundleName = bundle ?? "default";
585
- const existingScope = getScope(bundleName);
586
- if (existingScope && existingScope.url.origin === url.origin) {
587
- logDebug(
588
- "WebpackRuntime",
589
- `Reusing scope "${existingScope.scopedName}" (turbopackModules=${existingScope.turbopackModules.length})`
753
+ ns.pageComponentCache ??= {};
754
+ const cacheKey = `${bundle}:${route}`;
755
+ const remoteRequire = self.__remote_webpack_require__?.[bundle];
756
+ const turbopackScope = remoteRequire?.type === "turbopack" ? getScope(bundle) : void 0;
757
+ const applyBundleCss = () => {
758
+ const elements = ns.cssCache[bundle] ?? [];
759
+ if (styleContainer) {
760
+ for (const el of elements) {
761
+ styleContainer.appendChild(el.cloneNode(true));
762
+ }
763
+ } else {
764
+ for (const el of elements) {
765
+ document.head.appendChild(el);
766
+ }
767
+ }
768
+ };
769
+ const cachedEntry = ns.pageComponentCache[cacheKey];
770
+ if (cachedEntry) {
771
+ applyBundleCss();
772
+ return cachedEntry;
773
+ }
774
+ const nextCssOriginal = document.querySelector(
775
+ `[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
776
+ );
777
+ const nextCssOriginalParent = nextCssOriginal?.parentNode ?? null;
778
+ const nextCssOriginalNextSibling = nextCssOriginal?.nextSibling ?? null;
779
+ if (nextCssOriginal) {
780
+ nextCssOriginalParent?.removeChild(nextCssOriginal);
781
+ }
782
+ const nextCss = document.createElement("noscript");
783
+ nextCss.id = "__next_css__DO_NOT_USE__";
784
+ nextCss.setAttribute("data-bundle", bundle);
785
+ nextCss.setAttribute("data-route", route);
786
+ const nextCssEnd = document.createElement("noscript");
787
+ nextCssEnd.id = "__next_css__DO_NOT_USE_END__";
788
+ nextCssEnd.setAttribute("data-bundle", bundle);
789
+ nextCssEnd.setAttribute("data-route", route);
790
+ document.head.appendChild(nextCssEnd);
791
+ document.head.appendChild(nextCss);
792
+ const componentLoaderChunk = (turbopackScope ? findTurbopackPagesLoaderId(turbopackScope, route) : void 0) ?? Object.keys(remoteRequire?.m ?? {}).find(
793
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
794
+ ) ?? Object.keys(remoteRequire?.m ?? {}).find(
795
+ (key) => key.includes("/next/dist/client/page-loader.js")
796
+ ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
797
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
798
+ ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
799
+ (key) => key.includes("/next/dist/client/page-loader.js")
800
+ ) ?? ""] ?? -1;
801
+ const appLoaderChunk = (turbopackScope ? findTurbopackPagesLoaderId(turbopackScope, "/_app") : void 0) ?? Object.keys(remoteRequire?.m ?? {}).find(
802
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
803
+ ) ?? Object.keys(remoteRequire?.m ?? {}).find(
804
+ (key) => key.includes("/next/dist/client/page-loader.js")
805
+ ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
806
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
807
+ ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
808
+ (key) => key.includes("/next/dist/client/page-loader.js")
809
+ ) ?? ""] ?? -1;
810
+ if (!isLoaderId(componentLoaderChunk) || !isLoaderId(appLoaderChunk)) {
811
+ throw new RemoteComponentsError(
812
+ `Next.js client pages loader not found in bundle "${bundle}".`
590
813
  );
591
- existingScope.resolveClientUrl = resolveClientUrl;
592
- if (runtime === RUNTIME_TURBOPACK) {
593
- await Promise.allSettled(
594
- scripts.map(
595
- (script) => script.src ? loadChunkWithScope(existingScope, script.src) : Promise.resolve(void 0)
596
- )
814
+ }
815
+ const __NEXT_P_ORIGINAL = self.__NEXT_P;
816
+ const selfOriginal = self;
817
+ delete selfOriginal.__NEXT_P;
818
+ try {
819
+ loadPagesLoaderModule(bundle, componentLoaderChunk, turbopackScope);
820
+ if (isLoaderId(appLoaderChunk)) {
821
+ loadPagesLoaderModule(bundle, appLoaderChunk, turbopackScope);
822
+ }
823
+ if (self.__NEXT_P) {
824
+ logDebug(
825
+ "ComponentLoader",
826
+ `Next.js Pages loader registry for "${route}" in "${bundle}": ${self.__NEXT_P.map((entry) => entry?.[0] ?? "<empty>").join(", ")}`
597
827
  );
828
+ const componentEntry = self.__NEXT_P.find(
829
+ (entry) => entry?.[0] === route
830
+ ) ?? self.__NEXT_P[0];
831
+ const appEntry = self.__NEXT_P.find((entry) => entry?.[0] === "/_app") ?? self.__NEXT_P[2];
832
+ const [, componentLoader] = componentEntry ?? [
833
+ void 0,
834
+ () => ({ default: null })
835
+ ];
836
+ const [, appLoader] = appEntry ?? [
837
+ void 0,
838
+ () => ({
839
+ default: null
840
+ })
841
+ ];
842
+ const { default: Component = null } = componentLoader();
843
+ const { default: App = null } = appLoader();
844
+ const cssCache = ns.cssCache;
845
+ if (!cssCache[bundle]) {
846
+ const cssRE = /\.s?css$/;
847
+ Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
848
+ self.__remote_webpack_require__?.[bundle]?.(id);
849
+ });
850
+ Object.keys(self.__remote_webpack_module_map__?.[bundle] ?? {}).filter((path) => cssRE.test(path)).forEach((path) => {
851
+ const id = self.__remote_webpack_module_map__?.[bundle]?.[path];
852
+ if (id) {
853
+ self.__remote_webpack_require__?.[bundle]?.(id);
854
+ }
855
+ });
856
+ const elements = [];
857
+ let node = nextCss.previousSibling;
858
+ while (node && node !== nextCssEnd) {
859
+ elements.push(node);
860
+ node.remove();
861
+ node = nextCss.previousSibling;
862
+ }
863
+ cssCache[bundle] = elements;
864
+ }
865
+ applyBundleCss();
866
+ const result = { Component, App };
867
+ ns.pageComponentCache[cacheKey] = result;
868
+ return result;
598
869
  }
599
- return existingScope;
600
- }
601
- const scope = createScope(bundleName, url, runtime, resolveClientUrl);
602
- registerScope(scope);
603
- if (runtime === RUNTIME_WEBPACK && self.__remote_webpack_require__?.[bundleName]) {
604
- scope.webpackRequire = self.__remote_webpack_require__[bundleName];
605
- }
606
- ns.bundleUrls[bundleName] = url;
607
- if (scope.scopedName !== bundleName) {
608
- ns.bundleUrls[scope.scopedName] = url;
609
- }
610
- self.__webpack_get_script_filename__ = () => null;
611
- const willCreateDispatchers = typeof self.__webpack_require__ !== "function" || ns.dispatcherRuntime !== "turbopack";
612
- if (willCreateDispatchers) {
613
- if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
614
- self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
615
- self.__original_webpack_require__ = self.__webpack_require__;
870
+ logDebug(
871
+ "ComponentLoader",
872
+ `Next.js Pages loaders for route "${route}" in "${bundle}" did not populate __NEXT_P`
873
+ );
874
+ return { Component: null, App: null };
875
+ } finally {
876
+ if (typeof __NEXT_P_ORIGINAL === "undefined") {
877
+ delete self.__NEXT_P;
878
+ } else {
879
+ self.__NEXT_P = __NEXT_P_ORIGINAL;
616
880
  }
617
- self.__webpack_chunk_load__ = createChunkDispatcher();
618
- self.__webpack_require__ = createModuleDispatcher(runtime);
619
- ns.dispatcherRuntime = runtime;
620
- self.__webpack_require_type__ = runtime;
621
- if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
622
- self.__remote_webpack_require__[bundleName] = self.__webpack_require__;
623
- self.__remote_webpack_require__[bundleName].type = "turbopack";
881
+ if (nextCssOriginal && nextCssOriginalParent) {
882
+ const restoreBefore = nextCssOriginalNextSibling?.parentNode === nextCssOriginalParent ? nextCssOriginalNextSibling : null;
883
+ nextCssOriginalParent.insertBefore(nextCssOriginal, restoreBefore);
624
884
  }
885
+ nextCss.remove();
886
+ nextCssEnd.remove();
887
+ }
888
+ }
889
+ function isLoaderId(id) {
890
+ return typeof id === "string" && id.length > 0 || typeof id === "number" && id !== -1;
891
+ }
892
+ function loadPagesLoaderModule(bundle, id, turbopackScope) {
893
+ const self = globalThis;
894
+ if (turbopackScope) {
895
+ delete turbopackScope.moduleCache[String(id)];
896
+ requireModule(turbopackScope, id);
897
+ return;
625
898
  }
626
- if (self.__remote_webpack_require__?.[bundleName] && scope.scopedName !== bundleName) {
627
- self.__remote_webpack_require__[scope.scopedName] = self.__remote_webpack_require__[bundleName];
899
+ const remoteRequire = self.__remote_webpack_require__?.[bundle];
900
+ if (remoteRequire?.c) {
901
+ delete remoteRequire.c[id];
628
902
  }
629
- if (runtime === RUNTIME_TURBOPACK) {
630
- const results = await Promise.allSettled(
631
- scripts.map((script) => {
632
- if (script.src) {
633
- return loadChunkWithScope(scope, script.src);
903
+ remoteRequire?.(id);
904
+ }
905
+ function findTurbopackPagesLoaderId(scope, route) {
906
+ const modules = getTurbopackModules(scope);
907
+ if (!modules)
908
+ return void 0;
909
+ const routeLiteral = JSON.stringify(route);
910
+ const singleQuotedRouteLiteral = `'${route.replaceAll("'", "\\'")}'`;
911
+ const flat = modules.flat();
912
+ for (let index = 0; index < flat.length; index++) {
913
+ const entry = flat[index];
914
+ if (typeof entry === "function") {
915
+ const code = entry.toString();
916
+ if (code.includes("__NEXT_P") && (code.includes(routeLiteral) || code.includes(singleQuotedRouteLiteral))) {
917
+ const id = findPreviousModuleId(flat, index);
918
+ if (isLoaderId(id) && isTurbopackPagesLoaderId(id)) {
919
+ logDebug(
920
+ "SharedModules",
921
+ `Resolved Turbopack Pages loader for route "${route}" in "${scope.scopedName}" as "${id}"`
922
+ );
923
+ return id;
634
924
  }
635
- return Promise.resolve(void 0);
636
- })
637
- );
638
- for (const result of results) {
639
- if (result.status === "rejected") {
640
- logWarn(
641
- "WebpackRuntime",
642
- `Initial chunk load failed: ${String(result.reason)}`
643
- );
644
925
  }
926
+ continue;
645
927
  }
646
- }
647
- return scope;
648
- }
649
- function createModuleDispatcher(runtime) {
650
- return (id) => {
651
- const self = globalThis;
652
- const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
653
- bundle: "default",
654
- id
655
- };
656
- const bundleName = bundle ?? "default";
657
- const remoteRuntime = self.__remote_webpack_require__?.[bundleName] ? self.__remote_webpack_require__[bundleName]?.type || "webpack" : runtime;
658
- logDebug(
659
- "ModuleDispatcher",
660
- `Resolving "${id}" (bundle: "${bundleName}", runtime: "${remoteRuntime}")`
661
- );
662
- try {
663
- if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
664
- const scope2 = getScope(bundle);
665
- if (scope2?.webpackRequire)
666
- return scope2.webpackRequire(moduleId);
667
- return self.__remote_webpack_require__?.[bundle]?.(moduleId);
668
- }
669
- const scope = getScope(bundleName);
670
- if (scope) {
671
- return requireModule(scope, moduleId ?? id, id);
672
- }
673
- throw new Error(
674
- `Module "${id}" not found \u2014 no scope for bundle "${bundleName}".`
675
- );
676
- } catch (requireError) {
677
- logWarn(
678
- "ModuleDispatcher",
679
- `Module require failed: ${String(requireError)}`
680
- );
681
- if (typeof self.__original_webpack_require__ !== "function") {
682
- throw new RemoteComponentsError(
683
- `Module "${id}" not found in remote component bundle "${bundleName}".`,
684
- {
685
- cause: requireError instanceof Error ? requireError : void 0
686
- }
687
- );
688
- }
689
- try {
928
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
929
+ continue;
930
+ if (typeof Element !== "undefined" && entry instanceof Element)
931
+ continue;
932
+ for (const [id, moduleInit] of Object.entries(
933
+ entry
934
+ )) {
935
+ if (typeof moduleInit !== "function")
936
+ continue;
937
+ const code = moduleInit.toString();
938
+ if (code.includes("__NEXT_P") && (code.includes(routeLiteral) || code.includes(singleQuotedRouteLiteral)) && isTurbopackPagesLoaderId(id)) {
690
939
  logDebug(
691
- "ModuleDispatcher",
692
- "Falling back to original webpack require"
693
- );
694
- return self.__original_webpack_require__(id);
695
- } catch (originalError) {
696
- throw new RemoteComponentsError(
697
- `Module "${id}" not found in remote component bundle "${bundleName}".`,
698
- { cause: originalError instanceof Error ? originalError : void 0 }
940
+ "SharedModules",
941
+ `Resolved Turbopack Pages loader for route "${route}" in "${scope.scopedName}" as "${id}"`
699
942
  );
943
+ return id;
700
944
  }
701
945
  }
702
- };
946
+ }
947
+ return void 0;
948
+ }
949
+ function isTurbopackPagesLoaderId(id) {
950
+ if (typeof id === "number")
951
+ return true;
952
+ return id.includes("[next]/entry/page-loader.ts") || id.includes("/next/dist/client/page-loader.js");
953
+ }
954
+ function findPreviousModuleId(entries, factoryIndex) {
955
+ for (let index = factoryIndex - 1; index >= 0; index--) {
956
+ const entry = entries[index];
957
+ if (isLoaderId(entry))
958
+ return entry;
959
+ if (typeof entry === "function")
960
+ return void 0;
961
+ }
962
+ return void 0;
703
963
  }
704
964
 
705
965
  export {
966
+ applySharedModules,
967
+ loadChunkWithScope,
968
+ createChunkDispatcher,
706
969
  initializeSharedModules,
707
- setupRemoteScope
970
+ requireModule,
971
+ nextClientPagesLoader
708
972
  };
709
- //# sourceMappingURL=chunk-MTMDXJLM.js.map
973
+ //# sourceMappingURL=chunk-4NW46ZVD.js.map