remote-components 0.3.4 → 0.3.6

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 (153) hide show
  1. package/dist/app-63L5THIQ.js +12 -0
  2. package/dist/app-63L5THIQ.js.map +1 -0
  3. package/dist/app-A5QE7XRH.cjs +12 -0
  4. package/dist/app-A5QE7XRH.cjs.map +1 -0
  5. package/dist/chunk-2VQGCACH.js +190 -0
  6. package/dist/chunk-2VQGCACH.js.map +1 -0
  7. package/dist/chunk-42N2ZLE2.js +703 -0
  8. package/dist/chunk-42N2ZLE2.js.map +1 -0
  9. package/dist/chunk-6IUP26UK.cjs +57 -0
  10. package/dist/chunk-6IUP26UK.cjs.map +1 -0
  11. package/dist/chunk-7MVFHOIP.cjs +60 -0
  12. package/dist/chunk-7MVFHOIP.cjs.map +1 -0
  13. package/dist/chunk-CREXMFMF.cjs +155 -0
  14. package/dist/chunk-CREXMFMF.cjs.map +1 -0
  15. package/dist/chunk-CTUJSWCM.js +215 -0
  16. package/dist/chunk-CTUJSWCM.js.map +1 -0
  17. package/dist/chunk-ENYGL5CO.js +11 -0
  18. package/dist/chunk-ENYGL5CO.js.map +1 -0
  19. package/dist/chunk-ER73O65F.cjs +703 -0
  20. package/dist/chunk-ER73O65F.cjs.map +1 -0
  21. package/dist/chunk-F44NODUS.cjs +709 -0
  22. package/dist/chunk-F44NODUS.cjs.map +1 -0
  23. package/dist/chunk-GAXJTFBV.js +20 -0
  24. package/dist/chunk-GAXJTFBV.js.map +1 -0
  25. package/dist/chunk-HNZVEIKN.js +358 -0
  26. package/dist/chunk-HNZVEIKN.js.map +1 -0
  27. package/dist/chunk-KE7QPAQ4.cjs +21 -0
  28. package/dist/chunk-KE7QPAQ4.cjs.map +1 -0
  29. package/dist/chunk-KEPHL25S.js +60 -0
  30. package/dist/chunk-KEPHL25S.js.map +1 -0
  31. package/dist/chunk-KKBEMQU7.cjs +670 -0
  32. package/dist/chunk-KKBEMQU7.cjs.map +1 -0
  33. package/dist/chunk-KYJWRZ2B.js +709 -0
  34. package/dist/chunk-KYJWRZ2B.js.map +1 -0
  35. package/dist/chunk-N5VQR2PW.cjs +215 -0
  36. package/dist/chunk-N5VQR2PW.cjs.map +1 -0
  37. package/dist/chunk-OO4AMJWO.js +155 -0
  38. package/dist/chunk-OO4AMJWO.js.map +1 -0
  39. package/dist/chunk-R4QFK5TN.cjs +358 -0
  40. package/dist/chunk-R4QFK5TN.cjs.map +1 -0
  41. package/dist/chunk-RUWR74XQ.cjs +152 -0
  42. package/dist/chunk-RUWR74XQ.cjs.map +1 -0
  43. package/dist/chunk-S2A4TFLS.js +152 -0
  44. package/dist/chunk-S2A4TFLS.js.map +1 -0
  45. package/dist/chunk-SHFJ5OQA.cjs +11 -0
  46. package/dist/chunk-SHFJ5OQA.cjs.map +1 -0
  47. package/dist/chunk-TCFLEBQM.cjs +20 -0
  48. package/dist/chunk-TCFLEBQM.cjs.map +1 -0
  49. package/dist/chunk-W5ESPGHH.js +670 -0
  50. package/dist/chunk-W5ESPGHH.js.map +1 -0
  51. package/dist/chunk-X6YKUJKH.js +21 -0
  52. package/dist/chunk-X6YKUJKH.js.map +1 -0
  53. package/dist/chunk-XCFYWSLD.cjs +190 -0
  54. package/dist/chunk-XCFYWSLD.cjs.map +1 -0
  55. package/dist/chunk-ZPMTZ3KJ.js +57 -0
  56. package/dist/chunk-ZPMTZ3KJ.js.map +1 -0
  57. package/dist/config/nextjs.cjs +76 -351
  58. package/dist/config/nextjs.cjs.map +1 -1
  59. package/dist/config/nextjs.js +26 -266
  60. package/dist/config/nextjs.js.map +1 -1
  61. package/dist/config/webpack.cjs +12 -240
  62. package/dist/config/webpack.cjs.map +1 -1
  63. package/dist/config/webpack.js +6 -207
  64. package/dist/config/webpack.js.map +1 -1
  65. package/dist/host/html.cjs +139 -2447
  66. package/dist/host/html.cjs.map +1 -1
  67. package/dist/host/html.js +66 -2345
  68. package/dist/host/html.js.map +1 -1
  69. package/dist/host/nextjs/app/client-only.cjs +53 -2825
  70. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  71. package/dist/host/nextjs/app/client-only.js +31 -2780
  72. package/dist/host/nextjs/app/client-only.js.map +1 -1
  73. package/dist/host/nextjs/app.cjs +34 -2
  74. package/dist/host/nextjs/app.cjs.map +1 -1
  75. package/dist/host/nextjs/app.js +35 -3
  76. package/dist/host/nextjs/app.js.map +1 -1
  77. package/dist/host/proxy/client.cjs +8 -38
  78. package/dist/host/proxy/client.cjs.map +1 -1
  79. package/dist/host/proxy/client.js +4 -7
  80. package/dist/host/proxy/client.js.map +1 -1
  81. package/dist/host/proxy.cjs +19 -56
  82. package/dist/host/proxy.cjs.map +1 -1
  83. package/dist/host/proxy.js +8 -20
  84. package/dist/host/proxy.js.map +1 -1
  85. package/dist/host/react.cjs +17 -2756
  86. package/dist/host/react.cjs.map +1 -1
  87. package/dist/host/react.js +13 -2723
  88. package/dist/host/react.js.map +1 -1
  89. package/dist/internal/host/nextjs/app-client.cjs +38 -24
  90. package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
  91. package/dist/internal/host/nextjs/app-client.js +38 -24
  92. package/dist/internal/host/nextjs/app-client.js.map +1 -1
  93. package/dist/internal/host/nextjs/remote-component-links.cjs +24 -13
  94. package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -1
  95. package/dist/internal/host/nextjs/remote-component-links.d.ts +3 -0
  96. package/dist/internal/host/nextjs/remote-component-links.js +24 -13
  97. package/dist/internal/host/nextjs/remote-component-links.js.map +1 -1
  98. package/dist/internal/host/server/fetch-remote-component.cjs +1 -18
  99. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  100. package/dist/internal/host/server/fetch-remote-component.js +1 -18
  101. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  102. package/dist/internal/host/shared/lifecycle.cjs +69 -0
  103. package/dist/internal/host/shared/lifecycle.cjs.map +1 -0
  104. package/dist/internal/host/shared/lifecycle.d.ts +34 -0
  105. package/dist/internal/host/shared/lifecycle.js +44 -0
  106. package/dist/internal/host/shared/lifecycle.js.map +1 -0
  107. package/dist/internal/host/shared/pipeline.cjs +222 -0
  108. package/dist/internal/host/shared/pipeline.cjs.map +1 -0
  109. package/dist/internal/host/shared/pipeline.d.ts +153 -0
  110. package/dist/internal/host/shared/pipeline.js +200 -0
  111. package/dist/internal/host/shared/pipeline.js.map +1 -0
  112. package/dist/internal/runtime/loaders/component-loader.cjs +5 -2
  113. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  114. package/dist/internal/runtime/loaders/component-loader.js +5 -2
  115. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  116. package/dist/internal/runtime/turbopack/patterns.cjs +1 -1
  117. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
  118. package/dist/internal/runtime/turbopack/patterns.js +1 -1
  119. package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
  120. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -1
  121. package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -1
  122. package/dist/internal/runtime/turbopack/remote-scope.cjs +1 -5
  123. package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
  124. package/dist/internal/runtime/turbopack/remote-scope.js +1 -5
  125. package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
  126. package/dist/internal/utils.cjs +1 -1
  127. package/dist/internal/utils.cjs.map +1 -1
  128. package/dist/internal/utils.d.ts +5 -5
  129. package/dist/internal/utils.js +1 -1
  130. package/dist/internal/utils.js.map +1 -1
  131. package/dist/remote/html.cjs +15 -314
  132. package/dist/remote/html.cjs.map +1 -1
  133. package/dist/remote/html.js +7 -305
  134. package/dist/remote/html.js.map +1 -1
  135. package/dist/remote/middleware.cjs +16 -41
  136. package/dist/remote/middleware.cjs.map +1 -1
  137. package/dist/script-6W5JRBZK.cjs +26 -0
  138. package/dist/script-6W5JRBZK.cjs.map +1 -0
  139. package/dist/script-IFEBOLIA.js +26 -0
  140. package/dist/script-IFEBOLIA.js.map +1 -0
  141. package/dist/static-loader-X4TSF5KW.js +11 -0
  142. package/dist/static-loader-X4TSF5KW.js.map +1 -0
  143. package/dist/static-loader-ZYD5BO4D.cjs +11 -0
  144. package/dist/static-loader-ZYD5BO4D.cjs.map +1 -0
  145. package/dist/turbopack-NPGO3MWS.js +55 -0
  146. package/dist/turbopack-NPGO3MWS.js.map +1 -0
  147. package/dist/turbopack-WRMKPNN4.cjs +55 -0
  148. package/dist/turbopack-WRMKPNN4.cjs.map +1 -0
  149. package/dist/webpack-DUBHPYD6.js +92 -0
  150. package/dist/webpack-DUBHPYD6.js.map +1 -0
  151. package/dist/webpack-KSCMCL7M.cjs +92 -0
  152. package/dist/webpack-KSCMCL7M.cjs.map +1 -0
  153. package/package.json +10 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/loaders/component-loader.ts"],"sourcesContent":["import * as React from 'react';\nimport * as JSXDevRuntime from 'react/jsx-dev-runtime';\nimport * as JSXRuntime from 'react/jsx-runtime';\nimport * as ReactDOM from 'react-dom';\nimport * as ReactDOMClient from 'react-dom/client';\nimport { applySharedModules } from '#internal/config/webpack/apply-shared-modules';\nimport { nextClientPagesLoader } from '#internal/config/webpack/next-client-pages-loader';\nimport type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { ConsumeLoaderPayload } from '#internal/host/shared/server-handoff';\nimport {\n buildCoreShared,\n buildWebpackResolve,\n} from '#internal/host/shared/shared-module-resolver';\nimport { createRSCStream } from '#internal/runtime/rsc';\nimport { importRSCClientBrowser } from '#internal/runtime/rsc-imports';\nimport { setupRemoteScope } from '#internal/runtime/turbopack/remote-scope-setup';\nimport { initializeSharedModules } from '#internal/runtime/turbopack/shared-modules';\nimport type { GlobalScope, LoaderResult } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { loadScripts } from './script-loader';\n\n/**\n * Props accepted by {@link loadRemoteComponent}.\n *\n * Extends {@link ConsumeLoaderPayload} (the SSR-resolved fields needed for\n * hydration) with loader-specific fields (`url`, `shared`, `container`, etc.).\n * `remoteShared` is narrowed from optional to required (defaults to `{}` at\n * the call site).\n */\nexport interface ConsumeLoaderProps extends ConsumeLoaderPayload {\n url: URL;\n shared:\n | Promise<Record<string, (bundle?: string) => Promise<unknown>>>\n | Record<string, (bundle?: string) => Promise<unknown>>;\n remoteShared: Record<string, string>;\n container?: HTMLHeadElement | ShadowRoot | null;\n rscName?: string;\n resolveClientUrl?: InternalResolveClientUrl;\n}\n\n/**\n * Main loader function that orchestrates the component loading process\n */\nexport async function loadRemoteComponent({\n url,\n name,\n rscName,\n bundle,\n route = '/',\n runtime = 'webpack',\n data,\n nextData,\n scripts = [],\n shared = Promise.resolve({}),\n remoteShared = {},\n container,\n resolveClientUrl,\n}: ConsumeLoaderProps): Promise<LoaderResult> {\n try {\n // Load scripts if using webpack runtime\n if (runtime === 'webpack') {\n const self = globalThis as GlobalScope;\n // disable webpack entrypoint execution for the remote\n if (!self.__DISABLE_WEBPACK_EXEC__) {\n self.__DISABLE_WEBPACK_EXEC__ = {};\n }\n // disable webpack entrypoint execution for the current remote bundle\n self.__DISABLE_WEBPACK_EXEC__[bundle] = true;\n await loadScripts(scripts, resolveClientUrl);\n }\n\n const hostShared = await shared;\n logDebug(\n 'ComponentLoader',\n `loadRemoteComponent: bundle=\"${bundle}\", name=\"${name}\"`,\n );\n logDebug(\n 'ComponentLoader',\n `Host shared modules available: ${Object.keys(hostShared)}`,\n );\n logDebug(\n 'ComponentLoader',\n `Remote shared modules requested: ${JSON.stringify(remoteShared)}`,\n );\n\n // Setup remote scope and load turbopack chunks\n const scope = await setupRemoteScope(\n runtime,\n scripts,\n url,\n bundle,\n resolveClientUrl,\n );\n\n // Initialize turbopack shared modules (React, etc.) now that chunks are loaded\n if (runtime === 'turbopack') {\n await initializeSharedModules(\n scope,\n buildCoreShared(hostShared),\n remoteShared,\n );\n }\n\n // Setup shared modules\n if (bundle) {\n const resolve = await buildWebpackResolve(\n hostShared,\n remoteShared,\n bundle,\n {\n '/react/index.js': React,\n '/react/jsx-dev-runtime.js': JSXDevRuntime,\n '/react/jsx-runtime.js': JSXRuntime,\n '/react-dom/index.js': ReactDOM,\n '/react-dom/client.js': ReactDOMClient,\n },\n 'ComponentLoader',\n );\n applySharedModules(bundle, resolve);\n } else {\n logWarn(\n 'ComponentLoader',\n 'No bundle specified, skipping shared module setup',\n );\n }\n\n // Load component based on data type\n if (data.length > 0) {\n return await loadRSCComponent(rscName ?? name, data);\n } else if (nextData) {\n return loadNextPagesComponent(bundle, route, nextData, name, container);\n }\n\n return loadRSCComponent(rscName ?? name, [`0:[null]\\n`]); // Fallback to empty RSC payload\n } catch (error) {\n return {\n component: null,\n error: new RemoteComponentsError(\n `Failed to load remote component \"${name}\".`,\n {\n cause: error instanceof Error ? error : new Error(String(error)),\n },\n ),\n };\n }\n}\n\n/**\n * Loads RSC (React Server Components) based component\n */\nasync function loadRSCComponent(\n rscName: string,\n data: string[],\n): Promise<LoaderResult> {\n const { createFromReadableStream } = await importRSCClientBrowser();\n if (typeof createFromReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'Failed to import \"react-server-dom-webpack\". Is Next.js installed correctly?',\n );\n }\n\n const stream = createRSCStream(rscName, data);\n const component = createFromReadableStream(stream);\n\n return { component };\n}\n\n/**\n * Loads Next.js Pages Router based component\n */\nfunction loadNextPagesComponent(\n bundle: string,\n route: string,\n nextData: NonNullable<ConsumeLoaderPayload['nextData']>,\n name: string,\n container?: HTMLHeadElement | ShadowRoot | null,\n): LoaderResult {\n const { Component, App } = nextClientPagesLoader(bundle, route, container);\n\n if (!Component) {\n throw new RemoteComponentsError(\n `Remote Component \"${name}\" is trying to load the component for route \"${route}\" but it is not available.`,\n );\n }\n\n // error tolerance when app component is not found\n const component = App\n ? React.createElement(App, { Component, ...nextData.props })\n : React.createElement(Component, nextData.props);\n\n return { component };\n}\n"],"mappings":";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Ac,WAAW,SAAS,KAAK;AAEjD,SAAO,EAAE,UAAU;AACrB;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtime/loaders/component-loader.ts"],"sourcesContent":["import * as React from 'react';\nimport * as JSXDevRuntime from 'react/jsx-dev-runtime';\nimport * as JSXRuntime from 'react/jsx-runtime';\nimport * as ReactDOM from 'react-dom';\nimport * as ReactDOMClient from 'react-dom/client';\nimport { applySharedModules } from '#internal/config/webpack/apply-shared-modules';\nimport { nextClientPagesLoader } from '#internal/config/webpack/next-client-pages-loader';\nimport type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { ConsumeLoaderPayload } from '#internal/host/shared/server-handoff';\nimport {\n buildCoreShared,\n buildWebpackResolve,\n} from '#internal/host/shared/shared-module-resolver';\nimport { createRSCStream } from '#internal/runtime/rsc';\nimport { importRSCClientBrowser } from '#internal/runtime/rsc-imports';\nimport { setupRemoteScope } from '#internal/runtime/turbopack/remote-scope-setup';\nimport { initializeSharedModules } from '#internal/runtime/turbopack/shared-modules';\nimport type { GlobalScope, LoaderResult } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { loadScripts } from './script-loader';\n\n/**\n * Props accepted by {@link loadRemoteComponent}.\n *\n * Extends {@link ConsumeLoaderPayload} (the SSR-resolved fields needed for\n * hydration) with loader-specific fields (`url`, `shared`, `container`, etc.).\n * `remoteShared` is narrowed from optional to required (defaults to `{}` at\n * the call site).\n */\nexport interface ConsumeLoaderProps extends ConsumeLoaderPayload {\n url: URL;\n shared:\n | Promise<Record<string, (bundle?: string) => Promise<unknown>>>\n | Record<string, (bundle?: string) => Promise<unknown>>;\n remoteShared: Record<string, string>;\n container?: HTMLHeadElement | ShadowRoot | null;\n rscName?: string;\n resolveClientUrl?: InternalResolveClientUrl;\n}\n\n/**\n * Main loader function that orchestrates the component loading process\n */\nexport async function loadRemoteComponent({\n url,\n name,\n rscName,\n bundle,\n route = '/',\n runtime = 'webpack',\n data,\n nextData,\n scripts = [],\n shared = Promise.resolve({}),\n remoteShared = {},\n container,\n resolveClientUrl,\n}: ConsumeLoaderProps): Promise<LoaderResult> {\n try {\n // Load scripts if using webpack runtime\n if (runtime === 'webpack') {\n const self = globalThis as GlobalScope;\n // disable webpack entrypoint execution for the remote\n if (!self.__DISABLE_WEBPACK_EXEC__) {\n self.__DISABLE_WEBPACK_EXEC__ = {};\n }\n // disable webpack entrypoint execution for the current remote bundle\n self.__DISABLE_WEBPACK_EXEC__[bundle] = true;\n await loadScripts(scripts, resolveClientUrl);\n }\n\n const hostShared = await shared;\n logDebug(\n 'ComponentLoader',\n `loadRemoteComponent: bundle=\"${bundle}\", name=\"${name}\"`,\n );\n logDebug(\n 'ComponentLoader',\n `Host shared modules available: ${Object.keys(hostShared)}`,\n );\n logDebug(\n 'ComponentLoader',\n `Remote shared modules requested: ${JSON.stringify(remoteShared)}`,\n );\n\n // Setup remote scope and load turbopack chunks\n const scope = await setupRemoteScope(\n runtime,\n scripts,\n url,\n bundle,\n resolveClientUrl,\n );\n\n // Initialize turbopack shared modules (React, etc.) now that chunks are loaded\n if (runtime === 'turbopack') {\n await initializeSharedModules(\n scope,\n buildCoreShared(hostShared),\n remoteShared,\n );\n }\n\n // Setup shared modules\n if (bundle) {\n const resolve = await buildWebpackResolve(\n hostShared,\n remoteShared,\n bundle,\n {\n '/react/index.js': React,\n '/react/jsx-dev-runtime.js': JSXDevRuntime,\n '/react/jsx-runtime.js': JSXRuntime,\n '/react-dom/index.js': ReactDOM,\n '/react-dom/client.js': ReactDOMClient,\n },\n 'ComponentLoader',\n );\n applySharedModules(bundle, resolve);\n } else {\n logWarn(\n 'ComponentLoader',\n 'No bundle specified, skipping shared module setup',\n );\n }\n\n // Rewrite plain bundle references in RSC data to the scoped name so\n // the client dispatchers resolve the correct scope.\n const scopedData = data.map((chunk) =>\n chunk.replaceAll(`[${bundle}]`, `[${scope.scopedName}]`),\n );\n\n // Load component based on data type\n if (scopedData.length > 0) {\n return await loadRSCComponent(rscName ?? name, scopedData);\n } else if (nextData) {\n return loadNextPagesComponent(bundle, route, nextData, name, container);\n }\n\n return loadRSCComponent(rscName ?? name, [`0:[null]\\n`]); // Fallback to empty RSC payload\n } catch (error) {\n return {\n component: null,\n error: new RemoteComponentsError(\n `Failed to load remote component \"${name}\".`,\n {\n cause: error instanceof Error ? error : new Error(String(error)),\n },\n ),\n };\n }\n}\n\n/**\n * Loads RSC (React Server Components) based component\n */\nasync function loadRSCComponent(\n rscName: string,\n data: string[],\n): Promise<LoaderResult> {\n const { createFromReadableStream } = await importRSCClientBrowser();\n if (typeof createFromReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'Failed to import \"react-server-dom-webpack\". Is Next.js installed correctly?',\n );\n }\n\n const stream = createRSCStream(rscName, data);\n const component = createFromReadableStream(stream);\n\n return { component };\n}\n\n/**\n * Loads Next.js Pages Router based component\n */\nfunction loadNextPagesComponent(\n bundle: string,\n route: string,\n nextData: NonNullable<ConsumeLoaderPayload['nextData']>,\n name: string,\n container?: HTMLHeadElement | ShadowRoot | null,\n): LoaderResult {\n const { Component, App } = nextClientPagesLoader(bundle, route, container);\n\n if (!Component) {\n throw new RemoteComponentsError(\n `Remote Component \"${name}\" is trying to load the component for route \"${route}\" but it is not available.`,\n );\n }\n\n // error tolerance when app component is not found\n const component = App\n ? React.createElement(App, { Component, ...nextData.props })\n : React.createElement(Component, nextData.props);\n\n return { component };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AACvB,oBAA+B;AAC/B,iBAA4B;AAC5B,eAA0B;AAC1B,qBAAgC;AAChC,kCAAmC;AACnC,sCAAsC;AAGtC,oCAGO;AACP,iBAAgC;AAChC,yBAAuC;AACvC,gCAAiC;AACjC,4BAAwC;AAExC,mBAAsC;AACtC,oBAAkC;AAClC,2BAA4B;AAwB5B,eAAsB,oBAAoB;AAAA,EACxC;A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AAM,aAAa;AAAA,IACzD;AAGA,QAAI,WAAW,SAAS,GAAG;AACzB,aAAO,MAAM,iBAAiB,WAAW,MAAM,UAAU;AAAA,IAC3D,WAAW,UAAU;AACnB,aAAO,uBAAuB,QAAQ,OAAO,UAAU,MAAM,SAAS;AAAA,IACxE;AAEA,WAAO,iBAAiB,WAAW,MAAM,CAAC;AAAA,CAAY,CAAC;AAAA,EACzD,SAAS,OAAP;AACA,WAAO;AAAA,MACL,WAAW;AAAA,MACX,OAAO,IAAI;AAAA,QACT,oCAAoC;AAAA,QACpC;AAAA,UACE,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAKA,eAAe,iBACb,SACA,MACuB;AACvB,QAAM,EAAE,yBAAyB,IAAI,UAAM,2CAAuB;AAClE,MAAI,OAAO,6BAA6B,YAAY;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,aAAS,4BAAgB,SAAS,IAAI;AAC5C,QAAM,YAAY,yBAAyB,MAAM;AAEjD,SAAO,EAAE,UAAU;AACrB;AAKA,SAAS,uBACP,QACA,OACA,UACA,MACA,WACc;AACd,QAAM,EAAE,WAAW,IAAI,QAAI,uDAAsB,QAAQ,OAAO,SAAS;AAEzE,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR,qBAAqB,oDAAoD;AAAA,IAC3E;AAAA,EACF;AAGA,QAAM,YAAY,MACd,MAAM,cAAc,KAAK,EAAE,WAAW,GAAG,SAAS,MAAM,CAAC,IACzD,MAAM,cAAc,WAAW,SAAS,KAAK;AAEjD,SAAO,EAAE,UAAU;AACrB;","names":[]}
@@ -88,8 +88,11 @@ async function loadRemoteComponent({
88
88
  "No bundle specified, skipping shared module setup"
89
89
  );
90
90
  }
91
- if (data.length > 0) {
92
- return await loadRSCComponent(rscName ?? name, data);
91
+ const scopedData = data.map(
92
+ (chunk) => chunk.replaceAll(`[${bundle}]`, `[${scope.scopedName}]`)
93
+ );
94
+ if (scopedData.length > 0) {
95
+ return await loadRSCComponent(rscName ?? name, scopedData);
93
96
  } else if (nextData) {
94
97
  return loadNextPagesComponent(bundle, route, nextData, name, container);
95
98
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/loaders/component-loader.ts"],"sourcesContent":["import * as React from 'react';\nimport * as JSXDevRuntime from 'react/jsx-dev-runtime';\nimport * as JSXRuntime from 'react/jsx-runtime';\nimport * as ReactDOM from 'react-dom';\nimport * as ReactDOMClient from 'react-dom/client';\nimport { applySharedModules } from '#internal/config/webpack/apply-shared-modules';\nimport { nextClientPagesLoader } from '#internal/config/webpack/next-client-pages-loader';\nimport type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { ConsumeLoaderPayload } from '#internal/host/shared/server-handoff';\nimport {\n buildCoreShared,\n buildWebpackResolve,\n} from '#internal/host/shared/shared-module-resolver';\nimport { createRSCStream } from '#internal/runtime/rsc';\nimport { importRSCClientBrowser } from '#internal/runtime/rsc-imports';\nimport { setupRemoteScope } from '#internal/runtime/turbopack/remote-scope-setup';\nimport { initializeSharedModules } from '#internal/runtime/turbopack/shared-modules';\nimport type { GlobalScope, LoaderResult } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { loadScripts } from './script-loader';\n\n/**\n * Props accepted by {@link loadRemoteComponent}.\n *\n * Extends {@link ConsumeLoaderPayload} (the SSR-resolved fields needed for\n * hydration) with loader-specific fields (`url`, `shared`, `container`, etc.).\n * `remoteShared` is narrowed from optional to required (defaults to `{}` at\n * the call site).\n */\nexport interface ConsumeLoaderProps extends ConsumeLoaderPayload {\n url: URL;\n shared:\n | Promise<Record<string, (bundle?: string) => Promise<unknown>>>\n | Record<string, (bundle?: string) => Promise<unknown>>;\n remoteShared: Record<string, string>;\n container?: HTMLHeadElement | ShadowRoot | null;\n rscName?: string;\n resolveClientUrl?: InternalResolveClientUrl;\n}\n\n/**\n * Main loader function that orchestrates the component loading process\n */\nexport async function loadRemoteComponent({\n url,\n name,\n rscName,\n bundle,\n route = '/',\n runtime = 'webpack',\n data,\n nextData,\n scripts = [],\n shared = Promise.resolve({}),\n remoteShared = {},\n container,\n resolveClientUrl,\n}: ConsumeLoaderProps): Promise<LoaderResult> {\n try {\n // Load scripts if using webpack runtime\n if (runtime === 'webpack') {\n const self = globalThis as GlobalScope;\n // disable webpack entrypoint execution for the remote\n if (!self.__DISABLE_WEBPACK_EXEC__) {\n self.__DISABLE_WEBPACK_EXEC__ = {};\n }\n // disable webpack entrypoint execution for the current remote bundle\n self.__DISABLE_WEBPACK_EXEC__[bundle] = true;\n await loadScripts(scripts, resolveClientUrl);\n }\n\n const hostShared = await shared;\n logDebug(\n 'ComponentLoader',\n `loadRemoteComponent: bundle=\"${bundle}\", name=\"${name}\"`,\n );\n logDebug(\n 'ComponentLoader',\n `Host shared modules available: ${Object.keys(hostShared)}`,\n );\n logDebug(\n 'ComponentLoader',\n `Remote shared modules requested: ${JSON.stringify(remoteShared)}`,\n );\n\n // Setup remote scope and load turbopack chunks\n const scope = await setupRemoteScope(\n runtime,\n scripts,\n url,\n bundle,\n resolveClientUrl,\n );\n\n // Initialize turbopack shared modules (React, etc.) now that chunks are loaded\n if (runtime === 'turbopack') {\n await initializeSharedModules(\n scope,\n buildCoreShared(hostShared),\n remoteShared,\n );\n }\n\n // Setup shared modules\n if (bundle) {\n const resolve = await buildWebpackResolve(\n hostShared,\n remoteShared,\n bundle,\n {\n '/react/index.js': React,\n '/react/jsx-dev-runtime.js': JSXDevRuntime,\n '/react/jsx-runtime.js': JSXRuntime,\n '/react-dom/index.js': ReactDOM,\n '/react-dom/client.js': ReactDOMClient,\n },\n 'ComponentLoader',\n );\n applySharedModules(bundle, resolve);\n } else {\n logWarn(\n 'ComponentLoader',\n 'No bundle specified, skipping shared module setup',\n );\n }\n\n // Load component based on data type\n if (data.length > 0) {\n return await loadRSCComponent(rscName ?? name, data);\n } else if (nextData) {\n return loadNextPagesComponent(bundle, route, nextData, name, container);\n }\n\n return loadRSCComponent(rscName ?? name, [`0:[null]\\n`]); // Fallback to empty RSC payload\n } catch (error) {\n return {\n component: null,\n error: new RemoteComponentsError(\n `Failed to load remote component \"${name}\".`,\n {\n cause: error instanceof Error ? error : new Error(String(error)),\n },\n ),\n };\n }\n}\n\n/**\n * Loads RSC (React Server Components) based component\n */\nasync function loadRSCComponent(\n rscName: string,\n data: string[],\n): Promise<LoaderResult> {\n const { createFromReadableStream } = await importRSCClientBrowser();\n if (typeof createFromReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'Failed to import \"react-server-dom-webpack\". Is Next.js installed correctly?',\n );\n }\n\n const stream = createRSCStream(rscName, data);\n const component = createFromReadableStream(stream);\n\n return { component };\n}\n\n/**\n * Loads Next.js Pages Router based component\n */\nfunction loadNextPagesComponent(\n bundle: string,\n route: string,\n nextData: NonNullable<ConsumeLoaderPayload['nextData']>,\n name: string,\n container?: HTMLHeadElement | ShadowRoot | null,\n): LoaderResult {\n const { Component, App } = nextClientPagesLoader(bundle, route, container);\n\n if (!Component) {\n throw new RemoteComponentsError(\n `Remote Component \"${name}\" is trying to load the component for route \"${route}\" but it is not available.`,\n );\n }\n\n // error tolerance when app component is not found\n const component = App\n ? React.createElement(App, { Component, ...nextData.props })\n : React.createElement(Component, nextData.props);\n\n return { component };\n}\n"],"mappings":"AAAA,YAAY,WAAW;AACvB,YAAY,mBAAmB;AAC/B,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAC1B,YAAY,oBAAoB;AAChC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AAGtC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AACvC,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AAExC,SAAS,6BAA6B;AACtC,SAAS,UAAU,eAAe;AAClC,SAAS,m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O,MAAM,iBAAiB,WAAW,MAAM,IAAI;AAAA,IACrD,WAAW,UAAU;AACnB,aAAO,uBAAuB,QAAQ,OAAO,UAAU,MAAM,SAAS;AAAA,IACxE;AAEA,WAAO,iBAAiB,WAAW,MAAM,CAAC;AAAA,CAAY,CAAC;AAAA,EACzD,SAAS,OAAP;AACA,WAAO;AAAA,MACL,WAAW;AAAA,MACX,OAAO,IAAI;AAAA,QACT,oCAAoC;AAAA,QACpC;AAAA,UACE,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAKA,eAAe,iBACb,SACA,MACuB;AACvB,QAAM,EAAE,yBAAyB,IAAI,MAAM,uBAAuB;AAClE,MAAI,OAAO,6BAA6B,YAAY;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,gBAAgB,SAAS,IAAI;AAC5C,QAAM,YAAY,yBAAyB,MAAM;AAEjD,SAAO,EAAE,UAAU;AACrB;AAKA,SAAS,uBACP,QACA,OACA,UACA,MACA,WACc;AACd,QAAM,EAAE,WAAW,IAAI,IAAI,sBAAsB,QAAQ,OAAO,SAAS;AAEzE,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR,qBAAqB,oDAAoD;AAAA,IAC3E;AAAA,EACF;AAGA,QAAM,YAAY,MACd,MAAM,cAAc,KAAK,EAAE,WAAW,GAAG,SAAS,MAAM,CAAC,IACzD,MAAM,cAAc,WAAW,SAAS,KAAK;AAEjD,SAAO,EAAE,UAAU;AACrB;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtime/loaders/component-loader.ts"],"sourcesContent":["import * as React from 'react';\nimport * as JSXDevRuntime from 'react/jsx-dev-runtime';\nimport * as JSXRuntime from 'react/jsx-runtime';\nimport * as ReactDOM from 'react-dom';\nimport * as ReactDOMClient from 'react-dom/client';\nimport { applySharedModules } from '#internal/config/webpack/apply-shared-modules';\nimport { nextClientPagesLoader } from '#internal/config/webpack/next-client-pages-loader';\nimport type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { ConsumeLoaderPayload } from '#internal/host/shared/server-handoff';\nimport {\n buildCoreShared,\n buildWebpackResolve,\n} from '#internal/host/shared/shared-module-resolver';\nimport { createRSCStream } from '#internal/runtime/rsc';\nimport { importRSCClientBrowser } from '#internal/runtime/rsc-imports';\nimport { setupRemoteScope } from '#internal/runtime/turbopack/remote-scope-setup';\nimport { initializeSharedModules } from '#internal/runtime/turbopack/shared-modules';\nimport type { GlobalScope, LoaderResult } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { loadScripts } from './script-loader';\n\n/**\n * Props accepted by {@link loadRemoteComponent}.\n *\n * Extends {@link ConsumeLoaderPayload} (the SSR-resolved fields needed for\n * hydration) with loader-specific fields (`url`, `shared`, `container`, etc.).\n * `remoteShared` is narrowed from optional to required (defaults to `{}` at\n * the call site).\n */\nexport interface ConsumeLoaderProps extends ConsumeLoaderPayload {\n url: URL;\n shared:\n | Promise<Record<string, (bundle?: string) => Promise<unknown>>>\n | Record<string, (bundle?: string) => Promise<unknown>>;\n remoteShared: Record<string, string>;\n container?: HTMLHeadElement | ShadowRoot | null;\n rscName?: string;\n resolveClientUrl?: InternalResolveClientUrl;\n}\n\n/**\n * Main loader function that orchestrates the component loading process\n */\nexport async function loadRemoteComponent({\n url,\n name,\n rscName,\n bundle,\n route = '/',\n runtime = 'webpack',\n data,\n nextData,\n scripts = [],\n shared = Promise.resolve({}),\n remoteShared = {},\n container,\n resolveClientUrl,\n}: ConsumeLoaderProps): Promise<LoaderResult> {\n try {\n // Load scripts if using webpack runtime\n if (runtime === 'webpack') {\n const self = globalThis as GlobalScope;\n // disable webpack entrypoint execution for the remote\n if (!self.__DISABLE_WEBPACK_EXEC__) {\n self.__DISABLE_WEBPACK_EXEC__ = {};\n }\n // disable webpack entrypoint execution for the current remote bundle\n self.__DISABLE_WEBPACK_EXEC__[bundle] = true;\n await loadScripts(scripts, resolveClientUrl);\n }\n\n const hostShared = await shared;\n logDebug(\n 'ComponentLoader',\n `loadRemoteComponent: bundle=\"${bundle}\", name=\"${name}\"`,\n );\n logDebug(\n 'ComponentLoader',\n `Host shared modules available: ${Object.keys(hostShared)}`,\n );\n logDebug(\n 'ComponentLoader',\n `Remote shared modules requested: ${JSON.stringify(remoteShared)}`,\n );\n\n // Setup remote scope and load turbopack chunks\n const scope = await setupRemoteScope(\n runtime,\n scripts,\n url,\n bundle,\n resolveClientUrl,\n );\n\n // Initialize turbopack shared modules (React, etc.) now that chunks are loaded\n if (runtime === 'turbopack') {\n await initializeSharedModules(\n scope,\n buildCoreShared(hostShared),\n remoteShared,\n );\n }\n\n // Setup shared modules\n if (bundle) {\n const resolve = await buildWebpackResolve(\n hostShared,\n remoteShared,\n bundle,\n {\n '/react/index.js': React,\n '/react/jsx-dev-runtime.js': JSXDevRuntime,\n '/react/jsx-runtime.js': JSXRuntime,\n '/react-dom/index.js': ReactDOM,\n '/react-dom/client.js': ReactDOMClient,\n },\n 'ComponentLoader',\n );\n applySharedModules(bundle, resolve);\n } else {\n logWarn(\n 'ComponentLoader',\n 'No bundle specified, skipping shared module setup',\n );\n }\n\n // Rewrite plain bundle references in RSC data to the scoped name so\n // the client dispatchers resolve the correct scope.\n const scopedData = data.map((chunk) =>\n chunk.replaceAll(`[${bundle}]`, `[${scope.scopedName}]`),\n );\n\n // Load component based on data type\n if (scopedData.length > 0) {\n return await loadRSCComponent(rscName ?? name, scopedData);\n } else if (nextData) {\n return loadNextPagesComponent(bundle, route, nextData, name, container);\n }\n\n return loadRSCComponent(rscName ?? name, [`0:[null]\\n`]); // Fallback to empty RSC payload\n } catch (error) {\n return {\n component: null,\n error: new RemoteComponentsError(\n `Failed to load remote component \"${name}\".`,\n {\n cause: error instanceof Error ? error : new Error(String(error)),\n },\n ),\n };\n }\n}\n\n/**\n * Loads RSC (React Server Components) based component\n */\nasync function loadRSCComponent(\n rscName: string,\n data: string[],\n): Promise<LoaderResult> {\n const { createFromReadableStream } = await importRSCClientBrowser();\n if (typeof createFromReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'Failed to import \"react-server-dom-webpack\". Is Next.js installed correctly?',\n );\n }\n\n const stream = createRSCStream(rscName, data);\n const component = createFromReadableStream(stream);\n\n return { component };\n}\n\n/**\n * Loads Next.js Pages Router based component\n */\nfunction loadNextPagesComponent(\n bundle: string,\n route: string,\n nextData: NonNullable<ConsumeLoaderPayload['nextData']>,\n name: string,\n container?: HTMLHeadElement | ShadowRoot | null,\n): LoaderResult {\n const { Component, App } = nextClientPagesLoader(bundle, route, container);\n\n if (!Component) {\n throw new RemoteComponentsError(\n `Remote Component \"${name}\" is trying to load the component for route \"${route}\" but it is not available.`,\n );\n }\n\n // error tolerance when app component is not found\n const component = App\n ? React.createElement(App, { Component, ...nextData.props })\n : React.createElement(Component, nextData.props);\n\n return { component };\n}\n"],"mappings":"AAAA,YAAY,WAAW;AACvB,YAAY,mBAAmB;AAC/B,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAC1B,YAAY,oBAAoB;AAChC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AAGtC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,8BAA8B;AACvC,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AAExC,SAAS,6BAA6B;AACtC,SAAS,UAAU,eAAe;AAClC,SAAS,mBAAmB;AAwB5B,eAAsB,oBAAoB;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA,UAAU,CAAC;AAAA,EACX,SAAS,QAAQ,QAAQ,CAAC,CAAC;AAAA,EAC3B,eAAe,CAAC;AAAA,EAChB;AAAA,EACA;AACF,GAA8C;AAC5C,MAAI;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CAAY,CAAC;AAAA,EACzD,SAAS,OAAP;AACA,WAAO;AAAA,MACL,WAAW;AAAA,MACX,OAAO,IAAI;AAAA,QACT,oCAAoC;AAAA,QACpC;AAAA,UACE,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAKA,eAAe,iBACb,SACA,MACuB;AACvB,QAAM,EAAE,yBAAyB,IAAI,MAAM,uBAAuB;AAClE,MAAI,OAAO,6BAA6B,YAAY;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,gBAAgB,SAAS,IAAI;AAC5C,QAAM,YAAY,yBAAyB,MAAM;AAEjD,SAAO,EAAE,UAAU;AACrB;AAKA,SAAS,uBACP,QACA,OACA,UACA,MACA,WACc;AACd,QAAM,EAAE,WAAW,IAAI,IAAI,sBAAsB,QAAQ,OAAO,SAAS;AAEzE,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR,qBAAqB,oDAAoD;AAAA,IAC3E;AAAA,EACF;AAGA,QAAM,YAAY,MACd,MAAM,cAAc,KAAK,EAAE,WAAW,GAAG,SAAS,MAAM,CAAC,IACzD,MAAM,cAAc,WAAW,SAAS,KAAK;AAEjD,SAAO,EAAE,UAAU;AACrB;","names":[]}
@@ -42,7 +42,7 @@ const REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(
42
42
  `\\.TURBOPACK_REMOTE_SHARED\\s*=\\s*await (?:__turbopack_context__|[a-z])\\.A\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
43
43
  );
44
44
  const ASYNC_MODULE_LOADER_RE = new RegExp(
45
- `(?:__turbopack_context__|e)\\.A\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\)`
45
+ `(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\)`
46
46
  );
47
47
  const ASYNC_MODULE_CALLBACK_RE = new RegExp(
48
48
  `(?:parentImport|[a-z])\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/patterns.ts"],"sourcesContent":["/**\n * Regex patterns for parsing Turbopack's minified and development code.\n *\n * Turbopack outputs different variable names in dev vs production builds:\n * - Development: __turbopack_context__, parentImport, chunk, self\n * - Minified: e, t, etc.\n *\n * Module IDs are numeric in Next.js 16+ (e.g. `984803`) but full string paths in\n * Next.js 15.x dev mode (e.g. `\"[project]/.../react/index.js [app-client] (ecmascript)\"`).\n * ID-capturing patterns match `\"quoted string\"|digits` via the shared\n * `MODULE_ID_PATTERN` fragment. Use `extractGroup()` to both match and strip quotes\n * in one step.\n */\n\n/** Reusable fragment that matches a turbopack module ID: quoted string or numeric. */\nconst MODULE_ID_PATTERN = '\"[^\"]+\"|[0-9]+';\n\n/** Strips surrounding double-quotes from a captured regex value. */\nfunction stripQuotes(value: string): string {\n if (value.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\n/**\n * Runs a regex against `input` and returns the named capture group with\n * quotes stripped, or `undefined` if there's no match.\n */\nexport function extractGroup(\n re: RegExp,\n input: string,\n group: string,\n): string | undefined {\n const raw = re.exec(input)?.groups?.[group];\n return raw ? stripQuotes(raw) : undefined;\n}\n\n/**\n * Matches: self.TURBOPACK_REMOTE_SHARED or e.TURBOPACK_REMOTE_SHARED\n *\n * @example\n * // Development:\n * \"self.TURBOPACK_REMOTE_SHARED=await __turbopack_context__.A(984803)\"\n *\n * // Minified:\n * \"e.TURBOPACK_REMOTE_SHARED=await e.A(984803)\"\n */\nexport const REMOTE_SHARED_MARKER_RE =\n /(?:self|[a-z])\\.TURBOPACK_REMOTE_SHARED/;\n\n/**\n * Extracts the module ID from a TURBOPACK_REMOTE_SHARED assignment.\n *\n * Captures:\n * - `sharedModuleId`: The module ID (may be quoted for string paths).\n *\n * @example\n * // Next.js 16:\n * \"self.TURBOPACK_REMOTE_SHARED=await __turbopack_context__.A(984803)\"\n * // -> sharedModuleId = \"984803\"\n *\n * // Next.js 15.x (string IDs, spaces around `=`):\n * 'self.TURBOPACK_REMOTE_SHARED = await __turbopack_context__.A(\"[project]/...app-remote.tsx [app-client] (ecmascript, async loader)\")'\n * // -> sharedModuleId = \"[project]/...app-remote.tsx [app-client] (ecmascript, async loader)\"\n *\n * // Minified:\n * \"t.TURBOPACK_REMOTE_SHARED=await e.A(123456)\"\n * // -> sharedModuleId = \"123456\"\n */\nexport const REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(\n `\\\\.TURBOPACK_REMOTE_SHARED\\\\s*=\\\\s*await (?:__turbopack_context__|[a-z])\\\\.A\\\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Matches async module loader calls: ctx.A(moduleId)\n *\n * Captures:\n * - `asyncSharedModuleId`: The module ID (may be quoted).\n *\n * @example\n * // Next.js 16:\n * \"() => __turbopack_context__.A(460400)\"\n * // -> asyncSharedModuleId = \"460400\"\n *\n * // Next.js 15.x:\n * '() => __turbopack_context__.A(\"[project]/.../react/index.js [app-client] (ecmascript, async loader)\")'\n * // -> asyncSharedModuleId = \"[project]/.../react/index.js [app-client] (ecmascript, async loader)\"\n *\n * // Minified:\n * \"() => e.A(460400)\"\n * // -> asyncSharedModuleId = \"460400\"\n */\nexport const ASYNC_MODULE_LOADER_RE = new RegExp(\n `(?:__turbopack_context__|e)\\\\.A\\\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Extracts the final module ID from an async module `.v()` callback.\n * The callback always ends by calling its argument (parentImport / single-letter\n * variable) with the real module ID. This matches that final call regardless of\n * surrounding structure (whitespace, `return` statements, block vs expression bodies).\n *\n * Handles both Promise.resolve (no extra chunks) and Promise.all (with chunks).\n *\n * Captures:\n * - `sharedModuleId`: The module ID (may be quoted).\n *\n * @example\n * // Next.js 16 minified (Promise.resolve):\n * \"e=>{e.v(e=>Promise.resolve().then(()=>e(633334)))}\"\n * // -> sharedModuleId = \"633334\"\n *\n * // Next.js 16 minified (Promise.all):\n * \"e=>{e.v(t=>Promise.all([\\\"chunk.js\\\"].map(t=>e.l(t))).then(()=>t(633334)))}\"\n * // -> sharedModuleId = \"633334\"\n *\n * // Next.js 15.x development (multi-line):\n * '(__turbopack_context__) => {\\n__turbopack_context__.v((parentImport) => {\\n return Promise.resolve().then(() => {\\n return parentImport(\"[project]/.../react/index.js [app-client] (ecmascript)\");\\n });\\n});\\n}'\n * // -> sharedModuleId = \"[project]/.../react/index.js [app-client] (ecmascript)\"\n */\nexport const ASYNC_MODULE_CALLBACK_RE = new RegExp(\n `(?:parentImport|[a-z])\\\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Detects Turbopack runtime global usage in a chunk.\n *\n * Matches either dot-notation or bracket-notation access off `globalThis` or `self`:\n * - globalThis.TURBOPACK / self.TURBOPACK\n * - globalThis[\"TURBOPACK\"] / self['TURBOPACK'] (whitespace tolerated)\n */\nexport const TURBOPACK_GLOBAL_RE =\n /(?:globalThis|self)\\s*(?:\\.TURBOPACK|\\[\\s*[\"']TURBOPACK[\"']\\s*\\])/;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,MAAM,oBAAoB;AAG1B,SAAS,YAAY,OAAuB;AAC1C,MAAI,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,GAAG;AAChD,WAAO,MAAM,MAAM,GAAG,EAAE;AAAA,EAC1B;AACA,SAAO;AACT;AAMO,SAAS,aACd,IACA,OACA,OACoB;AACpB,QAAM,MAAM,GAAG,KAAK,KAAK,GAAG,SAAS,KAAK;AAC1C,SAAO,MAAM,YAAY,GAAG,IAAI;AAClC;AAYO,MAAM,0BACX;AAqBK,MAAM,8BAA8B,IAAI;AAAA,EAC7C,oGAAoG;AACtG;AAqBO,MAAM,yBAAyB,IAAI;AAAA,EACxC,4DAA4D;AAC9D;AA0BO,MAAM,2BAA2B,IAAI;AAAA,EAC1C,8CAA8C;AAChD;AASO,MAAM,sBACX;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtime/turbopack/patterns.ts"],"sourcesContent":["/**\n * Regex patterns for parsing Turbopack's minified and development code.\n *\n * Turbopack outputs different variable names in dev vs production builds:\n * - Development: __turbopack_context__, parentImport, chunk, self\n * - Minified: e, t, etc.\n *\n * Module IDs are numeric in Next.js 16+ (e.g. `984803`) but full string paths in\n * Next.js 15.x dev mode (e.g. `\"[project]/.../react/index.js [app-client] (ecmascript)\"`).\n * ID-capturing patterns match `\"quoted string\"|digits` via the shared\n * `MODULE_ID_PATTERN` fragment. Use `extractGroup()` to both match and strip quotes\n * in one step.\n */\n\n/** Reusable fragment that matches a turbopack module ID: quoted string or numeric. */\nconst MODULE_ID_PATTERN = '\"[^\"]+\"|[0-9]+';\n\n/** Strips surrounding double-quotes from a captured regex value. */\nfunction stripQuotes(value: string): string {\n if (value.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\n/**\n * Runs a regex against `input` and returns the named capture group with\n * quotes stripped, or `undefined` if there's no match.\n */\nexport function extractGroup(\n re: RegExp,\n input: string,\n group: string,\n): string | undefined {\n const raw = re.exec(input)?.groups?.[group];\n return raw ? stripQuotes(raw) : undefined;\n}\n\n/**\n * Matches: self.TURBOPACK_REMOTE_SHARED or e.TURBOPACK_REMOTE_SHARED\n *\n * @example\n * // Development:\n * \"self.TURBOPACK_REMOTE_SHARED=await __turbopack_context__.A(984803)\"\n *\n * // Minified:\n * \"e.TURBOPACK_REMOTE_SHARED=await e.A(984803)\"\n */\nexport const REMOTE_SHARED_MARKER_RE =\n /(?:self|[a-z])\\.TURBOPACK_REMOTE_SHARED/;\n\n/**\n * Extracts the module ID from a TURBOPACK_REMOTE_SHARED assignment.\n *\n * Captures:\n * - `sharedModuleId`: The module ID (may be quoted for string paths).\n *\n * @example\n * // Next.js 16:\n * \"self.TURBOPACK_REMOTE_SHARED=await __turbopack_context__.A(984803)\"\n * // -> sharedModuleId = \"984803\"\n *\n * // Next.js 15.x (string IDs, spaces around `=`):\n * 'self.TURBOPACK_REMOTE_SHARED = await __turbopack_context__.A(\"[project]/...app-remote.tsx [app-client] (ecmascript, async loader)\")'\n * // -> sharedModuleId = \"[project]/...app-remote.tsx [app-client] (ecmascript, async loader)\"\n *\n * // Minified:\n * \"t.TURBOPACK_REMOTE_SHARED=await e.A(123456)\"\n * // -> sharedModuleId = \"123456\"\n */\nexport const REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(\n `\\\\.TURBOPACK_REMOTE_SHARED\\\\s*=\\\\s*await (?:__turbopack_context__|[a-z])\\\\.A\\\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Matches async module loader calls: ctx.A(moduleId)\n *\n * Captures:\n * - `asyncSharedModuleId`: The module ID (may be quoted).\n *\n * @example\n * // Next.js 16:\n * \"() => __turbopack_context__.A(460400)\"\n * // -> asyncSharedModuleId = \"460400\"\n *\n * // Next.js 15.x:\n * '() => __turbopack_context__.A(\"[project]/.../react/index.js [app-client] (ecmascript, async loader)\")'\n * // -> asyncSharedModuleId = \"[project]/.../react/index.js [app-client] (ecmascript, async loader)\"\n *\n * // Minified:\n * \"() => e.A(460400)\"\n * // -> asyncSharedModuleId = \"460400\"\n */\nexport const ASYNC_MODULE_LOADER_RE = new RegExp(\n `(?:__turbopack_context__|[a-z])\\\\.A\\\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Extracts the final module ID from an async module `.v()` callback.\n * The callback always ends by calling its argument (parentImport / single-letter\n * variable) with the real module ID. This matches that final call regardless of\n * surrounding structure (whitespace, `return` statements, block vs expression bodies).\n *\n * Handles both Promise.resolve (no extra chunks) and Promise.all (with chunks).\n *\n * Captures:\n * - `sharedModuleId`: The module ID (may be quoted).\n *\n * @example\n * // Next.js 16 minified (Promise.resolve):\n * \"e=>{e.v(e=>Promise.resolve().then(()=>e(633334)))}\"\n * // -> sharedModuleId = \"633334\"\n *\n * // Next.js 16 minified (Promise.all):\n * \"e=>{e.v(t=>Promise.all([\\\"chunk.js\\\"].map(t=>e.l(t))).then(()=>t(633334)))}\"\n * // -> sharedModuleId = \"633334\"\n *\n * // Next.js 15.x development (multi-line):\n * '(__turbopack_context__) => {\\n__turbopack_context__.v((parentImport) => {\\n return Promise.resolve().then(() => {\\n return parentImport(\"[project]/.../react/index.js [app-client] (ecmascript)\");\\n });\\n});\\n}'\n * // -> sharedModuleId = \"[project]/.../react/index.js [app-client] (ecmascript)\"\n */\nexport const ASYNC_MODULE_CALLBACK_RE = new RegExp(\n `(?:parentImport|[a-z])\\\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Detects Turbopack runtime global usage in a chunk.\n *\n * Matches either dot-notation or bracket-notation access off `globalThis` or `self`:\n * - globalThis.TURBOPACK / self.TURBOPACK\n * - globalThis[\"TURBOPACK\"] / self['TURBOPACK'] (whitespace tolerated)\n */\nexport const TURBOPACK_GLOBAL_RE =\n /(?:globalThis|self)\\s*(?:\\.TURBOPACK|\\[\\s*[\"']TURBOPACK[\"']\\s*\\])/;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,MAAM,oBAAoB;AAG1B,SAAS,YAAY,OAAuB;AAC1C,MAAI,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,GAAG;AAChD,WAAO,MAAM,MAAM,GAAG,EAAE;AAAA,EAC1B;AACA,SAAO;AACT;AAMO,SAAS,aACd,IACA,OACA,OACoB;AACpB,QAAM,MAAM,GAAG,KAAK,KAAK,GAAG,SAAS,KAAK;AAC1C,SAAO,MAAM,YAAY,GAAG,IAAI;AAClC;AAYO,MAAM,0BACX;AAqBK,MAAM,8BAA8B,IAAI;AAAA,EAC7C,oGAAoG;AACtG;AAqBO,MAAM,yBAAyB,IAAI;AAAA,EACxC,gEAAgE;AAClE;AA0BO,MAAM,2BAA2B,IAAI;AAAA,EAC1C,8CAA8C;AAChD;AASO,MAAM,sBACX;","names":[]}
@@ -14,7 +14,7 @@ const REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(
14
14
  `\\.TURBOPACK_REMOTE_SHARED\\s*=\\s*await (?:__turbopack_context__|[a-z])\\.A\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
15
15
  );
16
16
  const ASYNC_MODULE_LOADER_RE = new RegExp(
17
- `(?:__turbopack_context__|e)\\.A\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\)`
17
+ `(?:__turbopack_context__|[a-z])\\.A\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\)`
18
18
  );
19
19
  const ASYNC_MODULE_CALLBACK_RE = new RegExp(
20
20
  `(?:parentImport|[a-z])\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\)`
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/patterns.ts"],"sourcesContent":["/**\n * Regex patterns for parsing Turbopack's minified and development code.\n *\n * Turbopack outputs different variable names in dev vs production builds:\n * - Development: __turbopack_context__, parentImport, chunk, self\n * - Minified: e, t, etc.\n *\n * Module IDs are numeric in Next.js 16+ (e.g. `984803`) but full string paths in\n * Next.js 15.x dev mode (e.g. `\"[project]/.../react/index.js [app-client] (ecmascript)\"`).\n * ID-capturing patterns match `\"quoted string\"|digits` via the shared\n * `MODULE_ID_PATTERN` fragment. Use `extractGroup()` to both match and strip quotes\n * in one step.\n */\n\n/** Reusable fragment that matches a turbopack module ID: quoted string or numeric. */\nconst MODULE_ID_PATTERN = '\"[^\"]+\"|[0-9]+';\n\n/** Strips surrounding double-quotes from a captured regex value. */\nfunction stripQuotes(value: string): string {\n if (value.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\n/**\n * Runs a regex against `input` and returns the named capture group with\n * quotes stripped, or `undefined` if there's no match.\n */\nexport function extractGroup(\n re: RegExp,\n input: string,\n group: string,\n): string | undefined {\n const raw = re.exec(input)?.groups?.[group];\n return raw ? stripQuotes(raw) : undefined;\n}\n\n/**\n * Matches: self.TURBOPACK_REMOTE_SHARED or e.TURBOPACK_REMOTE_SHARED\n *\n * @example\n * // Development:\n * \"self.TURBOPACK_REMOTE_SHARED=await __turbopack_context__.A(984803)\"\n *\n * // Minified:\n * \"e.TURBOPACK_REMOTE_SHARED=await e.A(984803)\"\n */\nexport const REMOTE_SHARED_MARKER_RE =\n /(?:self|[a-z])\\.TURBOPACK_REMOTE_SHARED/;\n\n/**\n * Extracts the module ID from a TURBOPACK_REMOTE_SHARED assignment.\n *\n * Captures:\n * - `sharedModuleId`: The module ID (may be quoted for string paths).\n *\n * @example\n * // Next.js 16:\n * \"self.TURBOPACK_REMOTE_SHARED=await __turbopack_context__.A(984803)\"\n * // -> sharedModuleId = \"984803\"\n *\n * // Next.js 15.x (string IDs, spaces around `=`):\n * 'self.TURBOPACK_REMOTE_SHARED = await __turbopack_context__.A(\"[project]/...app-remote.tsx [app-client] (ecmascript, async loader)\")'\n * // -> sharedModuleId = \"[project]/...app-remote.tsx [app-client] (ecmascript, async loader)\"\n *\n * // Minified:\n * \"t.TURBOPACK_REMOTE_SHARED=await e.A(123456)\"\n * // -> sharedModuleId = \"123456\"\n */\nexport const REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(\n `\\\\.TURBOPACK_REMOTE_SHARED\\\\s*=\\\\s*await (?:__turbopack_context__|[a-z])\\\\.A\\\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Matches async module loader calls: ctx.A(moduleId)\n *\n * Captures:\n * - `asyncSharedModuleId`: The module ID (may be quoted).\n *\n * @example\n * // Next.js 16:\n * \"() => __turbopack_context__.A(460400)\"\n * // -> asyncSharedModuleId = \"460400\"\n *\n * // Next.js 15.x:\n * '() => __turbopack_context__.A(\"[project]/.../react/index.js [app-client] (ecmascript, async loader)\")'\n * // -> asyncSharedModuleId = \"[project]/.../react/index.js [app-client] (ecmascript, async loader)\"\n *\n * // Minified:\n * \"() => e.A(460400)\"\n * // -> asyncSharedModuleId = \"460400\"\n */\nexport const ASYNC_MODULE_LOADER_RE = new RegExp(\n `(?:__turbopack_context__|e)\\\\.A\\\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Extracts the final module ID from an async module `.v()` callback.\n * The callback always ends by calling its argument (parentImport / single-letter\n * variable) with the real module ID. This matches that final call regardless of\n * surrounding structure (whitespace, `return` statements, block vs expression bodies).\n *\n * Handles both Promise.resolve (no extra chunks) and Promise.all (with chunks).\n *\n * Captures:\n * - `sharedModuleId`: The module ID (may be quoted).\n *\n * @example\n * // Next.js 16 minified (Promise.resolve):\n * \"e=>{e.v(e=>Promise.resolve().then(()=>e(633334)))}\"\n * // -> sharedModuleId = \"633334\"\n *\n * // Next.js 16 minified (Promise.all):\n * \"e=>{e.v(t=>Promise.all([\\\"chunk.js\\\"].map(t=>e.l(t))).then(()=>t(633334)))}\"\n * // -> sharedModuleId = \"633334\"\n *\n * // Next.js 15.x development (multi-line):\n * '(__turbopack_context__) => {\\n__turbopack_context__.v((parentImport) => {\\n return Promise.resolve().then(() => {\\n return parentImport(\"[project]/.../react/index.js [app-client] (ecmascript)\");\\n });\\n});\\n}'\n * // -> sharedModuleId = \"[project]/.../react/index.js [app-client] (ecmascript)\"\n */\nexport const ASYNC_MODULE_CALLBACK_RE = new RegExp(\n `(?:parentImport|[a-z])\\\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Detects Turbopack runtime global usage in a chunk.\n *\n * Matches either dot-notation or bracket-notation access off `globalThis` or `self`:\n * - globalThis.TURBOPACK / self.TURBOPACK\n * - globalThis[\"TURBOPACK\"] / self['TURBOPACK'] (whitespace tolerated)\n */\nexport const TURBOPACK_GLOBAL_RE =\n /(?:globalThis|self)\\s*(?:\\.TURBOPACK|\\[\\s*[\"']TURBOPACK[\"']\\s*\\])/;\n"],"mappings":"AAeA,MAAM,oBAAoB;AAG1B,SAAS,YAAY,OAAuB;AAC1C,MAAI,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,GAAG;AAChD,WAAO,MAAM,MAAM,GAAG,EAAE;AAAA,EAC1B;AACA,SAAO;AACT;AAMO,SAAS,aACd,IACA,OACA,OACoB;AACpB,QAAM,MAAM,GAAG,KAAK,KAAK,GAAG,SAAS,KAAK;AAC1C,SAAO,MAAM,YAAY,GAAG,IAAI;AAClC;AAYO,MAAM,0BACX;AAqBK,MAAM,8BAA8B,IAAI;AAAA,EAC7C,oGAAoG;AACtG;AAqBO,MAAM,yBAAyB,IAAI;AAAA,EACxC,4DAA4D;AAC9D;AA0BO,MAAM,2BAA2B,IAAI;AAAA,EAC1C,8CAA8C;AAChD;AASO,MAAM,sBACX;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtime/turbopack/patterns.ts"],"sourcesContent":["/**\n * Regex patterns for parsing Turbopack's minified and development code.\n *\n * Turbopack outputs different variable names in dev vs production builds:\n * - Development: __turbopack_context__, parentImport, chunk, self\n * - Minified: e, t, etc.\n *\n * Module IDs are numeric in Next.js 16+ (e.g. `984803`) but full string paths in\n * Next.js 15.x dev mode (e.g. `\"[project]/.../react/index.js [app-client] (ecmascript)\"`).\n * ID-capturing patterns match `\"quoted string\"|digits` via the shared\n * `MODULE_ID_PATTERN` fragment. Use `extractGroup()` to both match and strip quotes\n * in one step.\n */\n\n/** Reusable fragment that matches a turbopack module ID: quoted string or numeric. */\nconst MODULE_ID_PATTERN = '\"[^\"]+\"|[0-9]+';\n\n/** Strips surrounding double-quotes from a captured regex value. */\nfunction stripQuotes(value: string): string {\n if (value.startsWith('\"') && value.endsWith('\"')) {\n return value.slice(1, -1);\n }\n return value;\n}\n\n/**\n * Runs a regex against `input` and returns the named capture group with\n * quotes stripped, or `undefined` if there's no match.\n */\nexport function extractGroup(\n re: RegExp,\n input: string,\n group: string,\n): string | undefined {\n const raw = re.exec(input)?.groups?.[group];\n return raw ? stripQuotes(raw) : undefined;\n}\n\n/**\n * Matches: self.TURBOPACK_REMOTE_SHARED or e.TURBOPACK_REMOTE_SHARED\n *\n * @example\n * // Development:\n * \"self.TURBOPACK_REMOTE_SHARED=await __turbopack_context__.A(984803)\"\n *\n * // Minified:\n * \"e.TURBOPACK_REMOTE_SHARED=await e.A(984803)\"\n */\nexport const REMOTE_SHARED_MARKER_RE =\n /(?:self|[a-z])\\.TURBOPACK_REMOTE_SHARED/;\n\n/**\n * Extracts the module ID from a TURBOPACK_REMOTE_SHARED assignment.\n *\n * Captures:\n * - `sharedModuleId`: The module ID (may be quoted for string paths).\n *\n * @example\n * // Next.js 16:\n * \"self.TURBOPACK_REMOTE_SHARED=await __turbopack_context__.A(984803)\"\n * // -> sharedModuleId = \"984803\"\n *\n * // Next.js 15.x (string IDs, spaces around `=`):\n * 'self.TURBOPACK_REMOTE_SHARED = await __turbopack_context__.A(\"[project]/...app-remote.tsx [app-client] (ecmascript, async loader)\")'\n * // -> sharedModuleId = \"[project]/...app-remote.tsx [app-client] (ecmascript, async loader)\"\n *\n * // Minified:\n * \"t.TURBOPACK_REMOTE_SHARED=await e.A(123456)\"\n * // -> sharedModuleId = \"123456\"\n */\nexport const REMOTE_SHARED_ASSIGNMENT_RE = new RegExp(\n `\\\\.TURBOPACK_REMOTE_SHARED\\\\s*=\\\\s*await (?:__turbopack_context__|[a-z])\\\\.A\\\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Matches async module loader calls: ctx.A(moduleId)\n *\n * Captures:\n * - `asyncSharedModuleId`: The module ID (may be quoted).\n *\n * @example\n * // Next.js 16:\n * \"() => __turbopack_context__.A(460400)\"\n * // -> asyncSharedModuleId = \"460400\"\n *\n * // Next.js 15.x:\n * '() => __turbopack_context__.A(\"[project]/.../react/index.js [app-client] (ecmascript, async loader)\")'\n * // -> asyncSharedModuleId = \"[project]/.../react/index.js [app-client] (ecmascript, async loader)\"\n *\n * // Minified:\n * \"() => e.A(460400)\"\n * // -> asyncSharedModuleId = \"460400\"\n */\nexport const ASYNC_MODULE_LOADER_RE = new RegExp(\n `(?:__turbopack_context__|[a-z])\\\\.A\\\\((?<asyncSharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Extracts the final module ID from an async module `.v()` callback.\n * The callback always ends by calling its argument (parentImport / single-letter\n * variable) with the real module ID. This matches that final call regardless of\n * surrounding structure (whitespace, `return` statements, block vs expression bodies).\n *\n * Handles both Promise.resolve (no extra chunks) and Promise.all (with chunks).\n *\n * Captures:\n * - `sharedModuleId`: The module ID (may be quoted).\n *\n * @example\n * // Next.js 16 minified (Promise.resolve):\n * \"e=>{e.v(e=>Promise.resolve().then(()=>e(633334)))}\"\n * // -> sharedModuleId = \"633334\"\n *\n * // Next.js 16 minified (Promise.all):\n * \"e=>{e.v(t=>Promise.all([\\\"chunk.js\\\"].map(t=>e.l(t))).then(()=>t(633334)))}\"\n * // -> sharedModuleId = \"633334\"\n *\n * // Next.js 15.x development (multi-line):\n * '(__turbopack_context__) => {\\n__turbopack_context__.v((parentImport) => {\\n return Promise.resolve().then(() => {\\n return parentImport(\"[project]/.../react/index.js [app-client] (ecmascript)\");\\n });\\n});\\n}'\n * // -> sharedModuleId = \"[project]/.../react/index.js [app-client] (ecmascript)\"\n */\nexport const ASYNC_MODULE_CALLBACK_RE = new RegExp(\n `(?:parentImport|[a-z])\\\\((?<sharedModuleId>${MODULE_ID_PATTERN})\\\\)`,\n);\n\n/**\n * Detects Turbopack runtime global usage in a chunk.\n *\n * Matches either dot-notation or bracket-notation access off `globalThis` or `self`:\n * - globalThis.TURBOPACK / self.TURBOPACK\n * - globalThis[\"TURBOPACK\"] / self['TURBOPACK'] (whitespace tolerated)\n */\nexport const TURBOPACK_GLOBAL_RE =\n /(?:globalThis|self)\\s*(?:\\.TURBOPACK|\\[\\s*[\"']TURBOPACK[\"']\\s*\\])/;\n"],"mappings":"AAeA,MAAM,oBAAoB;AAG1B,SAAS,YAAY,OAAuB;AAC1C,MAAI,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,GAAG;AAChD,WAAO,MAAM,MAAM,GAAG,EAAE;AAAA,EAC1B;AACA,SAAO;AACT;AAMO,SAAS,aACd,IACA,OACA,OACoB;AACpB,QAAM,MAAM,GAAG,KAAK,KAAK,GAAG,SAAS,KAAK;AAC1C,SAAO,MAAM,YAAY,GAAG,IAAI;AAClC;AAYO,MAAM,0BACX;AAqBK,MAAM,8BAA8B,IAAI;AAAA,EAC7C,oGAAoG;AACtG;AAqBO,MAAM,yBAAyB,IAAI;AAAA,EACxC,gEAAgE;AAClE;AA0BO,MAAM,2BAA2B,IAAI;AAAA,EAC1C,8CAA8C;AAChD;AASO,MAAM,sBACX;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/remote-scope-setup.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkDispatcher, loadChunkWithScope } from './chunk-loader';\nimport { requireModule } from './module';\nimport {\n createScope,\n getScope,\n type RemoteScope,\n registerScope,\n} from './remote-scope';\n\n/**\n * Sets up the bundler runtime environment for remote components.\n *\n * Creates a RemoteScope that encapsulates all per-remote state (base URL,\n * proxy callback, module cache, shared modules) and registers it in the\n * global scope registry. Global dispatchers (__webpack_require__,\n * __webpack_chunk_load__) are set once and route to the correct scope.\n *\n * Shared module initialization is NOT performed here — callers must invoke\n * `initializeSharedModules` separately after this function returns. This\n * separation ensures shared modules are initialized after turbopack chunks\n * are loaded (so the primary bundle-introspection path is used), avoiding\n * the fallback that keys shared modules by file path instead of numeric ID.\n *\n * @returns The scope (newly created or reused) for the bundle.\n */\nexport async function setupRemoteScope(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<RemoteScope> {\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n const bundleName = bundle ?? 'default';\n\n // When the same remote loads a second component (e.g. switching from basic\n // to styled), reuse the existing scope. The chunk cache is keyed by URL and\n // returns cached promises without re-running handleTurbopackChunk, so\n // turbopackModules, moduleCache, and sharedModules from the first load are\n // all still valid. Only resolveClientUrl may have changed.\n const existingScope = getScope(bundleName);\n if (existingScope && existingScope.url.origin === url.origin) {\n logDebug(\n 'WebpackRuntime',\n `Reusing scope \"${existingScope.scopedName}\" (turbopackModules=${existingScope.turbopackModules.length})`,\n );\n existingScope.resolveClientUrl = resolveClientUrl;\n\n // Still load scripts — chunk cache deduplicates already-loaded chunks,\n // and a different component may reference additional chunks.\n if (runtime === RUNTIME_TURBOPACK) {\n await Promise.allSettled(\n scripts.map((script) =>\n script.src\n ? loadChunkWithScope(existingScope, script.src)\n : Promise.resolve(undefined),\n ),\n );\n }\n return existingScope;\n }\n\n const scope = createScope(bundleName, url, runtime, resolveClientUrl);\n registerScope(scope);\n\n // For webpack remotes the remote's own scripts have already loaded (via\n // loadScripts in component-loader) and populated __remote_webpack_require__\n // under the plain bundle name. Capture the reference on the scope so\n // downstream code (applySharedModules, module dispatcher) can use it\n // without reaching into the global.\n if (\n runtime === RUNTIME_WEBPACK &&\n self.__remote_webpack_require__?.[bundleName]\n ) {\n scope.webpackRequire = self.__remote_webpack_require__[bundleName];\n }\n\n ns.bundleUrls[bundleName] = url;\n // Also register under scopedName so webpack hosts (patch-require.ts) can\n // resolve cross-origin remotes whose bundle identifiers were rewritten.\n if (scope.scopedName !== bundleName) {\n ns.bundleUrls[scope.scopedName] = url;\n }\n self.__webpack_get_script_filename__ = () => null;\n\n const willCreateDispatchers =\n typeof self.__webpack_require__ !== 'function' ||\n ns.dispatcherRuntime !== 'turbopack';\n\n if (willCreateDispatchers) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkDispatcher();\n self.__webpack_require__ = createModuleDispatcher(runtime);\n // Write-through needed: dispatcherRuntime is a primitive string,\n // so the legacy global can't be aliased by reference in getNamespace().\n ns.dispatcherRuntime = runtime;\n self.__webpack_require_type__ = runtime;\n\n // @legacy(v0.3.4) — __remote_webpack_require__ write-through for turbopack remotes.\n // Needed by PatchRequirePlugin which reads this global at runtime.\n // Remove once PatchRequirePlugin reads from scope.\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n self.__remote_webpack_require__[bundleName] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[bundleName].type = 'turbopack';\n }\n }\n\n // @legacy(v0.3.4) — __remote_webpack_require__ scoped-name alias.\n // Ensures PatchRequirePlugin can find webpack remotes under rewritten\n // bundle identifiers. Remove once PatchRequirePlugin reads from scope.\n if (\n self.__remote_webpack_require__?.[bundleName] &&\n scope.scopedName !== bundleName\n ) {\n self.__remote_webpack_require__[scope.scopedName] =\n self.__remote_webpack_require__[bundleName];\n }\n\n // load all initial chunks directly via scope — no global dispatch needed\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return loadChunkWithScope(scope, script.src);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n return scope;\n}\n\n/**\n * Creates the global module dispatcher for __webpack_require__.\n * Called by external code (React's RSC runtime) that doesn't have access to\n * a scope. Parses the module ID to find the correct scope and delegates\n * to scope-local module resolution.\n */\nfunction createModuleDispatcher(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const bundleName = bundle ?? 'default';\n const remoteRuntime = self.__remote_webpack_require__?.[bundleName]\n ? self.__remote_webpack_require__[bundleName]?.type || 'webpack'\n : runtime;\n\n logDebug(\n 'ModuleDispatcher',\n `Resolving \"${id}\" (bundle: \"${bundleName}\", runtime: \"${remoteRuntime}\")`,\n );\n\n try {\n // for webpack remotes, prefer scope-based dispatch then fall back to global\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n const scope = getScope(bundle);\n if (scope?.webpackRequire) return scope.webpackRequire(moduleId);\n // @legacy(v0.3.4) — global fallback for hosts that populated\n // __remote_webpack_require__ without calling setupWebpackRuntime.\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n\n // Look up scope by parsed bundle name. Works with both the scoped\n // name (Next.js hosts with server-side rewriting) and the plain\n // bundle name (static/HTML hosts with unrewritten chunks).\n const scope = getScope(bundleName);\n if (scope) {\n return requireModule(scope, moduleId ?? id, id);\n }\n\n throw new Error(\n `Module \"${id}\" not found — no scope for bundle \"${bundleName}\".`,\n );\n } catch (requireError) {\n logWarn(\n 'ModuleDispatcher',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug(\n 'ModuleDispatcher',\n 'Falling back to original webpack require',\n );\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAIO;AACP,uBAA6B;AAC7B,sBAAuC;AAEvC,mBAAsC;AACtC,oBAAkC;AAClC,0BAA0D;AAC1D,oBAA8B;AAC9B,0BAKO;AAkBP,eAAsB,iBACpB,SACA,UAAoC,CAAC,GACrC,MAAW,IAAI,IAAI,SAAS,IAAI,GAChC,QACA,kBACsB;AACtB,QAAM,OAAO;AACb,QAAM,SAAK,+BAAa;AACxB,QAAM,aAAa,UAAU;AAO7B,QAAM,oBAAgB,8BAAS,UAAU;AACzC,MAAI,iBAAiB,cAAc,IAAI,WAAW,IAAI,QAAQ;AAC5D;AAAA,MACE;AAAA,MACA,kBAAkB,cAAc,iCAAiC,cAAc,iBAAiB;AAAA,IAClG;AACA,kBAAc,mBAAmB;AAIjC,QAAI,YAAY,oCAAmB;AACjC,YAAM,QAAQ;AAAA,QACZ,QAAQ;AAAA,UAAI,CAAC,WACX,OAAO,UACH,wCAAmB,eAAe,OAAO,GAAG,IAC5C,QAAQ,QAAQ,MAAS;AAAA,QAC/B;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,QAAM,YAAQ,iCAAY,YAAY,KAAK,SAAS,gBAAgB;AACpE,yCAAc,KAAK;AAOnB,MACE,YAAY,oCACZ,KAAK,6BAA6B,UAAU,GAC5C;AACA,UAAM,iBAAiB,KAAK,2BAA2B,UAAU;AAAA,EACnE;AAEA,KAAG,WAAW,UAAU,IAAI;AAG5B,MAAI,MAAM,eAAe,YAAY;AACnC,OAAG,WAAW,MAAM,UAAU,IAAI;AAAA,EACpC;AACA,OAAK,kCAAkC,MAAM;AAE7C,QAAM,wBACJ,OAAO,KAAK,wBAAwB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D;AAEJ;AAAA,MACE;AAAA,MACA,cAAc,iBAAiB,0BAA0B;AAAA,IAC3D;AAEA,QAAI;AAEF,UAAI,kBAAkB,oCAAmB,UAAU,UAAU;AAC3D,cAAMA,aAAQ,8BAAS,MAAM;AAC7B,YAAIA,QAAO;AAAgB,iBAAOA,OAAM,eAAe,QAAQ;AAG/D,eAAO,KAAK,6BAA6B,MAAM,IAAI,QAAQ;AAAA,MAC7D;AAKA,YAAM,YAAQ,8BAAS,UAAU;AACjC,UAAI,OAAO;AACT,mBAAO,6BAAc,OAAO,YAAY,IAAI,EAAE;AAAA,MAChD;AAEA,YAAM,IAAI;AAAA,QACR,WAAW,6CAAwC;AAAA,MACrD;AAAA,IACF,SAAS,cAAP;AACA;AAAA,QACE;AAAA,QACA,0BAA0B,OAAO,YAAY;AAAA,MAC/C;AACA,UAAI,OAAO,KAAK,iCAAiC,YAAY;AAC3D,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD;AAAA,YACE,OAAO,wBAAwB,QAAQ,eAAe;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AACA,UAAI;AACF;AAAA,UACE;AAAA,UACA;AAAA,QACF;AACA,eAAO,KAAK,6BAA6B,EAAE;AAAA,MAC7C,SAAS,eAAP;AACA,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD,EAAE,OAAO,yBAAyB,QAAQ,gBAAgB,OAAU;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["scope"]}
1
+ {"version":3,"sources":["../../../../src/runtime/turbopack/remote-scope-setup.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkDispatcher, loadChunkWithScope } from './chunk-loader';\nimport { requireModule } from './module';\nimport {\n createScope,\n getScope,\n type RemoteScope,\n registerScope,\n} from './remote-scope';\n\n/**\n * Sets up the bundler runtime environment for remote components.\n *\n * Creates a RemoteScope that encapsulates all per-remote state (base URL,\n * proxy callback, module cache, shared modules) and registers it in the\n * global scope registry. Global dispatchers (__webpack_require__,\n * __webpack_chunk_load__) are set once and route to the correct scope.\n *\n * Shared module initialization is NOT performed here — callers must invoke\n * `initializeSharedModules` separately after this function returns. This\n * separation ensures shared modules are initialized after turbopack chunks\n * are loaded (so the primary bundle-introspection path is used), avoiding\n * the fallback that keys shared modules by file path instead of numeric ID.\n *\n * @returns The scope (newly created or reused) for the bundle.\n */\nexport async function setupRemoteScope(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<RemoteScope> {\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n const bundleName = bundle ?? 'default';\n\n // When the same remote loads a second component (e.g. switching from basic\n // to styled), reuse the existing scope. The chunk cache is keyed by URL and\n // returns cached promises without re-running handleTurbopackChunk, so\n // turbopackModules, moduleCache, and sharedModules from the first load are\n // all still valid. Only resolveClientUrl may have changed.\n //\n // Origin-only comparison is sufficient because bundleName already identifies\n // a specific remote — different paths on the same origin would be a different\n // bundle with a different name, so getScope() wouldn't return a match.\n const existingScope = getScope(bundleName);\n if (existingScope && existingScope.url.origin === url.origin) {\n logDebug(\n 'WebpackRuntime',\n `Reusing scope \"${existingScope.scopedName}\" (turbopackModules=${existingScope.turbopackModules.length})`,\n );\n existingScope.resolveClientUrl = resolveClientUrl;\n\n // Still load scripts — chunk cache deduplicates already-loaded chunks,\n // and a different component may reference additional chunks.\n if (runtime === RUNTIME_TURBOPACK) {\n await Promise.allSettled(\n scripts.map((script) =>\n script.src\n ? loadChunkWithScope(existingScope, script.src)\n : Promise.resolve(undefined),\n ),\n );\n }\n return existingScope;\n }\n\n const scope = createScope(bundleName, url, runtime, resolveClientUrl);\n registerScope(scope);\n\n // For webpack remotes the remote's own scripts have already loaded (via\n // loadScripts in component-loader) and populated __remote_webpack_require__\n // under the plain bundle name. Capture the reference on the scope so\n // downstream code (applySharedModules, module dispatcher) can use it\n // without reaching into the global.\n if (\n runtime === RUNTIME_WEBPACK &&\n self.__remote_webpack_require__?.[bundleName]\n ) {\n scope.webpackRequire = self.__remote_webpack_require__[bundleName];\n }\n\n ns.bundleUrls[bundleName] = url;\n // Also register under scopedName so webpack hosts (patch-require.ts) can\n // resolve cross-origin remotes whose bundle identifiers were rewritten.\n if (scope.scopedName !== bundleName) {\n ns.bundleUrls[scope.scopedName] = url;\n }\n self.__webpack_get_script_filename__ = () => null;\n\n const willCreateDispatchers =\n typeof self.__webpack_require__ !== 'function' ||\n ns.dispatcherRuntime !== 'turbopack';\n\n if (willCreateDispatchers) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkDispatcher();\n self.__webpack_require__ = createModuleDispatcher(runtime);\n // Write-through needed: dispatcherRuntime is a primitive string,\n // so the legacy global can't be aliased by reference in getNamespace().\n ns.dispatcherRuntime = runtime;\n self.__webpack_require_type__ = runtime;\n\n // @legacy(v0.3.4) — __remote_webpack_require__ write-through for turbopack remotes.\n // Needed by PatchRequirePlugin which reads this global at runtime.\n // Remove once PatchRequirePlugin reads from scope.\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n self.__remote_webpack_require__[bundleName] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[bundleName].type = 'turbopack';\n }\n }\n\n // @legacy(v0.3.4) — __remote_webpack_require__ scoped-name alias.\n // Ensures PatchRequirePlugin can find webpack remotes under rewritten\n // bundle identifiers. Remove once PatchRequirePlugin reads from scope.\n if (\n self.__remote_webpack_require__?.[bundleName] &&\n scope.scopedName !== bundleName\n ) {\n self.__remote_webpack_require__[scope.scopedName] =\n self.__remote_webpack_require__[bundleName];\n }\n\n // load all initial chunks directly via scope — no global dispatch needed\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return loadChunkWithScope(scope, script.src);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n return scope;\n}\n\n/**\n * Creates the global module dispatcher for __webpack_require__.\n * Called by external code (React's RSC runtime) that doesn't have access to\n * a scope. Parses the module ID to find the correct scope and delegates\n * to scope-local module resolution.\n */\nfunction createModuleDispatcher(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const bundleName = bundle ?? 'default';\n const remoteRuntime = self.__remote_webpack_require__?.[bundleName]\n ? self.__remote_webpack_require__[bundleName]?.type || 'webpack'\n : runtime;\n\n logDebug(\n 'ModuleDispatcher',\n `Resolving \"${id}\" (bundle: \"${bundleName}\", runtime: \"${remoteRuntime}\")`,\n );\n\n try {\n // for webpack remotes, prefer scope-based dispatch then fall back to global\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n const scope = getScope(bundle);\n if (scope?.webpackRequire) return scope.webpackRequire(moduleId);\n // @legacy(v0.3.4) — global fallback for hosts that populated\n // __remote_webpack_require__ without calling setupWebpackRuntime.\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n\n // Look up scope by parsed bundle name. Works with both the scoped\n // name (Next.js hosts with server-side rewriting) and the plain\n // bundle name (static/HTML hosts with unrewritten chunks).\n const scope = getScope(bundleName);\n if (scope) {\n return requireModule(scope, moduleId ?? id, id);\n }\n\n throw new Error(\n `Module \"${id}\" not found — no scope for bundle \"${bundleName}\".`,\n );\n } catch (requireError) {\n logWarn(\n 'ModuleDispatcher',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug(\n 'ModuleDispatcher',\n 'Falling back to original webpack require',\n );\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAIO;AACP,uBAA6B;AAC7B,sBAAuC;AAEvC,mBAAsC;AACtC,oBAAkC;AAClC,0BAA0D;AAC1D,oBAA8B;AAC9B,0BAKO;AAkBP,eAAsB,iBACpB,SACA,UAAoC,CAAC,GACrC,MAAW,IAAI,IAAI,SAAS,IAAI,GAChC,QACA,kBACsB;AACtB,QAAM,OAAO;AACb,QAAM,SAAK,+BAAa;AACxB,QAAM,aAAa,UAAU;AAW7B,QAAM,oBAAgB,8BAAS,UAAU;AACzC,MAAI,iBAAiB,cAAc,IAAI,WAAW,IAAI,QAAQ;AAC5D;AAAA,MACE;AAAA,MACA,kBAAkB,cAAc,iCAAiC,cAAc,iBAAiB;AAAA,IAClG;AACA,kBAAc,mBAAmB;AAIjC,QAAI,YAAY,oCAAmB;AACjC,YAAM,QAAQ;AAAA,QACZ,QAAQ;AAAA,UAAI,CAAC,WACX,OAAO,UACH,wCAAmB,eAAe,OAAO,GAAG,IAC5C,QAAQ,QAAQ,MAAS;AAAA,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AA,UACxD,EAAE,OAAO,yBAAyB,QAAQ,gBAAgB,OAAU;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["scope"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/remote-scope-setup.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkDispatcher, loadChunkWithScope } from './chunk-loader';\nimport { requireModule } from './module';\nimport {\n createScope,\n getScope,\n type RemoteScope,\n registerScope,\n} from './remote-scope';\n\n/**\n * Sets up the bundler runtime environment for remote components.\n *\n * Creates a RemoteScope that encapsulates all per-remote state (base URL,\n * proxy callback, module cache, shared modules) and registers it in the\n * global scope registry. Global dispatchers (__webpack_require__,\n * __webpack_chunk_load__) are set once and route to the correct scope.\n *\n * Shared module initialization is NOT performed here — callers must invoke\n * `initializeSharedModules` separately after this function returns. This\n * separation ensures shared modules are initialized after turbopack chunks\n * are loaded (so the primary bundle-introspection path is used), avoiding\n * the fallback that keys shared modules by file path instead of numeric ID.\n *\n * @returns The scope (newly created or reused) for the bundle.\n */\nexport async function setupRemoteScope(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<RemoteScope> {\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n const bundleName = bundle ?? 'default';\n\n // When the same remote loads a second component (e.g. switching from basic\n // to styled), reuse the existing scope. The chunk cache is keyed by URL and\n // returns cached promises without re-running handleTurbopackChunk, so\n // turbopackModules, moduleCache, and sharedModules from the first load are\n // all still valid. Only resolveClientUrl may have changed.\n const existingScope = getScope(bundleName);\n if (existingScope && existingScope.url.origin === url.origin) {\n logDebug(\n 'WebpackRuntime',\n `Reusing scope \"${existingScope.scopedName}\" (turbopackModules=${existingScope.turbopackModules.length})`,\n );\n existingScope.resolveClientUrl = resolveClientUrl;\n\n // Still load scripts — chunk cache deduplicates already-loaded chunks,\n // and a different component may reference additional chunks.\n if (runtime === RUNTIME_TURBOPACK) {\n await Promise.allSettled(\n scripts.map((script) =>\n script.src\n ? loadChunkWithScope(existingScope, script.src)\n : Promise.resolve(undefined),\n ),\n );\n }\n return existingScope;\n }\n\n const scope = createScope(bundleName, url, runtime, resolveClientUrl);\n registerScope(scope);\n\n // For webpack remotes the remote's own scripts have already loaded (via\n // loadScripts in component-loader) and populated __remote_webpack_require__\n // under the plain bundle name. Capture the reference on the scope so\n // downstream code (applySharedModules, module dispatcher) can use it\n // without reaching into the global.\n if (\n runtime === RUNTIME_WEBPACK &&\n self.__remote_webpack_require__?.[bundleName]\n ) {\n scope.webpackRequire = self.__remote_webpack_require__[bundleName];\n }\n\n ns.bundleUrls[bundleName] = url;\n // Also register under scopedName so webpack hosts (patch-require.ts) can\n // resolve cross-origin remotes whose bundle identifiers were rewritten.\n if (scope.scopedName !== bundleName) {\n ns.bundleUrls[scope.scopedName] = url;\n }\n self.__webpack_get_script_filename__ = () => null;\n\n const willCreateDispatchers =\n typeof self.__webpack_require__ !== 'function' ||\n ns.dispatcherRuntime !== 'turbopack';\n\n if (willCreateDispatchers) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkDispatcher();\n self.__webpack_require__ = createModuleDispatcher(runtime);\n // Write-through needed: dispatcherRuntime is a primitive string,\n // so the legacy global can't be aliased by reference in getNamespace().\n ns.dispatcherRuntime = runtime;\n self.__webpack_require_type__ = runtime;\n\n // @legacy(v0.3.4) — __remote_webpack_require__ write-through for turbopack remotes.\n // Needed by PatchRequirePlugin which reads this global at runtime.\n // Remove once PatchRequirePlugin reads from scope.\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n self.__remote_webpack_require__[bundleName] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[bundleName].type = 'turbopack';\n }\n }\n\n // @legacy(v0.3.4) — __remote_webpack_require__ scoped-name alias.\n // Ensures PatchRequirePlugin can find webpack remotes under rewritten\n // bundle identifiers. Remove once PatchRequirePlugin reads from scope.\n if (\n self.__remote_webpack_require__?.[bundleName] &&\n scope.scopedName !== bundleName\n ) {\n self.__remote_webpack_require__[scope.scopedName] =\n self.__remote_webpack_require__[bundleName];\n }\n\n // load all initial chunks directly via scope — no global dispatch needed\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return loadChunkWithScope(scope, script.src);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n return scope;\n}\n\n/**\n * Creates the global module dispatcher for __webpack_require__.\n * Called by external code (React's RSC runtime) that doesn't have access to\n * a scope. Parses the module ID to find the correct scope and delegates\n * to scope-local module resolution.\n */\nfunction createModuleDispatcher(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const bundleName = bundle ?? 'default';\n const remoteRuntime = self.__remote_webpack_require__?.[bundleName]\n ? self.__remote_webpack_require__[bundleName]?.type || 'webpack'\n : runtime;\n\n logDebug(\n 'ModuleDispatcher',\n `Resolving \"${id}\" (bundle: \"${bundleName}\", runtime: \"${remoteRuntime}\")`,\n );\n\n try {\n // for webpack remotes, prefer scope-based dispatch then fall back to global\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n const scope = getScope(bundle);\n if (scope?.webpackRequire) return scope.webpackRequire(moduleId);\n // @legacy(v0.3.4) — global fallback for hosts that populated\n // __remote_webpack_require__ without calling setupWebpackRuntime.\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n\n // Look up scope by parsed bundle name. Works with both the scoped\n // name (Next.js hosts with server-side rewriting) and the plain\n // bundle name (static/HTML hosts with unrewritten chunks).\n const scope = getScope(bundleName);\n if (scope) {\n return requireModule(scope, moduleId ?? id, id);\n }\n\n throw new Error(\n `Module \"${id}\" not found — no scope for bundle \"${bundleName}\".`,\n );\n } catch (requireError) {\n logWarn(\n 'ModuleDispatcher',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug(\n 'ModuleDispatcher',\n 'Falling back to original webpack require',\n );\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B;AAEvC,SAAS,6BAA6B;AACtC,SAAS,UAAU,eAAe;AAClC,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAkBP,eAAsB,iBACpB,SACA,UAAoC,CAAC,GACrC,MAAW,IAAI,IAAI,SAAS,IAAI,GAChC,QACA,kBACsB;AACtB,QAAM,OAAO;AACb,Q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AP;AACA;AAAA,QACE;AAAA,QACA,0BAA0B,OAAO,YAAY;AAAA,MAC/C;AACA,UAAI,OAAO,KAAK,iCAAiC,YAAY;AAC3D,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD;AAAA,YACE,OAAO,wBAAwB,QAAQ,eAAe;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AACA,UAAI;AACF;AAAA,UACE;AAAA,UACA;AAAA,QACF;AACA,eAAO,KAAK,6BAA6B,EAAE;AAAA,MAC7C,SAAS,eAAP;AACA,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD,EAAE,OAAO,yBAAyB,QAAQ,gBAAgB,OAAU;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["scope"]}
1
+ {"version":3,"sources":["../../../../src/runtime/turbopack/remote-scope-setup.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport {\n RUNTIME_TURBOPACK,\n RUNTIME_WEBPACK,\n type Runtime,\n} from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport type { GlobalScope } from '#internal/runtime/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\nimport { logDebug, logWarn } from '#internal/utils/logger';\nimport { createChunkDispatcher, loadChunkWithScope } from './chunk-loader';\nimport { requireModule } from './module';\nimport {\n createScope,\n getScope,\n type RemoteScope,\n registerScope,\n} from './remote-scope';\n\n/**\n * Sets up the bundler runtime environment for remote components.\n *\n * Creates a RemoteScope that encapsulates all per-remote state (base URL,\n * proxy callback, module cache, shared modules) and registers it in the\n * global scope registry. Global dispatchers (__webpack_require__,\n * __webpack_chunk_load__) are set once and route to the correct scope.\n *\n * Shared module initialization is NOT performed here — callers must invoke\n * `initializeSharedModules` separately after this function returns. This\n * separation ensures shared modules are initialized after turbopack chunks\n * are loaded (so the primary bundle-introspection path is used), avoiding\n * the fallback that keys shared modules by file path instead of numeric ID.\n *\n * @returns The scope (newly created or reused) for the bundle.\n */\nexport async function setupRemoteScope(\n runtime: Runtime,\n scripts: { src: string | null }[] = [],\n url: URL = new URL(location.href),\n bundle?: string,\n resolveClientUrl?: InternalResolveClientUrl,\n): Promise<RemoteScope> {\n const self = globalThis as GlobalScope;\n const ns = getNamespace();\n const bundleName = bundle ?? 'default';\n\n // When the same remote loads a second component (e.g. switching from basic\n // to styled), reuse the existing scope. The chunk cache is keyed by URL and\n // returns cached promises without re-running handleTurbopackChunk, so\n // turbopackModules, moduleCache, and sharedModules from the first load are\n // all still valid. Only resolveClientUrl may have changed.\n //\n // Origin-only comparison is sufficient because bundleName already identifies\n // a specific remote — different paths on the same origin would be a different\n // bundle with a different name, so getScope() wouldn't return a match.\n const existingScope = getScope(bundleName);\n if (existingScope && existingScope.url.origin === url.origin) {\n logDebug(\n 'WebpackRuntime',\n `Reusing scope \"${existingScope.scopedName}\" (turbopackModules=${existingScope.turbopackModules.length})`,\n );\n existingScope.resolveClientUrl = resolveClientUrl;\n\n // Still load scripts — chunk cache deduplicates already-loaded chunks,\n // and a different component may reference additional chunks.\n if (runtime === RUNTIME_TURBOPACK) {\n await Promise.allSettled(\n scripts.map((script) =>\n script.src\n ? loadChunkWithScope(existingScope, script.src)\n : Promise.resolve(undefined),\n ),\n );\n }\n return existingScope;\n }\n\n const scope = createScope(bundleName, url, runtime, resolveClientUrl);\n registerScope(scope);\n\n // For webpack remotes the remote's own scripts have already loaded (via\n // loadScripts in component-loader) and populated __remote_webpack_require__\n // under the plain bundle name. Capture the reference on the scope so\n // downstream code (applySharedModules, module dispatcher) can use it\n // without reaching into the global.\n if (\n runtime === RUNTIME_WEBPACK &&\n self.__remote_webpack_require__?.[bundleName]\n ) {\n scope.webpackRequire = self.__remote_webpack_require__[bundleName];\n }\n\n ns.bundleUrls[bundleName] = url;\n // Also register under scopedName so webpack hosts (patch-require.ts) can\n // resolve cross-origin remotes whose bundle identifiers were rewritten.\n if (scope.scopedName !== bundleName) {\n ns.bundleUrls[scope.scopedName] = url;\n }\n self.__webpack_get_script_filename__ = () => null;\n\n const willCreateDispatchers =\n typeof self.__webpack_require__ !== 'function' ||\n ns.dispatcherRuntime !== 'turbopack';\n\n if (willCreateDispatchers) {\n // preserve original webpack functions for fallback\n if (\n !self.__original_webpack_require__ &&\n !self.__original_webpack_chunk_load__\n ) {\n self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;\n self.__original_webpack_require__ = self.__webpack_require__;\n }\n\n self.__webpack_chunk_load__ = createChunkDispatcher();\n self.__webpack_require__ = createModuleDispatcher(runtime);\n // Write-through needed: dispatcherRuntime is a primitive string,\n // so the legacy global can't be aliased by reference in getNamespace().\n ns.dispatcherRuntime = runtime;\n self.__webpack_require_type__ = runtime;\n\n // @legacy(v0.3.4) — __remote_webpack_require__ write-through for turbopack remotes.\n // Needed by PatchRequirePlugin which reads this global at runtime.\n // Remove once PatchRequirePlugin reads from scope.\n if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {\n self.__remote_webpack_require__[bundleName] =\n self.__webpack_require__ as (remoteId: string | number) => unknown;\n self.__remote_webpack_require__[bundleName].type = 'turbopack';\n }\n }\n\n // @legacy(v0.3.4) — __remote_webpack_require__ scoped-name alias.\n // Ensures PatchRequirePlugin can find webpack remotes under rewritten\n // bundle identifiers. Remove once PatchRequirePlugin reads from scope.\n if (\n self.__remote_webpack_require__?.[bundleName] &&\n scope.scopedName !== bundleName\n ) {\n self.__remote_webpack_require__[scope.scopedName] =\n self.__remote_webpack_require__[bundleName];\n }\n\n // load all initial chunks directly via scope — no global dispatch needed\n if (runtime === RUNTIME_TURBOPACK) {\n const results = await Promise.allSettled(\n scripts.map((script) => {\n if (script.src) {\n return loadChunkWithScope(scope, script.src);\n }\n return Promise.resolve(undefined);\n }),\n );\n\n for (const result of results) {\n if (result.status === 'rejected') {\n logWarn(\n 'WebpackRuntime',\n `Initial chunk load failed: ${String(result.reason)}`,\n );\n }\n }\n }\n\n return scope;\n}\n\n/**\n * Creates the global module dispatcher for __webpack_require__.\n * Called by external code (React's RSC runtime) that doesn't have access to\n * a scope. Parses the module ID to find the correct scope and delegates\n * to scope-local module resolution.\n */\nfunction createModuleDispatcher(runtime: Runtime): (id: string) => unknown {\n return (id: string) => {\n const self = globalThis as GlobalScope;\n const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)\n ?.groups ?? {\n bundle: 'default',\n id,\n };\n const bundleName = bundle ?? 'default';\n const remoteRuntime = self.__remote_webpack_require__?.[bundleName]\n ? self.__remote_webpack_require__[bundleName]?.type || 'webpack'\n : runtime;\n\n logDebug(\n 'ModuleDispatcher',\n `Resolving \"${id}\" (bundle: \"${bundleName}\", runtime: \"${remoteRuntime}\")`,\n );\n\n try {\n // for webpack remotes, prefer scope-based dispatch then fall back to global\n if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {\n const scope = getScope(bundle);\n if (scope?.webpackRequire) return scope.webpackRequire(moduleId);\n // @legacy(v0.3.4) — global fallback for hosts that populated\n // __remote_webpack_require__ without calling setupWebpackRuntime.\n return self.__remote_webpack_require__?.[bundle]?.(moduleId);\n }\n\n // Look up scope by parsed bundle name. Works with both the scoped\n // name (Next.js hosts with server-side rewriting) and the plain\n // bundle name (static/HTML hosts with unrewritten chunks).\n const scope = getScope(bundleName);\n if (scope) {\n return requireModule(scope, moduleId ?? id, id);\n }\n\n throw new Error(\n `Module \"${id}\" not found — no scope for bundle \"${bundleName}\".`,\n );\n } catch (requireError) {\n logWarn(\n 'ModuleDispatcher',\n `Module require failed: ${String(requireError)}`,\n );\n if (typeof self.__original_webpack_require__ !== 'function') {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n {\n cause: requireError instanceof Error ? requireError : undefined,\n },\n );\n }\n try {\n logDebug(\n 'ModuleDispatcher',\n 'Falling back to original webpack require',\n );\n return self.__original_webpack_require__(id);\n } catch (originalError) {\n throw new RemoteComponentsError(\n `Module \"${id}\" not found in remote component bundle \"${bundleName}\".`,\n { cause: originalError instanceof Error ? originalError : undefined },\n );\n }\n }\n };\n}\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B;AAEvC,SAAS,6BAA6B;AACtC,SAAS,UAAU,eAAe;AAClC,SAAS,uBAAuB,0BAA0B;AAC1D,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAkBP,eAAsB,iBACpB,SACA,UAAoC,CAAC,GACrC,MAAW,IAAI,IAAI,SAAS,IAAI,GAChC,QACA,kBACsB;AACtB,QAAM,OAAO;AACb,QAAM,KAAK,aAAa;AACxB,QAAM,aAAa,UAAU;AAW7B,QAAM,gBAAgB,SAAS,UAAU;AACzC,MAAI,iBAAiB,cAAc,IAAI,WAAW,IAAI,QAAQ;AAC5D;AAAA,MACE;AAAA,MACA,kBAAkB,cAAc,iCAAiC,cAAc,iBAAiB;AAAA,IAClG;AACA,kBAAc,mBAAmB;AAIjC,QAAI,YAAY,mBAAmB;AACjC,YAAM,QAAQ;AAAA,QACZ,QAAQ;AAAA,UAAI,CAAC,WACX,OAAO,MACH,mBAAmB,eAAe,OAAO,GAAG,IAC5C,QAAQ,QAAQ,MAAS;AAAA,QAC/B;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,YAAY,YAAY,KAAK,SAAS,gBAAgB;AACpE,gBAAc,KAAK;AAOnB,MACE,YAAY,mBACZ,KAAK,6BAA6B,UAAU,GAC5C;AACA,UAAM,iBAAiB,KAAK,2BAA2B,UAAU;AAAA,EACnE;AAEA,KAAG,WAAW,UAAU,IAAI;AAG5B,MAAI,MAAM,eAAe,YAAY;AACnC,OAAG,WAAW,MAAM,UAAU,IAAI;AAAA,EACpC;AACA,OAAK,kCAAkC,MAAM;AAE7C,QAAM,wBACJ,OAAO,KAAK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AQ,YACrD;AAEJ;AAAA,MACE;AAAA,MACA,cAAc,iBAAiB,0BAA0B;AAAA,IAC3D;AAEA,QAAI;AAEF,UAAI,kBAAkB,mBAAmB,UAAU,UAAU;AAC3D,cAAMA,SAAQ,SAAS,MAAM;AAC7B,YAAIA,QAAO;AAAgB,iBAAOA,OAAM,eAAe,QAAQ;AAG/D,eAAO,KAAK,6BAA6B,MAAM,IAAI,QAAQ;AAAA,MAC7D;AAKA,YAAM,QAAQ,SAAS,UAAU;AACjC,UAAI,OAAO;AACT,eAAO,cAAc,OAAO,YAAY,IAAI,EAAE;AAAA,MAChD;AAEA,YAAM,IAAI;AAAA,QACR,WAAW,6CAAwC;AAAA,MACrD;AAAA,IACF,SAAS,cAAP;AACA;AAAA,QACE;AAAA,QACA,0BAA0B,OAAO,YAAY;AAAA,MAC/C;AACA,UAAI,OAAO,KAAK,iCAAiC,YAAY;AAC3D,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD;AAAA,YACE,OAAO,wBAAwB,QAAQ,eAAe;AAAA,UACxD;AAAA,QACF;AAAA,MACF;AACA,UAAI;AACF;AAAA,UACE;AAAA,UACA;AAAA,QACF;AACA,eAAO,KAAK,6BAA6B,EAAE;AAAA,MAC7C,SAAS,eAAP;AACA,cAAM,IAAI;AAAA,UACR,WAAW,6CAA6C;AAAA,UACxD,EAAE,OAAO,yBAAyB,QAAQ,gBAAgB,OAAU;AAAA,QACtE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["scope"]}
@@ -34,11 +34,7 @@ function getRegistry() {
34
34
  return (0, import_namespace.getNamespace)().scopes;
35
35
  }
36
36
  function createScope(name, url, runtime, resolveClientUrl) {
37
- const isCrossOrigin = url.origin !== location.origin;
38
- const scopedName = (0, import_utils.computeScopedName)(name, {
39
- remoteHost: url.host,
40
- isCrossOrigin
41
- });
37
+ const scopedName = (0, import_utils.computeScopedName)(name, { remoteHost: url.host });
42
38
  const globalKey = (0, import_constants.getBundleKey)(scopedName);
43
39
  return {
44
40
  name,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/remote-scope.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { getBundleKey, type Runtime } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport { computeScopedName } from '#internal/utils';\nimport { logDebug, logWarn } from '#internal/utils/logger';\n\n/**\n * Encapsulates all per-remote state so that two remotes sharing the same\n * bundle name but served from different origins never collide.\n *\n * A scope is created once per `setupRemoteScope` call and threaded\n * directly through internal code paths (chunk loading, module resolution,\n * shared modules). Global dispatchers (`__webpack_require__`,\n * `__webpack_chunk_load__`) only exist for external callers (RSC runtime)\n * and resolve the correct scope via the registry.\n */\nexport interface RemoteScope {\n /** Plain bundle name (e.g. \"remote-component-registry\") */\n name: string;\n /** Origin-qualified key — unique even when two remotes share a name */\n scopedName: string;\n /** Escaped key used as suffix for TURBOPACK_ globals */\n globalKey: string;\n /** Base URL for resolving relative chunk paths */\n url: URL;\n /** Bundler runtime type */\n runtime: Runtime;\n /** Proxy callback for routing chunks through the host */\n resolveClientUrl?: InternalResolveClientUrl;\n /** Per-scope cache of executed Turbopack module exports */\n moduleCache: Record<string, unknown>;\n /** Per-scope shared modules provided by the host (React, etc.) */\n sharedModules: Record<string, unknown>;\n /** Per-scope globalThis substitute passed to module initializers as `g` */\n moduleGlobal: Record<string, unknown>;\n /**\n * Webpack's bundle-scoped require function, populated from\n * `__remote_webpack_require__[bundleName]` for webpack remotes.\n * Undefined for turbopack remotes.\n */\n webpackRequire?: ((id: string | number) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n type?: string;\n };\n /**\n * Flat array of captured turbopack module entries: [scriptEl, id, factory, ...].\n * Populated by the push interceptor in handleTurbopackChunk. This is the\n * primary source of truth for getTurbopackModules — immune to the turbopack\n * runtime replacing the TURBOPACK global (canary builds use a deferred-loading\n * pattern that swaps the array for an immediate-processing dispatcher).\n */\n turbopackModules: unknown[];\n}\n\nfunction getRegistry(): Map<string, RemoteScope> {\n return getNamespace().scopes;\n}\n\nexport function createScope(\n name: string,\n url: URL,\n runtime: Runtime,\n resolveClientUrl?: InternalResolveClientUrl,\n): RemoteScope {\n const isCrossOrigin = url.origin !== location.origin;\n const scopedName = computeScopedName(name, {\n remoteHost: url.host,\n isCrossOrigin,\n });\n const globalKey = getBundleKey(scopedName);\n return {\n name,\n scopedName,\n globalKey,\n url,\n runtime,\n resolveClientUrl,\n moduleCache: {},\n sharedModules: {},\n moduleGlobal: {},\n turbopackModules: [],\n };\n}\n\nexport function registerScope(scope: RemoteScope): void {\n const registry = getRegistry();\n registry.set(scope.scopedName, scope);\n\n // Also register under the plain name so hosts without server-side RSC\n // rewriting (static/HTML hosts) can look up cross-origin scopes by\n // the bundle name that appears in unrewritten chunk/module IDs.\n if (scope.scopedName !== scope.name) {\n const existing = registry.get(scope.name);\n if (existing && existing.scopedName !== scope.scopedName) {\n logWarn(\n 'RemoteScope',\n `Plain name \"${scope.name}\" already registered by scope \"${existing.scopedName}\" — ` +\n `overwriting with \"${scope.scopedName}\". Static hosts will only resolve the latest one.`,\n );\n }\n registry.set(scope.name, scope);\n }\n\n logDebug(\n 'RemoteScope',\n `Registered scope \"${scope.scopedName}\" (${registry.size} total)`,\n );\n}\n\n/**\n * Resolves a scope by name. Accepts either the scoped name (used by Next.js\n * hosts that rewrite RSC data server-side) or the plain bundle name (used by\n * static/HTML hosts where chunks arrive unrewritten).\n */\nexport function getScope(name: string): RemoteScope | undefined {\n return getRegistry().get(name);\n}\n\n/** Formats a `[scopedName] path` string for use in chunk/module IDs. */\nexport function formatRemoteId(scope: RemoteScope, path: string): string {\n return `[${scope.scopedName}] ${path}`;\n}\n\n/**\n * Parses the `[bundle] path` format used in chunk/module IDs.\n * Uses REMOTE_COMPONENT_REGEX (the same pattern used by the module dispatcher\n * and script loader) so the two parsing paths can never diverge.\n */\nexport function parseRemoteId(id: string): {\n bundle: string;\n path: string;\n prefix: string;\n} {\n const groups = REMOTE_COMPONENT_REGEX.exec(id)?.groups;\n if (groups?.bundle && groups.id) {\n return {\n bundle: groups.bundle,\n path: groups.id,\n prefix: groups.prefix ?? '',\n };\n }\n return { bundle: 'default', path: id, prefix: '' };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA2C;AAC3C,uBAA6B;AAC7B,sBAAuC;AACvC,mBAAkC;AAClC,oBAAkC;AAkDlC,SAAS,cAAwC;AAC/C,aAAO,+BAAa,EAAE;AACxB;AAEO,SAAS,YACd,MACA,KACA,SACA,kBACa;AACb,QAAM,gBAAgB,IAAI,WAAW,SAAS;AAC9C,QAAM,iBAAa,gCAAkB,MAAM;AAAA,IACzC,YAAY,IAAI;AAAA,IAChB;AAAA,EACF,CAAC;AACD,QAAM,gBAAY,+BAAa,UAAU;AACzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa,CAAC;AAAA,IACd,eAAe,CAAC;AAAA,IAChB,cAAc,CAAC;AAAA,IACf,kBAAkB,CAAC;AAAA,EACrB;AACF;AAEO,SAAS,cAAc,OAA0B;AACtD,QAAM,WAAW,YAAY;AAC7B,WAAS,IAAI,MAAM,YAAY,KAAK;AAKpC,MAAI,MAAM,eAAe,MAAM,MAAM;AACnC,UAAM,WAAW,SAAS,IAAI,MAAM,IAAI;AACxC,QAAI,YAAY,SAAS,eAAe,MAAM,YAAY;AACxD;AAAA,QACE;AAAA,QACA,eAAe,MAAM,sCAAsC,SAAS,wCAC7C,MAAM;AAAA,MAC/B;AAAA,IACF;AACA,aAAS,IAAI,MAAM,MAAM,KAAK;AAAA,EAChC;AAEA;AAAA,IACE;AAAA,IACA,qBAAqB,MAAM,gBAAgB,SAAS;AAAA,EACtD;AACF;AAOO,SAAS,SAAS,MAAuC;AAC9D,SAAO,YAAY,EAAE,IAAI,IAAI;AAC/B;AAGO,SAAS,eAAe,OAAoB,MAAsB;AACvE,SAAO,IAAI,MAAM,eAAe;AAClC;AAOO,SAAS,cAAc,IAI5B;AACA,QAAM,SAAS,uCAAuB,KAAK,EAAE,GAAG;AAChD,MAAI,QAAQ,UAAU,OAAO,IAAI;AAC/B,WAAO;AAAA,MACL,QAAQ,OAAO;AAAA,MACf,MAAM,OAAO;AAAA,MACb,QAAQ,OAAO,UAAU;AAAA,IAC3B;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,WAAW,MAAM,IAAI,QAAQ,GAAG;AACnD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtime/turbopack/remote-scope.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { getBundleKey, type Runtime } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport { computeScopedName } from '#internal/utils';\nimport { logDebug, logWarn } from '#internal/utils/logger';\n\n/**\n * Encapsulates all per-remote state so that two remotes sharing the same\n * bundle name but served from different origins never collide.\n *\n * A scope is created once per `setupRemoteScope` call and threaded\n * directly through internal code paths (chunk loading, module resolution,\n * shared modules). Global dispatchers (`__webpack_require__`,\n * `__webpack_chunk_load__`) only exist for external callers (RSC runtime)\n * and resolve the correct scope via the registry.\n */\nexport interface RemoteScope {\n /** Plain bundle name (e.g. \"remote-component-registry\") */\n name: string;\n /** Origin-qualified key — unique even when two remotes share a name */\n scopedName: string;\n /** Escaped key used as suffix for TURBOPACK_ globals */\n globalKey: string;\n /** Base URL for resolving relative chunk paths */\n url: URL;\n /** Bundler runtime type */\n runtime: Runtime;\n /** Proxy callback for routing chunks through the host */\n resolveClientUrl?: InternalResolveClientUrl;\n /** Per-scope cache of executed Turbopack module exports */\n moduleCache: Record<string, unknown>;\n /** Per-scope shared modules provided by the host (React, etc.) */\n sharedModules: Record<string, unknown>;\n /** Per-scope globalThis substitute passed to module initializers as `g` */\n moduleGlobal: Record<string, unknown>;\n /**\n * Webpack's bundle-scoped require function, populated from\n * `__remote_webpack_require__[bundleName]` for webpack remotes.\n * Undefined for turbopack remotes.\n */\n webpackRequire?: ((id: string | number) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n type?: string;\n };\n /**\n * Flat array of captured turbopack module entries: [scriptEl, id, factory, ...].\n * Populated by the push interceptor in handleTurbopackChunk. This is the\n * primary source of truth for getTurbopackModules — immune to the turbopack\n * runtime replacing the TURBOPACK global (canary builds use a deferred-loading\n * pattern that swaps the array for an immediate-processing dispatcher).\n */\n turbopackModules: unknown[];\n}\n\nfunction getRegistry(): Map<string, RemoteScope> {\n return getNamespace().scopes;\n}\n\nexport function createScope(\n name: string,\n url: URL,\n runtime: Runtime,\n resolveClientUrl?: InternalResolveClientUrl,\n): RemoteScope {\n const scopedName = computeScopedName(name, { remoteHost: url.host });\n const globalKey = getBundleKey(scopedName);\n return {\n name,\n scopedName,\n globalKey,\n url,\n runtime,\n resolveClientUrl,\n moduleCache: {},\n sharedModules: {},\n moduleGlobal: {},\n turbopackModules: [],\n };\n}\n\nexport function registerScope(scope: RemoteScope): void {\n const registry = getRegistry();\n registry.set(scope.scopedName, scope);\n\n // Also register under the plain name so static/HTML hosts (which don't\n // rewrite RSC chunk IDs) can look up scopes by the unrewritten bundle name.\n if (scope.scopedName !== scope.name) {\n const existing = registry.get(scope.name);\n if (existing && existing.scopedName !== scope.scopedName) {\n logWarn(\n 'RemoteScope',\n `Plain name \"${scope.name}\" already registered by scope \"${existing.scopedName}\" — ` +\n `overwriting with \"${scope.scopedName}\". Static hosts will only resolve the latest one.`,\n );\n }\n registry.set(scope.name, scope);\n }\n\n logDebug(\n 'RemoteScope',\n `Registered scope \"${scope.scopedName}\" (${registry.size} total)`,\n );\n}\n\n/**\n * Resolves a scope by name. Accepts either the scoped name (used by Next.js\n * hosts that rewrite RSC data server-side) or the plain bundle name (used by\n * static/HTML hosts where chunks arrive unrewritten).\n */\nexport function getScope(name: string): RemoteScope | undefined {\n return getRegistry().get(name);\n}\n\n/** Formats a `[scopedName] path` string for use in chunk/module IDs. */\nexport function formatRemoteId(scope: RemoteScope, path: string): string {\n return `[${scope.scopedName}] ${path}`;\n}\n\n/**\n * Parses the `[bundle] path` format used in chunk/module IDs.\n * Uses REMOTE_COMPONENT_REGEX (the same pattern used by the module dispatcher\n * and script loader) so the two parsing paths can never diverge.\n */\nexport function parseRemoteId(id: string): {\n bundle: string;\n path: string;\n prefix: string;\n} {\n const groups = REMOTE_COMPONENT_REGEX.exec(id)?.groups;\n if (groups?.bundle && groups.id) {\n return {\n bundle: groups.bundle,\n path: groups.id,\n prefix: groups.prefix ?? '',\n };\n }\n return { bundle: 'default', path: id, prefix: '' };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA2C;AAC3C,uBAA6B;AAC7B,sBAAuC;AACvC,mBAAkC;AAClC,oBAAkC;AAkDlC,SAAS,cAAwC;AAC/C,aAAO,+BAAa,EAAE;AACxB;AAEO,SAAS,YACd,MACA,KACA,SACA,kBACa;AACb,QAAM,iBAAa,gCAAkB,MAAM,EAAE,YAAY,IAAI,KAAK,CAAC;AACnE,QAAM,gBAAY,+BAAa,UAAU;AACzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa,CAAC;AAAA,IACd,eAAe,CAAC;AAAA,IAChB,cAAc,CAAC;AAAA,IACf,kBAAkB,CAAC;AAAA,EACrB;AACF;AAEO,SAAS,cAAc,OAA0B;AACtD,QAAM,WAAW,YAAY;AAC7B,WAAS,IAAI,MAAM,YAAY,KAAK;AAIpC,MAAI,MAAM,eAAe,MAAM,MAAM;AACnC,UAAM,WAAW,SAAS,IAAI,MAAM,IAAI;AACxC,QAAI,YAAY,SAAS,eAAe,MAAM,YAAY;AACxD;AAAA,QACE;AAAA,QACA,eAAe,MAAM,sCAAsC,SAAS,wCAC7C,MAAM;AAAA,MAC/B;AAAA,IACF;AACA,aAAS,IAAI,MAAM,MAAM,KAAK;AAAA,EAChC;AAEA;AAAA,IACE;AAAA,IACA,qBAAqB,MAAM,gBAAgB,SAAS;AAAA,EACtD;AACF;AAOO,SAAS,SAAS,MAAuC;AAC9D,SAAO,YAAY,EAAE,IAAI,IAAI;AAC/B;AAGO,SAAS,eAAe,OAAoB,MAAsB;AACvE,SAAO,IAAI,MAAM,eAAe;AAClC;AAOO,SAAS,cAAc,IAI5B;AACA,QAAM,SAAS,uCAAuB,KAAK,EAAE,GAAG;AAChD,MAAI,QAAQ,UAAU,OAAO,IAAI;AAC/B,WAAO;AAAA,MACL,QAAQ,OAAO;AAAA,MACf,MAAM,OAAO;AAAA,MACb,QAAQ,OAAO,UAAU;AAAA,IAC3B;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,WAAW,MAAM,IAAI,QAAQ,GAAG;AACnD;","names":[]}
@@ -7,11 +7,7 @@ function getRegistry() {
7
7
  return getNamespace().scopes;
8
8
  }
9
9
  function createScope(name, url, runtime, resolveClientUrl) {
10
- const isCrossOrigin = url.origin !== location.origin;
11
- const scopedName = computeScopedName(name, {
12
- remoteHost: url.host,
13
- isCrossOrigin
14
- });
10
+ const scopedName = computeScopedName(name, { remoteHost: url.host });
15
11
  const globalKey = getBundleKey(scopedName);
16
12
  return {
17
13
  name,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/turbopack/remote-scope.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { getBundleKey, type Runtime } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport { computeScopedName } from '#internal/utils';\nimport { logDebug, logWarn } from '#internal/utils/logger';\n\n/**\n * Encapsulates all per-remote state so that two remotes sharing the same\n * bundle name but served from different origins never collide.\n *\n * A scope is created once per `setupRemoteScope` call and threaded\n * directly through internal code paths (chunk loading, module resolution,\n * shared modules). Global dispatchers (`__webpack_require__`,\n * `__webpack_chunk_load__`) only exist for external callers (RSC runtime)\n * and resolve the correct scope via the registry.\n */\nexport interface RemoteScope {\n /** Plain bundle name (e.g. \"remote-component-registry\") */\n name: string;\n /** Origin-qualified key — unique even when two remotes share a name */\n scopedName: string;\n /** Escaped key used as suffix for TURBOPACK_ globals */\n globalKey: string;\n /** Base URL for resolving relative chunk paths */\n url: URL;\n /** Bundler runtime type */\n runtime: Runtime;\n /** Proxy callback for routing chunks through the host */\n resolveClientUrl?: InternalResolveClientUrl;\n /** Per-scope cache of executed Turbopack module exports */\n moduleCache: Record<string, unknown>;\n /** Per-scope shared modules provided by the host (React, etc.) */\n sharedModules: Record<string, unknown>;\n /** Per-scope globalThis substitute passed to module initializers as `g` */\n moduleGlobal: Record<string, unknown>;\n /**\n * Webpack's bundle-scoped require function, populated from\n * `__remote_webpack_require__[bundleName]` for webpack remotes.\n * Undefined for turbopack remotes.\n */\n webpackRequire?: ((id: string | number) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n type?: string;\n };\n /**\n * Flat array of captured turbopack module entries: [scriptEl, id, factory, ...].\n * Populated by the push interceptor in handleTurbopackChunk. This is the\n * primary source of truth for getTurbopackModules — immune to the turbopack\n * runtime replacing the TURBOPACK global (canary builds use a deferred-loading\n * pattern that swaps the array for an immediate-processing dispatcher).\n */\n turbopackModules: unknown[];\n}\n\nfunction getRegistry(): Map<string, RemoteScope> {\n return getNamespace().scopes;\n}\n\nexport function createScope(\n name: string,\n url: URL,\n runtime: Runtime,\n resolveClientUrl?: InternalResolveClientUrl,\n): RemoteScope {\n const isCrossOrigin = url.origin !== location.origin;\n const scopedName = computeScopedName(name, {\n remoteHost: url.host,\n isCrossOrigin,\n });\n const globalKey = getBundleKey(scopedName);\n return {\n name,\n scopedName,\n globalKey,\n url,\n runtime,\n resolveClientUrl,\n moduleCache: {},\n sharedModules: {},\n moduleGlobal: {},\n turbopackModules: [],\n };\n}\n\nexport function registerScope(scope: RemoteScope): void {\n const registry = getRegistry();\n registry.set(scope.scopedName, scope);\n\n // Also register under the plain name so hosts without server-side RSC\n // rewriting (static/HTML hosts) can look up cross-origin scopes by\n // the bundle name that appears in unrewritten chunk/module IDs.\n if (scope.scopedName !== scope.name) {\n const existing = registry.get(scope.name);\n if (existing && existing.scopedName !== scope.scopedName) {\n logWarn(\n 'RemoteScope',\n `Plain name \"${scope.name}\" already registered by scope \"${existing.scopedName}\" — ` +\n `overwriting with \"${scope.scopedName}\". Static hosts will only resolve the latest one.`,\n );\n }\n registry.set(scope.name, scope);\n }\n\n logDebug(\n 'RemoteScope',\n `Registered scope \"${scope.scopedName}\" (${registry.size} total)`,\n );\n}\n\n/**\n * Resolves a scope by name. Accepts either the scoped name (used by Next.js\n * hosts that rewrite RSC data server-side) or the plain bundle name (used by\n * static/HTML hosts where chunks arrive unrewritten).\n */\nexport function getScope(name: string): RemoteScope | undefined {\n return getRegistry().get(name);\n}\n\n/** Formats a `[scopedName] path` string for use in chunk/module IDs. */\nexport function formatRemoteId(scope: RemoteScope, path: string): string {\n return `[${scope.scopedName}] ${path}`;\n}\n\n/**\n * Parses the `[bundle] path` format used in chunk/module IDs.\n * Uses REMOTE_COMPONENT_REGEX (the same pattern used by the module dispatcher\n * and script loader) so the two parsing paths can never diverge.\n */\nexport function parseRemoteId(id: string): {\n bundle: string;\n path: string;\n prefix: string;\n} {\n const groups = REMOTE_COMPONENT_REGEX.exec(id)?.groups;\n if (groups?.bundle && groups.id) {\n return {\n bundle: groups.bundle,\n path: groups.id,\n prefix: groups.prefix ?? '',\n };\n }\n return { bundle: 'default', path: id, prefix: '' };\n}\n"],"mappings":"AACA,SAAS,oBAAkC;AAC3C,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B;AACvC,SA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C3B;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,WAAW,MAAM,IAAI,QAAQ,GAAG;AACnD;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtime/turbopack/remote-scope.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { getBundleKey, type Runtime } from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { REMOTE_COMPONENT_REGEX } from '#internal/runtime/patterns';\nimport { computeScopedName } from '#internal/utils';\nimport { logDebug, logWarn } from '#internal/utils/logger';\n\n/**\n * Encapsulates all per-remote state so that two remotes sharing the same\n * bundle name but served from different origins never collide.\n *\n * A scope is created once per `setupRemoteScope` call and threaded\n * directly through internal code paths (chunk loading, module resolution,\n * shared modules). Global dispatchers (`__webpack_require__`,\n * `__webpack_chunk_load__`) only exist for external callers (RSC runtime)\n * and resolve the correct scope via the registry.\n */\nexport interface RemoteScope {\n /** Plain bundle name (e.g. \"remote-component-registry\") */\n name: string;\n /** Origin-qualified key — unique even when two remotes share a name */\n scopedName: string;\n /** Escaped key used as suffix for TURBOPACK_ globals */\n globalKey: string;\n /** Base URL for resolving relative chunk paths */\n url: URL;\n /** Bundler runtime type */\n runtime: Runtime;\n /** Proxy callback for routing chunks through the host */\n resolveClientUrl?: InternalResolveClientUrl;\n /** Per-scope cache of executed Turbopack module exports */\n moduleCache: Record<string, unknown>;\n /** Per-scope shared modules provided by the host (React, etc.) */\n sharedModules: Record<string, unknown>;\n /** Per-scope globalThis substitute passed to module initializers as `g` */\n moduleGlobal: Record<string, unknown>;\n /**\n * Webpack's bundle-scoped require function, populated from\n * `__remote_webpack_require__[bundleName]` for webpack remotes.\n * Undefined for turbopack remotes.\n */\n webpackRequire?: ((id: string | number) => unknown) & {\n m?: Record<string | number, (module: { exports: unknown }) => void>;\n type?: string;\n };\n /**\n * Flat array of captured turbopack module entries: [scriptEl, id, factory, ...].\n * Populated by the push interceptor in handleTurbopackChunk. This is the\n * primary source of truth for getTurbopackModules — immune to the turbopack\n * runtime replacing the TURBOPACK global (canary builds use a deferred-loading\n * pattern that swaps the array for an immediate-processing dispatcher).\n */\n turbopackModules: unknown[];\n}\n\nfunction getRegistry(): Map<string, RemoteScope> {\n return getNamespace().scopes;\n}\n\nexport function createScope(\n name: string,\n url: URL,\n runtime: Runtime,\n resolveClientUrl?: InternalResolveClientUrl,\n): RemoteScope {\n const scopedName = computeScopedName(name, { remoteHost: url.host });\n const globalKey = getBundleKey(scopedName);\n return {\n name,\n scopedName,\n globalKey,\n url,\n runtime,\n resolveClientUrl,\n moduleCache: {},\n sharedModules: {},\n moduleGlobal: {},\n turbopackModules: [],\n };\n}\n\nexport function registerScope(scope: RemoteScope): void {\n const registry = getRegistry();\n registry.set(scope.scopedName, scope);\n\n // Also register under the plain name so static/HTML hosts (which don't\n // rewrite RSC chunk IDs) can look up scopes by the unrewritten bundle name.\n if (scope.scopedName !== scope.name) {\n const existing = registry.get(scope.name);\n if (existing && existing.scopedName !== scope.scopedName) {\n logWarn(\n 'RemoteScope',\n `Plain name \"${scope.name}\" already registered by scope \"${existing.scopedName}\" — ` +\n `overwriting with \"${scope.scopedName}\". Static hosts will only resolve the latest one.`,\n );\n }\n registry.set(scope.name, scope);\n }\n\n logDebug(\n 'RemoteScope',\n `Registered scope \"${scope.scopedName}\" (${registry.size} total)`,\n );\n}\n\n/**\n * Resolves a scope by name. Accepts either the scoped name (used by Next.js\n * hosts that rewrite RSC data server-side) or the plain bundle name (used by\n * static/HTML hosts where chunks arrive unrewritten).\n */\nexport function getScope(name: string): RemoteScope | undefined {\n return getRegistry().get(name);\n}\n\n/** Formats a `[scopedName] path` string for use in chunk/module IDs. */\nexport function formatRemoteId(scope: RemoteScope, path: string): string {\n return `[${scope.scopedName}] ${path}`;\n}\n\n/**\n * Parses the `[bundle] path` format used in chunk/module IDs.\n * Uses REMOTE_COMPONENT_REGEX (the same pattern used by the module dispatcher\n * and script loader) so the two parsing paths can never diverge.\n */\nexport function parseRemoteId(id: string): {\n bundle: string;\n path: string;\n prefix: string;\n} {\n const groups = REMOTE_COMPONENT_REGEX.exec(id)?.groups;\n if (groups?.bundle && groups.id) {\n return {\n bundle: groups.bundle,\n path: groups.id,\n prefix: groups.prefix ?? '',\n };\n }\n return { bundle: 'default', path: id, prefix: '' };\n}\n"],"mappings":"AACA,SAAS,oBAAkC;AAC3C,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B;AACvC,SAAS,yBAAyB;AAClC,SAAS,UAAU,eAAe;AAkDlC,SAAS,cAAwC;AAC/C,SAAO,aAAa,EAAE;AACxB;AAEO,SAAS,YACd,MACA,KACA,SACA,kBACa;AACb,QAAM,aAAa,kBAAkB,MAAM,EAAE,YAAY,IAAI,KAAK,CAAC;AACnE,QAAM,YAAY,aAAa,UAAU;AACzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa,CAAC;AAAA,IACd,eAAe,CAAC;AAAA,IAChB,cAAc,CAAC;AAAA,IACf,kBAAkB,CAAC;AAAA,EACrB;AACF;AAEO,SAAS,cAAc,OAA0B;AACtD,QAAM,WAAW,YAAY;AAC7B,WAAS,IAAI,MAAM,YAAY,KAAK;AAIpC,MAAI,MAAM,eAAe,MAAM,MAAM;AACnC,UAAM,WAAW,SAAS,IAAI,MAAM,IAAI;AACxC,QAAI,YAAY,SAAS,eAAe,MAAM,YAAY;AACxD;AAAA,QACE;AAAA,QACA,eAAe,MAAM,sCAAsC,SAAS,wCAC7C,MAAM;AAAA,MAC/B;AAAA,IACF;AACA,aAAS,IAAI,MAAM,MAAM,KAAK;AAAA,EAChC;AAEA;AAAA,IACE;AAAA,IACA,qBAAqB,MAAM,gBAAgB,SAAS;AAAA,EACtD;AACF;AAOO,SAAS,SAAS,MAAuC;AAC9D,SAAO,YAAY,EAAE,IAAI,IAAI;AAC/B;AAGO,SAAS,eAAe,OAAoB,MAAsB;AACvE,SAAO,IAAI,MAAM,eAAe;AAClC;AAOO,SAAS,cAAc,IAI5B;AACA,QAAM,SAAS,uBAAuB,KAAK,EAAE,GAAG;AAChD,MAAI,QAAQ,UAAU,OAAO,IAAI;AAC/B,WAAO;AAAA,MACL,QAAQ,OAAO;AAAA,MACf,MAAM,OAAO;AAAA,MACb,QAAQ,OAAO,UAAU;AAAA,IAC3B;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,WAAW,MAAM,IAAI,QAAQ,GAAG;AACnD;","names":[]}
@@ -27,7 +27,7 @@ function escapeString(str) {
27
27
  return str.replace(/[^a-z0-9]/g, "_");
28
28
  }
29
29
  function computeScopedName(name, options) {
30
- return options.isCrossOrigin ? `${name}_${escapeString(options.remoteHost.toLowerCase())}` : name;
30
+ return `${name}_${escapeString(options.remoteHost.toLowerCase())}`;
31
31
  }
32
32
  const attrToProp = {
33
33
  fetchpriority: "fetchPriority",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\n/**\n * Computes the origin-qualified scoped name for a bundle. Same-origin\n * remotes keep the plain name; cross-origin remotes append the escaped\n * host (hostname + port) to avoid collisions between bundles that share\n * a name but are served from different origins.\n *\n * Used on both the server (to rewrite RSC flight data) and the client\n * (to create and look up RemoteScopes). Both sides must produce the\n * same value for a given remote.\n */\nexport function computeScopedName(\n name: string,\n options: { remoteHost: string; isCrossOrigin: boolean },\n): string {\n return options.isCrossOrigin\n ? `${name}_${escapeString(options.remoteHost.toLowerCase())}`\n : name;\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAYO,SAAS,kBACd,MACA,SACQ;AACR,SAAO,QAAQ,gBACX,GAAG,QAAQ,aAAa,QAAQ,WAAW,YAAY,CAAC,MACxD;AACN;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\n/**\n * Computes the origin-qualified scoped name for a bundle by appending\n * the escaped host (hostname + port). This ensures the server and client\n * always agree on the scoped name — the server's cross-origin detection\n * (based on deployment URL) can differ from the client's (based on\n * `location.origin`), so the name must not depend on that distinction.\n *\n * Used on both the server (to rewrite RSC flight data) and the client\n * (to create and look up RemoteScopes). Both sides must produce the\n * same value for a given remote.\n */\nexport function computeScopedName(\n name: string,\n options: { remoteHost: string },\n): string {\n return `${name}_${escapeString(options.remoteHost.toLowerCase())}`;\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAaO,SAAS,kBACd,MACA,SACQ;AACR,SAAO,GAAG,QAAQ,aAAa,QAAQ,WAAW,YAAY,CAAC;AACjE;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
@@ -1,9 +1,10 @@
1
1
  declare function escapeString(str: string): string;
2
2
  /**
3
- * Computes the origin-qualified scoped name for a bundle. Same-origin
4
- * remotes keep the plain name; cross-origin remotes append the escaped
5
- * host (hostname + port) to avoid collisions between bundles that share
6
- * a name but are served from different origins.
3
+ * Computes the origin-qualified scoped name for a bundle by appending
4
+ * the escaped host (hostname + port). This ensures the server and client
5
+ * always agree on the scoped name the server's cross-origin detection
6
+ * (based on deployment URL) can differ from the client's (based on
7
+ * `location.origin`), so the name must not depend on that distinction.
7
8
  *
8
9
  * Used on both the server (to rewrite RSC flight data) and the client
9
10
  * (to create and look up RemoteScopes). Both sides must produce the
@@ -11,7 +12,6 @@ declare function escapeString(str: string): string;
11
12
  */
12
13
  declare function computeScopedName(name: string, options: {
13
14
  remoteHost: string;
14
- isCrossOrigin: boolean;
15
15
  }): string;
16
16
  declare const attrToProp: Record<string, string>;
17
17
 
@@ -2,7 +2,7 @@ function escapeString(str) {
2
2
  return str.replace(/[^a-z0-9]/g, "_");
3
3
  }
4
4
  function computeScopedName(name, options) {
5
- return options.isCrossOrigin ? `${name}_${escapeString(options.remoteHost.toLowerCase())}` : name;
5
+ return `${name}_${escapeString(options.remoteHost.toLowerCase())}`;
6
6
  }
7
7
  const attrToProp = {
8
8
  fetchpriority: "fetchPriority",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\n/**\n * Computes the origin-qualified scoped name for a bundle. Same-origin\n * remotes keep the plain name; cross-origin remotes append the escaped\n * host (hostname + port) to avoid collisions between bundles that share\n * a name but are served from different origins.\n *\n * Used on both the server (to rewrite RSC flight data) and the client\n * (to create and look up RemoteScopes). Both sides must produce the\n * same value for a given remote.\n */\nexport function computeScopedName(\n name: string,\n options: { remoteHost: string; isCrossOrigin: boolean },\n): string {\n return options.isCrossOrigin\n ? `${name}_${escapeString(options.remoteHost.toLowerCase())}`\n : name;\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":"AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAYO,SAAS,kBACd,MACA,SACQ;AACR,SAAO,QAAQ,gBACX,GAAG,QAAQ,aAAa,QAAQ,WAAW,YAAY,CAAC,MACxD;AACN;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export function escapeString(str: string) {\n return str.replace(/[^a-z0-9]/g, '_');\n}\n\n/**\n * Computes the origin-qualified scoped name for a bundle by appending\n * the escaped host (hostname + port). This ensures the server and client\n * always agree on the scoped name — the server's cross-origin detection\n * (based on deployment URL) can differ from the client's (based on\n * `location.origin`), so the name must not depend on that distinction.\n *\n * Used on both the server (to rewrite RSC flight data) and the client\n * (to create and look up RemoteScopes). Both sides must produce the\n * same value for a given remote.\n */\nexport function computeScopedName(\n name: string,\n options: { remoteHost: string },\n): string {\n return `${name}_${escapeString(options.remoteHost.toLowerCase())}`;\n}\n\nexport const attrToProp = {\n fetchpriority: 'fetchPriority',\n crossorigin: 'crossOrigin',\n imagesrcset: 'imageSrcSet',\n imagesizes: 'imageSizes',\n srcset: 'srcSet',\n} as Record<string, string>;\n"],"mappings":"AAAO,SAAS,aAAa,KAAa;AACxC,SAAO,IAAI,QAAQ,cAAc,GAAG;AACtC;AAaO,SAAS,kBACd,MACA,SACQ;AACR,SAAO,GAAG,QAAQ,aAAa,QAAQ,WAAW,YAAY,CAAC;AACjE;AAEO,MAAM,aAAa;AAAA,EACxB,eAAe;AAAA,EACf,aAAa;AAAA,EACb,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,QAAQ;AACV;","names":[]}