remote-components 0.4.6 → 0.4.8

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 (44) hide show
  1. package/dist/{chunk-IVJ37EUX.cjs → chunk-EW5O3Q24.cjs} +7 -7
  2. package/dist/{chunk-LRR2OE4G.js → chunk-FF4SXSSG.js} +2 -2
  3. package/dist/{chunk-AEW3XYKI.cjs → chunk-KAFPXSRI.cjs} +6 -6
  4. package/dist/{chunk-WCCUTJJR.js → chunk-KCUEMMYL.js} +2 -2
  5. package/dist/{chunk-U2OFZFJI.cjs → chunk-O4ED3BUP.cjs} +10 -10
  6. package/dist/{chunk-6GHGHHQ3.js → chunk-STMO56U2.js} +81 -11
  7. package/dist/chunk-STMO56U2.js.map +1 -0
  8. package/dist/{chunk-NOHDLKL6.js → chunk-VJO4PTWG.js} +3 -3
  9. package/dist/{chunk-OP2PTYS6.cjs → chunk-YJJFRORQ.cjs} +107 -37
  10. package/dist/chunk-YJJFRORQ.cjs.map +1 -0
  11. package/dist/host/html.cjs +13 -13
  12. package/dist/host/html.js +5 -5
  13. package/dist/host/nextjs/app/client-only.cjs +6 -6
  14. package/dist/host/nextjs/app/client-only.js +4 -4
  15. package/dist/host/react.cjs +5 -5
  16. package/dist/host/react.js +4 -4
  17. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
  18. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
  19. package/dist/internal/runtime/turbopack/module.cjs +71 -8
  20. package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
  21. package/dist/internal/runtime/turbopack/module.d.ts +21 -0
  22. package/dist/internal/runtime/turbopack/module.js +71 -8
  23. package/dist/internal/runtime/turbopack/module.js.map +1 -1
  24. package/dist/internal/runtime/turbopack/shared-modules.cjs +9 -2
  25. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
  26. package/dist/internal/runtime/turbopack/shared-modules.js +10 -3
  27. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
  28. package/dist/{turbopack-7PFUIFBT.cjs → turbopack-RXVSOWF7.cjs} +8 -8
  29. package/dist/{turbopack-NUCVQCQL.js → turbopack-XDIGB4GI.js} +3 -3
  30. package/dist/{webpack-34PB2JBT.js → webpack-3QXPAZN4.js} +2 -2
  31. package/dist/{webpack-DEFHHH6B.cjs → webpack-HKD7RZRE.cjs} +5 -5
  32. package/package.json +1 -1
  33. package/dist/chunk-6GHGHHQ3.js.map +0 -1
  34. package/dist/chunk-OP2PTYS6.cjs.map +0 -1
  35. /package/dist/{chunk-IVJ37EUX.cjs.map → chunk-EW5O3Q24.cjs.map} +0 -0
  36. /package/dist/{chunk-LRR2OE4G.js.map → chunk-FF4SXSSG.js.map} +0 -0
  37. /package/dist/{chunk-AEW3XYKI.cjs.map → chunk-KAFPXSRI.cjs.map} +0 -0
  38. /package/dist/{chunk-WCCUTJJR.js.map → chunk-KCUEMMYL.js.map} +0 -0
  39. /package/dist/{chunk-U2OFZFJI.cjs.map → chunk-O4ED3BUP.cjs.map} +0 -0
  40. /package/dist/{chunk-NOHDLKL6.js.map → chunk-VJO4PTWG.js.map} +0 -0
  41. /package/dist/{turbopack-7PFUIFBT.cjs.map → turbopack-RXVSOWF7.cjs.map} +0 -0
  42. /package/dist/{turbopack-NUCVQCQL.js.map → turbopack-XDIGB4GI.js.map} +0 -0
  43. /package/dist/{webpack-34PB2JBT.js.map → webpack-3QXPAZN4.js.map} +0 -0
  44. /package/dist/{webpack-DEFHHH6B.cjs.map → webpack-HKD7RZRE.cjs.map} +0 -0
@@ -2,6 +2,27 @@ import { logDebug, logError } from "#internal/utils/logger";
2
2
  import { loadChunkWithScope } from "./chunk-loader";
3
3
  import { formatRemoteId } from "./remote-scope";
4
4
  import { getSharedModule, getTurbopackModules } from "./shared-modules";
5
+ function RelativeURL(inputUrl) {
6
+ const realUrl = new URL(inputUrl, "x:/");
7
+ const values = {};
8
+ for (const key in realUrl) {
9
+ values[key] = realUrl[key];
10
+ }
11
+ values.href = inputUrl;
12
+ values.pathname = inputUrl.replace(/[?#].*/, "");
13
+ values.origin = "";
14
+ values.protocol = "";
15
+ values.toString = () => inputUrl;
16
+ values.toJSON = () => inputUrl;
17
+ for (const key in values) {
18
+ Object.defineProperty(this, key, {
19
+ enumerable: true,
20
+ configurable: true,
21
+ value: values[key]
22
+ });
23
+ }
24
+ }
25
+ RelativeURL.prototype = URL.prototype;
5
26
  function requireModule(scope, moduleId, fullId) {
6
27
  const idStr = String(moduleId);
7
28
  const sharedModule = getSharedModule(scope, moduleId);
@@ -183,13 +204,17 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
183
204
  r(requireId) {
184
205
  return scopedRequire(requireId);
185
206
  },
186
- // value exports
207
+ // exportValue — mirrors upstream Turbopack's `exportValue`, which sets
208
+ // `module.exports = value` regardless of value type. Most importantly,
209
+ // when Turbopack emits an async-loader module the body is
210
+ // ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))
211
+ // The function must be stored as-is so that the consumer's `ctx.A(id)`
212
+ // can invoke it with the real parent-import resolver. Calling it eagerly
213
+ // here (the prior remote-components behavior) ran the loader with the
214
+ // wrong argument and stored a `Promise` as `exports.default`, which then
215
+ // crashed `ctx.A` with `.default is not a function`.
187
216
  v(value) {
188
- if (typeof value === "function") {
189
- exports.default = value((vid) => scopedRequire(vid));
190
- } else {
191
- moduleExports.exports = value;
192
- }
217
+ moduleExports.exports = value;
193
218
  },
194
219
  // exportUrl — used by static asset modules (images, fonts, JSON, etc.).
195
220
  // Turbopack emits a tiny module whose entire body is ctx.q(url), which
@@ -202,6 +227,20 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
202
227
  moduleExports.exports = value;
203
228
  }
204
229
  },
230
+ // exportNamespace — Turbopack emits `ctx.n(namespace, esmId?)` when a
231
+ // module's exports should be replaced wholesale with a precomputed ESM
232
+ // namespace object (commonly at module evaluation time for re-export
233
+ // patterns and CJS-to-ESM interop wrappers). Mirrors upstream
234
+ // `exportNamespace` which sets both `module.exports` and
235
+ // `module.namespaceObject`; remote-components keeps a single exports
236
+ // record per module, so we assign to `exports` only.
237
+ n(namespace, esmId) {
238
+ if (esmId != null) {
239
+ scope.moduleCache[String(esmId)] = namespace;
240
+ } else {
241
+ moduleExports.exports = namespace;
242
+ }
243
+ },
205
244
  // async module initializer
206
245
  async a(mod) {
207
246
  let result;
@@ -212,10 +251,24 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
212
251
  );
213
252
  exports.default = result;
214
253
  },
215
- // async module loader — resolves directly via scope
254
+ // async module loader — resolves directly via scope.
255
+ //
256
+ // Upstream Turbopack's `asyncLoader` treats `require(id)` itself as the
257
+ // loader function (see `module.exports = loaderFn` set by the factory).
258
+ // remote-components additionally supports `{ default: loaderFn }`, which
259
+ // is what a factory using `ctx.s([['default', () => fn]], ...)` produces.
260
+ // Both shapes must be accepted: when `ctx.n(loaderFn, esmId)` injects a
261
+ // function directly into the cache, the require result is the function
262
+ // itself and there is no `.default` to dereference.
216
263
  async A(Aid) {
217
264
  const mod = scopedRequire(Aid);
218
- return mod.default((parentId) => scopedRequire(parentId));
265
+ const loader = typeof mod === "function" ? mod : mod?.default;
266
+ if (typeof loader !== "function") {
267
+ throw new Error(
268
+ `Async module loader for "${Aid}" is not a function (got ${typeof loader})`
269
+ );
270
+ }
271
+ return loader((parentId) => scopedRequire(parentId));
219
272
  },
220
273
  // dynamic import tracking — no-op for remote components
221
274
  j() {
@@ -239,6 +292,16 @@ function createTurbopackContext(scope, exports, moduleExports, modules, moduleIn
239
292
  `Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
240
293
  );
241
294
  },
295
+ // resolveAbsolutePath — Turbopack uses this to construct file:// URLs
296
+ // for source-map and debug output. Browser context has no real
297
+ // filesystem path; passing the input through unchanged keeps the
298
+ // surface satisfied without inventing values.
299
+ P(path) {
300
+ return path;
301
+ },
302
+ // relativeURL constructor — see RelativeURL function declaration above
303
+ // for the constructor-vs-method-shorthand explanation.
304
+ U: RelativeURL,
242
305
  // globalThis substitute shared across all modules in this scope
243
306
  g: scope.moduleGlobal,
244
307
  m: moduleExports,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/module.ts"],"sourcesContent":["import { logDebug, logError } from '#internal/utils/logger';\nimport { loadChunkWithScope } from './chunk-loader';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\nimport { getSharedModule, getTurbopackModules } from './shared-modules';\n\n/**\n * Function signature for Turbopack module initializers.\n * These functions are generated by Turbopack and initialize module exports.\n */\nexport type TurbopackModuleInit = (\n turbopackContext: TurbopackContext,\n module: TurbopackModule,\n exports: Record<string, unknown>,\n) => void;\n\ninterface TurbopackHotModule {\n active: boolean;\n data: Record<string, unknown>;\n accept(): void;\n dispose(callback?: (data: Record<string, unknown>) => void): void;\n invalidate(): void;\n}\n\ninterface TurbopackModule {\n exports: Record<string, unknown>;\n hot: TurbopackHotModule;\n}\n\n/**\n * The context object passed to Turbopack module initializers.\n * This provides the runtime API that modules use for imports, exports, and HMR.\n */\ninterface TurbopackContext {\n /** HMR (Hot Module Replacement) - not implemented for remote components */\n k: {\n register(): void;\n registerExports(): void;\n signature(): (fn: unknown) => unknown;\n };\n /** ESM exports setup */\n s: (\n bindings:\n | Record<string, () => unknown>\n | [...([string, () => unknown] | [string, number, () => unknown])],\n esmId?: string | number,\n ) => void;\n /** Import module */\n i: (importId: string | number) => Record<string, unknown> | undefined;\n /** Require module */\n r: (requireId: string | number) => unknown;\n /** Value exports */\n v: (value: unknown) => void;\n /**\n * Export URL — used by static asset modules (images, fonts, JSON, etc.).\n * The entire body of a Turbopack asset module is a single `ctx.q(url)` call\n * that sets `module.exports` to the asset URL string.\n */\n q: (value: unknown, esmId?: string | number) => void;\n /** Async module initializer */\n a: (\n mod: (\n handleDeps: unknown,\n setResult: (value: unknown) => void,\n ) => Promise<void>,\n ) => Promise<void>;\n /** Async module loader */\n A: (Aid: string | number) => Promise<unknown>;\n /**\n * Dynamic import tracking. Called in production chunks after ctx.s() to\n * register async/dynamic module relationships. e.g. t.j(importedMod, 58790)\n */\n j: (module: unknown, esmId?: string | number) => void;\n /** Chunk loader */\n l: (url: string) => Promise<unknown> | undefined;\n /** Global object for this bundle */\n g: unknown;\n /** Module object */\n m: TurbopackModule;\n /** Exports object */\n e: Record<string, unknown>;\n}\n\n/**\n * Turbopack pushes chunks as flat arrays in one of two shapes:\n *\n * Module chunk (common case):\n * [scriptElement, id1, factory1, id2, factory2, ...]\n * - index 0: the script Element (document.currentScript) or undefined\n * - alternating pairs: numeric ID (prod) or path string (dev), then factory function\n *\n * Runtime manifest (bootstrapper only, no module factories):\n * [scriptElement, { otherChunks: [...], runtimeModuleIds: [...] }]\n *\n * Newer Next.js canary versions may also store modules as a plain object\n * { [moduleId]: factory } rather than as an array.\n */\ntype BundleModules =\n | (\n | Element\n | string\n | number\n | TurbopackModuleInit\n | Record<string, TurbopackModuleInit>\n | null\n | undefined\n )[]\n | Record<string, TurbopackModuleInit>\n | undefined;\n\n/**\n * Resolves a module within a scope: checks shared modules first, then\n * falls back to Turbopack module resolution. This is the scope-local\n * equivalent of the global __webpack_require__ dispatcher.\n */\nexport function requireModule(\n scope: RemoteScope,\n moduleId: string | number,\n fullId?: string,\n): unknown {\n const idStr = String(moduleId);\n\n // Shared modules are NOT cached in moduleCache because ctx.s() also\n // uses moduleCache for esmId lookups. Caching the host's frozen module\n // object here would cause ctx.s() to attempt Object.defineProperty on\n // it, failing with \"Cannot redefine property\" for non-configurable\n // exports. Keeping shared modules in their own map avoids the collision.\n //\n // Exact shared IDs must win over stale remote moduleCache entries. This is\n // a compatibility guard for the old shared-modules architecture, where a\n // remote chunk can instantiate a shared module before the broker has claimed\n // that ID. Delete this special ordering once all shared modules are resolved\n // through scope adapters before any remote factory can execute.\n const sharedModule = getSharedModule(scope, moduleId);\n if (sharedModule !== null) {\n if (scope.moduleCache[idStr]) {\n logDebug(\n 'TurbopackModule',\n `Shared module \"${idStr}\" resolved from host and overrides a cached remote copy in \"${scope.scopedName}\"`,\n );\n }\n return sharedModule;\n }\n\n // moduleCache is checked first inside handleTurbopackModule too, but\n // checking here keeps non-shared re-entry cheap.\n if (scope.moduleCache[idStr]) return scope.moduleCache[idStr];\n\n return handleTurbopackModule(\n scope,\n idStr,\n fullId ?? formatRemoteId(scope, idStr),\n );\n}\n\n/**\n * Handles Turbopack module resolution and execution.\n * Finds a module in the Turbopack bundle, executes its initializer with a\n * custom runtime context, and returns the module exports.\n */\nexport function handleTurbopackModule(\n scope: RemoteScope,\n moduleId: string,\n id: string,\n): unknown {\n // Cache check must come before module init lookup. Module initializers\n // re-enter handleTurbopackModule for their own imports, so without this\n // guard circular dependencies would infinite-loop.\n if (scope.moduleCache[moduleId]) {\n return scope.moduleCache[moduleId];\n }\n\n const modules = getTurbopackModules(scope) as BundleModules;\n\n // Log only if bundle is completely missing (critical error)\n if (!modules) {\n logError(\n 'TurbopackModule',\n `TURBOPACK_${scope.globalKey} is undefined (scope: \"${scope.scopedName}\")`,\n );\n }\n\n const moduleInit = findModuleInit(modules, moduleId);\n const exports = {} as Record<string, unknown>;\n const moduleExports = {\n exports,\n hot: createNoopHotModule(),\n };\n\n if (typeof moduleInit !== 'function') {\n throw new Error(\n `Module ${id} not found in bundle ${scope.name} with id ${moduleId}`,\n );\n }\n\n // store a reference to the module exports in the cache before execution\n // to handle circular dependencies\n scope.moduleCache[moduleId] = moduleExports.exports;\n\n // execute the module initializer with our custom Turbopack context\n moduleInit(\n createTurbopackContext(\n scope,\n exports,\n moduleExports,\n modules,\n moduleInit,\n id,\n ),\n moduleExports,\n exports,\n );\n\n // update the cache with the final exports (may have changed during execution)\n if (scope.moduleCache[moduleId] !== moduleExports.exports) {\n scope.moduleCache[moduleId] = moduleExports.exports;\n }\n\n return moduleExports.exports;\n}\n\n/**\n * Finds the module initializer function for a given ID in the Turbopack bundle.\n * Handles all bundle shapes: flat array, object map, nested arrays, and\n * embedded object entries within arrays. Performs exact match first, then\n * falls back to startsWith for dev-mode IDs with appended qualifiers.\n */\nexport function findModuleInit(\n modules: BundleModules | unknown[] | undefined,\n moduleId: string,\n): TurbopackModuleInit | undefined {\n if (!modules || typeof modules !== 'object') return;\n\n // Object format: { [id]: factory } (newer Next.js canary builds)\n if (!Array.isArray(modules)) {\n const key =\n moduleId in modules\n ? moduleId\n : Object.keys(modules).find((k) => k.startsWith(moduleId));\n return key !== undefined ? modules[key] : undefined;\n }\n\n const flat = modules.flat();\n\n // Two-pass ID search: exact match first to avoid prefix false positives.\n // The startsWith fallback handles dev-mode IDs with appended qualifiers\n // such as \"[project]/path.tsx [app-client] (ecmascript, async loader)\".\n let idx = flat.findIndex((e) => String(e) === String(moduleId));\n if (idx < 0) {\n idx = flat.findIndex(\n (e) => typeof e === 'string' && e.startsWith(moduleId),\n );\n }\n if (idx >= 0) {\n // Factory is the first function entry that follows the module ID\n return flat\n .slice(idx + 1)\n .find((e): e is TurbopackModuleInit => typeof e === 'function');\n }\n\n // Embedded object map: entries of the form { [moduleId]: factory }\n for (const entry of flat) {\n if (!entry || typeof entry !== 'object') continue;\n const obj = entry as Record<string, TurbopackModuleInit>;\n if (moduleId in obj) return obj[moduleId];\n const prefixKey = Object.keys(obj).find((k) => k.startsWith(moduleId));\n if (prefixKey) return obj[prefixKey];\n }\n return undefined;\n}\n\n/**\n * Creates the Turbopack context object that provides the runtime API for modules.\n * All context methods close over the scope directly — no global dispatch needed\n * for internal module-to-module calls.\n */\nfunction createTurbopackContext(\n scope: RemoteScope,\n exports: Record<string, unknown>,\n moduleExports: TurbopackModule,\n modules: BundleModules,\n moduleInit: TurbopackModuleInit,\n id: string,\n): TurbopackContext {\n /** Scope-local require: shared modules → turbopack module resolution. */\n const scopedRequire = (moduleId: string | number): unknown =>\n requireModule(scope, moduleId, formatRemoteId(scope, String(moduleId)));\n\n return {\n // HMR not implemented for Remote Components\n k: {\n register() {\n // omit\n },\n registerExports() {\n // omit\n },\n signature() {\n return (fn: unknown) => fn;\n },\n },\n\n // ESM exports setup\n s(\n bindings:\n | Record<string, () => unknown>\n | [...([string, () => unknown] | [string, number, () => unknown])],\n esmId?: string | number,\n ) {\n let mod = exports;\n if (typeof esmId === 'string' || typeof esmId === 'number') {\n if (!scope.moduleCache[esmId]) {\n scope.moduleCache[esmId] = {} as Record<string, unknown>;\n }\n mod = scope.moduleCache[esmId] as Record<string, unknown>;\n }\n\n Object.defineProperty(mod, '__esModule', { value: true });\n if (Array.isArray(bindings)) {\n let i = 0;\n while (i < bindings.length) {\n const propName = bindings[i++] as string;\n const tagOrFunc = bindings[i++];\n if (typeof tagOrFunc === 'number') {\n Object.defineProperty(mod, propName, {\n value: bindings[i++],\n enumerable: true,\n writable: false,\n });\n } else {\n const getterFn = tagOrFunc as () => unknown;\n if (typeof bindings[i] === 'function') {\n const setterFn = bindings[i++] as (v: unknown) => unknown;\n Object.defineProperty(mod, propName, {\n get: getterFn,\n set: setterFn,\n enumerable: true,\n });\n } else {\n Object.defineProperty(mod, propName, {\n get: getterFn,\n enumerable: true,\n });\n }\n }\n }\n }\n },\n\n // import — resolves directly via scope, no global dispatch\n i(importId: string | number) {\n let mod: Record<string, unknown> | undefined;\n if (typeof importId === 'string') {\n // parse export syntax if present (e.g., \"module <export foo as bar>\")\n const { exportSource, exportName } =\n /\\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(\n importId,\n )?.groups ?? {};\n const normalizedId = importId.replace(\n /\\s+<export(?<specifier>.*)>$/,\n '',\n );\n mod = scopedRequire(normalizedId) as\n | Record<string, unknown>\n | undefined;\n // map the requested export to the module exports\n if (\n mod &&\n exportSource &&\n exportName &&\n (exportSource === '*' || typeof mod[exportSource] !== 'undefined') &&\n typeof mod[exportName] === 'undefined'\n ) {\n if (exportSource === '*') {\n mod[exportName] = mod;\n } else {\n mod[exportName] = mod[exportSource];\n }\n }\n } else {\n mod = scopedRequire(importId) as Record<string, unknown> | undefined;\n }\n\n if (typeof mod !== 'object' || mod === null) {\n mod = { default: mod };\n } else if (\n !('default' in mod) &&\n // ES module namespace objects have a null prototype, so calling\n // mod.toString() directly throws. Use Object.prototype.toString\n // to safely detect them.\n Object.prototype.toString.call(mod) !== '[object Module]'\n ) {\n try {\n mod.default = mod;\n } catch {\n // ignore if mod is not extensible\n }\n }\n return mod;\n },\n\n // require — resolves directly via scope\n r(requireId: string | number) {\n return scopedRequire(requireId);\n },\n\n // value exports\n v(value: unknown) {\n if (typeof value === 'function') {\n exports.default = value((vid: string | number) => scopedRequire(vid));\n } else {\n moduleExports.exports = value as Record<string, unknown>;\n }\n },\n\n // exportUrl — used by static asset modules (images, fonts, JSON, etc.).\n // Turbopack emits a tiny module whose entire body is ctx.q(url), which\n // sets module.exports to the asset URL string so importers get the URL\n // as the module's default export.\n q(value: unknown, esmId?: string | number) {\n if (esmId != null) {\n scope.moduleCache[String(esmId)] = value as Record<string, unknown>;\n } else {\n moduleExports.exports = value as Record<string, unknown>;\n }\n },\n\n // async module initializer\n async a(\n mod: (\n handleDeps: unknown,\n setResult: (value: unknown) => void,\n ) => Promise<void>,\n ) {\n let result;\n await mod(\n () => {\n // not implemented\n },\n (value) => (result = value),\n );\n exports.default = result;\n },\n\n // async module loader — resolves directly via scope\n async A(Aid: string | number) {\n const mod = scopedRequire(Aid) as {\n default: (\n parentImport: (parentId: string) => unknown,\n ) => Promise<unknown>;\n };\n return mod.default((parentId: string) => scopedRequire(parentId));\n },\n\n // dynamic import tracking — no-op for remote components\n j() {\n // omit\n },\n\n // chunk loader — loads directly via scope, no global dispatch\n l(url: string) {\n // find the script tag that loaded the current module to determine base URL\n const flatModules = Array.isArray(modules) ? modules : [];\n const moduleInitIndex = flatModules.indexOf(moduleInit);\n if (moduleInitIndex !== -1) {\n const scriptIndex = flatModules\n .slice(0, moduleInitIndex)\n .findLastIndex((bundleEntry) => bundleEntry instanceof Element);\n if (scriptIndex !== -1) {\n const script = flatModules[scriptIndex] as HTMLScriptElement;\n const scriptSrc = script.getAttribute('data-turbopack-src') || '';\n const nextIndex = scriptSrc.indexOf('/_next');\n const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : '';\n const chunkUrl = `${baseUrl}/_next/${url}`;\n return loadChunkWithScope(scope, formatRemoteId(scope, chunkUrl));\n }\n }\n throw new Error(\n `Failed to load Turbopack chunk \"${url}\" for module \"${id}\". Check the URL is correct.`,\n );\n },\n\n // globalThis substitute shared across all modules in this scope\n g: scope.moduleGlobal,\n m: moduleExports,\n e: exports,\n };\n}\n\nfunction createNoopHotModule(): TurbopackHotModule {\n // Remote Components does not implement HMR, but Next.js dev page-loader\n // modules still call module.hot.* when Turbopack emits Pages Router code.\n return {\n active: true,\n data: {},\n accept() {},\n dispose() {},\n invalidate() {},\n };\n}\n"],"mappings":"AAAA,SAAS,UAAU,gBAAgB;AACnC,SAAS,0BAA0B;AACnC,SAAS,sBAAwC;AACjD,SAAS,iBAAiB,2BAA2B;AA+G9C,SAAS,cACd,OACA,UACA,QACS;AACT,QAAM,QAAQ,OAAO,QAAQ;AAa7B,QAAM,eAAe,gBAAgB,OAAO,QAAQ;AACpD,MAAI,iBAAiB,MAAM;AACzB,QAAI,MAAM,YAAY,KAAK,GAAG;AAC5B;AAAA,QACE;AAAA,QACA,kBAAkB,oEAAoE,MAAM;AAAA,MAC9F;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAIA,MAAI,MAAM,YAAY,KAAK;AAAG,WAAO,MAAM,YAAY,KAAK;AAE5D,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,UAAU,eAAe,OAAO,KAAK;AAAA,EACvC;AACF;AAOO,SAAS,sBACd,OACA,UACA,IACS;AAIT,MAAI,MAAM,YAAY,QAAQ,GAAG;AAC/B,WAAO,MAAM,YAAY,QAAQ;AAAA,EACnC;AAEA,QAAM,UAAU,oBAAoB,KAAK;AAGzC,MAAI,CAAC,SAAS;AACZ;AAAA,MACE;AAAA,MACA,aAAa,MAAM,mCAAmC,MAAM;AAAA,IAC9D;AAAA,EACF;AAEA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G;AAAA,EACL;AACF;AAEA,SAAS,sBAA0C;AAGjD,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,MAAM,CAAC;AAAA,IACP,SAAS;AAAA,IAAC;AAAA,IACV,UAAU;AAAA,IAAC;AAAA,IACX,aAAa;AAAA,IAAC;AAAA,EAChB;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtime/turbopack/module.ts"],"sourcesContent":["import { logDebug, logError } from '#internal/utils/logger';\nimport { loadChunkWithScope } from './chunk-loader';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\nimport { getSharedModule, getTurbopackModules } from './shared-modules';\n\n/**\n * Function signature for Turbopack module initializers.\n * These functions are generated by Turbopack and initialize module exports.\n */\nexport type TurbopackModuleInit = (\n turbopackContext: TurbopackContext,\n module: TurbopackModule,\n exports: Record<string, unknown>,\n) => void;\n\ninterface TurbopackHotModule {\n active: boolean;\n data: Record<string, unknown>;\n accept(): void;\n dispose(callback?: (data: Record<string, unknown>) => void): void;\n invalidate(): void;\n}\n\ninterface TurbopackModule {\n exports: Record<string, unknown>;\n hot: TurbopackHotModule;\n}\n\n/**\n * The context object passed to Turbopack module initializers.\n * This provides the runtime API that modules use for imports, exports, and HMR.\n */\ninterface TurbopackContext {\n /** HMR (Hot Module Replacement) - not implemented for remote components */\n k: {\n register(): void;\n registerExports(): void;\n signature(): (fn: unknown) => unknown;\n };\n /** ESM exports setup */\n s: (\n bindings:\n | Record<string, () => unknown>\n | [...([string, () => unknown] | [string, number, () => unknown])],\n esmId?: string | number,\n ) => void;\n /** Import module */\n i: (importId: string | number) => Record<string, unknown> | undefined;\n /** Require module */\n r: (requireId: string | number) => unknown;\n /** Value exports */\n v: (value: unknown) => void;\n /**\n * Export URL — used by static asset modules (images, fonts, JSON, etc.).\n * The entire body of a Turbopack asset module is a single `ctx.q(url)` call\n * that sets `module.exports` to the asset URL string.\n */\n q: (value: unknown, esmId?: string | number) => void;\n /**\n * Export namespace — used when Turbopack inlines a precomputed ESM\n * namespace object as the module's exports. Called as `ctx.n(namespace)`\n * for the current module, or `ctx.n(namespace, esmId)` to target another\n * cached module. Mirrors upstream Turbopack's `exportNamespace` helper.\n */\n n: (namespace: unknown, esmId?: string | number) => void;\n /** Async module initializer */\n a: (\n mod: (\n handleDeps: unknown,\n setResult: (value: unknown) => void,\n ) => Promise<void>,\n ) => Promise<void>;\n /** Async module loader */\n A: (Aid: string | number) => Promise<unknown>;\n /**\n * Dynamic import tracking. Called in production chunks after ctx.s() to\n * register async/dynamic module relationships. e.g. t.j(importedMod, 58790)\n */\n j: (module: unknown, esmId?: string | number) => void;\n /** Chunk loader */\n l: (url: string) => Promise<unknown> | undefined;\n /**\n * Resolve absolute path — Turbopack uses this when constructing source-\n * map and debug URLs (e.g. ``${`file://${ctx.P('rel/path')}`}``). Browser\n * context has no real filesystem path, so the polyfill passes the input\n * through unchanged.\n */\n P: (path: string) => string;\n /**\n * Relative URL constructor — invoked as `new ctx.U(input)` by code that\n * Turbopack compiles from `new URL(<rel>, import.meta.url)`. Must be a\n * real constructor (not method shorthand) so `new` works; prototype is\n * `URL.prototype` so `instanceof URL` holds on the result.\n */\n U: new (\n input: string,\n ) => URL;\n /** Global object for this bundle */\n g: unknown;\n /** Module object */\n m: TurbopackModule;\n /** Exports object */\n e: Record<string, unknown>;\n}\n\n/**\n * Relative URL constructor — mirrors Turbopack's `relativeURL` helper for\n * the source pattern `new URL('./asset', import.meta.url)`. Declared as a\n * named function expression (not method shorthand) so that `new ctx.U(...)`\n * works; method shorthand creates non-constructable functions that throw\n * `TypeError: ... is not a constructor` under `new`.\n *\n * The body mirrors upstream Turbopack byte-for-byte: take the input URL\n * relative to a synthetic base, copy URL fields onto `this` as plain\n * values, override `href`/`pathname`/`origin`/`protocol`/`toString`/`toJSON`\n * to preserve the original input as the canonical representation, and\n * inherit `URL.prototype` so `instanceof URL` holds.\n */\nfunction RelativeURL(this: URL, inputUrl: string): void {\n const realUrl = new URL(inputUrl, 'x:/');\n const values: Record<string, unknown> = {};\n for (const key in realUrl) {\n values[key] = (realUrl as unknown as Record<string, unknown>)[key];\n }\n values.href = inputUrl;\n values.pathname = inputUrl.replace(/[?#].*/, '');\n values.origin = '';\n values.protocol = '';\n values.toString = () => inputUrl;\n values.toJSON = () => inputUrl;\n for (const key in values) {\n Object.defineProperty(this, key, {\n enumerable: true,\n configurable: true,\n value: values[key],\n });\n }\n}\nRelativeURL.prototype = URL.prototype;\n\n/**\n * Turbopack pushes chunks as flat arrays in one of two shapes:\n *\n * Module chunk (common case):\n * [scriptElement, id1, factory1, id2, factory2, ...]\n * - index 0: the script Element (document.currentScript) or undefined\n * - alternating pairs: numeric ID (prod) or path string (dev), then factory function\n *\n * Runtime manifest (bootstrapper only, no module factories):\n * [scriptElement, { otherChunks: [...], runtimeModuleIds: [...] }]\n *\n * Newer Next.js canary versions may also store modules as a plain object\n * { [moduleId]: factory } rather than as an array.\n */\ntype BundleModules =\n | (\n | Element\n | string\n | number\n | TurbopackModuleInit\n | Record<string, TurbopackModuleInit>\n | null\n | undefined\n )[]\n | Record<string, TurbopackModuleInit>\n | undefined;\n\n/**\n * Resolves a module within a scope: checks shared modules first, then\n * falls back to Turbopack module resolution. This is the scope-local\n * equivalent of the global __webpack_require__ dispatcher.\n */\nexport function requireModule(\n scope: RemoteScope,\n moduleId: string | number,\n fullId?: string,\n): unknown {\n const idStr = String(moduleId);\n\n // Shared modules are NOT cached in moduleCache because ctx.s() also\n // uses moduleCache for esmId lookups. Caching the host's frozen module\n // object here would cause ctx.s() to attempt Object.defineProperty on\n // it, failing with \"Cannot redefine property\" for non-configurable\n // exports. Keeping shared modules in their own map avoids the collision.\n //\n // Exact shared IDs must win over stale remote moduleCache entries. This is\n // a compatibility guard for the old shared-modules architecture, where a\n // remote chunk can instantiate a shared module before the broker has claimed\n // that ID. Delete this special ordering once all shared modules are resolved\n // through scope adapters before any remote factory can execute.\n const sharedModule = getSharedModule(scope, moduleId);\n if (sharedModule !== null) {\n if (scope.moduleCache[idStr]) {\n logDebug(\n 'TurbopackModule',\n `Shared module \"${idStr}\" resolved from host and overrides a cached remote copy in \"${scope.scopedName}\"`,\n );\n }\n return sharedModule;\n }\n\n // moduleCache is checked first inside handleTurbopackModule too, but\n // checking here keeps non-shared re-entry cheap.\n if (scope.moduleCache[idStr]) return scope.moduleCache[idStr];\n\n return handleTurbopackModule(\n scope,\n idStr,\n fullId ?? formatRemoteId(scope, idStr),\n );\n}\n\n/**\n * Handles Turbopack module resolution and execution.\n * Finds a module in the Turbopack bundle, executes its initializer with a\n * custom runtime context, and returns the module exports.\n */\nexport function handleTurbopackModule(\n scope: RemoteScope,\n moduleId: string,\n id: string,\n): unknown {\n // Cache check must come before module init lookup. Module initializers\n // re-enter handleTurbopackModule for their own imports, so without this\n // guard circular dependencies would infinite-loop.\n if (scope.moduleCache[moduleId]) {\n return scope.moduleCache[moduleId];\n }\n\n const modules = getTurbopackModules(scope) as BundleModules;\n\n // Log only if bundle is completely missing (critical error)\n if (!modules) {\n logError(\n 'TurbopackModule',\n `TURBOPACK_${scope.globalKey} is undefined (scope: \"${scope.scopedName}\")`,\n );\n }\n\n const moduleInit = findModuleInit(modules, moduleId);\n const exports = {} as Record<string, unknown>;\n const moduleExports = {\n exports,\n hot: createNoopHotModule(),\n };\n\n if (typeof moduleInit !== 'function') {\n throw new Error(\n `Module ${id} not found in bundle ${scope.name} with id ${moduleId}`,\n );\n }\n\n // store a reference to the module exports in the cache before execution\n // to handle circular dependencies\n scope.moduleCache[moduleId] = moduleExports.exports;\n\n // execute the module initializer with our custom Turbopack context\n moduleInit(\n createTurbopackContext(\n scope,\n exports,\n moduleExports,\n modules,\n moduleInit,\n id,\n ),\n moduleExports,\n exports,\n );\n\n // update the cache with the final exports (may have changed during execution)\n if (scope.moduleCache[moduleId] !== moduleExports.exports) {\n scope.moduleCache[moduleId] = moduleExports.exports;\n }\n\n return moduleExports.exports;\n}\n\n/**\n * Finds the module initializer function for a given ID in the Turbopack bundle.\n * Handles all bundle shapes: flat array, object map, nested arrays, and\n * embedded object entries within arrays. Performs exact match first, then\n * falls back to startsWith for dev-mode IDs with appended qualifiers.\n */\nexport function findModuleInit(\n modules: BundleModules | unknown[] | undefined,\n moduleId: string,\n): TurbopackModuleInit | undefined {\n if (!modules || typeof modules !== 'object') return;\n\n // Object format: { [id]: factory } (newer Next.js canary builds)\n if (!Array.isArray(modules)) {\n const key =\n moduleId in modules\n ? moduleId\n : Object.keys(modules).find((k) => k.startsWith(moduleId));\n return key !== undefined ? modules[key] : undefined;\n }\n\n const flat = modules.flat();\n\n // Two-pass ID search: exact match first to avoid prefix false positives.\n // The startsWith fallback handles dev-mode IDs with appended qualifiers\n // such as \"[project]/path.tsx [app-client] (ecmascript, async loader)\".\n let idx = flat.findIndex((e) => String(e) === String(moduleId));\n if (idx < 0) {\n idx = flat.findIndex(\n (e) => typeof e === 'string' && e.startsWith(moduleId),\n );\n }\n if (idx >= 0) {\n // Factory is the first function entry that follows the module ID\n return flat\n .slice(idx + 1)\n .find((e): e is TurbopackModuleInit => typeof e === 'function');\n }\n\n // Embedded object map: entries of the form { [moduleId]: factory }\n for (const entry of flat) {\n if (!entry || typeof entry !== 'object') continue;\n const obj = entry as Record<string, TurbopackModuleInit>;\n if (moduleId in obj) return obj[moduleId];\n const prefixKey = Object.keys(obj).find((k) => k.startsWith(moduleId));\n if (prefixKey) return obj[prefixKey];\n }\n return undefined;\n}\n\n/**\n * Creates the Turbopack context object that provides the runtime API for modules.\n * All context methods close over the scope directly — no global dispatch needed\n * for internal module-to-module calls.\n */\nfunction createTurbopackContext(\n scope: RemoteScope,\n exports: Record<string, unknown>,\n moduleExports: TurbopackModule,\n modules: BundleModules,\n moduleInit: TurbopackModuleInit,\n id: string,\n): TurbopackContext {\n /** Scope-local require: shared modules → turbopack module resolution. */\n const scopedRequire = (moduleId: string | number): unknown =>\n requireModule(scope, moduleId, formatRemoteId(scope, String(moduleId)));\n\n return {\n // HMR not implemented for Remote Components\n k: {\n register() {\n // omit\n },\n registerExports() {\n // omit\n },\n signature() {\n return (fn: unknown) => fn;\n },\n },\n\n // ESM exports setup\n s(\n bindings:\n | Record<string, () => unknown>\n | [...([string, () => unknown] | [string, number, () => unknown])],\n esmId?: string | number,\n ) {\n let mod = exports;\n if (typeof esmId === 'string' || typeof esmId === 'number') {\n if (!scope.moduleCache[esmId]) {\n scope.moduleCache[esmId] = {} as Record<string, unknown>;\n }\n mod = scope.moduleCache[esmId] as Record<string, unknown>;\n }\n\n Object.defineProperty(mod, '__esModule', { value: true });\n if (Array.isArray(bindings)) {\n let i = 0;\n while (i < bindings.length) {\n const propName = bindings[i++] as string;\n const tagOrFunc = bindings[i++];\n if (typeof tagOrFunc === 'number') {\n Object.defineProperty(mod, propName, {\n value: bindings[i++],\n enumerable: true,\n writable: false,\n });\n } else {\n const getterFn = tagOrFunc as () => unknown;\n if (typeof bindings[i] === 'function') {\n const setterFn = bindings[i++] as (v: unknown) => unknown;\n Object.defineProperty(mod, propName, {\n get: getterFn,\n set: setterFn,\n enumerable: true,\n });\n } else {\n Object.defineProperty(mod, propName, {\n get: getterFn,\n enumerable: true,\n });\n }\n }\n }\n }\n },\n\n // import — resolves directly via scope, no global dispatch\n i(importId: string | number) {\n let mod: Record<string, unknown> | undefined;\n if (typeof importId === 'string') {\n // parse export syntax if present (e.g., \"module <export foo as bar>\")\n const { exportSource, exportName } =\n /\\s+<export (?<exportSource>.*?) as (?<exportName>.*?)>$/.exec(\n importId,\n )?.groups ?? {};\n const normalizedId = importId.replace(\n /\\s+<export(?<specifier>.*)>$/,\n '',\n );\n mod = scopedRequire(normalizedId) as\n | Record<string, unknown>\n | undefined;\n // map the requested export to the module exports\n if (\n mod &&\n exportSource &&\n exportName &&\n (exportSource === '*' || typeof mod[exportSource] !== 'undefined') &&\n typeof mod[exportName] === 'undefined'\n ) {\n if (exportSource === '*') {\n mod[exportName] = mod;\n } else {\n mod[exportName] = mod[exportSource];\n }\n }\n } else {\n mod = scopedRequire(importId) as Record<string, unknown> | undefined;\n }\n\n if (typeof mod !== 'object' || mod === null) {\n mod = { default: mod };\n } else if (\n !('default' in mod) &&\n // ES module namespace objects have a null prototype, so calling\n // mod.toString() directly throws. Use Object.prototype.toString\n // to safely detect them.\n Object.prototype.toString.call(mod) !== '[object Module]'\n ) {\n try {\n mod.default = mod;\n } catch {\n // ignore if mod is not extensible\n }\n }\n return mod;\n },\n\n // require — resolves directly via scope\n r(requireId: string | number) {\n return scopedRequire(requireId);\n },\n\n // exportValue — mirrors upstream Turbopack's `exportValue`, which sets\n // `module.exports = value` regardless of value type. Most importantly,\n // when Turbopack emits an async-loader module the body is\n // ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))\n // The function must be stored as-is so that the consumer's `ctx.A(id)`\n // can invoke it with the real parent-import resolver. Calling it eagerly\n // here (the prior remote-components behavior) ran the loader with the\n // wrong argument and stored a `Promise` as `exports.default`, which then\n // crashed `ctx.A` with `.default is not a function`.\n v(value: unknown) {\n moduleExports.exports = value as Record<string, unknown>;\n },\n\n // exportUrl — used by static asset modules (images, fonts, JSON, etc.).\n // Turbopack emits a tiny module whose entire body is ctx.q(url), which\n // sets module.exports to the asset URL string so importers get the URL\n // as the module's default export.\n q(value: unknown, esmId?: string | number) {\n if (esmId != null) {\n scope.moduleCache[String(esmId)] = value as Record<string, unknown>;\n } else {\n moduleExports.exports = value as Record<string, unknown>;\n }\n },\n\n // exportNamespace — Turbopack emits `ctx.n(namespace, esmId?)` when a\n // module's exports should be replaced wholesale with a precomputed ESM\n // namespace object (commonly at module evaluation time for re-export\n // patterns and CJS-to-ESM interop wrappers). Mirrors upstream\n // `exportNamespace` which sets both `module.exports` and\n // `module.namespaceObject`; remote-components keeps a single exports\n // record per module, so we assign to `exports` only.\n n(namespace: unknown, esmId?: string | number) {\n if (esmId != null) {\n scope.moduleCache[String(esmId)] = namespace as Record<string, unknown>;\n } else {\n moduleExports.exports = namespace as Record<string, unknown>;\n }\n },\n\n // async module initializer\n async a(\n mod: (\n handleDeps: unknown,\n setResult: (value: unknown) => void,\n ) => Promise<void>,\n ) {\n let result;\n await mod(\n () => {\n // not implemented\n },\n (value) => (result = value),\n );\n exports.default = result;\n },\n\n // async module loader — resolves directly via scope.\n //\n // Upstream Turbopack's `asyncLoader` treats `require(id)` itself as the\n // loader function (see `module.exports = loaderFn` set by the factory).\n // remote-components additionally supports `{ default: loaderFn }`, which\n // is what a factory using `ctx.s([['default', () => fn]], ...)` produces.\n // Both shapes must be accepted: when `ctx.n(loaderFn, esmId)` injects a\n // function directly into the cache, the require result is the function\n // itself and there is no `.default` to dereference.\n async A(Aid: string | number) {\n const mod = scopedRequire(Aid);\n const loader =\n typeof mod === 'function'\n ? (mod as (p: (id: string) => unknown) => Promise<unknown>)\n : ((mod as { default?: unknown } | null | undefined)?.default as\n | ((p: (id: string) => unknown) => Promise<unknown>)\n | undefined);\n if (typeof loader !== 'function') {\n throw new Error(\n `Async module loader for \"${Aid}\" is not a function (got ${typeof loader})`,\n );\n }\n return loader((parentId: string) => scopedRequire(parentId));\n },\n\n // dynamic import tracking — no-op for remote components\n j() {\n // omit\n },\n\n // chunk loader — loads directly via scope, no global dispatch\n l(url: string) {\n // find the script tag that loaded the current module to determine base URL\n const flatModules = Array.isArray(modules) ? modules : [];\n const moduleInitIndex = flatModules.indexOf(moduleInit);\n if (moduleInitIndex !== -1) {\n const scriptIndex = flatModules\n .slice(0, moduleInitIndex)\n .findLastIndex((bundleEntry) => bundleEntry instanceof Element);\n if (scriptIndex !== -1) {\n const script = flatModules[scriptIndex] as HTMLScriptElement;\n const scriptSrc = script.getAttribute('data-turbopack-src') || '';\n const nextIndex = scriptSrc.indexOf('/_next');\n const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : '';\n const chunkUrl = `${baseUrl}/_next/${url}`;\n return loadChunkWithScope(scope, formatRemoteId(scope, chunkUrl));\n }\n }\n throw new Error(\n `Failed to load Turbopack chunk \"${url}\" for module \"${id}\". Check the URL is correct.`,\n );\n },\n\n // resolveAbsolutePath — Turbopack uses this to construct file:// URLs\n // for source-map and debug output. Browser context has no real\n // filesystem path; passing the input through unchanged keeps the\n // surface satisfied without inventing values.\n P(path: string): string {\n return path;\n },\n\n // relativeURL constructor — see RelativeURL function declaration above\n // for the constructor-vs-method-shorthand explanation.\n U: RelativeURL as unknown as new (input: string) => URL,\n\n // globalThis substitute shared across all modules in this scope\n g: scope.moduleGlobal,\n m: moduleExports,\n e: exports,\n };\n}\n\nfunction createNoopHotModule(): TurbopackHotModule {\n // Remote Components does not implement HMR, but Next.js dev page-loader\n // modules still call module.hot.* when Turbopack emits Pages Router code.\n return {\n active: true,\n data: {},\n accept() {},\n dispose() {},\n invalidate() {},\n };\n}\n"],"mappings":"AAAA,SAAS,UAAU,gBAAgB;AACnC,SAAS,0BAA0B;AACnC,SAAS,sBAAwC;AACjD,SAAS,iBAAiB,2BAA2B;AAmHrD,SAAS,YAAuB,UAAwB;AACtD,QAAM,UAAU,IAAI,IAAI,UAAU,KAAK;AACvC,QAAM,SAAkC,CAAC;AACzC,aAAW,OAAO,SAAS;AACzB,WAAO,GAAG,IAAK,QAA+C,GAAG;AAAA,EACnE;AACA,SAAO,OAAO;AACd,SAAO,WAAW,SAAS,QAAQ,UAAU,EAAE;AAC/C,SAAO,SAAS;AAChB,SAAO,WAAW;AAClB,SAAO,WAAW,MAAM;AACxB,SAAO,SAAS,MAAM;AACtB,aAAW,OAAO,QAAQ;AACxB,WAAO,eAAe,MAAM,KAAK;AAAA,MAC/B,YAAY;AAAA,MACZ,cAAc;AAAA,MACd,OAAO,OAAO,GAAG;AAAA,IACnB,CAAC;AAAA,EACH;AACF;AACA,YAAY,YAAY,IAAI;AAkCrB,SAAS,cACd,OACA,UACA,QACS;AACT,QAAM,QAAQ,OAAO,QAAQ;AAa7B,QAAM,eAAe,gBAAgB,OAAO,QAAQ;AACpD,MAAI,iBAAiB,MAAM;AACzB,QAAI,MAAM,YAAY,KAAK,GAAG;AAC5B;AAAA,QACE;AAAA,QACA,kBAAk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AAAA,MACF;AACA,aAAO,OAAO,CAAC,aAAqB,cAAc,QAAQ,CAAC;AAAA,IAC7D;AAAA;AAAA,IAGA,IAAI;AAAA,IAEJ;AAAA;AAAA,IAGA,EAAE,KAAa;AAEb,YAAM,cAAc,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC;AACxD,YAAM,kBAAkB,YAAY,QAAQ,UAAU;AACtD,UAAI,oBAAoB,IAAI;AAC1B,cAAM,cAAc,YACjB,MAAM,GAAG,eAAe,EACxB,cAAc,CAAC,gBAAgB,uBAAuB,OAAO;AAChE,YAAI,gBAAgB,IAAI;AACtB,gBAAM,SAAS,YAAY,WAAW;AACtC,gBAAM,YAAY,OAAO,aAAa,oBAAoB,KAAK;AAC/D,gBAAM,YAAY,UAAU,QAAQ,QAAQ;AAC5C,gBAAM,UAAU,cAAc,KAAK,UAAU,MAAM,GAAG,SAAS,IAAI;AACnE,gBAAM,WAAW,GAAG,iBAAiB;AACrC,iBAAO,mBAAmB,OAAO,eAAe,OAAO,QAAQ,CAAC;AAAA,QAClE;AAAA,MACF;AACA,YAAM,IAAI;AAAA,QACR,mCAAmC,oBAAoB;AAAA,MACzD;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,EAAE,MAAsB;AACtB,aAAO;AAAA,IACT;AAAA;AAAA;AAAA,IAIA,GAAG;AAAA;AAAA,IAGH,GAAG,MAAM;AAAA,IACT,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACF;AAEA,SAAS,sBAA0C;AAGjD,SAAO;AAAA,IACL,QAAQ;AAAA,IACR,MAAM,CAAC;AAAA,IACP,SAAS;AAAA,IAAC;AAAA,IACV,UAAU;AAAA,IAAC;AAAA,IACX,aAAa;AAAA,IAAC;AAAA,EAChB;AACF;","names":[]}
@@ -67,12 +67,19 @@ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}
67
67
  "sharedModuleId"
68
68
  );
69
69
  if (sharedModuleId) {
70
- const { default: sharedModuleInitializerInstance } = (0, import_module.handleTurbopackModule)(
70
+ const moduleExports = (0, import_module.handleTurbopackModule)(
71
71
  scope,
72
72
  sharedModuleId,
73
73
  (0, import_remote_scope.formatRemoteId)(scope, String(sharedModuleInitializerId))
74
74
  );
75
- sharedModuleInitializer = sharedModuleInitializerInstance;
75
+ const loaderCandidate = typeof moduleExports === "function" ? moduleExports : moduleExports?.default;
76
+ if (typeof loaderCandidate === "function") {
77
+ sharedModuleInitializer = loaderCandidate(
78
+ (parentId) => (0, import_module.requireModule)(scope, parentId)
79
+ );
80
+ } else if (loaderCandidate && typeof loaderCandidate.then === "function") {
81
+ sharedModuleInitializer = loaderCandidate;
82
+ }
76
83
  }
77
84
  }
78
85
  if (sharedModuleInitializer) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/shared-modules.ts"],"sourcesContent":["import {\n createSharedModulePlan,\n installSharedModulePlan,\n isSharedModuleManifest,\n type RemoteSharedModules,\n SHARED_MODULE_MANIFEST_PROTOCOL,\n type SharedModuleFactory,\n type SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { findModuleInit, handleTurbopackModule } from './module';\nimport {\n ASYNC_MODULE_CALLBACK_RE,\n ASYNC_MODULE_LOADER_RE,\n extractGroup,\n normalizeModuleId,\n REMOTE_SHARED_ASSIGNMENT_RE,\n REMOTE_SHARED_MARKER_RE,\n} from './patterns';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\n\nconst DEDUPLICATION_WARNING =\n 'This module will not be deduplicated — the remote may load its own copy, ' +\n 'which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).';\n// `asyncSharedModuleId` accepts: quoted string, integer, or integer in\n// scientific notation (e.g. `35e3`). Production minifiers occasionally\n// emit the scientific form; see normalizeModuleId() / MODULE_ID_PATTERN\n// in ./patterns.ts for the matching marker-extraction path.\nconst INLINE_REMOTE_SHARED_RE =\n /[\"']?__remote_shared_module_(?<specifier>[^\"':]+)[\"']?\\s*:\\s*\\(\\)\\s*=>\\s*(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>\"[^\"]+\"|[0-9]+e[0-9]+|[0-9]+)\\)/g;\n\n/**\n * Returns the flat module list for a scope.\n *\n * The primary source is `scope.turbopackModules` — a flat array populated by\n * the push interceptor in handleTurbopackChunk. This is immune to the\n * turbopack runtime replacing the TURBOPACK global (canary builds swap the\n * array for a deferred-loading dispatcher object).\n *\n * Falls back to reading the global for pre-populated bundles where the push\n * interceptor was never installed.\n */\nexport function getTurbopackModules(scope: RemoteScope): unknown[] | undefined {\n if (scope.turbopackModules.length > 0) {\n return scope.turbopackModules;\n }\n\n // Fallback: read the global for pre-populated bundles or legacy setups.\n const self = globalThis as GlobalScope;\n const raw = self[`TURBOPACK_${scope.globalKey}`];\n if (!raw) return undefined;\n\n if (Array.isArray(raw)) {\n return (raw as unknown[]).flat();\n }\n return Object.entries(raw as Record<string, unknown>).flat();\n}\n\n/**\n * Initializes shared modules between the host application and remote components.\n * This enables sharing of common dependencies like React to avoid duplicate instances.\n *\n * The function works by:\n * 1. Looking for a shared module initializer in the Turbopack bundle\n * 2. Extracting module IDs from the initializer\n * 3. Loading the corresponding host modules and mapping them to the remote's expected IDs\n */\nexport async function initializeSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory> = {},\n remoteShared: RemoteSharedModules = {},\n // biome-ignore lint/suspicious/noConfusingVoidType: Runtime is undefined but in TS land service it is void\n): Promise<void[]> {\n const allModules = getTurbopackModules(scope);\n\n logDebug(\n 'SharedModules',\n `initializeSharedModules: scope=\"${scope.scopedName}\", ` +\n `allModules=${allModules ? allModules.length : 'null'}, ` +\n `hostShared=[${Object.keys(hostShared).join(', ')}], ` +\n `remoteShared=${JSON.stringify(remoteShared)}`,\n );\n\n let sharedModuleInitializer: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }> | null = null;\n\n // find the shared module initializer in the Turbopack bundle\n if (allModules) {\n // find the shared module initializer module id by looking for\n // a function that contains the TURBOPACK_REMOTE_SHARED pattern\n const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {\n if (typeof idOrFunc !== 'function') {\n return false;\n }\n const funcCode = idOrFunc.toString();\n return REMOTE_SHARED_MARKER_RE.test(funcCode);\n });\n\n // if found, extract the shared module initializer\n // first element in the array is always the source script element\n if (sharedModuleInitializerIndex > 0) {\n const sharedModuleInitializerCode = (\n allModules[sharedModuleInitializerIndex] as () => unknown\n ).toString();\n const sharedModuleInitializerId = allModules[\n sharedModuleInitializerIndex - 1\n ] as string | number;\n // extract the shared module id from the function code\n const sharedModuleId = extractGroup(\n REMOTE_SHARED_ASSIGNMENT_RE,\n sharedModuleInitializerCode,\n 'sharedModuleId',\n );\n // load the shared module initializer using the extracted module id\n if (sharedModuleId) {\n const { default: sharedModuleInitializerInstance } =\n handleTurbopackModule(\n scope,\n sharedModuleId,\n formatRemoteId(scope, String(sharedModuleInitializerId)),\n ) as {\n default: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n };\n sharedModuleInitializer = sharedModuleInitializerInstance;\n }\n }\n\n // if we have a shared module initializer, load the shared modules from the host application\n if (sharedModuleInitializer) {\n const { shared } = await sharedModuleInitializer;\n // map shared module ids to their initializer functions\n const sharedModuleIds = extractSharedModuleIds(shared, scope);\n logDebug(\n 'SharedModules',\n `Resolved shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(sharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(sharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n const inlineSharedModuleIds = extractInlineSharedModuleIds(\n allModules,\n scope,\n );\n if (Object.keys(inlineSharedModuleIds).length > 0) {\n logDebug(\n 'SharedModules',\n `Resolved inline shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(inlineSharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(inlineSharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for inline ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n logWarn(\n 'SharedModules',\n `No shared module initializer found in bundle for scope=\"${scope.scopedName}\" — falling back to remoteShared mapping`,\n );\n } else {\n logWarn(\n 'SharedModules',\n `No TURBOPACK modules found for scope=\"${scope.scopedName}\" (TURBOPACK_${scope.globalKey} is empty)`,\n );\n }\n\n const normalizedRemoteShared =\n normalizeRemoteSharedForTurbopackFallback(remoteShared);\n return installSharedModules(\n scope,\n hostShared,\n normalizedRemoteShared,\n (_id, module) =>\n `Shared module \"${module}\" not found for \"${scope.name}\". ${DEDUPLICATION_WARNING}`,\n );\n}\n\n/**\n * Extracts shared module IDs from the shared module initializer functions.\n * This parses the minified Turbopack code to find the module ID mappings.\n */\nfunction extractSharedModuleIds(\n shared: Record<string, string | (() => Promise<unknown>)>,\n scope: RemoteScope,\n): Record<string, string> {\n return Object.entries(shared)\n .filter(([, value]) => typeof value === 'function')\n .reduce<Record<string, string>>((acc, [key, value]) => {\n const asyncSharedModuleId = extractGroup(\n ASYNC_MODULE_LOADER_RE,\n value.toString(),\n 'asyncSharedModuleId',\n );\n\n if (asyncSharedModuleId) {\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (asyncSharedModule) {\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n // map the shared module id to the actual module name\n acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(\n '__remote_shared_module_',\n '',\n );\n }\n }\n return acc;\n }, {});\n}\n\nfunction extractInlineSharedModuleIds(\n allModules: unknown[],\n scope: RemoteScope,\n): Record<string, string> {\n const sharedModuleIds: Record<string, string> = {};\n\n for (const idOrFunc of allModules) {\n if (typeof idOrFunc !== 'function') continue;\n\n const funcCode = idOrFunc.toString();\n if (!funcCode.includes('__remote_shared_module_')) continue;\n\n INLINE_REMOTE_SHARED_RE.lastIndex = 0;\n for (const match of funcCode.matchAll(INLINE_REMOTE_SHARED_RE)) {\n const specifier = match.groups?.specifier;\n const rawAsyncSharedModuleId = stripQuotes(\n match.groups?.asyncSharedModuleId,\n );\n const asyncSharedModuleId = rawAsyncSharedModuleId\n ? normalizeModuleId(rawAsyncSharedModuleId)\n : undefined;\n if (!specifier || !asyncSharedModuleId) continue;\n\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (!asyncSharedModule) continue;\n\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n sharedModuleIds[sharedModuleId ?? asyncSharedModuleId] = specifier;\n }\n }\n\n return sharedModuleIds;\n}\n\nfunction stripQuotes(value: string | undefined): string | undefined {\n if (value?.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\nfunction installSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory>,\n sharedModuleIds: RemoteSharedModules,\n missingMessage: (id: string, module: string) => string,\n): Promise<undefined[]> {\n const plan = createSharedModulePlan({\n bundle: scope.name,\n hostShared,\n remoteShared: sharedModuleIds,\n scope: `remote:${scope.scopedName}`,\n callerTag: 'SharedModules',\n });\n\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n // Compatibility with the old shared-modules architecture: a remote\n // factory may have already cached its own implementation for this ID.\n // The broker-owned scope.sharedModules entry must replace it. Remove\n // this cache cleanup once Turbopack remotes cannot execute shared\n // factories before the scoped share plan is installed.\n delete scope.moduleCache[entry.id];\n }\n }\n\n return installSharedModulePlan({\n plan,\n target: scope.sharedModules,\n callerTag: 'SharedModules',\n onMissing: (entry) => {\n logError('SharedModules', missingMessage(entry.id, entry.specifier));\n },\n }).then((results) => {\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n delete scope.moduleCache[entry.id];\n }\n }\n return results;\n });\n}\n\nfunction preferSharedManifest(\n sharedModuleIds: Record<string, string>,\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (!isSharedModuleManifest(remoteShared)) return sharedModuleIds;\n\n const extractedIdBySpecifier = new Map(\n Object.entries(sharedModuleIds).map(([id, specifier]) => [specifier, id]),\n );\n\n return {\n protocol: SHARED_MODULE_MANIFEST_PROTOCOL,\n requirements: remoteShared.requirements.map((requirement) => {\n return {\n ...requirement,\n id: extractedIdBySpecifier.get(requirement.specifier) ?? requirement.id,\n };\n }),\n };\n}\n\nfunction normalizeRemoteSharedForTurbopackFallback(\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (isSharedModuleManifest(remoteShared)) {\n return {\n ...remoteShared,\n requirements: remoteShared.requirements.map((requirement) => ({\n ...requirement,\n id:\n typeof requirement.id === 'string'\n ? requirement.id.replace('[app-ssr]', '[app-client]')\n : requirement.id,\n })),\n } satisfies SharedModuleManifest;\n }\n\n // @legacy(remote-components<=0.4.x): normalize server-side generated\n // Turbopack IDs from the historical shared map until 0.4.x remotes are\n // outside the compatibility window.\n return Object.fromEntries(\n Object.entries(remoteShared).map(([id, module]) => [\n id.replace('[app-ssr]', '[app-client]'),\n module,\n ]),\n );\n}\n\n/**\n * Returns a shared module for the given scope and module ID.\n * Shared modules are common dependencies like React that are provided by the host.\n */\nexport function getSharedModule(\n scope: RemoteScope,\n id: string | number,\n): unknown {\n const idStr = String(id);\n\n // Exact match first (covers both string and numeric IDs)\n if (scope.sharedModules[idStr] !== undefined) {\n return scope.sharedModules[idStr];\n }\n\n // Fallback: the id may be a bundle-prefixed string like \"[bundle] /react/index.js\"\n // or a Turbopack dev id like \"[project]/node_modules/react/index.js [client]\".\n // Only path-like keys use the dev-id qualifier match to avoid \"react\"\n // matching \"react-dom\".\n for (const [key, value] of Object.entries(scope.sharedModules)) {\n if (\n typeof value !== 'undefined' &&\n idStr !== key &&\n matchesSharedModuleKey(idStr, key)\n ) {\n return value;\n }\n }\n\n return null;\n}\n\nfunction matchesSharedModuleKey(id: string, key: string): boolean {\n if (id.endsWith(key)) return true;\n if (!key.includes('/') && !key.endsWith('.js')) return false;\n\n const index = id.lastIndexOf(key);\n if (index < 0) return false;\n\n const afterKey = id.slice(index + key.length);\n return /^\\s+(?:\\[[^\\]]+\\]\\s*)?(?:\\([^)]*\\))?$/.test(afterKey);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAQO;AAEP,oBAA4C;AAC5C,oBAAsD;AACtD,sBAOO;AACP,0BAAiD;AAEjD,MAAM,wBACJ;AAMF,MAAM,0BACJ;AAaK,SAAS,oBAAoB,OAA2C;AAC7E,MAAI,MAAM,iBAAiB,SAAS,GAAG;AACrC,WAAO,MAAM;AAAA,EACf;AAGA,QAAM,OAAO;AACb,QAAM,MAAM,KAAK,aAAa,MAAM,WAAW;AAC/C,MAAI,CAAC;AAAK,WAAO;AAEjB,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAQ,IAAkB,KAAK;AAAA,EACjC;AACA,SAAO,OAAO,QAAQ,GAA8B,EAAE,KAAK;AAC7D;AAWA,eAAsB,wBACpB,OACA,aAAkD,CAAC,GACnD,eAAoC,CAAC,GAEpB;AACjB,QAAM,aAAa,oBAAoB,KAAK;AAE5C;AAAA,IACE;AAAA,IACA,mCAAmC,MAAM,2BACzB,aAAa,WAAW,SAAS,uBAChC,OAAO,KAAK,UAAU,EAAE,KAAK,IAAI,oBAChC,KAAK,UAAU,YAAY;AAAA,EAC/C;AAEA,MAAI,0BAEQ;AAGZ,MAAI,YAAY;AAGd,UAAM,+BAA+B,WAAW,UAAU,CAAC,aAAa;AACtE,UAAI,OAAO,aAAa,YAAY;AAClC,eAAO;AAAA,MACT;AACA,YAAM,WAAW,SAAS,SAAS;AACnC,aAAO,wCAAwB,KA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AwC,KAAK,QAAQ;AAC9D;","names":["module"]}
1
+ {"version":3,"sources":["../../../../src/runtime/turbopack/shared-modules.ts"],"sourcesContent":["import {\n createSharedModulePlan,\n installSharedModulePlan,\n isSharedModuleManifest,\n type RemoteSharedModules,\n SHARED_MODULE_MANIFEST_PROTOCOL,\n type SharedModuleFactory,\n type SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { findModuleInit, handleTurbopackModule, requireModule } from './module';\nimport {\n ASYNC_MODULE_CALLBACK_RE,\n ASYNC_MODULE_LOADER_RE,\n extractGroup,\n normalizeModuleId,\n REMOTE_SHARED_ASSIGNMENT_RE,\n REMOTE_SHARED_MARKER_RE,\n} from './patterns';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\n\nconst DEDUPLICATION_WARNING =\n 'This module will not be deduplicated — the remote may load its own copy, ' +\n 'which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).';\n// `asyncSharedModuleId` accepts: quoted string, integer, or integer in\n// scientific notation (e.g. `35e3`). Production minifiers occasionally\n// emit the scientific form; see normalizeModuleId() / MODULE_ID_PATTERN\n// in ./patterns.ts for the matching marker-extraction path.\nconst INLINE_REMOTE_SHARED_RE =\n /[\"']?__remote_shared_module_(?<specifier>[^\"':]+)[\"']?\\s*:\\s*\\(\\)\\s*=>\\s*(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>\"[^\"]+\"|[0-9]+e[0-9]+|[0-9]+)\\)/g;\n\n/**\n * Returns the flat module list for a scope.\n *\n * The primary source is `scope.turbopackModules` — a flat array populated by\n * the push interceptor in handleTurbopackChunk. This is immune to the\n * turbopack runtime replacing the TURBOPACK global (canary builds swap the\n * array for a deferred-loading dispatcher object).\n *\n * Falls back to reading the global for pre-populated bundles where the push\n * interceptor was never installed.\n */\nexport function getTurbopackModules(scope: RemoteScope): unknown[] | undefined {\n if (scope.turbopackModules.length > 0) {\n return scope.turbopackModules;\n }\n\n // Fallback: read the global for pre-populated bundles or legacy setups.\n const self = globalThis as GlobalScope;\n const raw = self[`TURBOPACK_${scope.globalKey}`];\n if (!raw) return undefined;\n\n if (Array.isArray(raw)) {\n return (raw as unknown[]).flat();\n }\n return Object.entries(raw as Record<string, unknown>).flat();\n}\n\n/**\n * Initializes shared modules between the host application and remote components.\n * This enables sharing of common dependencies like React to avoid duplicate instances.\n *\n * The function works by:\n * 1. Looking for a shared module initializer in the Turbopack bundle\n * 2. Extracting module IDs from the initializer\n * 3. Loading the corresponding host modules and mapping them to the remote's expected IDs\n */\nexport async function initializeSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory> = {},\n remoteShared: RemoteSharedModules = {},\n // biome-ignore lint/suspicious/noConfusingVoidType: Runtime is undefined but in TS land service it is void\n): Promise<void[]> {\n const allModules = getTurbopackModules(scope);\n\n logDebug(\n 'SharedModules',\n `initializeSharedModules: scope=\"${scope.scopedName}\", ` +\n `allModules=${allModules ? allModules.length : 'null'}, ` +\n `hostShared=[${Object.keys(hostShared).join(', ')}], ` +\n `remoteShared=${JSON.stringify(remoteShared)}`,\n );\n\n let sharedModuleInitializer: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }> | null = null;\n\n // find the shared module initializer in the Turbopack bundle\n if (allModules) {\n // find the shared module initializer module id by looking for\n // a function that contains the TURBOPACK_REMOTE_SHARED pattern\n const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {\n if (typeof idOrFunc !== 'function') {\n return false;\n }\n const funcCode = idOrFunc.toString();\n return REMOTE_SHARED_MARKER_RE.test(funcCode);\n });\n\n // if found, extract the shared module initializer\n // first element in the array is always the source script element\n if (sharedModuleInitializerIndex > 0) {\n const sharedModuleInitializerCode = (\n allModules[sharedModuleInitializerIndex] as () => unknown\n ).toString();\n const sharedModuleInitializerId = allModules[\n sharedModuleInitializerIndex - 1\n ] as string | number;\n // extract the shared module id from the function code\n const sharedModuleId = extractGroup(\n REMOTE_SHARED_ASSIGNMENT_RE,\n sharedModuleInitializerCode,\n 'sharedModuleId',\n );\n // Load the shared-module-initializer module. Turbopack emits its\n // factory body as\n // ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))\n // so `module.exports` IS the loader function (upstream `exportValue`\n // semantics). Earlier versions of remote-components' `ctx.v` eagerly\n // invoked the function and stored the resulting Promise on\n // `exports.default` — that shape is preserved here as a fallback for\n // bundles built against the old runtime, but the primary path now\n // invokes the loader explicitly with `requireModule` as the parent\n // import (the actual scope-bound require).\n if (sharedModuleId) {\n const moduleExports = handleTurbopackModule(\n scope,\n sharedModuleId,\n formatRemoteId(scope, String(sharedModuleInitializerId)),\n );\n type Loader = (\n parentImport: (id: string | number) => unknown,\n ) => Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n const loaderCandidate =\n typeof moduleExports === 'function'\n ? moduleExports\n : (moduleExports as { default?: unknown })?.default;\n if (typeof loaderCandidate === 'function') {\n sharedModuleInitializer = (loaderCandidate as Loader)((parentId) =>\n requireModule(scope, parentId),\n );\n } else if (\n loaderCandidate &&\n typeof (loaderCandidate as { then?: unknown }).then === 'function'\n ) {\n sharedModuleInitializer = loaderCandidate as Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n }\n }\n }\n\n // if we have a shared module initializer, load the shared modules from the host application\n if (sharedModuleInitializer) {\n const { shared } = await sharedModuleInitializer;\n // map shared module ids to their initializer functions\n const sharedModuleIds = extractSharedModuleIds(shared, scope);\n logDebug(\n 'SharedModules',\n `Resolved shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(sharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(sharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n const inlineSharedModuleIds = extractInlineSharedModuleIds(\n allModules,\n scope,\n );\n if (Object.keys(inlineSharedModuleIds).length > 0) {\n logDebug(\n 'SharedModules',\n `Resolved inline shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(inlineSharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(inlineSharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for inline ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n logWarn(\n 'SharedModules',\n `No shared module initializer found in bundle for scope=\"${scope.scopedName}\" — falling back to remoteShared mapping`,\n );\n } else {\n logWarn(\n 'SharedModules',\n `No TURBOPACK modules found for scope=\"${scope.scopedName}\" (TURBOPACK_${scope.globalKey} is empty)`,\n );\n }\n\n const normalizedRemoteShared =\n normalizeRemoteSharedForTurbopackFallback(remoteShared);\n return installSharedModules(\n scope,\n hostShared,\n normalizedRemoteShared,\n (_id, module) =>\n `Shared module \"${module}\" not found for \"${scope.name}\". ${DEDUPLICATION_WARNING}`,\n );\n}\n\n/**\n * Extracts shared module IDs from the shared module initializer functions.\n * This parses the minified Turbopack code to find the module ID mappings.\n */\nfunction extractSharedModuleIds(\n shared: Record<string, string | (() => Promise<unknown>)>,\n scope: RemoteScope,\n): Record<string, string> {\n return Object.entries(shared)\n .filter(([, value]) => typeof value === 'function')\n .reduce<Record<string, string>>((acc, [key, value]) => {\n const asyncSharedModuleId = extractGroup(\n ASYNC_MODULE_LOADER_RE,\n value.toString(),\n 'asyncSharedModuleId',\n );\n\n if (asyncSharedModuleId) {\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (asyncSharedModule) {\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n // map the shared module id to the actual module name\n acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(\n '__remote_shared_module_',\n '',\n );\n }\n }\n return acc;\n }, {});\n}\n\nfunction extractInlineSharedModuleIds(\n allModules: unknown[],\n scope: RemoteScope,\n): Record<string, string> {\n const sharedModuleIds: Record<string, string> = {};\n\n for (const idOrFunc of allModules) {\n if (typeof idOrFunc !== 'function') continue;\n\n const funcCode = idOrFunc.toString();\n if (!funcCode.includes('__remote_shared_module_')) continue;\n\n INLINE_REMOTE_SHARED_RE.lastIndex = 0;\n for (const match of funcCode.matchAll(INLINE_REMOTE_SHARED_RE)) {\n const specifier = match.groups?.specifier;\n const rawAsyncSharedModuleId = stripQuotes(\n match.groups?.asyncSharedModuleId,\n );\n const asyncSharedModuleId = rawAsyncSharedModuleId\n ? normalizeModuleId(rawAsyncSharedModuleId)\n : undefined;\n if (!specifier || !asyncSharedModuleId) continue;\n\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (!asyncSharedModule) continue;\n\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n sharedModuleIds[sharedModuleId ?? asyncSharedModuleId] = specifier;\n }\n }\n\n return sharedModuleIds;\n}\n\nfunction stripQuotes(value: string | undefined): string | undefined {\n if (value?.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\nfunction installSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory>,\n sharedModuleIds: RemoteSharedModules,\n missingMessage: (id: string, module: string) => string,\n): Promise<undefined[]> {\n const plan = createSharedModulePlan({\n bundle: scope.name,\n hostShared,\n remoteShared: sharedModuleIds,\n scope: `remote:${scope.scopedName}`,\n callerTag: 'SharedModules',\n });\n\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n // Compatibility with the old shared-modules architecture: a remote\n // factory may have already cached its own implementation for this ID.\n // The broker-owned scope.sharedModules entry must replace it. Remove\n // this cache cleanup once Turbopack remotes cannot execute shared\n // factories before the scoped share plan is installed.\n delete scope.moduleCache[entry.id];\n }\n }\n\n return installSharedModulePlan({\n plan,\n target: scope.sharedModules,\n callerTag: 'SharedModules',\n onMissing: (entry) => {\n logError('SharedModules', missingMessage(entry.id, entry.specifier));\n },\n }).then((results) => {\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n delete scope.moduleCache[entry.id];\n }\n }\n return results;\n });\n}\n\nfunction preferSharedManifest(\n sharedModuleIds: Record<string, string>,\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (!isSharedModuleManifest(remoteShared)) return sharedModuleIds;\n\n const extractedIdBySpecifier = new Map(\n Object.entries(sharedModuleIds).map(([id, specifier]) => [specifier, id]),\n );\n\n return {\n protocol: SHARED_MODULE_MANIFEST_PROTOCOL,\n requirements: remoteShared.requirements.map((requirement) => {\n return {\n ...requirement,\n id: extractedIdBySpecifier.get(requirement.specifier) ?? requirement.id,\n };\n }),\n };\n}\n\nfunction normalizeRemoteSharedForTurbopackFallback(\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (isSharedModuleManifest(remoteShared)) {\n return {\n ...remoteShared,\n requirements: remoteShared.requirements.map((requirement) => ({\n ...requirement,\n id:\n typeof requirement.id === 'string'\n ? requirement.id.replace('[app-ssr]', '[app-client]')\n : requirement.id,\n })),\n } satisfies SharedModuleManifest;\n }\n\n // @legacy(remote-components<=0.4.x): normalize server-side generated\n // Turbopack IDs from the historical shared map until 0.4.x remotes are\n // outside the compatibility window.\n return Object.fromEntries(\n Object.entries(remoteShared).map(([id, module]) => [\n id.replace('[app-ssr]', '[app-client]'),\n module,\n ]),\n );\n}\n\n/**\n * Returns a shared module for the given scope and module ID.\n * Shared modules are common dependencies like React that are provided by the host.\n */\nexport function getSharedModule(\n scope: RemoteScope,\n id: string | number,\n): unknown {\n const idStr = String(id);\n\n // Exact match first (covers both string and numeric IDs)\n if (scope.sharedModules[idStr] !== undefined) {\n return scope.sharedModules[idStr];\n }\n\n // Fallback: the id may be a bundle-prefixed string like \"[bundle] /react/index.js\"\n // or a Turbopack dev id like \"[project]/node_modules/react/index.js [client]\".\n // Only path-like keys use the dev-id qualifier match to avoid \"react\"\n // matching \"react-dom\".\n for (const [key, value] of Object.entries(scope.sharedModules)) {\n if (\n typeof value !== 'undefined' &&\n idStr !== key &&\n matchesSharedModuleKey(idStr, key)\n ) {\n return value;\n }\n }\n\n return null;\n}\n\nfunction matchesSharedModuleKey(id: string, key: string): boolean {\n if (id.endsWith(key)) return true;\n if (!key.includes('/') && !key.endsWith('.js')) return false;\n\n const index = id.lastIndexOf(key);\n if (index < 0) return false;\n\n const afterKey = id.slice(index + key.length);\n return /^\\s+(?:\\[[^\\]]+\\]\\s*)?(?:\\([^)]*\\))?$/.test(afterKey);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAQO;AAEP,oBAA4C;AAC5C,oBAAqE;AACrE,sBAOO;AACP,0BAAiD;AAEjD,MAAM,wBACJ;AAMF,MAAM,0BACJ;AAaK,SAAS,oBAAoB,OAA2C;AAC7E,MAAI,MAAM,iBAAiB,SAAS,GAAG;AACrC,WAAO,MAAM;AAAA,EACf;AAGA,QAAM,OAAO;AACb,QAAM,MAAM,KAAK,aAAa,MAAM,WAAW;AAC/C,MAAI,CAAC;AAAK,WAAO;AAEjB,MAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,WAAQ,IAAkB,KAAK;AAAA,EACjC;AACA,SAAO,OAAO,QAAQ,GAA8B,EAAE,KAAK;AAC7D;AAWA,eAAsB,wBACpB,OACA,aAAkD,CAAC,GACnD,eAAoC,CAAC,GAEpB;AACjB,QAAM,aAAa,oBAAoB,KAAK;AAE5C;AAAA,IACE;AAAA,IACA,mCAAmC,MAAM,2BACzB,aAAa,WAAW,SAAS,uBAChC,OAAO,KAAK,UAAU,EAAE,KAAK,IAAI,oBAChC,KAAK,UAAU,YAAY;AAAA,EAC/C;AAEA,MAAI,0BAEQ;AAGZ,MAAI,YAAY;AAGd,UAAM,+BAA+B,WAAW,UAAU,CAAC,aAAa;AACtE,UAAI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T;AAEA,SAAS,uBAAuB,IAAY,KAAsB;AAChE,MAAI,GAAG,SAAS,GAAG;AAAG,WAAO;AAC7B,MAAI,CAAC,IAAI,SAAS,GAAG,KAAK,CAAC,IAAI,SAAS,KAAK;AAAG,WAAO;AAEvD,QAAM,QAAQ,GAAG,YAAY,GAAG;AAChC,MAAI,QAAQ;AAAG,WAAO;AAEtB,QAAM,WAAW,GAAG,MAAM,QAAQ,IAAI,MAAM;AAC5C,SAAO,wCAAwC,KAAK,QAAQ;AAC9D;","names":["module"]}
@@ -5,7 +5,7 @@ import {
5
5
  SHARED_MODULE_MANIFEST_PROTOCOL
6
6
  } from "#internal/host/shared/shared-broker";
7
7
  import { logDebug, logError, logWarn } from "#internal/utils/logger";
8
- import { findModuleInit, handleTurbopackModule } from "./module";
8
+ import { findModuleInit, handleTurbopackModule, requireModule } from "./module";
9
9
  import {
10
10
  ASYNC_MODULE_CALLBACK_RE,
11
11
  ASYNC_MODULE_LOADER_RE,
@@ -54,12 +54,19 @@ async function initializeSharedModules(scope, hostShared = {}, remoteShared = {}
54
54
  "sharedModuleId"
55
55
  );
56
56
  if (sharedModuleId) {
57
- const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
57
+ const moduleExports = handleTurbopackModule(
58
58
  scope,
59
59
  sharedModuleId,
60
60
  formatRemoteId(scope, String(sharedModuleInitializerId))
61
61
  );
62
- sharedModuleInitializer = sharedModuleInitializerInstance;
62
+ const loaderCandidate = typeof moduleExports === "function" ? moduleExports : moduleExports?.default;
63
+ if (typeof loaderCandidate === "function") {
64
+ sharedModuleInitializer = loaderCandidate(
65
+ (parentId) => requireModule(scope, parentId)
66
+ );
67
+ } else if (loaderCandidate && typeof loaderCandidate.then === "function") {
68
+ sharedModuleInitializer = loaderCandidate;
69
+ }
63
70
  }
64
71
  }
65
72
  if (sharedModuleInitializer) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/shared-modules.ts"],"sourcesContent":["import {\n createSharedModulePlan,\n installSharedModulePlan,\n isSharedModuleManifest,\n type RemoteSharedModules,\n SHARED_MODULE_MANIFEST_PROTOCOL,\n type SharedModuleFactory,\n type SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { findModuleInit, handleTurbopackModule } from './module';\nimport {\n ASYNC_MODULE_CALLBACK_RE,\n ASYNC_MODULE_LOADER_RE,\n extractGroup,\n normalizeModuleId,\n REMOTE_SHARED_ASSIGNMENT_RE,\n REMOTE_SHARED_MARKER_RE,\n} from './patterns';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\n\nconst DEDUPLICATION_WARNING =\n 'This module will not be deduplicated — the remote may load its own copy, ' +\n 'which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).';\n// `asyncSharedModuleId` accepts: quoted string, integer, or integer in\n// scientific notation (e.g. `35e3`). Production minifiers occasionally\n// emit the scientific form; see normalizeModuleId() / MODULE_ID_PATTERN\n// in ./patterns.ts for the matching marker-extraction path.\nconst INLINE_REMOTE_SHARED_RE =\n /[\"']?__remote_shared_module_(?<specifier>[^\"':]+)[\"']?\\s*:\\s*\\(\\)\\s*=>\\s*(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>\"[^\"]+\"|[0-9]+e[0-9]+|[0-9]+)\\)/g;\n\n/**\n * Returns the flat module list for a scope.\n *\n * The primary source is `scope.turbopackModules` — a flat array populated by\n * the push interceptor in handleTurbopackChunk. This is immune to the\n * turbopack runtime replacing the TURBOPACK global (canary builds swap the\n * array for a deferred-loading dispatcher object).\n *\n * Falls back to reading the global for pre-populated bundles where the push\n * interceptor was never installed.\n */\nexport function getTurbopackModules(scope: RemoteScope): unknown[] | undefined {\n if (scope.turbopackModules.length > 0) {\n return scope.turbopackModules;\n }\n\n // Fallback: read the global for pre-populated bundles or legacy setups.\n const self = globalThis as GlobalScope;\n const raw = self[`TURBOPACK_${scope.globalKey}`];\n if (!raw) return undefined;\n\n if (Array.isArray(raw)) {\n return (raw as unknown[]).flat();\n }\n return Object.entries(raw as Record<string, unknown>).flat();\n}\n\n/**\n * Initializes shared modules between the host application and remote components.\n * This enables sharing of common dependencies like React to avoid duplicate instances.\n *\n * The function works by:\n * 1. Looking for a shared module initializer in the Turbopack bundle\n * 2. Extracting module IDs from the initializer\n * 3. Loading the corresponding host modules and mapping them to the remote's expected IDs\n */\nexport async function initializeSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory> = {},\n remoteShared: RemoteSharedModules = {},\n // biome-ignore lint/suspicious/noConfusingVoidType: Runtime is undefined but in TS land service it is void\n): Promise<void[]> {\n const allModules = getTurbopackModules(scope);\n\n logDebug(\n 'SharedModules',\n `initializeSharedModules: scope=\"${scope.scopedName}\", ` +\n `allModules=${allModules ? allModules.length : 'null'}, ` +\n `hostShared=[${Object.keys(hostShared).join(', ')}], ` +\n `remoteShared=${JSON.stringify(remoteShared)}`,\n );\n\n let sharedModuleInitializer: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }> | null = null;\n\n // find the shared module initializer in the Turbopack bundle\n if (allModules) {\n // find the shared module initializer module id by looking for\n // a function that contains the TURBOPACK_REMOTE_SHARED pattern\n const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {\n if (typeof idOrFunc !== 'function') {\n return false;\n }\n const funcCode = idOrFunc.toString();\n return REMOTE_SHARED_MARKER_RE.test(funcCode);\n });\n\n // if found, extract the shared module initializer\n // first element in the array is always the source script element\n if (sharedModuleInitializerIndex > 0) {\n const sharedModuleInitializerCode = (\n allModules[sharedModuleInitializerIndex] as () => unknown\n ).toString();\n const sharedModuleInitializerId = allModules[\n sharedModuleInitializerIndex - 1\n ] as string | number;\n // extract the shared module id from the function code\n const sharedModuleId = extractGroup(\n REMOTE_SHARED_ASSIGNMENT_RE,\n sharedModuleInitializerCode,\n 'sharedModuleId',\n );\n // load the shared module initializer using the extracted module id\n if (sharedModuleId) {\n const { default: sharedModuleInitializerInstance } =\n handleTurbopackModule(\n scope,\n sharedModuleId,\n formatRemoteId(scope, String(sharedModuleInitializerId)),\n ) as {\n default: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n };\n sharedModuleInitializer = sharedModuleInitializerInstance;\n }\n }\n\n // if we have a shared module initializer, load the shared modules from the host application\n if (sharedModuleInitializer) {\n const { shared } = await sharedModuleInitializer;\n // map shared module ids to their initializer functions\n const sharedModuleIds = extractSharedModuleIds(shared, scope);\n logDebug(\n 'SharedModules',\n `Resolved shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(sharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(sharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n const inlineSharedModuleIds = extractInlineSharedModuleIds(\n allModules,\n scope,\n );\n if (Object.keys(inlineSharedModuleIds).length > 0) {\n logDebug(\n 'SharedModules',\n `Resolved inline shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(inlineSharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(inlineSharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for inline ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n logWarn(\n 'SharedModules',\n `No shared module initializer found in bundle for scope=\"${scope.scopedName}\" — falling back to remoteShared mapping`,\n );\n } else {\n logWarn(\n 'SharedModules',\n `No TURBOPACK modules found for scope=\"${scope.scopedName}\" (TURBOPACK_${scope.globalKey} is empty)`,\n );\n }\n\n const normalizedRemoteShared =\n normalizeRemoteSharedForTurbopackFallback(remoteShared);\n return installSharedModules(\n scope,\n hostShared,\n normalizedRemoteShared,\n (_id, module) =>\n `Shared module \"${module}\" not found for \"${scope.name}\". ${DEDUPLICATION_WARNING}`,\n );\n}\n\n/**\n * Extracts shared module IDs from the shared module initializer functions.\n * This parses the minified Turbopack code to find the module ID mappings.\n */\nfunction extractSharedModuleIds(\n shared: Record<string, string | (() => Promise<unknown>)>,\n scope: RemoteScope,\n): Record<string, string> {\n return Object.entries(shared)\n .filter(([, value]) => typeof value === 'function')\n .reduce<Record<string, string>>((acc, [key, value]) => {\n const asyncSharedModuleId = extractGroup(\n ASYNC_MODULE_LOADER_RE,\n value.toString(),\n 'asyncSharedModuleId',\n );\n\n if (asyncSharedModuleId) {\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (asyncSharedModule) {\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n // map the shared module id to the actual module name\n acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(\n '__remote_shared_module_',\n '',\n );\n }\n }\n return acc;\n }, {});\n}\n\nfunction extractInlineSharedModuleIds(\n allModules: unknown[],\n scope: RemoteScope,\n): Record<string, string> {\n const sharedModuleIds: Record<string, string> = {};\n\n for (const idOrFunc of allModules) {\n if (typeof idOrFunc !== 'function') continue;\n\n const funcCode = idOrFunc.toString();\n if (!funcCode.includes('__remote_shared_module_')) continue;\n\n INLINE_REMOTE_SHARED_RE.lastIndex = 0;\n for (const match of funcCode.matchAll(INLINE_REMOTE_SHARED_RE)) {\n const specifier = match.groups?.specifier;\n const rawAsyncSharedModuleId = stripQuotes(\n match.groups?.asyncSharedModuleId,\n );\n const asyncSharedModuleId = rawAsyncSharedModuleId\n ? normalizeModuleId(rawAsyncSharedModuleId)\n : undefined;\n if (!specifier || !asyncSharedModuleId) continue;\n\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (!asyncSharedModule) continue;\n\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n sharedModuleIds[sharedModuleId ?? asyncSharedModuleId] = specifier;\n }\n }\n\n return sharedModuleIds;\n}\n\nfunction stripQuotes(value: string | undefined): string | undefined {\n if (value?.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\nfunction installSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory>,\n sharedModuleIds: RemoteSharedModules,\n missingMessage: (id: string, module: string) => string,\n): Promise<undefined[]> {\n const plan = createSharedModulePlan({\n bundle: scope.name,\n hostShared,\n remoteShared: sharedModuleIds,\n scope: `remote:${scope.scopedName}`,\n callerTag: 'SharedModules',\n });\n\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n // Compatibility with the old shared-modules architecture: a remote\n // factory may have already cached its own implementation for this ID.\n // The broker-owned scope.sharedModules entry must replace it. Remove\n // this cache cleanup once Turbopack remotes cannot execute shared\n // factories before the scoped share plan is installed.\n delete scope.moduleCache[entry.id];\n }\n }\n\n return installSharedModulePlan({\n plan,\n target: scope.sharedModules,\n callerTag: 'SharedModules',\n onMissing: (entry) => {\n logError('SharedModules', missingMessage(entry.id, entry.specifier));\n },\n }).then((results) => {\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n delete scope.moduleCache[entry.id];\n }\n }\n return results;\n });\n}\n\nfunction preferSharedManifest(\n sharedModuleIds: Record<string, string>,\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (!isSharedModuleManifest(remoteShared)) return sharedModuleIds;\n\n const extractedIdBySpecifier = new Map(\n Object.entries(sharedModuleIds).map(([id, specifier]) => [specifier, id]),\n );\n\n return {\n protocol: SHARED_MODULE_MANIFEST_PROTOCOL,\n requirements: remoteShared.requirements.map((requirement) => {\n return {\n ...requirement,\n id: extractedIdBySpecifier.get(requirement.specifier) ?? requirement.id,\n };\n }),\n };\n}\n\nfunction normalizeRemoteSharedForTurbopackFallback(\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (isSharedModuleManifest(remoteShared)) {\n return {\n ...remoteShared,\n requirements: remoteShared.requirements.map((requirement) => ({\n ...requirement,\n id:\n typeof requirement.id === 'string'\n ? requirement.id.replace('[app-ssr]', '[app-client]')\n : requirement.id,\n })),\n } satisfies SharedModuleManifest;\n }\n\n // @legacy(remote-components<=0.4.x): normalize server-side generated\n // Turbopack IDs from the historical shared map until 0.4.x remotes are\n // outside the compatibility window.\n return Object.fromEntries(\n Object.entries(remoteShared).map(([id, module]) => [\n id.replace('[app-ssr]', '[app-client]'),\n module,\n ]),\n );\n}\n\n/**\n * Returns a shared module for the given scope and module ID.\n * Shared modules are common dependencies like React that are provided by the host.\n */\nexport function getSharedModule(\n scope: RemoteScope,\n id: string | number,\n): unknown {\n const idStr = String(id);\n\n // Exact match first (covers both string and numeric IDs)\n if (scope.sharedModules[idStr] !== undefined) {\n return scope.sharedModules[idStr];\n }\n\n // Fallback: the id may be a bundle-prefixed string like \"[bundle] /react/index.js\"\n // or a Turbopack dev id like \"[project]/node_modules/react/index.js [client]\".\n // Only path-like keys use the dev-id qualifier match to avoid \"react\"\n // matching \"react-dom\".\n for (const [key, value] of Object.entries(scope.sharedModules)) {\n if (\n typeof value !== 'undefined' &&\n idStr !== key &&\n matchesSharedModuleKey(idStr, key)\n ) {\n return value;\n }\n }\n\n return null;\n}\n\nfunction matchesSharedModuleKey(id: string, key: string): boolean {\n if (id.endsWith(key)) return true;\n if (!key.includes('/') && !key.endsWith('.js')) return false;\n\n const index = id.lastIndexOf(key);\n if (index < 0) return false;\n\n const afterKey = id.slice(index + key.length);\n return /^\\s+(?:\\[[^\\]]+\\]\\s*)?(?:\\([^)]*\\))?$/.test(afterKey);\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OAGK;AAEP,SAAS,UAAU,UAAU,eAAe;AAC5C,SAAS,gBAAgB,6BAA6B;AACtD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAwC;AAE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AAA,IACZ,OAAO,QAAQ,YAAY,EAAE,IAAI,CAAC,CAAC,IAAI,MAAM,MAAM;AAAA,MACjD,GAAG,QAAQ,aAAa,cAAc;AAAA,MACtC;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAMO,SAAS,gBACd,OACA,IACS;AACT,QAAM,QAAQ,OAAO,EAAE;AAGvB,MAAI,MAAM,cAAc,KAAK,MAAM,QAAW;AAC5C,WAAO,MAAM,cAAc,KAAK;AAAA,EAClC;AAMA,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,aAAa,GAAG;AAC9D,QACE,OAAO,UAAU,eACjB,UAAU,OACV,uBAAuB,OAAO,GAAG,GACjC;AACA,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,uBAAuB,IAAY,KAAsB;AAChE,MAAI,GAAG,SAAS,GAAG;AAAG,WAAO;AAC7B,MAAI,CAAC,IAAI,SAAS,GAAG,KAAK,CAAC,IAAI,SAAS,KAAK;AAAG,WAAO;AAEvD,QAAM,QAAQ,GAAG,YAAY,GAAG;AAChC,MAAI,QAAQ;AAAG,WAAO;AAEtB,QAAM,WAAW,GAAG,MAAM,QAAQ,IAAI,MAAM;AAC5C,SAAO,wCAAwC,KAAK,QAAQ;AAC9D;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtime/turbopack/shared-modules.ts"],"sourcesContent":["import {\n createSharedModulePlan,\n installSharedModulePlan,\n isSharedModuleManifest,\n type RemoteSharedModules,\n SHARED_MODULE_MANIFEST_PROTOCOL,\n type SharedModuleFactory,\n type SharedModuleManifest,\n} from '#internal/host/shared/shared-broker';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { logDebug, logError, logWarn } from '#internal/utils/logger';\nimport { findModuleInit, handleTurbopackModule, requireModule } from './module';\nimport {\n ASYNC_MODULE_CALLBACK_RE,\n ASYNC_MODULE_LOADER_RE,\n extractGroup,\n normalizeModuleId,\n REMOTE_SHARED_ASSIGNMENT_RE,\n REMOTE_SHARED_MARKER_RE,\n} from './patterns';\nimport { formatRemoteId, type RemoteScope } from './remote-scope';\n\nconst DEDUPLICATION_WARNING =\n 'This module will not be deduplicated — the remote may load its own copy, ' +\n 'which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).';\n// `asyncSharedModuleId` accepts: quoted string, integer, or integer in\n// scientific notation (e.g. `35e3`). Production minifiers occasionally\n// emit the scientific form; see normalizeModuleId() / MODULE_ID_PATTERN\n// in ./patterns.ts for the matching marker-extraction path.\nconst INLINE_REMOTE_SHARED_RE =\n /[\"']?__remote_shared_module_(?<specifier>[^\"':]+)[\"']?\\s*:\\s*\\(\\)\\s*=>\\s*(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>\"[^\"]+\"|[0-9]+e[0-9]+|[0-9]+)\\)/g;\n\n/**\n * Returns the flat module list for a scope.\n *\n * The primary source is `scope.turbopackModules` — a flat array populated by\n * the push interceptor in handleTurbopackChunk. This is immune to the\n * turbopack runtime replacing the TURBOPACK global (canary builds swap the\n * array for a deferred-loading dispatcher object).\n *\n * Falls back to reading the global for pre-populated bundles where the push\n * interceptor was never installed.\n */\nexport function getTurbopackModules(scope: RemoteScope): unknown[] | undefined {\n if (scope.turbopackModules.length > 0) {\n return scope.turbopackModules;\n }\n\n // Fallback: read the global for pre-populated bundles or legacy setups.\n const self = globalThis as GlobalScope;\n const raw = self[`TURBOPACK_${scope.globalKey}`];\n if (!raw) return undefined;\n\n if (Array.isArray(raw)) {\n return (raw as unknown[]).flat();\n }\n return Object.entries(raw as Record<string, unknown>).flat();\n}\n\n/**\n * Initializes shared modules between the host application and remote components.\n * This enables sharing of common dependencies like React to avoid duplicate instances.\n *\n * The function works by:\n * 1. Looking for a shared module initializer in the Turbopack bundle\n * 2. Extracting module IDs from the initializer\n * 3. Loading the corresponding host modules and mapping them to the remote's expected IDs\n */\nexport async function initializeSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory> = {},\n remoteShared: RemoteSharedModules = {},\n // biome-ignore lint/suspicious/noConfusingVoidType: Runtime is undefined but in TS land service it is void\n): Promise<void[]> {\n const allModules = getTurbopackModules(scope);\n\n logDebug(\n 'SharedModules',\n `initializeSharedModules: scope=\"${scope.scopedName}\", ` +\n `allModules=${allModules ? allModules.length : 'null'}, ` +\n `hostShared=[${Object.keys(hostShared).join(', ')}], ` +\n `remoteShared=${JSON.stringify(remoteShared)}`,\n );\n\n let sharedModuleInitializer: Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }> | null = null;\n\n // find the shared module initializer in the Turbopack bundle\n if (allModules) {\n // find the shared module initializer module id by looking for\n // a function that contains the TURBOPACK_REMOTE_SHARED pattern\n const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {\n if (typeof idOrFunc !== 'function') {\n return false;\n }\n const funcCode = idOrFunc.toString();\n return REMOTE_SHARED_MARKER_RE.test(funcCode);\n });\n\n // if found, extract the shared module initializer\n // first element in the array is always the source script element\n if (sharedModuleInitializerIndex > 0) {\n const sharedModuleInitializerCode = (\n allModules[sharedModuleInitializerIndex] as () => unknown\n ).toString();\n const sharedModuleInitializerId = allModules[\n sharedModuleInitializerIndex - 1\n ] as string | number;\n // extract the shared module id from the function code\n const sharedModuleId = extractGroup(\n REMOTE_SHARED_ASSIGNMENT_RE,\n sharedModuleInitializerCode,\n 'sharedModuleId',\n );\n // Load the shared-module-initializer module. Turbopack emits its\n // factory body as\n // ctx.v((parentImport) => Promise.all([...]).then(() => parentImport(id)))\n // so `module.exports` IS the loader function (upstream `exportValue`\n // semantics). Earlier versions of remote-components' `ctx.v` eagerly\n // invoked the function and stored the resulting Promise on\n // `exports.default` — that shape is preserved here as a fallback for\n // bundles built against the old runtime, but the primary path now\n // invokes the loader explicitly with `requireModule` as the parent\n // import (the actual scope-bound require).\n if (sharedModuleId) {\n const moduleExports = handleTurbopackModule(\n scope,\n sharedModuleId,\n formatRemoteId(scope, String(sharedModuleInitializerId)),\n );\n type Loader = (\n parentImport: (id: string | number) => unknown,\n ) => Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n const loaderCandidate =\n typeof moduleExports === 'function'\n ? moduleExports\n : (moduleExports as { default?: unknown })?.default;\n if (typeof loaderCandidate === 'function') {\n sharedModuleInitializer = (loaderCandidate as Loader)((parentId) =>\n requireModule(scope, parentId),\n );\n } else if (\n loaderCandidate &&\n typeof (loaderCandidate as { then?: unknown }).then === 'function'\n ) {\n sharedModuleInitializer = loaderCandidate as Promise<{\n shared: Record<string, string | (() => Promise<unknown>)>;\n }>;\n }\n }\n }\n\n // if we have a shared module initializer, load the shared modules from the host application\n if (sharedModuleInitializer) {\n const { shared } = await sharedModuleInitializer;\n // map shared module ids to their initializer functions\n const sharedModuleIds = extractSharedModuleIds(shared, scope);\n logDebug(\n 'SharedModules',\n `Resolved shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(sharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(sharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n const inlineSharedModuleIds = extractInlineSharedModuleIds(\n allModules,\n scope,\n );\n if (Object.keys(inlineSharedModuleIds).length > 0) {\n logDebug(\n 'SharedModules',\n `Resolved inline shared modules for scope=\"${scope.scopedName}\": ${JSON.stringify(inlineSharedModuleIds)}`,\n );\n\n return installSharedModules(\n scope,\n hostShared,\n preferSharedManifest(inlineSharedModuleIds, remoteShared),\n (id, module) =>\n `Host shared module \"${module}\" not found for inline ID ${id}. ${DEDUPLICATION_WARNING}`,\n );\n }\n\n logWarn(\n 'SharedModules',\n `No shared module initializer found in bundle for scope=\"${scope.scopedName}\" — falling back to remoteShared mapping`,\n );\n } else {\n logWarn(\n 'SharedModules',\n `No TURBOPACK modules found for scope=\"${scope.scopedName}\" (TURBOPACK_${scope.globalKey} is empty)`,\n );\n }\n\n const normalizedRemoteShared =\n normalizeRemoteSharedForTurbopackFallback(remoteShared);\n return installSharedModules(\n scope,\n hostShared,\n normalizedRemoteShared,\n (_id, module) =>\n `Shared module \"${module}\" not found for \"${scope.name}\". ${DEDUPLICATION_WARNING}`,\n );\n}\n\n/**\n * Extracts shared module IDs from the shared module initializer functions.\n * This parses the minified Turbopack code to find the module ID mappings.\n */\nfunction extractSharedModuleIds(\n shared: Record<string, string | (() => Promise<unknown>)>,\n scope: RemoteScope,\n): Record<string, string> {\n return Object.entries(shared)\n .filter(([, value]) => typeof value === 'function')\n .reduce<Record<string, string>>((acc, [key, value]) => {\n const asyncSharedModuleId = extractGroup(\n ASYNC_MODULE_LOADER_RE,\n value.toString(),\n 'asyncSharedModuleId',\n );\n\n if (asyncSharedModuleId) {\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (asyncSharedModule) {\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n // map the shared module id to the actual module name\n acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(\n '__remote_shared_module_',\n '',\n );\n }\n }\n return acc;\n }, {});\n}\n\nfunction extractInlineSharedModuleIds(\n allModules: unknown[],\n scope: RemoteScope,\n): Record<string, string> {\n const sharedModuleIds: Record<string, string> = {};\n\n for (const idOrFunc of allModules) {\n if (typeof idOrFunc !== 'function') continue;\n\n const funcCode = idOrFunc.toString();\n if (!funcCode.includes('__remote_shared_module_')) continue;\n\n INLINE_REMOTE_SHARED_RE.lastIndex = 0;\n for (const match of funcCode.matchAll(INLINE_REMOTE_SHARED_RE)) {\n const specifier = match.groups?.specifier;\n const rawAsyncSharedModuleId = stripQuotes(\n match.groups?.asyncSharedModuleId,\n );\n const asyncSharedModuleId = rawAsyncSharedModuleId\n ? normalizeModuleId(rawAsyncSharedModuleId)\n : undefined;\n if (!specifier || !asyncSharedModuleId) continue;\n\n const asyncSharedModule = findModuleInit(\n getTurbopackModules(scope),\n asyncSharedModuleId,\n );\n if (!asyncSharedModule) continue;\n\n const sharedModuleId = extractGroup(\n ASYNC_MODULE_CALLBACK_RE,\n asyncSharedModule.toString(),\n 'sharedModuleId',\n );\n sharedModuleIds[sharedModuleId ?? asyncSharedModuleId] = specifier;\n }\n }\n\n return sharedModuleIds;\n}\n\nfunction stripQuotes(value: string | undefined): string | undefined {\n if (value?.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\nfunction installSharedModules(\n scope: RemoteScope,\n hostShared: Record<string, SharedModuleFactory>,\n sharedModuleIds: RemoteSharedModules,\n missingMessage: (id: string, module: string) => string,\n): Promise<undefined[]> {\n const plan = createSharedModulePlan({\n bundle: scope.name,\n hostShared,\n remoteShared: sharedModuleIds,\n scope: `remote:${scope.scopedName}`,\n callerTag: 'SharedModules',\n });\n\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n // Compatibility with the old shared-modules architecture: a remote\n // factory may have already cached its own implementation for this ID.\n // The broker-owned scope.sharedModules entry must replace it. Remove\n // this cache cleanup once Turbopack remotes cannot execute shared\n // factories before the scoped share plan is installed.\n delete scope.moduleCache[entry.id];\n }\n }\n\n return installSharedModulePlan({\n plan,\n target: scope.sharedModules,\n callerTag: 'SharedModules',\n onMissing: (entry) => {\n logError('SharedModules', missingMessage(entry.id, entry.specifier));\n },\n }).then((results) => {\n for (const entry of plan.entries) {\n if (entry.status === 'resolved') {\n delete scope.moduleCache[entry.id];\n }\n }\n return results;\n });\n}\n\nfunction preferSharedManifest(\n sharedModuleIds: Record<string, string>,\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (!isSharedModuleManifest(remoteShared)) return sharedModuleIds;\n\n const extractedIdBySpecifier = new Map(\n Object.entries(sharedModuleIds).map(([id, specifier]) => [specifier, id]),\n );\n\n return {\n protocol: SHARED_MODULE_MANIFEST_PROTOCOL,\n requirements: remoteShared.requirements.map((requirement) => {\n return {\n ...requirement,\n id: extractedIdBySpecifier.get(requirement.specifier) ?? requirement.id,\n };\n }),\n };\n}\n\nfunction normalizeRemoteSharedForTurbopackFallback(\n remoteShared: RemoteSharedModules,\n): RemoteSharedModules {\n if (isSharedModuleManifest(remoteShared)) {\n return {\n ...remoteShared,\n requirements: remoteShared.requirements.map((requirement) => ({\n ...requirement,\n id:\n typeof requirement.id === 'string'\n ? requirement.id.replace('[app-ssr]', '[app-client]')\n : requirement.id,\n })),\n } satisfies SharedModuleManifest;\n }\n\n // @legacy(remote-components<=0.4.x): normalize server-side generated\n // Turbopack IDs from the historical shared map until 0.4.x remotes are\n // outside the compatibility window.\n return Object.fromEntries(\n Object.entries(remoteShared).map(([id, module]) => [\n id.replace('[app-ssr]', '[app-client]'),\n module,\n ]),\n );\n}\n\n/**\n * Returns a shared module for the given scope and module ID.\n * Shared modules are common dependencies like React that are provided by the host.\n */\nexport function getSharedModule(\n scope: RemoteScope,\n id: string | number,\n): unknown {\n const idStr = String(id);\n\n // Exact match first (covers both string and numeric IDs)\n if (scope.sharedModules[idStr] !== undefined) {\n return scope.sharedModules[idStr];\n }\n\n // Fallback: the id may be a bundle-prefixed string like \"[bundle] /react/index.js\"\n // or a Turbopack dev id like \"[project]/node_modules/react/index.js [client]\".\n // Only path-like keys use the dev-id qualifier match to avoid \"react\"\n // matching \"react-dom\".\n for (const [key, value] of Object.entries(scope.sharedModules)) {\n if (\n typeof value !== 'undefined' &&\n idStr !== key &&\n matchesSharedModuleKey(idStr, key)\n ) {\n return value;\n }\n }\n\n return null;\n}\n\nfunction matchesSharedModuleKey(id: string, key: string): boolean {\n if (id.endsWith(key)) return true;\n if (!key.includes('/') && !key.endsWith('.js')) return false;\n\n const index = id.lastIndexOf(key);\n if (index < 0) return false;\n\n const afterKey = id.slice(index + key.length);\n return /^\\s+(?:\\[[^\\]]+\\]\\s*)?(?:\\([^)]*\\))?$/.test(afterKey);\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,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"__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunkAEW3XYKIcjs = require('./chunk-AEW3XYKI.cjs');
3
+ var _chunkKAFPXSRIcjs = require('./chunk-KAFPXSRI.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
- var _chunkOP2PTYS6cjs = require('./chunk-OP2PTYS6.cjs');
8
+ var _chunkYJJFRORQcjs = require('./chunk-YJJFRORQ.cjs');
9
9
 
10
10
 
11
11
 
@@ -22,12 +22,12 @@ async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClient
22
22
  const hostShared = _chunkI7VKDF3Ecjs.buildHostShared.call(void 0, shared, resolveClientUrl, {
23
23
  includeRemoteComponentShared: true
24
24
  });
25
- await _chunkAEW3XYKIcjs.setupRemoteScope.call(void 0, "turbopack", [], url, bundle, resolveClientUrl);
25
+ await _chunkKAFPXSRIcjs.setupRemoteScope.call(void 0, "turbopack", [], url, bundle, resolveClientUrl);
26
26
  const {
27
27
  default: { createFromReadableStream }
28
28
  } = await Promise.resolve().then(() => _interopRequireWildcard(require("react-server-dom-webpack/client.browser")));
29
29
  async function preloadScripts(scripts, __) {
30
- const scope = await _chunkAEW3XYKIcjs.setupRemoteScope.call(void 0,
30
+ const scope = await _chunkKAFPXSRIcjs.setupRemoteScope.call(void 0,
31
31
  "turbopack",
32
32
  scripts.map((script) => ({
33
33
  src: script.getAttribute("src") || script.getAttribute("data-src") || script.src
@@ -36,7 +36,7 @@ async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClient
36
36
  bundle,
37
37
  resolveClientUrl
38
38
  );
39
- await _chunkOP2PTYS6cjs.initializeSharedModules.call(void 0,
39
+ await _chunkYJJFRORQcjs.initializeSharedModules.call(void 0,
40
40
  scope,
41
41
  _chunkI7VKDF3Ecjs.buildCoreShared.call(void 0, hostShared),
42
42
  _nullishCoalesce(remoteShared, () => ( {}))
@@ -45,12 +45,12 @@ async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClient
45
45
  return {
46
46
  self,
47
47
  createFromReadableStream,
48
- applySharedModules: _chunkOP2PTYS6cjs.applySharedModules,
49
- nextClientPagesLoader: _chunkOP2PTYS6cjs.nextClientPagesLoader,
48
+ applySharedModules: _chunkYJJFRORQcjs.applySharedModules,
49
+ nextClientPagesLoader: _chunkYJJFRORQcjs.nextClientPagesLoader,
50
50
  preloadScripts
51
51
  };
52
52
  }
53
53
 
54
54
 
55
55
  exports.turbopackRuntime = turbopackRuntime;
56
- //# sourceMappingURL=turbopack-7PFUIFBT.cjs.map
56
+ //# sourceMappingURL=turbopack-RXVSOWF7.cjs.map
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  setupRemoteScope
3
- } from "./chunk-LRR2OE4G.js";
3
+ } from "./chunk-FF4SXSSG.js";
4
4
  import {
5
5
  applySharedModules,
6
6
  initializeSharedModules,
7
7
  nextClientPagesLoader
8
- } from "./chunk-6GHGHHQ3.js";
8
+ } from "./chunk-STMO56U2.js";
9
9
  import {
10
10
  buildCoreShared,
11
11
  buildHostShared
@@ -53,4 +53,4 @@ async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClient
53
53
  export {
54
54
  turbopackRuntime
55
55
  };
56
- //# sourceMappingURL=turbopack-NUCVQCQL.js.map
56
+ //# sourceMappingURL=turbopack-XDIGB4GI.js.map
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  applySharedModules,
6
6
  nextClientPagesLoader
7
- } from "./chunk-6GHGHHQ3.js";
7
+ } from "./chunk-STMO56U2.js";
8
8
  import {
9
9
  NEXT_BUNDLE_PATH_RE,
10
10
  buildHostShared,
@@ -90,4 +90,4 @@ async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
90
90
  export {
91
91
  webpackRuntime
92
92
  };
93
- //# sourceMappingURL=webpack-34PB2JBT.js.map
93
+ //# sourceMappingURL=webpack-3QXPAZN4.js.map
@@ -4,7 +4,7 @@ var _chunk4MLJE6UPcjs = require('./chunk-4MLJE6UP.cjs');
4
4
 
5
5
 
6
6
 
7
- var _chunkOP2PTYS6cjs = require('./chunk-OP2PTYS6.cjs');
7
+ var _chunkYJJFRORQcjs = require('./chunk-YJJFRORQ.cjs');
8
8
 
9
9
 
10
10
 
@@ -77,17 +77,17 @@ async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
77
77
  },
78
78
  "WebpackRuntime"
79
79
  );
80
- _chunkOP2PTYS6cjs.applySharedModules.call(void 0, remoteBundle, resolve);
80
+ _chunkYJJFRORQcjs.applySharedModules.call(void 0, remoteBundle, resolve);
81
81
  }
82
82
  return {
83
83
  self,
84
84
  createFromReadableStream,
85
- applySharedModules: _chunkOP2PTYS6cjs.applySharedModules,
86
- nextClientPagesLoader: _chunkOP2PTYS6cjs.nextClientPagesLoader,
85
+ applySharedModules: _chunkYJJFRORQcjs.applySharedModules,
86
+ nextClientPagesLoader: _chunkYJJFRORQcjs.nextClientPagesLoader,
87
87
  preloadScripts
88
88
  };
89
89
  }
90
90
 
91
91
 
92
92
  exports.webpackRuntime = webpackRuntime;
93
- //# sourceMappingURL=webpack-DEFHHH6B.cjs.map
93
+ //# sourceMappingURL=webpack-HKD7RZRE.cjs.map