remote-components 0.3.3 → 0.3.4

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 (157) hide show
  1. package/dist/config/nextjs.cjs +86 -37
  2. package/dist/config/nextjs.cjs.map +1 -1
  3. package/dist/config/nextjs.js +86 -37
  4. package/dist/config/nextjs.js.map +1 -1
  5. package/dist/config/webpack.cjs +5 -1
  6. package/dist/config/webpack.cjs.map +1 -1
  7. package/dist/config/webpack.js +5 -1
  8. package/dist/config/webpack.js.map +1 -1
  9. package/dist/host/html.cjs +524 -338
  10. package/dist/host/html.cjs.map +1 -1
  11. package/dist/host/html.js +524 -338
  12. package/dist/host/html.js.map +1 -1
  13. package/dist/host/nextjs/app/client-only.cjs +462 -259
  14. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  15. package/dist/host/nextjs/app/client-only.js +436 -233
  16. package/dist/host/nextjs/app/client-only.js.map +1 -1
  17. package/dist/host/react.cjs +403 -228
  18. package/dist/host/react.cjs.map +1 -1
  19. package/dist/host/react.js +403 -228
  20. package/dist/host/react.js.map +1 -1
  21. package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
  22. package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
  23. package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
  24. package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
  25. package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
  26. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  27. package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
  28. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  29. package/dist/internal/host/nextjs/app-client.cjs +4 -3
  30. package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
  31. package/dist/internal/host/nextjs/app-client.js +4 -3
  32. package/dist/internal/host/nextjs/app-client.js.map +1 -1
  33. package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
  34. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
  35. package/dist/internal/host/nextjs/dom-flight.js +31 -39
  36. package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
  37. package/dist/internal/host/nextjs/image-shared.cjs +39 -3
  38. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
  39. package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
  40. package/dist/internal/host/nextjs/image-shared.js +29 -3
  41. package/dist/internal/host/nextjs/image-shared.js.map +1 -1
  42. package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
  43. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  44. package/dist/internal/host/server/fetch-remote-component.js +2 -1
  45. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  46. package/dist/internal/host/shared/polyfill.cjs +8 -7
  47. package/dist/internal/host/shared/polyfill.cjs.map +1 -1
  48. package/dist/internal/host/shared/polyfill.js +8 -7
  49. package/dist/internal/host/shared/polyfill.js.map +1 -1
  50. package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
  51. package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
  52. package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
  53. package/dist/internal/host/shared/shared-module-resolver.js +78 -0
  54. package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
  55. package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
  56. package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
  57. package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
  58. package/dist/internal/remote/nextjs/next-internals.js +26 -0
  59. package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
  60. package/dist/internal/runtime/html/apply-origin.cjs +11 -32
  61. package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
  62. package/dist/internal/runtime/html/apply-origin.js +11 -32
  63. package/dist/internal/runtime/html/apply-origin.js.map +1 -1
  64. package/dist/internal/runtime/html/html-spec.cjs +78 -0
  65. package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
  66. package/dist/internal/runtime/html/html-spec.d.ts +23 -0
  67. package/dist/internal/runtime/html/html-spec.js +41 -0
  68. package/dist/internal/runtime/html/html-spec.js.map +1 -0
  69. package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
  70. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
  71. package/dist/internal/runtime/html/parse-remote-html.js +29 -12
  72. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
  73. package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
  74. package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
  75. package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
  76. package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
  77. package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
  78. package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
  79. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  80. package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
  81. package/dist/internal/runtime/loaders/component-loader.js +28 -44
  82. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  83. package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
  84. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
  85. package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
  86. package/dist/internal/runtime/loaders/static-loader.js +15 -21
  87. package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
  88. package/dist/internal/runtime/namespace.cjs +82 -0
  89. package/dist/internal/runtime/namespace.cjs.map +1 -0
  90. package/dist/internal/runtime/namespace.d.ts +5 -0
  91. package/dist/internal/runtime/namespace.js +58 -0
  92. package/dist/internal/runtime/namespace.js.map +1 -0
  93. package/dist/internal/runtime/rsc-imports.cjs +86 -0
  94. package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
  95. package/dist/internal/runtime/rsc-imports.d.ts +39 -0
  96. package/dist/internal/runtime/rsc-imports.js +50 -0
  97. package/dist/internal/runtime/rsc-imports.js.map +1 -0
  98. package/dist/internal/runtime/rsc-runtime.cjs +17 -0
  99. package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
  100. package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
  101. package/dist/internal/runtime/rsc-runtime.js +1 -0
  102. package/dist/internal/runtime/rsc-runtime.js.map +1 -0
  103. package/dist/internal/runtime/rsc.cjs +23 -12
  104. package/dist/internal/runtime/rsc.cjs.map +1 -1
  105. package/dist/internal/runtime/rsc.d.ts +19 -2
  106. package/dist/internal/runtime/rsc.js +20 -11
  107. package/dist/internal/runtime/rsc.js.map +1 -1
  108. package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
  109. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
  110. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
  111. package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
  112. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
  113. package/dist/internal/runtime/turbopack/module.cjs +17 -4
  114. package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
  115. package/dist/internal/runtime/turbopack/module.d.ts +23 -1
  116. package/dist/internal/runtime/turbopack/module.js +16 -4
  117. package/dist/internal/runtime/turbopack/module.js.map +1 -1
  118. package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
  119. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
  120. package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
  121. package/dist/internal/runtime/turbopack/patterns.js +23 -7
  122. package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
  123. package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
  124. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
  125. package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
  126. package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
  127. package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
  128. package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
  129. package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
  130. package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
  131. package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
  132. package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
  133. package/dist/internal/runtime/turbopack/shared-modules.cjs +21 -15
  134. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
  135. package/dist/internal/runtime/turbopack/shared-modules.d.ts +9 -2
  136. package/dist/internal/runtime/turbopack/shared-modules.js +24 -18
  137. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
  138. package/dist/internal/runtime/types.cjs.map +1 -1
  139. package/dist/internal/runtime/types.d.ts +5 -41
  140. package/dist/internal/utils/logger.cjs +1 -1
  141. package/dist/internal/utils/logger.cjs.map +1 -1
  142. package/dist/internal/utils/logger.d.ts +2 -2
  143. package/dist/internal/utils/logger.js +1 -1
  144. package/dist/internal/utils/logger.js.map +1 -1
  145. package/dist/remote/html.cjs +78 -22
  146. package/dist/remote/html.cjs.map +1 -1
  147. package/dist/remote/html.js +78 -22
  148. package/dist/remote/html.js.map +1 -1
  149. package/dist/remote/nextjs/app.cjs +14 -55
  150. package/dist/remote/nextjs/app.cjs.map +1 -1
  151. package/dist/remote/nextjs/app.js +24 -45
  152. package/dist/remote/nextjs/app.js.map +1 -1
  153. package/dist/types-59251814.d.ts +94 -0
  154. package/package.json +1 -1
  155. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
  156. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
  157. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
@@ -205,7 +205,7 @@ var init_logger = __esm({
205
205
  init_constants();
206
206
  init_error();
207
207
  PREFIX = "remote-components";
208
- DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
208
+ DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true" || typeof process !== "undefined" && process.env.RC_DEBUG === "true";
209
209
  }
210
210
  });
211
211
 
@@ -240,6 +240,152 @@ var init_constants2 = __esm({
240
240
  }
241
241
  });
242
242
 
243
+ // src/runtime/namespace.ts
244
+ function getNamespace() {
245
+ const g = globalThis;
246
+ const existing = g.__remote_components__;
247
+ if (existing) {
248
+ return existing;
249
+ }
250
+ const ns = {
251
+ scopes: /* @__PURE__ */ new Map(),
252
+ chunkCache: {},
253
+ mountFns: {},
254
+ unmountFns: {},
255
+ bundleUrls: {},
256
+ moduleRegistry: {},
257
+ dispatcherRuntime: void 0,
258
+ hostSharedModules: {},
259
+ cssCache: {},
260
+ shadowRoots: {}
261
+ };
262
+ const nsRecord = ns;
263
+ for (const { global, prop } of LEGACY_ALIASES) {
264
+ const legacyValue = g[global];
265
+ if (legacyValue != null) {
266
+ nsRecord[prop] = legacyValue;
267
+ }
268
+ g[global] = ns[prop];
269
+ }
270
+ const gRecord = g;
271
+ for (const key of Object.keys(gRecord)) {
272
+ if (key.startsWith(SHADOW_ROOT_PREFIX)) {
273
+ const suffix = key.slice(SHADOW_ROOT_PREFIX.length);
274
+ ns.shadowRoots[suffix] = gRecord[key];
275
+ delete gRecord[key];
276
+ }
277
+ }
278
+ g.__remote_components__ = ns;
279
+ return ns;
280
+ }
281
+ var SHADOW_ROOT_PREFIX, LEGACY_ALIASES;
282
+ var init_namespace = __esm({
283
+ "src/runtime/namespace.ts"() {
284
+ "use strict";
285
+ SHADOW_ROOT_PREFIX = "__remote_components_shadowroot_";
286
+ LEGACY_ALIASES = [
287
+ { global: "__remote_component_scopes__", prop: "scopes" },
288
+ {
289
+ global: "__remote_components_turbopack_chunk_loader_promise__",
290
+ prop: "chunkCache"
291
+ },
292
+ { global: "__remote_script_entrypoint_mount__", prop: "mountFns" },
293
+ { global: "__remote_script_entrypoint_unmount__", prop: "unmountFns" },
294
+ { global: "__remote_bundle_url__", prop: "bundleUrls" },
295
+ { global: "__rc_module_registry__", prop: "moduleRegistry" },
296
+ {
297
+ global: "__remote_component_host_shared_modules__",
298
+ prop: "hostSharedModules"
299
+ },
300
+ { global: "__remote_next_css__", prop: "cssCache" }
301
+ ];
302
+ }
303
+ });
304
+
305
+ // src/runtime/patterns.ts
306
+ function collapseDoubleSlashes(path) {
307
+ return path.replace(DOUBLE_SLASH_RE, "/");
308
+ }
309
+ var REMOTE_COMPONENT_REGEX, NEXT_BUNDLE_PATH_RE, DOUBLE_SLASH_RE;
310
+ var init_patterns = __esm({
311
+ "src/runtime/patterns.ts"() {
312
+ "use strict";
313
+ REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
314
+ NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
315
+ DOUBLE_SLASH_RE = /(?<!:)\/\//g;
316
+ }
317
+ });
318
+
319
+ // src/runtime/turbopack/remote-scope.ts
320
+ function getRegistry() {
321
+ return getNamespace().scopes;
322
+ }
323
+ function createScope(name, url, runtime, resolveClientUrl) {
324
+ const isCrossOrigin = url.origin !== location.origin;
325
+ const scopedName = computeScopedName(name, {
326
+ remoteHost: url.host,
327
+ isCrossOrigin
328
+ });
329
+ const globalKey = getBundleKey(scopedName);
330
+ return {
331
+ name,
332
+ scopedName,
333
+ globalKey,
334
+ url,
335
+ runtime,
336
+ resolveClientUrl,
337
+ moduleCache: {},
338
+ sharedModules: {},
339
+ moduleGlobal: {},
340
+ turbopackModules: []
341
+ };
342
+ }
343
+ function registerScope(scope) {
344
+ const registry = getRegistry();
345
+ registry.set(scope.scopedName, scope);
346
+ if (scope.scopedName !== scope.name) {
347
+ const existing = registry.get(scope.name);
348
+ if (existing && existing.scopedName !== scope.scopedName) {
349
+ logWarn(
350
+ "RemoteScope",
351
+ `Plain name "${scope.name}" already registered by scope "${existing.scopedName}" \u2014 overwriting with "${scope.scopedName}". Static hosts will only resolve the latest one.`
352
+ );
353
+ }
354
+ registry.set(scope.name, scope);
355
+ }
356
+ logDebug(
357
+ "RemoteScope",
358
+ `Registered scope "${scope.scopedName}" (${registry.size} total)`
359
+ );
360
+ }
361
+ function getScope(name) {
362
+ return getRegistry().get(name);
363
+ }
364
+ function formatRemoteId(scope, path) {
365
+ return `[${scope.scopedName}] ${path}`;
366
+ }
367
+ function parseRemoteId(id) {
368
+ const groups = REMOTE_COMPONENT_REGEX.exec(id)?.groups;
369
+ if (groups?.bundle && groups.id) {
370
+ return {
371
+ bundle: groups.bundle,
372
+ path: groups.id,
373
+ prefix: groups.prefix ?? ""
374
+ };
375
+ }
376
+ return { bundle: "default", path: id, prefix: "" };
377
+ }
378
+ var init_remote_scope = __esm({
379
+ "src/runtime/turbopack/remote-scope.ts"() {
380
+ "use strict";
381
+ init_constants2();
382
+ init_namespace();
383
+ init_patterns();
384
+ init_utils();
385
+ init_logger();
386
+ }
387
+ });
388
+
243
389
  // src/config/webpack/apply-shared-modules.ts
244
390
  function applySharedModules(bundle, resolve) {
245
391
  logDebug(
@@ -251,13 +397,15 @@ function applySharedModules(bundle, resolve) {
251
397
  `Shared modules to resolve: ${Object.keys(resolve)}`
252
398
  );
253
399
  const self = globalThis;
254
- if (self.__remote_webpack_require__?.[bundle]) {
400
+ const scope = getScope(bundle);
401
+ const webpackBundle = scope?.webpackRequire ?? self.__remote_webpack_require__?.[bundle];
402
+ if (webpackBundle) {
255
403
  const modulePaths = Object.keys(
256
- self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
404
+ self.__remote_webpack_module_map__?.[bundle] ?? webpackBundle.m ?? {}
257
405
  );
258
406
  logDebug(
259
407
  "SharedModules",
260
- `Available module paths in __remote_webpack_require__[${bundle}]: ${modulePaths}`
408
+ `Available module paths for bundle "${bundle}": ${modulePaths}`
261
409
  );
262
410
  for (const [key, value] of Object.entries(resolve)) {
263
411
  const exactIds = modulePaths.filter((p) => p === key);
@@ -269,7 +417,6 @@ function applySharedModules(bundle, resolve) {
269
417
  );
270
418
  }
271
419
  for (const id of ids) {
272
- const webpackBundle = self.__remote_webpack_require__[bundle];
273
420
  if (webpackBundle.m) {
274
421
  const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id] ? `${self.__remote_webpack_module_map__[bundle][id]}` : id;
275
422
  if (resolvedId !== id) {
@@ -304,6 +451,7 @@ var DEDUPLICATION_SKIPPED;
304
451
  var init_apply_shared_modules = __esm({
305
452
  "src/config/webpack/apply-shared-modules.ts"() {
306
453
  "use strict";
454
+ init_remote_scope();
307
455
  init_logger();
308
456
  DEDUPLICATION_SKIPPED = "shared module deduplication skipped. The remote may load its own copy of shared dependencies.";
309
457
  }
@@ -375,10 +523,8 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
375
523
  ];
376
524
  const { default: Component } = componentLoader();
377
525
  const { default: App } = appLoader();
378
- if (!self.__remote_next_css__) {
379
- self.__remote_next_css__ = {};
380
- }
381
- if (!self.__remote_next_css__[bundle]) {
526
+ const cssCache = getNamespace().cssCache;
527
+ if (!cssCache[bundle]) {
382
528
  const cssRE = /\.s?css$/;
383
529
  Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).filter((id) => cssRE.test(id)).forEach((id) => {
384
530
  self.__remote_webpack_require__?.[bundle]?.(id);
@@ -396,15 +542,15 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
396
542
  node.remove();
397
543
  node = nextCss.previousSibling;
398
544
  }
399
- self.__remote_next_css__[bundle] = elements;
545
+ cssCache[bundle] = elements;
400
546
  }
401
547
  if (styleContainer) {
402
- const elements = self.__remote_next_css__[bundle];
548
+ const elements = cssCache[bundle];
403
549
  elements.forEach((el) => {
404
550
  styleContainer.appendChild(el.cloneNode(true));
405
551
  });
406
552
  } else {
407
- const elements = self.__remote_next_css__[bundle];
553
+ const elements = cssCache[bundle];
408
554
  elements.forEach((el) => {
409
555
  document.head.appendChild(el);
410
556
  });
@@ -423,96 +569,11 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
423
569
  var init_next_client_pages_loader = __esm({
424
570
  "src/config/webpack/next-client-pages-loader.ts"() {
425
571
  "use strict";
572
+ init_namespace();
426
573
  init_error();
427
574
  }
428
575
  });
429
576
 
430
- // src/runtime/patterns.ts
431
- function collapseDoubleSlashes(path) {
432
- return path.replace(DOUBLE_SLASH_RE, "/");
433
- }
434
- var REMOTE_COMPONENT_REGEX, NEXT_BUNDLE_PATH_RE, DOUBLE_SLASH_RE;
435
- var init_patterns = __esm({
436
- "src/runtime/patterns.ts"() {
437
- "use strict";
438
- REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
439
- NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
440
- DOUBLE_SLASH_RE = /(?<!:)\/\//g;
441
- }
442
- });
443
-
444
- // src/runtime/turbopack/remote-scope.ts
445
- function getRegistry() {
446
- const self = globalThis;
447
- if (!self.__remote_component_scopes__) {
448
- self.__remote_component_scopes__ = /* @__PURE__ */ new Map();
449
- }
450
- return self.__remote_component_scopes__;
451
- }
452
- function createScope(name, url, runtime, resolveClientUrl) {
453
- const isCrossOrigin = url.origin !== location.origin;
454
- const scopedName = computeScopedName(name, {
455
- remoteHost: url.host,
456
- isCrossOrigin
457
- });
458
- const globalKey = getBundleKey(scopedName);
459
- return {
460
- name,
461
- scopedName,
462
- globalKey,
463
- url,
464
- runtime,
465
- resolveClientUrl,
466
- moduleCache: {},
467
- sharedModules: {},
468
- moduleGlobal: {}
469
- };
470
- }
471
- function registerScope(scope) {
472
- const registry = getRegistry();
473
- registry.set(scope.scopedName, scope);
474
- if (scope.scopedName !== scope.name) {
475
- const existing = registry.get(scope.name);
476
- if (existing && existing.scopedName !== scope.scopedName) {
477
- logWarn(
478
- "RemoteScope",
479
- `Plain name "${scope.name}" already registered by scope "${existing.scopedName}" \u2014 overwriting with "${scope.scopedName}". Static hosts will only resolve the latest one.`
480
- );
481
- }
482
- registry.set(scope.name, scope);
483
- }
484
- logDebug(
485
- "RemoteScope",
486
- `Registered scope "${scope.scopedName}" (${registry.size} total)`
487
- );
488
- }
489
- function getScope(name) {
490
- return getRegistry().get(name);
491
- }
492
- function formatRemoteId(scope, path) {
493
- return `[${scope.scopedName}] ${path}`;
494
- }
495
- function parseRemoteId(id) {
496
- const groups = REMOTE_COMPONENT_REGEX.exec(id)?.groups;
497
- if (groups?.bundle && groups.id) {
498
- return {
499
- bundle: groups.bundle,
500
- path: groups.id,
501
- prefix: groups.prefix ?? ""
502
- };
503
- }
504
- return { bundle: "default", path: id, prefix: "" };
505
- }
506
- var init_remote_scope = __esm({
507
- "src/runtime/turbopack/remote-scope.ts"() {
508
- "use strict";
509
- init_constants2();
510
- init_patterns();
511
- init_utils();
512
- init_logger();
513
- }
514
- });
515
-
516
577
  // src/host/shared/remote-image-loader.ts
517
578
  function createRemoteImageLoader(bundle, resolveClientUrl) {
518
579
  const loader = Object.assign(
@@ -544,9 +605,9 @@ var init_remote_image_loader = __esm({
544
605
 
545
606
  // src/host/shared/polyfill.tsx
546
607
  function sharedPolyfills(shared, resolveClientUrl) {
547
- const self = globalThis;
608
+ const hostShared = getNamespace().hostSharedModules;
548
609
  const polyfill = {
549
- "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
610
+ "next/dist/client/components/navigation": hostShared["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
550
611
  useRouter() {
551
612
  return {
552
613
  push: (routerUrl) => {
@@ -577,7 +638,7 @@ function sharedPolyfills(shared, resolveClientUrl) {
577
638
  },
578
639
  __esModule: true
579
640
  })),
580
- "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
641
+ "next/dist/client/app-dir/link": hostShared["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
581
642
  default: ({
582
643
  scroll: _,
583
644
  replace,
@@ -627,7 +688,7 @@ function sharedPolyfills(shared, resolveClientUrl) {
627
688
  },
628
689
  __esModule: true
629
690
  })),
630
- "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
691
+ "next/dist/client/app-dir/form": hostShared["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
631
692
  default: () => {
632
693
  throw new Error("Next.js <Form> component not implemented");
633
694
  },
@@ -638,17 +699,17 @@ function sharedPolyfills(shared, resolveClientUrl) {
638
699
  // This gives us full next/image fidelity (fill, priority, srcSet, blur
639
700
  // placeholders, error handling) while routing image optimization through the
640
701
  // remote app's /_next/image endpoint.
641
- "next/dist/shared/lib/image-loader": self.__remote_component_host_shared_modules__?.["next/dist/shared/lib/image-loader"] ?? shared?.["next/dist/shared/lib/image-loader"] ?? ((bundle) => Promise.resolve({
702
+ "next/dist/shared/lib/image-loader": hostShared["next/dist/shared/lib/image-loader"] ?? shared?.["next/dist/shared/lib/image-loader"] ?? ((bundle) => Promise.resolve({
642
703
  default: createRemoteImageLoader(bundle, resolveClientUrl),
643
704
  __esModule: true
644
705
  })),
645
- "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
706
+ "next/dist/client/script": hostShared["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
646
707
  // TODO: implement <Script> component for non-Next.js host applications
647
708
  // do not throw an error for now
648
709
  default: () => null,
649
710
  __esModule: true
650
711
  })),
651
- "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
712
+ "next/router": hostShared["next/router"] ?? shared?.["next/router"] ?? (() => (
652
713
  // TODO: incomplete implementation
653
714
  Promise.resolve({
654
715
  useRouter() {
@@ -688,11 +749,82 @@ var init_polyfill = __esm({
688
749
  "src/host/shared/polyfill.tsx"() {
689
750
  "use strict";
690
751
  init_remote_image_loader();
752
+ init_namespace();
691
753
  init_logger();
692
754
  import_jsx_runtime = require("react/jsx-runtime");
693
755
  }
694
756
  });
695
757
 
758
+ // src/host/shared/shared-module-resolver.ts
759
+ function buildCoreShared(userShared) {
760
+ return {
761
+ react: async () => (await import("react")).default,
762
+ "react-dom": async () => (await import("react-dom")).default,
763
+ "react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
764
+ "react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
765
+ "react-dom/client": async () => (await import("react-dom/client")).default,
766
+ ...userShared
767
+ };
768
+ }
769
+ function buildHostShared(userShared, resolveClientUrl, options) {
770
+ const self = globalThis;
771
+ const result = {
772
+ ...sharedPolyfills(userShared, resolveClientUrl),
773
+ ...self.__remote_component_host_shared_modules__,
774
+ ...userShared
775
+ };
776
+ if (options?.includeRemoteComponentShared) {
777
+ Object.assign(result, self.__remote_component_shared__);
778
+ }
779
+ return result;
780
+ }
781
+ async function buildWebpackResolve(hostShared, remoteShared, bundle, reactModules, callerTag = "SharedModuleResolver") {
782
+ const resolve = {
783
+ ...reactModules,
784
+ ...Object.entries(remoteShared).reduce(
785
+ (acc, [key, value]) => {
786
+ if (typeof hostShared[value] !== "undefined") {
787
+ acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
788
+ } else {
789
+ logDebug(
790
+ callerTag,
791
+ `Remote requests "${value}" but host doesn't provide it`
792
+ );
793
+ }
794
+ return acc;
795
+ },
796
+ {}
797
+ )
798
+ };
799
+ await Promise.all(
800
+ Object.entries(resolve).map(async ([key, value]) => {
801
+ if (typeof value === "function") {
802
+ resolve[key] = await value(bundle);
803
+ }
804
+ return Promise.resolve(value);
805
+ })
806
+ );
807
+ return resolve;
808
+ }
809
+ var CORE_REACT_PATH_MAP, VENDOR_SHARED;
810
+ var init_shared_module_resolver = __esm({
811
+ "src/host/shared/shared-module-resolver.ts"() {
812
+ "use strict";
813
+ init_polyfill();
814
+ init_logger();
815
+ CORE_REACT_PATH_MAP = {
816
+ react: "/react/index.js",
817
+ "react/jsx-dev-runtime": "/react/jsx-dev-runtime.js",
818
+ "react/jsx-runtime": "/react/jsx-runtime.js",
819
+ "react-dom": "/react-dom/index.js",
820
+ "react-dom/client": "/react-dom/client.js"
821
+ };
822
+ VENDOR_SHARED = Object.fromEntries(
823
+ Object.entries(CORE_REACT_PATH_MAP).filter(([key]) => key !== "react-dom/client").map(([key, path]) => [key, `'${path}'`])
824
+ );
825
+ }
826
+ });
827
+
696
828
  // src/runtime/loaders/script-loader.ts
697
829
  async function loadScripts(scripts, resolveClientUrl) {
698
830
  await Promise.all(
@@ -792,34 +924,19 @@ async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
792
924
  ];
793
925
  });
794
926
  await loadScripts(scriptSrcs, resolveClientUrl);
795
- const hostShared = {
796
- ...sharedPolyfills(shared, resolveClientUrl),
797
- ...self.__remote_component_host_shared_modules__,
798
- ...shared
799
- };
800
- const resolve = {
801
- "/react/index.js": (await import("react")).default,
802
- "/react/jsx-dev-runtime.js": (await import("react/jsx-dev-runtime")).default,
803
- "/react/jsx-runtime.js": (await import("react/jsx-runtime")).default,
804
- "/react-dom/index.js": (await import("react-dom")).default,
805
- "/react-dom/client.js": (await import("react-dom/client")).default,
806
- ...Object.entries(remoteShared ?? {}).reduce(
807
- (acc, [key, value]) => {
808
- if (typeof hostShared[value] !== "undefined") {
809
- acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
810
- }
811
- return acc;
812
- },
813
- {}
814
- )
815
- };
816
- await Promise.all(
817
- Object.entries(resolve).map(async ([key, value]) => {
818
- if (typeof value === "function") {
819
- resolve[key] = await value(remoteBundle);
820
- }
821
- return Promise.resolve(value);
822
- })
927
+ const hostShared = buildHostShared(shared, resolveClientUrl);
928
+ const resolve = await buildWebpackResolve(
929
+ hostShared,
930
+ remoteShared ?? {},
931
+ remoteBundle,
932
+ {
933
+ "/react/index.js": (await import("react")).default,
934
+ "/react/jsx-dev-runtime.js": (await import("react/jsx-dev-runtime")).default,
935
+ "/react/jsx-runtime.js": (await import("react/jsx-runtime")).default,
936
+ "/react-dom/index.js": (await import("react-dom")).default,
937
+ "/react-dom/client.js": (await import("react-dom/client")).default
938
+ },
939
+ "WebpackRuntime"
823
940
  );
824
941
  applySharedModules(remoteBundle, resolve);
825
942
  }
@@ -836,7 +953,7 @@ var init_webpack = __esm({
836
953
  "use strict";
837
954
  init_apply_shared_modules();
838
955
  init_next_client_pages_loader();
839
- init_polyfill();
956
+ init_shared_module_resolver();
840
957
  init_script_loader();
841
958
  init_patterns();
842
959
  init_error();
@@ -844,15 +961,31 @@ var init_webpack = __esm({
844
961
  });
845
962
 
846
963
  // src/runtime/turbopack/patterns.ts
847
- var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, TURBOPACK_GLOBAL_RE;
964
+ function stripQuotes(value) {
965
+ if (value.startsWith('"') && value.endsWith('"')) {
966
+ return value.slice(1, -1);
967
+ }
968
+ return value;
969
+ }
970
+ function extractGroup(re, input, group) {
971
+ const raw = re.exec(input)?.groups?.[group];
972
+ return raw ? stripQuotes(raw) : void 0;
973
+ }
974
+ var MODULE_ID_PATTERN, REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_CALLBACK_RE, TURBOPACK_GLOBAL_RE;
848
975
  var init_patterns2 = __esm({
849
976
  "src/runtime/turbopack/patterns.ts"() {
850
977
  "use strict";
978
+ MODULE_ID_PATTERN = '"[^"]+"|[0-9]+';
851
979
  REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
852
- REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|[a-z])\.A\((?<sharedModuleId>[0-9]+)\)/;
853
- ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
854
- ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
855
- 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]+)\)\)\)\}/;
980
+ REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(
981
+ `\\.TURBOPACK_REMOTE_SHARED\\s*=\\s*await (?:__turbopack_context__|[a-z])\\.A\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
982
+ );
983
+ ASYNC_MODULE_LOADER_RE = new RegExp(
984
+ `(?:__turbopack_context__|e)\\.A\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\)`
985
+ );
986
+ ASYNC_MODULE_CALLBACK_RE = new RegExp(
987
+ `(?:parentImport|[a-z])\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
988
+ );
856
989
  TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
857
990
  }
858
991
  });
@@ -864,6 +997,7 @@ function loadChunkWithScope(scope, chunkId) {
864
997
  `loadChunkWithScope: "${chunkId}" (scope: "${scope.scopedName}")`
865
998
  );
866
999
  const self = globalThis;
1000
+ const ns = getNamespace();
867
1001
  const { bundle, path, prefix } = parseRemoteId(chunkId);
868
1002
  const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : scope.runtime;
869
1003
  if (remoteRuntime === RUNTIME_WEBPACK) {
@@ -874,35 +1008,31 @@ function loadChunkWithScope(scope, chunkId) {
874
1008
  if (url.endsWith(".css")) {
875
1009
  return;
876
1010
  }
877
- if (!self.__remote_components_turbopack_chunk_loader_promise__) {
878
- self.__remote_components_turbopack_chunk_loader_promise__ = {};
879
- }
880
- if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {
881
- return self.__remote_components_turbopack_chunk_loader_promise__[url];
1011
+ if (ns.chunkCache[url]) {
1012
+ logDebug("ChunkLoader", `Cache hit for "${chunkId}" (url="${url}")`);
1013
+ return ns.chunkCache[url];
882
1014
  }
883
1015
  const resolvedUrl = scope.resolveClientUrl?.(url) ?? url;
884
1016
  if (resolvedUrl !== url) {
885
1017
  logDebug("ChunkLoader", `Proxied chunk URL: "${url}" \u2192 "${resolvedUrl}"`);
886
1018
  }
887
- self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise(
888
- (resolve, reject) => {
889
- fetch(resolvedUrl).then((res) => res.text()).then((code) => {
890
- const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
891
- if (hasTurbopack) {
892
- return handleTurbopackChunk(code, scope, url);
893
- }
894
- }).then(resolve).catch((error) => {
895
- const isProxied = isProxiedUrl(resolvedUrl);
896
- if (isProxied) {
897
- reject(failedProxiedAssetError("chunk", url, resolvedUrl));
898
- } else {
899
- warnCrossOriginFetchError("ChunkLoader", url);
900
- reject(error);
901
- }
902
- });
903
- }
904
- );
905
- return self.__remote_components_turbopack_chunk_loader_promise__[url];
1019
+ ns.chunkCache[url] = new Promise((resolve, reject) => {
1020
+ fetch(resolvedUrl).then((res) => res.text()).then((code) => {
1021
+ const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
1022
+ if (hasTurbopack) {
1023
+ return handleTurbopackChunk(code, scope, url);
1024
+ }
1025
+ }).then(resolve).catch((error) => {
1026
+ const isProxied = isProxiedUrl(resolvedUrl);
1027
+ if (isProxied) {
1028
+ reject(failedProxiedAssetError("chunk", url, resolvedUrl));
1029
+ } else {
1030
+ warnCrossOriginFetchError("ChunkLoader", url);
1031
+ reject(error);
1032
+ }
1033
+ });
1034
+ });
1035
+ return ns.chunkCache[url];
906
1036
  }
907
1037
  function createChunkDispatcher() {
908
1038
  return function __chunk_dispatcher__(chunkId, scriptBundle) {
@@ -951,19 +1081,39 @@ async function handleTurbopackChunk(code, scope, url) {
951
1081
  `//# sourceMappingURL=${new URL(".", new URL(url, scope.url)).href}$1$2.js.map`
952
1082
  );
953
1083
  if (!self[`TURBOPACK_${globalKey}`]) {
954
- const chunkData = [];
955
- const turbopackObject = {
956
- push: (item) => {
957
- if (Array.isArray(item)) {
958
- chunkData.push(item);
959
- } else {
960
- chunkData.push([item]);
1084
+ const wrapPush = (target) => {
1085
+ const originalPush = target.push;
1086
+ if (typeof originalPush !== "function")
1087
+ return target;
1088
+ target.push = (...items) => {
1089
+ for (const item of items) {
1090
+ if (Array.isArray(item)) {
1091
+ for (const entry of item) {
1092
+ scope.turbopackModules.push(entry);
1093
+ }
1094
+ } else {
1095
+ scope.turbopackModules.push(item);
1096
+ }
961
1097
  }
962
- return chunkData.length;
963
- },
964
- __chunks__: chunkData
1098
+ return originalPush.apply(target, items);
1099
+ };
1100
+ return target;
965
1101
  };
966
- self[`TURBOPACK_${globalKey}`] = turbopackObject;
1102
+ const globalProp = `TURBOPACK_${globalKey}`;
1103
+ let currentValue = wrapPush([]);
1104
+ Object.defineProperty(self, globalProp, {
1105
+ get() {
1106
+ return currentValue;
1107
+ },
1108
+ set(newValue) {
1109
+ if (newValue && typeof newValue === "object") {
1110
+ wrapPush(newValue);
1111
+ }
1112
+ currentValue = newValue;
1113
+ },
1114
+ configurable: true,
1115
+ enumerable: true
1116
+ });
967
1117
  }
968
1118
  await new Promise((scriptResolve, scriptReject) => {
969
1119
  const blob = new Blob([transformedCode], {
@@ -1015,6 +1165,7 @@ var init_chunk_loader = __esm({
1015
1165
  "src/runtime/turbopack/chunk-loader.ts"() {
1016
1166
  "use strict";
1017
1167
  init_constants2();
1168
+ init_namespace();
1018
1169
  init_patterns();
1019
1170
  init_protected_rc_fallback();
1020
1171
  init_error();
@@ -1026,13 +1177,13 @@ var init_chunk_loader = __esm({
1026
1177
 
1027
1178
  // src/runtime/turbopack/shared-modules.ts
1028
1179
  function getTurbopackModules(scope) {
1180
+ if (scope.turbopackModules.length > 0) {
1181
+ return scope.turbopackModules;
1182
+ }
1029
1183
  const self = globalThis;
1030
1184
  const raw = self[`TURBOPACK_${scope.globalKey}`];
1031
1185
  if (!raw)
1032
1186
  return void 0;
1033
- if (typeof raw === "object" && "__chunks__" in raw) {
1034
- return raw.__chunks__.flat();
1035
- }
1036
1187
  if (Array.isArray(raw)) {
1037
1188
  return raw.flat();
1038
1189
  }
@@ -1056,7 +1207,11 @@ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}
1056
1207
  if (sharedModuleInitializerIndex > 0) {
1057
1208
  const sharedModuleInitializerCode = allModules[sharedModuleInitializerIndex].toString();
1058
1209
  const sharedModuleInitializerId = allModules[sharedModuleInitializerIndex - 1];
1059
- const { sharedModuleId } = REMOTE_SHARED_ASSIGNMENT_RE.exec(sharedModuleInitializerCode)?.groups ?? {};
1210
+ const sharedModuleId = extractGroup(
1211
+ REMOTE_SHARED_ASSIGNMENT_RE,
1212
+ sharedModuleInitializerCode,
1213
+ "sharedModuleId"
1214
+ );
1060
1215
  if (sharedModuleId) {
1061
1216
  const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
1062
1217
  scope,
@@ -1114,20 +1269,22 @@ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}
1114
1269
  }
1115
1270
  function extractSharedModuleIds(shared, scope) {
1116
1271
  return Object.entries(shared).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
1117
- const { asyncSharedModuleId } = ASYNC_MODULE_LOADER_RE.exec(value.toString())?.groups ?? {};
1272
+ const asyncSharedModuleId = extractGroup(
1273
+ ASYNC_MODULE_LOADER_RE,
1274
+ value.toString(),
1275
+ "asyncSharedModuleId"
1276
+ );
1118
1277
  if (asyncSharedModuleId) {
1119
- const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
1120
- let asyncSharedModule;
1121
- const turbopackModules = getTurbopackModules(scope) ?? [];
1122
- const asyncSharedModuleIdIndex = turbopackModules.indexOf(
1123
- asyncSharedModuleIdNumber
1278
+ const asyncSharedModule = findModuleInit(
1279
+ getTurbopackModules(scope),
1280
+ asyncSharedModuleId
1124
1281
  );
1125
- if (asyncSharedModuleIdIndex !== -1 && typeof turbopackModules[asyncSharedModuleIdIndex + 1] === "function") {
1126
- asyncSharedModule = turbopackModules[asyncSharedModuleIdIndex + 1];
1127
- }
1128
1282
  if (asyncSharedModule) {
1129
- const asyncSharedModuleCode = asyncSharedModule.toString();
1130
- const { sharedModuleId } = ASYNC_MODULE_RESOLVE_RE.exec(asyncSharedModuleCode)?.groups ?? ASYNC_MODULE_ALL_RE.exec(asyncSharedModuleCode)?.groups ?? {};
1283
+ const sharedModuleId = extractGroup(
1284
+ ASYNC_MODULE_CALLBACK_RE,
1285
+ asyncSharedModule.toString(),
1286
+ "sharedModuleId"
1287
+ );
1131
1288
  acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(
1132
1289
  "__remote_shared_module_",
1133
1290
  ""
@@ -1229,9 +1386,17 @@ function findModuleInit(modules, moduleId) {
1229
1386
  if (idx >= 0) {
1230
1387
  return flat.slice(idx + 1).find((e) => typeof e === "function");
1231
1388
  }
1232
- return flat.find(
1233
- (e) => Boolean(e && typeof e === "object" && moduleId in e)
1234
- )?.[moduleId];
1389
+ for (const entry of flat) {
1390
+ if (!entry || typeof entry !== "object")
1391
+ continue;
1392
+ const obj = entry;
1393
+ if (moduleId in obj)
1394
+ return obj[moduleId];
1395
+ const prefixKey = Object.keys(obj).find((k) => k.startsWith(moduleId));
1396
+ if (prefixKey)
1397
+ return obj[prefixKey];
1398
+ }
1399
+ return void 0;
1235
1400
  }
1236
1401
  function createTurbopackContext(scope, exports, moduleExports, modules, moduleInit, id) {
1237
1402
  const scopedRequire = (moduleId) => requireModule(scope, moduleId, formatRemoteId(scope, String(moduleId)));
@@ -1310,7 +1475,10 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
1310
1475
  }
1311
1476
  if (typeof mod !== "object" || mod === null) {
1312
1477
  mod = { default: mod };
1313
- } else if (!("default" in mod) && mod.toString() !== "[object Module]") {
1478
+ } else if (!("default" in mod) && // ES module namespace objects have a null prototype, so calling
1479
+ // mod.toString() directly throws. Use Object.prototype.toString
1480
+ // to safely detect them.
1481
+ Object.prototype.toString.call(mod) !== "[object Module]") {
1314
1482
  try {
1315
1483
  mod.default = mod;
1316
1484
  } catch {
@@ -1383,21 +1551,38 @@ var init_module = __esm({
1383
1551
  }
1384
1552
  });
1385
1553
 
1386
- // src/runtime/turbopack/webpack-runtime.ts
1387
- async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
1554
+ // src/runtime/turbopack/remote-scope-setup.ts
1555
+ async function setupRemoteScope(runtime, scripts = [], url = new URL(location.href), bundle, resolveClientUrl) {
1388
1556
  const self = globalThis;
1557
+ const ns = getNamespace();
1389
1558
  const bundleName = bundle ?? "default";
1559
+ const existingScope = getScope(bundleName);
1560
+ if (existingScope && existingScope.url.origin === url.origin) {
1561
+ logDebug(
1562
+ "WebpackRuntime",
1563
+ `Reusing scope "${existingScope.scopedName}" (turbopackModules=${existingScope.turbopackModules.length})`
1564
+ );
1565
+ existingScope.resolveClientUrl = resolveClientUrl;
1566
+ if (runtime === RUNTIME_TURBOPACK) {
1567
+ await Promise.allSettled(
1568
+ scripts.map(
1569
+ (script) => script.src ? loadChunkWithScope(existingScope, script.src) : Promise.resolve(void 0)
1570
+ )
1571
+ );
1572
+ }
1573
+ return existingScope;
1574
+ }
1390
1575
  const scope = createScope(bundleName, url, runtime, resolveClientUrl);
1391
1576
  registerScope(scope);
1392
- if (!self.__remote_bundle_url__) {
1393
- self.__remote_bundle_url__ = {};
1577
+ if (runtime === RUNTIME_WEBPACK && self.__remote_webpack_require__?.[bundleName]) {
1578
+ scope.webpackRequire = self.__remote_webpack_require__[bundleName];
1394
1579
  }
1395
- self.__remote_bundle_url__[bundleName] = url;
1580
+ ns.bundleUrls[bundleName] = url;
1396
1581
  if (scope.scopedName !== bundleName) {
1397
- self.__remote_bundle_url__[scope.scopedName] = url;
1582
+ ns.bundleUrls[scope.scopedName] = url;
1398
1583
  }
1399
1584
  self.__webpack_get_script_filename__ = () => null;
1400
- const willCreateDispatchers = typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack";
1585
+ const willCreateDispatchers = typeof self.__webpack_require__ !== "function" || ns.dispatcherRuntime !== "turbopack";
1401
1586
  if (willCreateDispatchers) {
1402
1587
  if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
1403
1588
  self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
@@ -1405,6 +1590,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
1405
1590
  }
1406
1591
  self.__webpack_chunk_load__ = createChunkDispatcher();
1407
1592
  self.__webpack_require__ = createModuleDispatcher(runtime);
1593
+ ns.dispatcherRuntime = runtime;
1408
1594
  self.__webpack_require_type__ = runtime;
1409
1595
  if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
1410
1596
  self.__remote_webpack_require__[bundleName] = self.__webpack_require__;
@@ -1432,15 +1618,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
1432
1618
  }
1433
1619
  }
1434
1620
  }
1435
- const coreShared = {
1436
- react: async () => (await import("react")).default,
1437
- "react-dom": async () => (await import("react-dom")).default,
1438
- "react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
1439
- "react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
1440
- "react-dom/client": async () => (await import("react-dom/client")).default,
1441
- ...shared
1442
- };
1443
- await initializeSharedModules(scope, coreShared, remoteShared);
1621
+ return scope;
1444
1622
  }
1445
1623
  function createModuleDispatcher(runtime) {
1446
1624
  return (id) => {
@@ -1457,6 +1635,9 @@ function createModuleDispatcher(runtime) {
1457
1635
  );
1458
1636
  try {
1459
1637
  if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
1638
+ const scope2 = getScope(bundle);
1639
+ if (scope2?.webpackRequire)
1640
+ return scope2.webpackRequire(moduleId);
1460
1641
  return self.__remote_webpack_require__?.[bundle]?.(moduleId);
1461
1642
  }
1462
1643
  const scope = getScope(bundleName);
@@ -1494,17 +1675,17 @@ function createModuleDispatcher(runtime) {
1494
1675
  }
1495
1676
  };
1496
1677
  }
1497
- var init_webpack_runtime = __esm({
1498
- "src/runtime/turbopack/webpack-runtime.ts"() {
1678
+ var init_remote_scope_setup = __esm({
1679
+ "src/runtime/turbopack/remote-scope-setup.ts"() {
1499
1680
  "use strict";
1500
1681
  init_constants2();
1682
+ init_namespace();
1501
1683
  init_patterns();
1502
1684
  init_error();
1503
1685
  init_logger();
1504
1686
  init_chunk_loader();
1505
1687
  init_module();
1506
1688
  init_remote_scope();
1507
- init_shared_modules();
1508
1689
  }
1509
1690
  });
1510
1691
 
@@ -1515,36 +1696,28 @@ __export(turbopack_exports, {
1515
1696
  });
1516
1697
  async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClientUrl) {
1517
1698
  const self = globalThis;
1518
- const hostShared = {
1519
- ...sharedPolyfills(shared, resolveClientUrl),
1520
- ...self.__remote_component_host_shared_modules__,
1521
- ...shared,
1522
- ...self.__remote_component_shared__
1523
- };
1524
- await setupWebpackRuntime(
1525
- "turbopack",
1526
- [],
1527
- url,
1528
- bundle,
1529
- hostShared,
1530
- remoteShared,
1531
- resolveClientUrl
1532
- );
1699
+ const hostShared = buildHostShared(shared, resolveClientUrl, {
1700
+ includeRemoteComponentShared: true
1701
+ });
1702
+ await setupRemoteScope("turbopack", [], url, bundle, resolveClientUrl);
1533
1703
  const {
1534
1704
  default: { createFromReadableStream }
1535
1705
  } = await import("react-server-dom-webpack/client.browser");
1536
- function preloadScripts(scripts, __) {
1537
- return setupWebpackRuntime(
1706
+ async function preloadScripts(scripts, __) {
1707
+ const scope = await setupRemoteScope(
1538
1708
  "turbopack",
1539
1709
  scripts.map((script) => ({
1540
1710
  src: script.getAttribute("src") || script.getAttribute("data-src") || script.src
1541
1711
  })),
1542
1712
  url,
1543
1713
  bundle,
1544
- hostShared,
1545
- remoteShared,
1546
1714
  resolveClientUrl
1547
1715
  );
1716
+ await initializeSharedModules(
1717
+ scope,
1718
+ buildCoreShared(hostShared),
1719
+ remoteShared ?? {}
1720
+ );
1548
1721
  }
1549
1722
  return {
1550
1723
  self,
@@ -1559,8 +1732,9 @@ var init_turbopack = __esm({
1559
1732
  "use strict";
1560
1733
  init_apply_shared_modules();
1561
1734
  init_next_client_pages_loader();
1562
- init_polyfill();
1563
- init_webpack_runtime();
1735
+ init_shared_module_resolver();
1736
+ init_remote_scope_setup();
1737
+ init_shared_modules();
1564
1738
  }
1565
1739
  });
1566
1740
 
@@ -1607,10 +1781,9 @@ async function importViaCallback(absoluteSrc, resolveClientUrl) {
1607
1781
  URL.revokeObjectURL(moduleBlobUrl);
1608
1782
  URL.revokeObjectURL(wrapperBlobUrl);
1609
1783
  }
1610
- const registry = globalThis.__rc_module_registry__;
1611
- const mod = registry?.[absoluteSrc] ?? {};
1612
- if (registry)
1613
- delete registry[absoluteSrc];
1784
+ const registry = getNamespace().moduleRegistry;
1785
+ const mod = registry[absoluteSrc] ?? {};
1786
+ delete registry[absoluteSrc];
1614
1787
  return mod;
1615
1788
  }
1616
1789
  async function importDirectly(absoluteSrc) {
@@ -1640,12 +1813,12 @@ function resolveScriptSrc(script, url) {
1640
1813
  return rawSrc;
1641
1814
  }
1642
1815
  async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
1643
- const self = globalThis;
1644
- if (self.__remote_script_entrypoint_mount__?.[url.href]) {
1645
- self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
1816
+ const ns = getNamespace();
1817
+ if (ns.mountFns[url.href]) {
1818
+ ns.mountFns[url.href] = /* @__PURE__ */ new Set();
1646
1819
  }
1647
- if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
1648
- self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
1820
+ if (ns.unmountFns[url.href]) {
1821
+ ns.unmountFns[url.href] = /* @__PURE__ */ new Set();
1649
1822
  }
1650
1823
  const mountUnmountSets = await Promise.all(
1651
1824
  scripts.map(async (script) => {
@@ -1657,25 +1830,19 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
1657
1830
  URL.revokeObjectURL(src);
1658
1831
  }
1659
1832
  if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
1660
- if (!self.__remote_script_entrypoint_mount__) {
1661
- self.__remote_script_entrypoint_mount__ = {};
1833
+ if (!ns.mountFns[url.href]) {
1834
+ ns.mountFns[url.href] = /* @__PURE__ */ new Set();
1662
1835
  }
1663
- if (!self.__remote_script_entrypoint_mount__[url.href]) {
1664
- self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
1665
- }
1666
- self.__remote_script_entrypoint_mount__[url.href]?.add(
1836
+ ns.mountFns[url.href]?.add(
1667
1837
  mod.mount || mod.default?.mount || (() => {
1668
1838
  })
1669
1839
  );
1670
1840
  }
1671
1841
  if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
1672
- if (!self.__remote_script_entrypoint_unmount__) {
1673
- self.__remote_script_entrypoint_unmount__ = {};
1674
- }
1675
- if (!self.__remote_script_entrypoint_unmount__[url.href]) {
1676
- self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
1842
+ if (!ns.unmountFns[url.href]) {
1843
+ ns.unmountFns[url.href] = /* @__PURE__ */ new Set();
1677
1844
  }
1678
- self.__remote_script_entrypoint_unmount__[url.href]?.add(
1845
+ ns.unmountFns[url.href]?.add(
1679
1846
  mod.unmount || mod.default?.unmount || (() => {
1680
1847
  })
1681
1848
  );
@@ -1716,6 +1883,7 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
1716
1883
  var init_static_loader = __esm({
1717
1884
  "src/runtime/loaders/static-loader.ts"() {
1718
1885
  "use strict";
1886
+ init_namespace();
1719
1887
  init_logger();
1720
1888
  }
1721
1889
  });
@@ -1841,8 +2009,8 @@ function resolveNameFromSrc(src, defaultName) {
1841
2009
  // src/host/html/index.tsx
1842
2010
  init_constants2();
1843
2011
 
1844
- // src/runtime/html/apply-origin.ts
1845
- var tagNames = [
2012
+ // src/runtime/html/html-spec.ts
2013
+ var ORIGIN_REWRITE_TAGS = [
1846
2014
  "img",
1847
2015
  "source",
1848
2016
  "video",
@@ -1853,10 +2021,37 @@ var tagNames = [
1853
2021
  "script",
1854
2022
  "link"
1855
2023
  ];
2024
+ var ID_SUFFIX_RSC = "_rsc";
2025
+ var ID_SUFFIX_SSR = "_ssr";
2026
+ var ID_SUFFIX_SHARED = "_shared";
2027
+ var DATA_BUNDLE = "data-bundle";
2028
+ var DATA_ROUTE = "data-route";
2029
+ var DATA_RUNTIME = "data-runtime";
2030
+ var DATA_TYPE = "data-type";
2031
+ var DATA_SRC = "data-src";
2032
+ var DATA_REMOTE_COMPONENTS_SHARED = "data-remote-components-shared";
2033
+ var TAG_REMOTE_COMPONENT = "remote-component";
2034
+ var NEXT_DATA_ID = "__NEXT_DATA__";
2035
+ var REMOTE_NEXT_DATA_ID = "__REMOTE_NEXT_DATA__";
2036
+ var NEXT_CONTAINER_ID = "__next";
2037
+
2038
+ // src/runtime/html/rewrite-srcset.ts
2039
+ function rewriteSrcset(srcset, base, resolve) {
2040
+ return srcset.split(",").map((entry) => {
2041
+ const [url, descriptor] = entry.trim().split(/\s+/);
2042
+ if (!url)
2043
+ return entry;
2044
+ const absoluteUrl = new URL(url, base).href;
2045
+ const resolvedUrl = resolve ? resolve(absoluteUrl) : absoluteUrl;
2046
+ return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
2047
+ }).join(", ");
2048
+ }
2049
+
2050
+ // src/runtime/html/apply-origin.ts
1856
2051
  function applyOriginToNodes(doc, url, resolveClientUrl) {
1857
2052
  if (url.origin !== location.origin) {
1858
2053
  const nodes = doc.querySelectorAll(
1859
- tagNames.map(
2054
+ ORIGIN_REWRITE_TAGS.map(
1860
2055
  (type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
1861
2056
  ).join(",")
1862
2057
  );
@@ -1874,29 +2069,17 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
1874
2069
  );
1875
2070
  }
1876
2071
  if (node.hasAttribute("srcset")) {
1877
- const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
1878
- const [urlPart, descriptor] = entry.trim().split(/\s+/);
1879
- if (!urlPart)
1880
- return entry;
1881
- const absoluteUrl = new URL(urlPart, url).href;
1882
- const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
1883
- return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
1884
- }).join(", ");
1885
- if (srcSet) {
1886
- node.setAttribute("srcset", srcSet);
2072
+ const raw = node.getAttribute("srcset");
2073
+ if (raw) {
2074
+ const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
2075
+ node.setAttribute("srcset", rewriteSrcset(raw, url, resolve));
1887
2076
  }
1888
2077
  }
1889
2078
  if (node.hasAttribute("imagesrcset")) {
1890
- const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
1891
- const [urlPart, descriptor] = entry.trim().split(/\s+/);
1892
- if (!urlPart)
1893
- return entry;
1894
- const absoluteUrl = new URL(urlPart, url).href;
1895
- const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
1896
- return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
1897
- }).join(", ");
1898
- if (srcSet) {
1899
- node.setAttribute("imagesrcset", srcSet);
2079
+ const raw = node.getAttribute("imagesrcset");
2080
+ if (raw) {
2081
+ const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
2082
+ node.setAttribute("imagesrcset", rewriteSrcset(raw, url, resolve));
1900
2083
  }
1901
2084
  }
1902
2085
  });
@@ -1942,26 +2125,28 @@ function buildMetadata(attrs, url) {
1942
2125
  // src/runtime/html/parse-remote-html.ts
1943
2126
  init_error();
1944
2127
  function validateSingleComponent(doc, name, url) {
1945
- if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
2128
+ if (doc.querySelectorAll(`div[${DATA_BUNDLE}][${DATA_ROUTE}]`).length > 1 && !doc.querySelector(
2129
+ `div[${DATA_BUNDLE}][${DATA_ROUTE}][id^="${name}"]`
2130
+ ) || doc.querySelectorAll(`${TAG_REMOTE_COMPONENT}:not([src])`).length > 1 && !doc.querySelector(`${TAG_REMOTE_COMPONENT}[name="${name}"]`)) {
1946
2131
  throw multipleRemoteComponentsError(url);
1947
2132
  }
1948
2133
  }
1949
2134
  function findComponentElement(doc, name) {
1950
- return doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) ?? doc.querySelector("div[data-bundle][data-route]") ?? doc.querySelector("div#__next") ?? doc.querySelector(`remote-component[name="${name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
2135
+ return doc.querySelector(`div[${DATA_BUNDLE}][${DATA_ROUTE}][id^="${name}"]`) ?? doc.querySelector(`div[${DATA_BUNDLE}][${DATA_ROUTE}]`) ?? doc.querySelector(`div#${NEXT_CONTAINER_ID}`) ?? doc.querySelector(`${TAG_REMOTE_COMPONENT}[name="${name}"]:not([src])`) ?? doc.querySelector(`${TAG_REMOTE_COMPONENT}:not([src])`);
1951
2136
  }
1952
2137
  function parseNextData(doc) {
1953
2138
  return JSON.parse(
1954
- (doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
2139
+ (doc.querySelector(`#${NEXT_DATA_ID}`) ?? doc.querySelector(`#${REMOTE_NEXT_DATA_ID}`))?.textContent ?? "null"
1955
2140
  );
1956
2141
  }
1957
2142
  function resolveComponentName(component, nextData, fallbackName) {
1958
- const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
1959
- const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
2143
+ const isRemoteComponent = component?.tagName.toLowerCase() === TAG_REMOTE_COMPONENT;
2144
+ const name = component?.getAttribute("id")?.replace(new RegExp(`${ID_SUFFIX_SSR}$`), "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
1960
2145
  return { name, isRemoteComponent };
1961
2146
  }
1962
2147
  function extractRemoteShared(doc, name, nextData) {
1963
2148
  const remoteSharedEl = doc.querySelector(
1964
- `#${name}_shared[data-remote-components-shared]`
2149
+ `#${name}${ID_SUFFIX_SHARED}[${DATA_REMOTE_COMPONENTS_SHARED}]`
1965
2150
  );
1966
2151
  const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
1967
2152
  remoteSharedEl?.remove();
@@ -1982,7 +2167,7 @@ function extractLinks(doc, component) {
1982
2167
  function extractScripts(doc, component, isRemoteComponent) {
1983
2168
  return Array.from(
1984
2169
  (isRemoteComponent ? component : doc).querySelectorAll(
1985
- "script[src],script[data-src]"
2170
+ `script[src],script[${DATA_SRC}]`
1986
2171
  )
1987
2172
  );
1988
2173
  }
@@ -1995,15 +2180,15 @@ function parseRemoteComponentDocument(doc, name, url) {
1995
2180
  nextData,
1996
2181
  name
1997
2182
  );
1998
- const rsc = doc.querySelector(`#${resolvedName}_rsc`);
2183
+ const rsc = doc.querySelector(`#${resolvedName}${ID_SUFFIX_RSC}`);
1999
2184
  const metadata = buildMetadata(
2000
2185
  {
2001
2186
  name: resolvedName,
2002
- bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle,
2003
- route: component?.getAttribute("data-route") ?? nextData?.page,
2004
- runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
2187
+ bundle: component?.getAttribute(DATA_BUNDLE) || nextData?.props.__REMOTE_COMPONENT__?.bundle,
2188
+ route: component?.getAttribute(DATA_ROUTE) ?? nextData?.page,
2189
+ runtime: component?.getAttribute(DATA_RUNTIME) ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? RUNTIME_SCRIPT,
2005
2190
  id: component?.getAttribute("id"),
2006
- type: component?.getAttribute("data-type")
2191
+ type: component?.getAttribute(DATA_TYPE)
2007
2192
  },
2008
2193
  url
2009
2194
  );
@@ -2031,6 +2216,9 @@ function parseRemoteComponentDocument(doc, name, url) {
2031
2216
  };
2032
2217
  }
2033
2218
 
2219
+ // src/host/html/index.tsx
2220
+ init_namespace();
2221
+
2034
2222
  // src/runtime/rsc.ts
2035
2223
  var import_web_streams_polyfill = require("web-streams-polyfill");
2036
2224
  function fixPayload(payload) {
@@ -2051,6 +2239,18 @@ function fixPayload(payload) {
2051
2239
  }
2052
2240
  }
2053
2241
  }
2242
+ function buildRSCChunks(rscName, data) {
2243
+ const chunks = [];
2244
+ for (const chunk of data) {
2245
+ for (const line of chunk.split("\n")) {
2246
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
2247
+ if (match?.groups?.rsc) {
2248
+ chunks.push(JSON.parse(`"${match.groups.rsc}"`));
2249
+ }
2250
+ }
2251
+ }
2252
+ return chunks;
2253
+ }
2054
2254
  function createRSCStream(rscName, data) {
2055
2255
  return new import_web_streams_polyfill.ReadableStream({
2056
2256
  type: "bytes",
@@ -2058,16 +2258,11 @@ function createRSCStream(rscName, data) {
2058
2258
  const encoder = new TextEncoder();
2059
2259
  const self = globalThis;
2060
2260
  if (data.length > 0) {
2061
- data.forEach((chunk) => {
2062
- const lines = chunk.split("\n");
2063
- for (const line of lines) {
2064
- const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
2065
- if (match?.groups?.rsc) {
2066
- self[rscName] = self[rscName] ?? [];
2067
- self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
2068
- }
2069
- }
2070
- });
2261
+ const parsed = buildRSCChunks(rscName, data);
2262
+ if (parsed.length > 0) {
2263
+ self[rscName] = self[rscName] ?? [];
2264
+ self[rscName].push(...parsed);
2265
+ }
2071
2266
  }
2072
2267
  const allChunks = (self[rscName] ?? [`0:[null]
2073
2268
  `]).join("");
@@ -2443,11 +2638,7 @@ if (typeof HTMLElement !== "undefined") {
2443
2638
  this.name = resolvedName;
2444
2639
  this.bundle = parsedMetadata.bundle;
2445
2640
  if (url) {
2446
- const self2 = globalThis;
2447
- if (!self2.__remote_bundle_url__) {
2448
- self2.__remote_bundle_url__ = {};
2449
- }
2450
- self2.__remote_bundle_url__[this.bundle] = url;
2641
+ getNamespace().bundleUrls[this.bundle] = url;
2451
2642
  }
2452
2643
  const metadataEl = document.createElement("script");
2453
2644
  metadataEl.type = "application/json";
@@ -2471,22 +2662,22 @@ if (typeof HTMLElement !== "undefined") {
2471
2662
  if (this.hostState.prevIsRemoteComponent) {
2472
2663
  if (this.hostState.prevUrl) {
2473
2664
  const prevUrl = this.hostState.prevUrl;
2474
- const self2 = globalThis;
2475
- if (self2.__remote_script_entrypoint_unmount__?.[prevUrl.href]) {
2665
+ const nsUnmount = getNamespace();
2666
+ if (nsUnmount.unmountFns[prevUrl.href]) {
2476
2667
  await Promise.all(
2477
- Array.from(
2478
- self2.__remote_script_entrypoint_unmount__[prevUrl.href] ?? []
2479
- ).map(async (unmount) => {
2480
- try {
2481
- await unmount(this.root);
2482
- } catch (e) {
2483
- logError(
2484
- "HtmlHost",
2485
- `Error while calling unmount() for Remote Component from ${prevUrl.href}.`,
2486
- e
2487
- );
2668
+ Array.from(nsUnmount.unmountFns[prevUrl.href] ?? []).map(
2669
+ async (unmount) => {
2670
+ try {
2671
+ await unmount(this.root);
2672
+ } catch (e) {
2673
+ logError(
2674
+ "HtmlHost",
2675
+ `Error while calling unmount() for Remote Component from ${prevUrl.href}.`,
2676
+ e
2677
+ );
2678
+ }
2488
2679
  }
2489
- })
2680
+ )
2490
2681
  );
2491
2682
  if (!isCurrentLoad()) {
2492
2683
  return abandonLoad();
@@ -2777,21 +2968,21 @@ if (typeof HTMLElement !== "undefined") {
2777
2968
  if (this.fouc) {
2778
2969
  this.root.removeChild(this.fouc);
2779
2970
  }
2780
- } else if (self.__remote_script_entrypoint_mount__?.[url.href]) {
2971
+ } else if (getNamespace().mountFns[url.href]) {
2781
2972
  await Promise.all(
2782
- Array.from(
2783
- self.__remote_script_entrypoint_mount__[url.href] ?? []
2784
- ).map(async (mount) => {
2785
- try {
2786
- await mount(this.root);
2787
- } catch (e) {
2788
- logError(
2789
- "HtmlHost",
2790
- `Error while calling mount() for Remote Component from ${url.href}.`,
2791
- e
2792
- );
2973
+ Array.from(getNamespace().mountFns[url.href] ?? []).map(
2974
+ async (mount) => {
2975
+ try {
2976
+ await mount(this.root);
2977
+ } catch (e) {
2978
+ logError(
2979
+ "HtmlHost",
2980
+ `Error while calling mount() for Remote Component from ${url.href}.`,
2981
+ e
2982
+ );
2983
+ }
2793
2984
  }
2794
- })
2985
+ )
2795
2986
  );
2796
2987
  this.dispatchLifecycleEvent("load", { src: this.src });
2797
2988
  } else {
@@ -2805,14 +2996,9 @@ if (typeof HTMLElement !== "undefined") {
2805
2996
  customElements.define("remote-component", RemoteComponent);
2806
2997
  }
2807
2998
  function registerSharedModules(modules = {}) {
2808
- const self = globalThis;
2809
- if (!self.__remote_component_host_shared_modules__) {
2810
- self.__remote_component_host_shared_modules__ = {};
2811
- }
2999
+ const ns = getNamespace();
2812
3000
  Object.entries(modules).forEach(([key, value]) => {
2813
- if (self.__remote_component_host_shared_modules__) {
2814
- self.__remote_component_host_shared_modules__[key] = value;
2815
- }
3001
+ ns.hostSharedModules[key] = value;
2816
3002
  });
2817
3003
  }
2818
3004
  // Annotate the CommonJS export names for ESM import in node: