remote-components 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/dist/config/nextjs.cjs +122 -62
  2. package/dist/config/nextjs.cjs.map +1 -1
  3. package/dist/config/nextjs.js +116 -56
  4. package/dist/config/nextjs.js.map +1 -1
  5. package/dist/config/webpack.cjs +5 -1
  6. package/dist/config/webpack.cjs.map +1 -1
  7. package/dist/config/webpack.js +5 -1
  8. package/dist/config/webpack.js.map +1 -1
  9. package/dist/host/defaults/app.cjs +2 -5
  10. package/dist/host/defaults/app.cjs.map +1 -1
  11. package/dist/host/defaults/app.d.ts +1 -3
  12. package/dist/host/defaults/app.js +1 -4
  13. package/dist/host/defaults/app.js.map +1 -1
  14. package/dist/host/defaults/pages.cjs +2 -5
  15. package/dist/host/defaults/pages.cjs.map +1 -1
  16. package/dist/host/defaults/pages.d.ts +1 -3
  17. package/dist/host/defaults/pages.js +1 -4
  18. package/dist/host/defaults/pages.js.map +1 -1
  19. package/dist/host/defaults/shared.cjs +32 -0
  20. package/dist/host/defaults/shared.cjs.map +1 -0
  21. package/dist/host/defaults/shared.d.ts +3 -0
  22. package/dist/host/defaults/shared.js +8 -0
  23. package/dist/host/defaults/shared.js.map +1 -0
  24. package/dist/host/html.cjs +533 -351
  25. package/dist/host/html.cjs.map +1 -1
  26. package/dist/host/html.js +533 -351
  27. package/dist/host/html.js.map +1 -1
  28. package/dist/host/nextjs/app/client-only.cjs +494 -285
  29. package/dist/host/nextjs/app/client-only.cjs.map +1 -1
  30. package/dist/host/nextjs/app/client-only.js +468 -259
  31. package/dist/host/nextjs/app/client-only.js.map +1 -1
  32. package/dist/host/react.cjs +412 -241
  33. package/dist/host/react.cjs.map +1 -1
  34. package/dist/host/react.js +412 -241
  35. package/dist/host/react.js.map +1 -1
  36. package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
  37. package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
  38. package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
  39. package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
  40. package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
  41. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
  42. package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
  43. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
  44. package/dist/internal/host/nextjs/app-client.cjs +6 -22
  45. package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
  46. package/dist/internal/host/nextjs/app-client.js +5 -11
  47. package/dist/internal/host/nextjs/app-client.js.map +1 -1
  48. package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
  49. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
  50. package/dist/internal/host/nextjs/dom-flight.js +31 -39
  51. package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
  52. package/dist/internal/host/nextjs/image-shared.cjs +39 -3
  53. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
  54. package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
  55. package/dist/internal/host/nextjs/image-shared.js +29 -3
  56. package/dist/internal/host/nextjs/image-shared.js.map +1 -1
  57. package/dist/internal/host/nextjs/shared-import.cjs +46 -0
  58. package/dist/internal/host/nextjs/shared-import.cjs.map +1 -0
  59. package/dist/internal/host/nextjs/shared-import.d.ts +3 -0
  60. package/dist/internal/host/nextjs/shared-import.js +12 -0
  61. package/dist/internal/host/nextjs/shared-import.js.map +1 -0
  62. package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
  63. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
  64. package/dist/internal/host/server/fetch-remote-component.js +2 -1
  65. package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
  66. package/dist/internal/host/shared/polyfill.cjs +8 -7
  67. package/dist/internal/host/shared/polyfill.cjs.map +1 -1
  68. package/dist/internal/host/shared/polyfill.js +8 -7
  69. package/dist/internal/host/shared/polyfill.js.map +1 -1
  70. package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
  71. package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
  72. package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
  73. package/dist/internal/host/shared/shared-module-resolver.js +78 -0
  74. package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
  75. package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
  76. package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
  77. package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
  78. package/dist/internal/remote/nextjs/next-internals.js +26 -0
  79. package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
  80. package/dist/internal/runtime/html/apply-origin.cjs +11 -32
  81. package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
  82. package/dist/internal/runtime/html/apply-origin.js +11 -32
  83. package/dist/internal/runtime/html/apply-origin.js.map +1 -1
  84. package/dist/internal/runtime/html/html-spec.cjs +78 -0
  85. package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
  86. package/dist/internal/runtime/html/html-spec.d.ts +23 -0
  87. package/dist/internal/runtime/html/html-spec.js +41 -0
  88. package/dist/internal/runtime/html/html-spec.js.map +1 -0
  89. package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
  90. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
  91. package/dist/internal/runtime/html/parse-remote-html.js +29 -12
  92. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
  93. package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
  94. package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
  95. package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
  96. package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
  97. package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
  98. package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
  99. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
  100. package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
  101. package/dist/internal/runtime/loaders/component-loader.js +28 -44
  102. package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
  103. package/dist/internal/runtime/loaders/script-loader.cjs +7 -0
  104. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -1
  105. package/dist/internal/runtime/loaders/script-loader.js +7 -0
  106. package/dist/internal/runtime/loaders/script-loader.js.map +1 -1
  107. package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
  108. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
  109. package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
  110. package/dist/internal/runtime/loaders/static-loader.js +15 -21
  111. package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
  112. package/dist/internal/runtime/namespace.cjs +82 -0
  113. package/dist/internal/runtime/namespace.cjs.map +1 -0
  114. package/dist/internal/runtime/namespace.d.ts +5 -0
  115. package/dist/internal/runtime/namespace.js +58 -0
  116. package/dist/internal/runtime/namespace.js.map +1 -0
  117. package/dist/internal/runtime/rsc-imports.cjs +86 -0
  118. package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
  119. package/dist/internal/runtime/rsc-imports.d.ts +39 -0
  120. package/dist/internal/runtime/rsc-imports.js +50 -0
  121. package/dist/internal/runtime/rsc-imports.js.map +1 -0
  122. package/dist/internal/{host/shared/resolved-data.cjs → runtime/rsc-runtime.cjs} +3 -3
  123. package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
  124. package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
  125. package/dist/internal/runtime/rsc-runtime.js +1 -0
  126. package/dist/internal/runtime/rsc.cjs +23 -12
  127. package/dist/internal/runtime/rsc.cjs.map +1 -1
  128. package/dist/internal/runtime/rsc.d.ts +19 -2
  129. package/dist/internal/runtime/rsc.js +20 -11
  130. package/dist/internal/runtime/rsc.js.map +1 -1
  131. package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
  132. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
  133. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
  134. package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
  135. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
  136. package/dist/internal/runtime/turbopack/module.cjs +19 -17
  137. package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
  138. package/dist/internal/runtime/turbopack/module.d.ts +23 -1
  139. package/dist/internal/runtime/turbopack/module.js +19 -18
  140. package/dist/internal/runtime/turbopack/module.js.map +1 -1
  141. package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
  142. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
  143. package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
  144. package/dist/internal/runtime/turbopack/patterns.js +23 -7
  145. package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
  146. package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
  147. package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
  148. package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
  149. package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
  150. package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
  151. package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
  152. package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
  153. package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
  154. package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
  155. package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
  156. package/dist/internal/runtime/turbopack/shared-modules.cjs +23 -15
  157. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
  158. package/dist/internal/runtime/turbopack/shared-modules.d.ts +13 -1
  159. package/dist/internal/runtime/turbopack/shared-modules.js +25 -18
  160. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
  161. package/dist/internal/runtime/types.cjs.map +1 -1
  162. package/dist/internal/runtime/types.d.ts +5 -41
  163. package/dist/internal/utils/logger.cjs +1 -1
  164. package/dist/internal/utils/logger.cjs.map +1 -1
  165. package/dist/internal/utils/logger.d.ts +2 -2
  166. package/dist/internal/utils/logger.js +1 -1
  167. package/dist/internal/utils/logger.js.map +1 -1
  168. package/dist/internal/utils/project-id-env.cjs +31 -0
  169. package/dist/internal/utils/project-id-env.cjs.map +1 -0
  170. package/dist/internal/utils/project-id-env.d.ts +7 -0
  171. package/dist/internal/utils/project-id-env.js +7 -0
  172. package/dist/internal/utils/project-id-env.js.map +1 -0
  173. package/dist/internal/utils/project-id.cjs +46 -0
  174. package/dist/internal/utils/project-id.cjs.map +1 -0
  175. package/dist/internal/utils/project-id.d.ts +8 -0
  176. package/dist/internal/utils/project-id.js +22 -0
  177. package/dist/internal/utils/project-id.js.map +1 -0
  178. package/dist/remote/defaults/app.cjs +2 -5
  179. package/dist/remote/defaults/app.cjs.map +1 -1
  180. package/dist/remote/defaults/app.d.ts +1 -3
  181. package/dist/remote/defaults/app.js +1 -4
  182. package/dist/remote/defaults/app.js.map +1 -1
  183. package/dist/remote/defaults/pages.cjs +2 -5
  184. package/dist/remote/defaults/pages.cjs.map +1 -1
  185. package/dist/remote/defaults/pages.d.ts +1 -3
  186. package/dist/remote/defaults/pages.js +1 -4
  187. package/dist/remote/defaults/pages.js.map +1 -1
  188. package/dist/remote/defaults/shared.cjs +32 -0
  189. package/dist/remote/defaults/shared.cjs.map +1 -0
  190. package/dist/remote/defaults/shared.d.ts +3 -0
  191. package/dist/remote/defaults/shared.js +8 -0
  192. package/dist/remote/defaults/shared.js.map +1 -0
  193. package/dist/remote/html.cjs +78 -22
  194. package/dist/remote/html.cjs.map +1 -1
  195. package/dist/remote/html.js +78 -22
  196. package/dist/remote/html.js.map +1 -1
  197. package/dist/remote/nextjs/app.cjs +16 -56
  198. package/dist/remote/nextjs/app.cjs.map +1 -1
  199. package/dist/remote/nextjs/app.js +26 -46
  200. package/dist/remote/nextjs/app.js.map +1 -1
  201. package/dist/remote/nextjs/pages.cjs +2 -1
  202. package/dist/remote/nextjs/pages.cjs.map +1 -1
  203. package/dist/remote/nextjs/pages.js +2 -1
  204. package/dist/remote/nextjs/pages.js.map +1 -1
  205. package/dist/types-59251814.d.ts +94 -0
  206. package/package.json +1 -1
  207. package/dist/internal/host/shared/resolved-data.cjs.map +0 -1
  208. package/dist/internal/host/shared/resolved-data.d.ts +0 -48
  209. package/dist/internal/host/shared/resolved-data.js +0 -1
  210. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
  211. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
  212. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
  213. /package/dist/internal/{host/shared/resolved-data.js.map → runtime/rsc-runtime.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtime/loaders/static-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type {\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\nimport { logError, warnCrossOriginFetchError } from '#internal/utils/logger';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = (\n globalThis as unknown as { __rc_module_registry__?: Record<string, T> }\n ).__rc_module_registry__;\n const mod = registry?.[absoluteSrc] ?? ({} as T);\n if (registry) delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const self = globalThis as typeof globalThis & MountUnmountFunctions;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n"],"mappings":"AAKA,SAAS,UAAU,iCAAiC;AAsBpD,eAAe,kBACb,aACA,kBACY;AACZ,QAAM,cAAc,iBAAiB,WAAW,KAAK;AACrD,QAAM,WAAW,IAAI,IAAI,aAAa,SAAS,IAAI,EAAE;AACrD,QAAM,WAAW,MAAM,MAAM,QAAQ;AACrC,MAAI,CAAC,SAAS;AAAI,UAAM,IAAI,MAAM,yBAAyB,SAAS,QAAQ;AAM5E,QAAM,WAAW,MAAM,SAAS,KAAK,GAClC,QAAQ,sBAAsB,KAAK,UAAU,WAAW,CAAC,EACzD;AAAA,IACC;AAAA,IACA,CAAC,GAAG,SAAS,OAAO,iBAAiB;AACnC,YAAM,oBAAoB,IAAI,IAAI,cAAc,WAAW,EAAE;AAC7D,YAAM,oBAAoB,IAAI;AAAA,QAC5B,iBAAiB,iBAAiB,KAAK;AAAA,QACvC,SAAS;AA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IAAI,YAAY,cACvB,OAAO,IAAI,SAAS,YAAY,YAChC;AACA,cAAI,CAAC,KAAK,sCAAsC;AAE9C,iBAAK,uCAAuC,CAAC;AAAA,UAC/C;AACA,cAAI,CAAC,KAAK,qCAAqC,IAAI,IAAI,GAAG;AACxD,iBAAK,qCAAqC,IAAI,IAAI,IAAI,oBAAI,IAAI;AAAA,UAChE;AACA,eAAK,qCAAqC,IAAI,IAAI,GAAG;AAAA,YACnD,IAAI,WACF,IAAI,SAAS,YACZ,MAAM;AAAA,YAEP;AAAA,UACJ;AAAA,QACF;AACA,eAAO;AAAA,UACL,OAAO,IAAI,SAAS,IAAI,SAAS;AAAA,UACjC,SAAS,IAAI,WAAW,IAAI,SAAS;AAAA,QACvC;AAAA,MACF,SAAS,GAAP;AACA;AAAA,UACE;AAAA,UACA,+CAA+C,OAAO,OAAO,IAAI;AAAA,UACjE;AAAA,QACF;AACA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,iBAAiB;AAAA,IACtB,CAAC,KAAK,EAAE,OAAO,QAAQ,MAAM;AAC3B,UAAI,OAAO,UAAU,YAAY;AAC/B,YAAI,MAAM,IAAI,KAAK;AAAA,MACrB;AACA,UAAI,OAAO,YAAY,YAAY;AACjC,YAAI,QAAQ,IAAI,OAAO;AAAA,MACzB;AACA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,MACE,OAAO,oBAAI,IAA4B;AAAA,MACvC,SAAS,oBAAI,IAA4B;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtime/loaders/static-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport type { MountOrUnmountFunction } from '#internal/runtime/types';\nimport { logError, warnCrossOriginFetchError } from '#internal/utils/logger';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = getNamespace().moduleRegistry as Record<string, T>;\n const mod = registry[absoluteSrc] ?? ({} as T);\n delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const ns = getNamespace();\n\n if (ns.mountFns[url.href]) {\n ns.mountFns[url.href] = new Set();\n }\n if (ns.unmountFns[url.href]) {\n ns.unmountFns[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!ns.mountFns[url.href]) {\n ns.mountFns[url.href] = new Set();\n }\n ns.mountFns[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!ns.unmountFns[url.href]) {\n ns.unmountFns[url.href] = new Set();\n }\n ns.unmountFns[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n"],"mappings":"AACA,SAAS,oBAAoB;AAE7B,SAAS,UAAU,iCAAiC;AAsBpD,eAAe,kBACb,aACA,kBACY;AACZ,QAAM,cAAc,iBAAiB,WAAW,KAAK;AACrD,QAAM,WAAW,IAAI,IAAI,aAAa,SAAS,IAAI,EAAE;AACrD,QAAM,WAAW,MAAM,MAAM,QAAQ;AACrC,MAAI,CAAC,SAAS;AAAI,UAAM,IAAI,MAAM,yBAAyB,SAAS,QAAQ;AAM5E,QAAM,WAAW,MAAM,SAAS,KAAK,GAClC,QAAQ,sBAAsB,KAAK,UAAU,WAAW,CAAC,EACzD;AAAA,IACC;AAAA,IACA,CAAC,GAAG,SAAS,OAAO,iBAAiB;AACnC,YAAM,oBA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UACJ;AAAA,QACF;AACA,YACE,OAAO,IAAI,YAAY,cACvB,OAAO,IAAI,SAAS,YAAY,YAChC;AACA,cAAI,CAAC,GAAG,WAAW,IAAI,IAAI,GAAG;AAC5B,eAAG,WAAW,IAAI,IAAI,IAAI,oBAAI,IAAI;AAAA,UACpC;AACA,aAAG,WAAW,IAAI,IAAI,GAAG;AAAA,YACvB,IAAI,WACF,IAAI,SAAS,YACZ,MAAM;AAAA,YAEP;AAAA,UACJ;AAAA,QACF;AACA,eAAO;AAAA,UACL,OAAO,IAAI,SAAS,IAAI,SAAS;AAAA,UACjC,SAAS,IAAI,WAAW,IAAI,SAAS;AAAA,QACvC;AAAA,MACF,SAAS,GAAP;AACA;AAAA,UACE;AAAA,UACA,+CAA+C,OAAO,OAAO,IAAI;AAAA,UACjE;AAAA,QACF;AACA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,iBAAiB;AAAA,IACtB,CAAC,KAAK,EAAE,OAAO,QAAQ,MAAM;AAC3B,UAAI,OAAO,UAAU,YAAY;AAC/B,YAAI,MAAM,IAAI,KAAK;AAAA,MACrB;AACA,UAAI,OAAO,YAAY,YAAY;AACjC,YAAI,QAAQ,IAAI,OAAO;AAAA,MACzB;AACA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,MACE,OAAO,oBAAI,IAA4B;AAAA,MACvC,SAAS,oBAAI,IAA4B;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var namespace_exports = {};
20
+ __export(namespace_exports, {
21
+ getNamespace: () => getNamespace
22
+ });
23
+ module.exports = __toCommonJS(namespace_exports);
24
+ const SHADOW_ROOT_PREFIX = "__remote_components_shadowroot_";
25
+ const LEGACY_ALIASES = [
26
+ { global: "__remote_component_scopes__", prop: "scopes" },
27
+ {
28
+ global: "__remote_components_turbopack_chunk_loader_promise__",
29
+ prop: "chunkCache"
30
+ },
31
+ { global: "__remote_script_entrypoint_mount__", prop: "mountFns" },
32
+ { global: "__remote_script_entrypoint_unmount__", prop: "unmountFns" },
33
+ { global: "__remote_bundle_url__", prop: "bundleUrls" },
34
+ { global: "__rc_module_registry__", prop: "moduleRegistry" },
35
+ {
36
+ global: "__remote_component_host_shared_modules__",
37
+ prop: "hostSharedModules"
38
+ },
39
+ { global: "__remote_next_css__", prop: "cssCache" }
40
+ ];
41
+ function getNamespace() {
42
+ const g = globalThis;
43
+ const existing = g.__remote_components__;
44
+ if (existing) {
45
+ return existing;
46
+ }
47
+ const ns = {
48
+ scopes: /* @__PURE__ */ new Map(),
49
+ chunkCache: {},
50
+ mountFns: {},
51
+ unmountFns: {},
52
+ bundleUrls: {},
53
+ moduleRegistry: {},
54
+ dispatcherRuntime: void 0,
55
+ hostSharedModules: {},
56
+ cssCache: {},
57
+ shadowRoots: {}
58
+ };
59
+ const nsRecord = ns;
60
+ for (const { global, prop } of LEGACY_ALIASES) {
61
+ const legacyValue = g[global];
62
+ if (legacyValue != null) {
63
+ nsRecord[prop] = legacyValue;
64
+ }
65
+ g[global] = ns[prop];
66
+ }
67
+ const gRecord = g;
68
+ for (const key of Object.keys(gRecord)) {
69
+ if (key.startsWith(SHADOW_ROOT_PREFIX)) {
70
+ const suffix = key.slice(SHADOW_ROOT_PREFIX.length);
71
+ ns.shadowRoots[suffix] = gRecord[key];
72
+ delete gRecord[key];
73
+ }
74
+ }
75
+ g.__remote_components__ = ns;
76
+ return ns;
77
+ }
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ getNamespace
81
+ });
82
+ //# sourceMappingURL=namespace.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/namespace.ts"],"sourcesContent":["import type { RemoteScope } from '#internal/runtime/turbopack/remote-scope';\nimport type {\n GlobalScope,\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\n\n/**\n * Typed namespace for all remote-components runtime state.\n *\n * Consolidates scattered `globalThis` globals into a single object at\n * `globalThis.__remote_components__`. Each property corresponds to a\n * previously independent global — see inline `@see` tags for the original\n * global name. Code that previously read from those globals still works\n * because each migration writes through to both the namespace and the\n * legacy global (pointing at the same underlying object).\n */\nexport interface RemoteComponentsNamespace {\n /** @see `__remote_component_scopes__` */\n scopes: Map<string, RemoteScope>;\n /** @see `__remote_components_turbopack_chunk_loader_promise__` */\n chunkCache: Record<string, Promise<unknown>>;\n /** @see `__remote_script_entrypoint_mount__` */\n mountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_script_entrypoint_unmount__` */\n unmountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_bundle_url__` */\n bundleUrls: Record<string, string | URL>;\n /** @see `__rc_module_registry__` */\n moduleRegistry: Record<string, unknown>;\n /** @see `__webpack_require_type__` */\n dispatcherRuntime: string | undefined;\n /** @see `__remote_component_host_shared_modules__` */\n hostSharedModules: Record<string, () => Promise<unknown>>;\n /** @see `__remote_next_css__` */\n cssCache: Record<string, ChildNode[]>;\n /** @see `__remote_components_shadowroot_*` */\n shadowRoots: Record<string, ShadowRoot | null>;\n}\n\n/** Prefix for legacy per-key shadow root globals (`__remote_components_shadowroot_*`). */\nconst SHADOW_ROOT_PREFIX = '__remote_components_shadowroot_';\n\n/**\n * Backward-compat aliases for globals used in <=0.3.3.\n *\n * Only includes object/Map values that can be aliased by reference.\n * Primitives (`dispatcherRuntime`) must use write-through at their call sites.\n * Dynamic-key shadow root globals are adopted separately in `getNamespace()`.\n */\nconst LEGACY_ALIASES: ReadonlyArray<{\n global: string;\n prop: keyof RemoteComponentsNamespace;\n}> = [\n { global: '__remote_component_scopes__', prop: 'scopes' },\n {\n global: '__remote_components_turbopack_chunk_loader_promise__',\n prop: 'chunkCache',\n },\n { global: '__remote_script_entrypoint_mount__', prop: 'mountFns' },\n { global: '__remote_script_entrypoint_unmount__', prop: 'unmountFns' },\n { global: '__remote_bundle_url__', prop: 'bundleUrls' },\n { global: '__rc_module_registry__', prop: 'moduleRegistry' },\n {\n global: '__remote_component_host_shared_modules__',\n prop: 'hostSharedModules',\n },\n { global: '__remote_next_css__', prop: 'cssCache' },\n];\n\n/**\n * Returns the single shared `RemoteComponentsNamespace` instance, creating\n * it on first access. The namespace lives at `globalThis.__remote_components__`\n * so every module in the page shares the same state regardless of how many\n * copies of the library are loaded.\n *\n * On first initialization this function also handles backward compatibility\n * with legacy globals:\n * 1. **Adopt**: if a legacy global already exists (written by older code before\n * the namespace was created), its value becomes the initial namespace value.\n * 2. **Alias**: legacy globals are assigned to point at the namespace's objects,\n * so older code that reads the legacy global sees the same reference.\n */\nexport function getNamespace(): RemoteComponentsNamespace {\n const g = globalThis as GlobalScope & MountUnmountFunctions;\n const existing = g.__remote_components__;\n if (existing) {\n return existing;\n }\n\n const ns: RemoteComponentsNamespace = {\n scopes: new Map(),\n chunkCache: {},\n mountFns: {},\n unmountFns: {},\n bundleUrls: {},\n moduleRegistry: {},\n dispatcherRuntime: undefined,\n hostSharedModules: {},\n cssCache: {},\n shadowRoots: {},\n };\n\n // Adopt any pre-existing legacy globals, then alias them to the namespace.\n const nsRecord = ns as unknown as Record<string, unknown>;\n for (const { global, prop } of LEGACY_ALIASES) {\n const legacyValue = (g as Record<string, unknown>)[global];\n if (legacyValue != null) {\n nsRecord[prop] = legacyValue;\n }\n (g as Record<string, unknown>)[global] = ns[prop];\n }\n\n // Adopt per-key shadow root globals used in <=0.3.3\n // (e.g. `globalThis.__remote_components_shadowroot_<key> = root`).\n const gRecord = g as Record<string, unknown>;\n for (const key of Object.keys(gRecord)) {\n if (key.startsWith(SHADOW_ROOT_PREFIX)) {\n const suffix = key.slice(SHADOW_ROOT_PREFIX.length);\n ns.shadowRoots[suffix] = gRecord[key] as ShadowRoot | null;\n delete gRecord[key];\n }\n }\n\n g.__remote_components__ = ns;\n return ns;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCA,MAAM,qBAAqB;AAS3B,MAAM,iBAGD;AAAA,EACH,EAAE,QAAQ,+BAA+B,MAAM,SAAS;AAAA,EACxD;AAAA,IACE,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EACA,EAAE,QAAQ,sCAAsC,MAAM,WAAW;AAAA,EACjE,EAAE,QAAQ,wCAAwC,MAAM,aAAa;AAAA,EACrE,EAAE,QAAQ,yBAAyB,MAAM,aAAa;AAAA,EACtD,EAAE,QAAQ,0BAA0B,MAAM,iBAAiB;AAAA,EAC3D;AAAA,IACE,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EACA,EAAE,QAAQ,uBAAuB,MAAM,WAAW;AACpD;AAeO,SAAS,eAA0C;AACxD,QAAM,IAAI;AACV,QAAM,WAAW,EAAE;AACnB,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,KAAgC;AAAA,IACpC,QAAQ,oBAAI,IAAI;AAAA,IAChB,YAAY,CAAC;AAAA,IACb,UAAU,CAAC;AAAA,IACX,YAAY,CAAC;AAAA,IACb,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACjB,mBAAmB;AAAA,IACnB,mBAAmB,CAAC;AAAA,IACpB,UAAU,CAAC;AAAA,IACX,aAAa,CAAC;AAAA,EAChB;AAGA,QAAM,WAAW;AACjB,aAAW,EAAE,QAAQ,KAAK,KAAK,gBAAgB;AAC7C,UAAM,cAAe,EAA8B,MAAM;AACzD,QAAI,eAAe,MAAM;AACvB,eAAS,IAAI,IAAI;AAAA,IACnB;AACA,IAAC,EAA8B,MAAM,IAAI,GAAG,IAAI;AAAA,EAClD;AAIA,QAAM,UAAU;AAChB,aAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,QAAI,IAAI,WAAW,kBAAkB,GAAG;AACtC,YAAM,SAAS,IAAI,MAAM,mBAAmB,MAAM;AAClD,SAAG,YAAY,MAAM,IAAI,QAAQ,GAAG;AACpC,aAAO,QAAQ,GAAG;AAAA,IACpB;AAAA,EACF;AAEA,IAAE,wBAAwB;AAC1B,SAAO;AACT;","names":[]}
@@ -0,0 +1,5 @@
1
+ import './turbopack/remote-scope.js';
2
+ export { R as RemoteComponentsNamespace, g as getNamespace } from '../../types-59251814.js';
3
+ import './url/resolve-client-url.js';
4
+ import './constants.js';
5
+ import './metadata.js';
@@ -0,0 +1,58 @@
1
+ const SHADOW_ROOT_PREFIX = "__remote_components_shadowroot_";
2
+ const LEGACY_ALIASES = [
3
+ { global: "__remote_component_scopes__", prop: "scopes" },
4
+ {
5
+ global: "__remote_components_turbopack_chunk_loader_promise__",
6
+ prop: "chunkCache"
7
+ },
8
+ { global: "__remote_script_entrypoint_mount__", prop: "mountFns" },
9
+ { global: "__remote_script_entrypoint_unmount__", prop: "unmountFns" },
10
+ { global: "__remote_bundle_url__", prop: "bundleUrls" },
11
+ { global: "__rc_module_registry__", prop: "moduleRegistry" },
12
+ {
13
+ global: "__remote_component_host_shared_modules__",
14
+ prop: "hostSharedModules"
15
+ },
16
+ { global: "__remote_next_css__", prop: "cssCache" }
17
+ ];
18
+ function getNamespace() {
19
+ const g = globalThis;
20
+ const existing = g.__remote_components__;
21
+ if (existing) {
22
+ return existing;
23
+ }
24
+ const ns = {
25
+ scopes: /* @__PURE__ */ new Map(),
26
+ chunkCache: {},
27
+ mountFns: {},
28
+ unmountFns: {},
29
+ bundleUrls: {},
30
+ moduleRegistry: {},
31
+ dispatcherRuntime: void 0,
32
+ hostSharedModules: {},
33
+ cssCache: {},
34
+ shadowRoots: {}
35
+ };
36
+ const nsRecord = ns;
37
+ for (const { global, prop } of LEGACY_ALIASES) {
38
+ const legacyValue = g[global];
39
+ if (legacyValue != null) {
40
+ nsRecord[prop] = legacyValue;
41
+ }
42
+ g[global] = ns[prop];
43
+ }
44
+ const gRecord = g;
45
+ for (const key of Object.keys(gRecord)) {
46
+ if (key.startsWith(SHADOW_ROOT_PREFIX)) {
47
+ const suffix = key.slice(SHADOW_ROOT_PREFIX.length);
48
+ ns.shadowRoots[suffix] = gRecord[key];
49
+ delete gRecord[key];
50
+ }
51
+ }
52
+ g.__remote_components__ = ns;
53
+ return ns;
54
+ }
55
+ export {
56
+ getNamespace
57
+ };
58
+ //# sourceMappingURL=namespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/namespace.ts"],"sourcesContent":["import type { RemoteScope } from '#internal/runtime/turbopack/remote-scope';\nimport type {\n GlobalScope,\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\n\n/**\n * Typed namespace for all remote-components runtime state.\n *\n * Consolidates scattered `globalThis` globals into a single object at\n * `globalThis.__remote_components__`. Each property corresponds to a\n * previously independent global — see inline `@see` tags for the original\n * global name. Code that previously read from those globals still works\n * because each migration writes through to both the namespace and the\n * legacy global (pointing at the same underlying object).\n */\nexport interface RemoteComponentsNamespace {\n /** @see `__remote_component_scopes__` */\n scopes: Map<string, RemoteScope>;\n /** @see `__remote_components_turbopack_chunk_loader_promise__` */\n chunkCache: Record<string, Promise<unknown>>;\n /** @see `__remote_script_entrypoint_mount__` */\n mountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_script_entrypoint_unmount__` */\n unmountFns: Record<string, Set<MountOrUnmountFunction>>;\n /** @see `__remote_bundle_url__` */\n bundleUrls: Record<string, string | URL>;\n /** @see `__rc_module_registry__` */\n moduleRegistry: Record<string, unknown>;\n /** @see `__webpack_require_type__` */\n dispatcherRuntime: string | undefined;\n /** @see `__remote_component_host_shared_modules__` */\n hostSharedModules: Record<string, () => Promise<unknown>>;\n /** @see `__remote_next_css__` */\n cssCache: Record<string, ChildNode[]>;\n /** @see `__remote_components_shadowroot_*` */\n shadowRoots: Record<string, ShadowRoot | null>;\n}\n\n/** Prefix for legacy per-key shadow root globals (`__remote_components_shadowroot_*`). */\nconst SHADOW_ROOT_PREFIX = '__remote_components_shadowroot_';\n\n/**\n * Backward-compat aliases for globals used in <=0.3.3.\n *\n * Only includes object/Map values that can be aliased by reference.\n * Primitives (`dispatcherRuntime`) must use write-through at their call sites.\n * Dynamic-key shadow root globals are adopted separately in `getNamespace()`.\n */\nconst LEGACY_ALIASES: ReadonlyArray<{\n global: string;\n prop: keyof RemoteComponentsNamespace;\n}> = [\n { global: '__remote_component_scopes__', prop: 'scopes' },\n {\n global: '__remote_components_turbopack_chunk_loader_promise__',\n prop: 'chunkCache',\n },\n { global: '__remote_script_entrypoint_mount__', prop: 'mountFns' },\n { global: '__remote_script_entrypoint_unmount__', prop: 'unmountFns' },\n { global: '__remote_bundle_url__', prop: 'bundleUrls' },\n { global: '__rc_module_registry__', prop: 'moduleRegistry' },\n {\n global: '__remote_component_host_shared_modules__',\n prop: 'hostSharedModules',\n },\n { global: '__remote_next_css__', prop: 'cssCache' },\n];\n\n/**\n * Returns the single shared `RemoteComponentsNamespace` instance, creating\n * it on first access. The namespace lives at `globalThis.__remote_components__`\n * so every module in the page shares the same state regardless of how many\n * copies of the library are loaded.\n *\n * On first initialization this function also handles backward compatibility\n * with legacy globals:\n * 1. **Adopt**: if a legacy global already exists (written by older code before\n * the namespace was created), its value becomes the initial namespace value.\n * 2. **Alias**: legacy globals are assigned to point at the namespace's objects,\n * so older code that reads the legacy global sees the same reference.\n */\nexport function getNamespace(): RemoteComponentsNamespace {\n const g = globalThis as GlobalScope & MountUnmountFunctions;\n const existing = g.__remote_components__;\n if (existing) {\n return existing;\n }\n\n const ns: RemoteComponentsNamespace = {\n scopes: new Map(),\n chunkCache: {},\n mountFns: {},\n unmountFns: {},\n bundleUrls: {},\n moduleRegistry: {},\n dispatcherRuntime: undefined,\n hostSharedModules: {},\n cssCache: {},\n shadowRoots: {},\n };\n\n // Adopt any pre-existing legacy globals, then alias them to the namespace.\n const nsRecord = ns as unknown as Record<string, unknown>;\n for (const { global, prop } of LEGACY_ALIASES) {\n const legacyValue = (g as Record<string, unknown>)[global];\n if (legacyValue != null) {\n nsRecord[prop] = legacyValue;\n }\n (g as Record<string, unknown>)[global] = ns[prop];\n }\n\n // Adopt per-key shadow root globals used in <=0.3.3\n // (e.g. `globalThis.__remote_components_shadowroot_<key> = root`).\n const gRecord = g as Record<string, unknown>;\n for (const key of Object.keys(gRecord)) {\n if (key.startsWith(SHADOW_ROOT_PREFIX)) {\n const suffix = key.slice(SHADOW_ROOT_PREFIX.length);\n ns.shadowRoots[suffix] = gRecord[key] as ShadowRoot | null;\n delete gRecord[key];\n }\n }\n\n g.__remote_components__ = ns;\n return ns;\n}\n"],"mappings":"AAyCA,MAAM,qBAAqB;AAS3B,MAAM,iBAGD;AAAA,EACH,EAAE,QAAQ,+BAA+B,MAAM,SAAS;AAAA,EACxD;AAAA,IACE,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EACA,EAAE,QAAQ,sCAAsC,MAAM,WAAW;AAAA,EACjE,EAAE,QAAQ,wCAAwC,MAAM,aAAa;AAAA,EACrE,EAAE,QAAQ,yBAAyB,MAAM,aAAa;AAAA,EACtD,EAAE,QAAQ,0BAA0B,MAAM,iBAAiB;AAAA,EAC3D;AAAA,IACE,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EACA,EAAE,QAAQ,uBAAuB,MAAM,WAAW;AACpD;AAeO,SAAS,eAA0C;AACxD,QAAM,IAAI;AACV,QAAM,WAAW,EAAE;AACnB,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AAEA,QAAM,KAAgC;AAAA,IACpC,QAAQ,oBAAI,IAAI;AAAA,IAChB,YAAY,CAAC;AAAA,IACb,UAAU,CAAC;AAAA,IACX,YAAY,CAAC;AAAA,IACb,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACjB,mBAAmB;AAAA,IACnB,mBAAmB,CAAC;AAAA,IACpB,UAAU,CAAC;AAAA,IACX,aAAa,CAAC;AAAA,EAChB;AAGA,QAAM,WAAW;AACjB,aAAW,EAAE,QAAQ,KAAK,KAAK,gBAAgB;AAC7C,UAAM,cAAe,EAA8B,MAAM;AACzD,QAAI,eAAe,MAAM;AACvB,eAAS,IAAI,IAAI;AAAA,IACnB;AACA,IAAC,EAA8B,MAAM,IAAI,GAAG,IAAI;AAAA,EAClD;AAIA,QAAM,UAAU;AAChB,aAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,QAAI,IAAI,WAAW,kBAAkB,GAAG;AACtC,YAAM,SAAS,IAAI,MAAM,mBAAmB,MAAM;AAClD,SAAG,YAAY,MAAM,IAAI,QAAQ,GAAG;AACpC,aAAO,QAAQ,GAAG;AAAA,IACpB;AAAA,EACF;AAEA,IAAE,wBAAwB;AAC1B,SAAO;AACT;","names":[]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var rsc_imports_exports = {};
30
+ __export(rsc_imports_exports, {
31
+ importRSCClientBrowser: () => importRSCClientBrowser,
32
+ importRSCClientEdge: () => importRSCClientEdge,
33
+ importRSCServer: () => importRSCServer
34
+ });
35
+ module.exports = __toCommonJS(rsc_imports_exports);
36
+ async function importRSCClientEdge() {
37
+ try {
38
+ return await import("next/dist/compiled/react-server-dom-webpack/client.edge");
39
+ } catch {
40
+ return await import("react-server-dom-webpack/client.edge");
41
+ }
42
+ }
43
+ async function importRSCClientBrowser() {
44
+ try {
45
+ return await import("next/dist/compiled/react-server-dom-webpack/client.browser");
46
+ } catch {
47
+ const mod = await import("react-server-dom-webpack/client.browser");
48
+ return mod.default ?? mod;
49
+ }
50
+ }
51
+ async function importRSCServer() {
52
+ const [primary, fallback] = await Promise.all(
53
+ process.env.TURBOPACK ? [
54
+ tryImport(
55
+ () => import("react-server-dom-turbopack/server")
56
+ ),
57
+ tryImport(
58
+ () => import("react-server-dom-turbopack/server.edge")
59
+ )
60
+ ] : [
61
+ tryImport(
62
+ () => import("react-server-dom-webpack/server")
63
+ ),
64
+ tryImport(
65
+ () => import("react-server-dom-webpack/server.edge")
66
+ )
67
+ ]
68
+ );
69
+ return {
70
+ renderToReadableStream: primary.renderToReadableStream ?? fallback.renderToReadableStream
71
+ };
72
+ }
73
+ async function tryImport(importer) {
74
+ try {
75
+ return await importer();
76
+ } catch {
77
+ return {};
78
+ }
79
+ }
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ importRSCClientBrowser,
83
+ importRSCClientEdge,
84
+ importRSCServer
85
+ });
86
+ //# sourceMappingURL=rsc-imports.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/rsc-imports.ts"],"sourcesContent":["/**\n * Single import hub for all React Server Components runtime modules.\n *\n * Each function encapsulates the try/catch fallback chain that probes\n * Next.js internal paths first, then falls back to the public\n * `react-server-dom-webpack` / `react-server-dom-turbopack` packages.\n * This keeps version-specific import paths out of business logic.\n */\n\nimport type {\n RSCClientBrowserRuntime,\n RSCClientEdgeRuntime,\n RSCServerRuntime,\n} from './rsc-runtime';\n\n/**\n * Imports the RSC client for the **edge** runtime (server-side).\n * Used by `fetch-remote-component.ts` to deserialise RSC flight data.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.edge` module.\n */\nexport async function importRSCClientEdge(): Promise<RSCClientEdgeRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n } catch {\n return await import('react-server-dom-webpack/client.edge');\n }\n}\n\n/**\n * Imports the RSC client for the **browser** runtime (client-side hydration).\n * Used by `component-loader.ts` to hydrate RSC streams in the browser.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.browser` module (which may use a\n * default export depending on the package version).\n */\nexport async function importRSCClientBrowser(): Promise<RSCClientBrowserRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.browser'\n );\n } catch {\n const mod = await import('react-server-dom-webpack/client.browser');\n // Some versions export `createFromReadableStream` as a default export\n return (mod.default ?? mod) as RSCClientBrowserRuntime;\n }\n}\n\n/**\n * Imports the RSC **server** renderer for `ExposeRemoteComponent`.\n *\n * When `TURBOPACK` is set in the environment, imports from\n * `react-server-dom-turbopack`; otherwise uses `react-server-dom-webpack`.\n * Each variant tries the primary path first (`/server`), falling back to\n * the `.edge` entry point.\n */\nexport async function importRSCServer(): Promise<RSCServerRuntime> {\n const [primary, fallback] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n\n return {\n renderToReadableStream:\n primary.renderToReadableStream ?? fallback.renderToReadableStream,\n };\n}\n\nasync function tryImport<T>(importer: () => Promise<T>): Promise<T> {\n try {\n return await importer();\n } catch {\n return {} as T;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,eAAsB,sBAAqD;AACzE,MAAI;AACF,WAAO,MAAM,OACX,yDACF;AAAA,EACF,QAAE;AACA,WAAO,MAAM,OAAO,sCAAsC;AAAA,EAC5D;AACF;AAUA,eAAsB,yBAA2D;AAC/E,MAAI;AACF,WAAO,MAAM,OACX,4DACF;AAAA,EACF,QAAE;AACA,UAAM,MAAM,MAAM,OAAO,yCAAyC;AAElE,WAAQ,IAAI,WAAW;AAAA,EACzB;AACF;AAUA,eAAsB,kBAA6C;AACjE,QAAM,CAAC,SAAS,QAAQ,IAAI,MAAM,QAAQ;AAAA,IACxC,QAAQ,IAAI,YACR;AAAA,MACE;AAAA,QACE,MAAM,OAAO,mCAAmC;AAAA,MAClD;AAAA,MACA;AAAA,QACE,MAAM,OAAO,wCAAwC;AAAA,MACvD;AAAA,IACF,IACA;AAAA,MACE;AAAA,QACE,MAAM,OAAO,iCAAiC;AAAA,MAChD;AAAA,MACA;AAAA,QACE,MAAM,OAAO,sCAAsC;AAAA,MACrD;AAAA,IACF;AAAA,EACN;AAEA,SAAO;AAAA,IACL,wBACE,QAAQ,0BAA0B,SAAS;AAAA,EAC/C;AACF;AAEA,eAAe,UAAa,UAAwC;AAClE,MAAI;AACF,WAAO,MAAM,SAAS;AAAA,EACxB,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
@@ -0,0 +1,39 @@
1
+ import { RSCClientEdgeRuntime, RSCClientBrowserRuntime, RSCServerRuntime } from './rsc-runtime.js';
2
+
3
+ /**
4
+ * Single import hub for all React Server Components runtime modules.
5
+ *
6
+ * Each function encapsulates the try/catch fallback chain that probes
7
+ * Next.js internal paths first, then falls back to the public
8
+ * `react-server-dom-webpack` / `react-server-dom-turbopack` packages.
9
+ * This keeps version-specific import paths out of business logic.
10
+ */
11
+
12
+ /**
13
+ * Imports the RSC client for the **edge** runtime (server-side).
14
+ * Used by `fetch-remote-component.ts` to deserialise RSC flight data.
15
+ *
16
+ * Tries the Next.js compiled path first, falls back to the bare
17
+ * `react-server-dom-webpack/client.edge` module.
18
+ */
19
+ declare function importRSCClientEdge(): Promise<RSCClientEdgeRuntime>;
20
+ /**
21
+ * Imports the RSC client for the **browser** runtime (client-side hydration).
22
+ * Used by `component-loader.ts` to hydrate RSC streams in the browser.
23
+ *
24
+ * Tries the Next.js compiled path first, falls back to the bare
25
+ * `react-server-dom-webpack/client.browser` module (which may use a
26
+ * default export depending on the package version).
27
+ */
28
+ declare function importRSCClientBrowser(): Promise<RSCClientBrowserRuntime>;
29
+ /**
30
+ * Imports the RSC **server** renderer for `ExposeRemoteComponent`.
31
+ *
32
+ * When `TURBOPACK` is set in the environment, imports from
33
+ * `react-server-dom-turbopack`; otherwise uses `react-server-dom-webpack`.
34
+ * Each variant tries the primary path first (`/server`), falling back to
35
+ * the `.edge` entry point.
36
+ */
37
+ declare function importRSCServer(): Promise<RSCServerRuntime>;
38
+
39
+ export { importRSCClientBrowser, importRSCClientEdge, importRSCServer };
@@ -0,0 +1,50 @@
1
+ async function importRSCClientEdge() {
2
+ try {
3
+ return await import("next/dist/compiled/react-server-dom-webpack/client.edge");
4
+ } catch {
5
+ return await import("react-server-dom-webpack/client.edge");
6
+ }
7
+ }
8
+ async function importRSCClientBrowser() {
9
+ try {
10
+ return await import("next/dist/compiled/react-server-dom-webpack/client.browser");
11
+ } catch {
12
+ const mod = await import("react-server-dom-webpack/client.browser");
13
+ return mod.default ?? mod;
14
+ }
15
+ }
16
+ async function importRSCServer() {
17
+ const [primary, fallback] = await Promise.all(
18
+ process.env.TURBOPACK ? [
19
+ tryImport(
20
+ () => import("react-server-dom-turbopack/server")
21
+ ),
22
+ tryImport(
23
+ () => import("react-server-dom-turbopack/server.edge")
24
+ )
25
+ ] : [
26
+ tryImport(
27
+ () => import("react-server-dom-webpack/server")
28
+ ),
29
+ tryImport(
30
+ () => import("react-server-dom-webpack/server.edge")
31
+ )
32
+ ]
33
+ );
34
+ return {
35
+ renderToReadableStream: primary.renderToReadableStream ?? fallback.renderToReadableStream
36
+ };
37
+ }
38
+ async function tryImport(importer) {
39
+ try {
40
+ return await importer();
41
+ } catch {
42
+ return {};
43
+ }
44
+ }
45
+ export {
46
+ importRSCClientBrowser,
47
+ importRSCClientEdge,
48
+ importRSCServer
49
+ };
50
+ //# sourceMappingURL=rsc-imports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/rsc-imports.ts"],"sourcesContent":["/**\n * Single import hub for all React Server Components runtime modules.\n *\n * Each function encapsulates the try/catch fallback chain that probes\n * Next.js internal paths first, then falls back to the public\n * `react-server-dom-webpack` / `react-server-dom-turbopack` packages.\n * This keeps version-specific import paths out of business logic.\n */\n\nimport type {\n RSCClientBrowserRuntime,\n RSCClientEdgeRuntime,\n RSCServerRuntime,\n} from './rsc-runtime';\n\n/**\n * Imports the RSC client for the **edge** runtime (server-side).\n * Used by `fetch-remote-component.ts` to deserialise RSC flight data.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.edge` module.\n */\nexport async function importRSCClientEdge(): Promise<RSCClientEdgeRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.edge'\n );\n } catch {\n return await import('react-server-dom-webpack/client.edge');\n }\n}\n\n/**\n * Imports the RSC client for the **browser** runtime (client-side hydration).\n * Used by `component-loader.ts` to hydrate RSC streams in the browser.\n *\n * Tries the Next.js compiled path first, falls back to the bare\n * `react-server-dom-webpack/client.browser` module (which may use a\n * default export depending on the package version).\n */\nexport async function importRSCClientBrowser(): Promise<RSCClientBrowserRuntime> {\n try {\n return await import(\n 'next/dist/compiled/react-server-dom-webpack/client.browser'\n );\n } catch {\n const mod = await import('react-server-dom-webpack/client.browser');\n // Some versions export `createFromReadableStream` as a default export\n return (mod.default ?? mod) as RSCClientBrowserRuntime;\n }\n}\n\n/**\n * Imports the RSC **server** renderer for `ExposeRemoteComponent`.\n *\n * When `TURBOPACK` is set in the environment, imports from\n * `react-server-dom-turbopack`; otherwise uses `react-server-dom-webpack`.\n * Each variant tries the primary path first (`/server`), falling back to\n * the `.edge` entry point.\n */\nexport async function importRSCServer(): Promise<RSCServerRuntime> {\n const [primary, fallback] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSCServerRuntime>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n\n return {\n renderToReadableStream:\n primary.renderToReadableStream ?? fallback.renderToReadableStream,\n };\n}\n\nasync function tryImport<T>(importer: () => Promise<T>): Promise<T> {\n try {\n return await importer();\n } catch {\n return {} as T;\n }\n}\n"],"mappings":"AAsBA,eAAsB,sBAAqD;AACzE,MAAI;AACF,WAAO,MAAM,OACX,yDACF;AAAA,EACF,QAAE;AACA,WAAO,MAAM,OAAO,sCAAsC;AAAA,EAC5D;AACF;AAUA,eAAsB,yBAA2D;AAC/E,MAAI;AACF,WAAO,MAAM,OACX,4DACF;AAAA,EACF,QAAE;AACA,UAAM,MAAM,MAAM,OAAO,yCAAyC;AAElE,WAAQ,IAAI,WAAW;AAAA,EACzB;AACF;AAUA,eAAsB,kBAA6C;AACjE,QAAM,CAAC,SAAS,QAAQ,IAAI,MAAM,QAAQ;AAAA,IACxC,QAAQ,IAAI,YACR;AAAA,MACE;AAAA,QACE,MAAM,OAAO,mCAAmC;AAAA,MAClD;AAAA,MACA;AAAA,QACE,MAAM,OAAO,wCAAwC;AAAA,MACvD;AAAA,IACF,IACA;AAAA,MACE;AAAA,QACE,MAAM,OAAO,iCAAiC;AAAA,MAChD;AAAA,MACA;AAAA,QACE,MAAM,OAAO,sCAAsC;AAAA,MACrD;AAAA,IACF;AAAA,EACN;AAEA,SAAO;AAAA,IACL,wBACE,QAAQ,0BAA0B,SAAS;AAAA,EAC/C;AACF;AAEA,eAAe,UAAa,UAAwC;AAClE,MAAI;AACF,WAAO,MAAM,SAAS;AAAA,EACxB,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
@@ -12,6 +12,6 @@ var __copyProps = (to, from, except, desc) => {
12
12
  return to;
13
13
  };
14
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var resolved_data_exports = {};
16
- module.exports = __toCommonJS(resolved_data_exports);
17
- //# sourceMappingURL=resolved-data.cjs.map
15
+ var rsc_runtime_exports = {};
16
+ module.exports = __toCommonJS(rsc_runtime_exports);
17
+ //# sourceMappingURL=rsc-runtime.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/rsc-runtime.ts"],"sourcesContent":["/**\n * Adapter interfaces for React Server Components runtimes.\n *\n * These decouple the rest of the codebase from the concrete module paths\n * (`next/dist/compiled/...`, `react-server-dom-webpack/...`, etc.) so that\n * version-specific import logic lives in a single place (`rsc-imports.ts`).\n */\n\ninterface ClientModuleEntry {\n id: string;\n name: string;\n chunks: string[];\n async: boolean;\n}\n\n/** Edge-runtime RSC client — used by `fetch-remote-component.ts` on the server. */\nexport interface RSCClientEdgeRuntime {\n createFromReadableStream(\n stream: ReadableStream<Uint8Array>,\n options: {\n serverConsumerManifest: {\n moduleLoading: {\n prefix?: string;\n crossOrigin?: boolean | null;\n };\n moduleMap: Record<string, unknown>;\n };\n },\n ): React.ReactNode;\n}\n\n/** Browser-runtime RSC client — used by `component-loader.ts` for hydration. */\nexport interface RSCClientBrowserRuntime {\n createFromReadableStream(stream: ReadableStream<Uint8Array>): React.ReactNode;\n}\n\n/** Server-side RSC renderer — used by the remote `ExposeRemoteComponent`. */\nexport interface RSCServerRuntime {\n renderToReadableStream?: (\n element: React.ReactNode,\n clientModules: Record<string, ClientModuleEntry>,\n options?: {\n onError?: (e: Error) => void;\n },\n ) => ReadableStream<Uint8Array>;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Adapter interfaces for React Server Components runtimes.
3
+ *
4
+ * These decouple the rest of the codebase from the concrete module paths
5
+ * (`next/dist/compiled/...`, `react-server-dom-webpack/...`, etc.) so that
6
+ * version-specific import logic lives in a single place (`rsc-imports.ts`).
7
+ */
8
+ interface ClientModuleEntry {
9
+ id: string;
10
+ name: string;
11
+ chunks: string[];
12
+ async: boolean;
13
+ }
14
+ /** Edge-runtime RSC client — used by `fetch-remote-component.ts` on the server. */
15
+ interface RSCClientEdgeRuntime {
16
+ createFromReadableStream(stream: ReadableStream<Uint8Array>, options: {
17
+ serverConsumerManifest: {
18
+ moduleLoading: {
19
+ prefix?: string;
20
+ crossOrigin?: boolean | null;
21
+ };
22
+ moduleMap: Record<string, unknown>;
23
+ };
24
+ }): React.ReactNode;
25
+ }
26
+ /** Browser-runtime RSC client — used by `component-loader.ts` for hydration. */
27
+ interface RSCClientBrowserRuntime {
28
+ createFromReadableStream(stream: ReadableStream<Uint8Array>): React.ReactNode;
29
+ }
30
+ /** Server-side RSC renderer — used by the remote `ExposeRemoteComponent`. */
31
+ interface RSCServerRuntime {
32
+ renderToReadableStream?: (element: React.ReactNode, clientModules: Record<string, ClientModuleEntry>, options?: {
33
+ onError?: (e: Error) => void;
34
+ }) => ReadableStream<Uint8Array>;
35
+ }
36
+
37
+ export { RSCClientBrowserRuntime, RSCClientEdgeRuntime, RSCServerRuntime };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=rsc-runtime.js.map
@@ -18,7 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var rsc_exports = {};
20
20
  __export(rsc_exports, {
21
- createRSCStream: () => createRSCStream
21
+ buildRSCChunks: () => buildRSCChunks,
22
+ createRSCStream: () => createRSCStream,
23
+ fixPayload: () => fixPayload
22
24
  });
23
25
  module.exports = __toCommonJS(rsc_exports);
24
26
  var import_web_streams_polyfill = require("web-streams-polyfill");
@@ -40,6 +42,18 @@ function fixPayload(payload) {
40
42
  }
41
43
  }
42
44
  }
45
+ function buildRSCChunks(rscName, data) {
46
+ const chunks = [];
47
+ for (const chunk of data) {
48
+ for (const line of chunk.split("\n")) {
49
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
50
+ if (match?.groups?.rsc) {
51
+ chunks.push(JSON.parse(`"${match.groups.rsc}"`));
52
+ }
53
+ }
54
+ }
55
+ return chunks;
56
+ }
43
57
  function createRSCStream(rscName, data) {
44
58
  return new import_web_streams_polyfill.ReadableStream({
45
59
  type: "bytes",
@@ -47,16 +61,11 @@ function createRSCStream(rscName, data) {
47
61
  const encoder = new TextEncoder();
48
62
  const self = globalThis;
49
63
  if (data.length > 0) {
50
- data.forEach((chunk) => {
51
- const lines = chunk.split("\n");
52
- for (const line of lines) {
53
- const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
54
- if (match?.groups?.rsc) {
55
- self[rscName] = self[rscName] ?? [];
56
- self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
57
- }
58
- }
59
- });
64
+ const parsed = buildRSCChunks(rscName, data);
65
+ if (parsed.length > 0) {
66
+ self[rscName] = self[rscName] ?? [];
67
+ self[rscName].push(...parsed);
68
+ }
60
69
  }
61
70
  const allChunks = (self[rscName] ?? [`0:[null]
62
71
  `]).join("");
@@ -87,6 +96,8 @@ function createRSCStream(rscName, data) {
87
96
  }
88
97
  // Annotate the CommonJS export names for ESM import in node:
89
98
  0 && (module.exports = {
90
- createRSCStream
99
+ buildRSCChunks,
100
+ createRSCStream,
101
+ fixPayload
91
102
  });
92
103
  //# sourceMappingURL=rsc.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload to make it compatible with React JSX development runtime\n */\nfunction fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n // if the current node is a React element, we need to fix the payload\n if (payload[0] === '$') {\n // fix the props (children or other React elements)\n fixPayload(payload[3]);\n if (payload.length === 4) {\n // add placeholder for the missing debug info\n payload.push(null, null, 1);\n }\n } else {\n // we are in an array, continue with visiting each item\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n // we are in an object, continue with visiting each property\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // when the remote component RSC scripts are not found or loaded\n // we need to load the RSC flight data parsing the chunks\n if (data.length > 0) {\n data.forEach((chunk) => {\n const lines = chunk.split('\\n');\n for (const line of lines) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n });\n }\n\n // get the RSC flight data from the global scope\n // the RSC flight data is stored in an array\n // fallback to an empty RSC payload if the data is not found\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n\n // clear the RSC flight data from the global scope\n self[rscName] = null;\n\n // process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n // parse the chunk to get the id, prefix and payload\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n // parse the payload to a JSON object\n const jsonPayload = JSON.parse(payload) as unknown[];\n // fix the payload to make it compatible with React JSX development runtime\n fixPayload(jsonPayload);\n // reconstruct the chunk to a string\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n // encode the chunk to a byte buffer\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n // close the stream when all chunks are enqueued\n controller.close();\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAA+B;AAK/B,SAAS,WAAW,SAAwB;AAC1C,MAAI,MAAM,QAAQ,OAAO,GAAG;AAE1B,QAAI,QAAQ,CAAC,MAAM,KAAK;AAEtB,iBAAW,QAAQ,CAAC,CAAC;AACrB,UAAI,QAAQ,WAAW,GAAG;AAExB,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,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAe,CAAC;AAAA,UACvD,OAAO;AAEL,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,UACjD;AAAA,QACF,OAAO;AAEL,qBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,QACjD;AAAA,MACF,CAAC;AAED,iBAAW,MAAM;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload arrays to be compatible with React JSX development runtime.\n * React elements in the wire format are 4-element arrays (`['$', type, key, props]`);\n * the dev runtime expects 7 elements with debug info in positions 4-6.\n */\nexport function fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n if (payload[0] === '$') {\n // React element — fix props recursively, then pad to 7 elements\n fixPayload(payload[3]);\n if (payload.length === 4) {\n payload.push(null, null, 1);\n }\n } else {\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Parses raw RSC script chunks (the `self[\"name\"].push(\"...\")` format produced\n * by `<RemoteComponentData>`) into a flat array of flight-data strings.\n *\n * This is a pure function — it reads from `data` only, never from `globalThis`.\n */\nexport function buildRSCChunks(rscName: string, data: string[]): string[] {\n const chunks: string[] = [];\n\n for (const chunk of data) {\n for (const line of chunk.split('\\n')) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n chunks.push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n }\n\n return chunks;\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream.\n *\n * First checks `data` for inline script chunks (parsed via {@link buildRSCChunks}),\n * merging them onto `globalThis[rscName]`. Then consumes the global array\n * (or falls back to an empty RSC payload) and pipes fixed chunks into the stream.\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // Parse inline script chunks and merge onto the global array\n if (data.length > 0) {\n const parsed = buildRSCChunks(rscName, data);\n if (parsed.length > 0) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(...parsed);\n }\n }\n\n // Consume the global RSC flight data, falling back to an empty payload\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n self[rscName] = null;\n\n // Process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n const jsonPayload = JSON.parse(payload) as unknown[];\n fixPayload(jsonPayload);\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n controller.close();\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAA+B;AAOxB,SAAS,WAAW,SAAwB;AACjD,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,QAAI,QAAQ,CAAC,MAAM,KAAK;AAEtB,iBAAW,QAAQ,CAAC,CAAC;AACrB,UAAI,QAAQ,WAAW,GAAG;AACxB,gBAAQ,KAAK,MAAM,MAAM,CAAC;AAAA,MAC5B;AAAA,IACF,OAAO;AACL,iBAAW,QAAQ,SAAS;AAC1B,mBAAW,IAAI;AAAA,MACj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AU,WAAW;AACrF,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAe,CAAC;AAAA,UACvD,OAAO;AACL,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,UACjD;AAAA,QACF,OAAO;AACL,qBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,QACjD;AAAA,MACF,CAAC;AACD,iBAAW,MAAM;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,8 +1,25 @@
1
1
  import { ReadableStream } from 'web-streams-polyfill';
2
2
 
3
3
  /**
4
- * Processes RSC flight data and creates a ReadableStream
4
+ * Fixes RSC payload arrays to be compatible with React JSX development runtime.
5
+ * React elements in the wire format are 4-element arrays (`['$', type, key, props]`);
6
+ * the dev runtime expects 7 elements with debug info in positions 4-6.
7
+ */
8
+ declare function fixPayload(payload: unknown): void;
9
+ /**
10
+ * Parses raw RSC script chunks (the `self["name"].push("...")` format produced
11
+ * by `<RemoteComponentData>`) into a flat array of flight-data strings.
12
+ *
13
+ * This is a pure function — it reads from `data` only, never from `globalThis`.
14
+ */
15
+ declare function buildRSCChunks(rscName: string, data: string[]): string[];
16
+ /**
17
+ * Processes RSC flight data and creates a ReadableStream.
18
+ *
19
+ * First checks `data` for inline script chunks (parsed via {@link buildRSCChunks}),
20
+ * merging them onto `globalThis[rscName]`. Then consumes the global array
21
+ * (or falls back to an empty RSC payload) and pipes fixed chunks into the stream.
5
22
  */
6
23
  declare function createRSCStream(rscName: string, data: string[]): ReadableStream<Uint8Array>;
7
24
 
8
- export { createRSCStream };
25
+ export { buildRSCChunks, createRSCStream, fixPayload };