remote-components 0.1.0 → 0.2.0

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 (469) hide show
  1. package/dist/{next/config.cjs → config/nextjs.cjs} +76 -101
  2. package/dist/config/nextjs.cjs.map +1 -0
  3. package/dist/{next/config.d.ts → config/nextjs.d.ts} +4 -4
  4. package/dist/{next/config.js → config/nextjs.js} +72 -97
  5. package/dist/config/nextjs.js.map +1 -0
  6. package/dist/{webpack.cjs → config/webpack.cjs} +13 -29
  7. package/dist/config/webpack.cjs.map +1 -0
  8. package/dist/{webpack.js → config/webpack.js} +12 -28
  9. package/dist/config/webpack.js.map +1 -0
  10. package/dist/{shared/remote → host/defaults}/app.cjs +2 -2
  11. package/dist/host/defaults/app.cjs.map +1 -0
  12. package/dist/host/defaults/app.js +8 -0
  13. package/dist/host/defaults/app.js.map +1 -0
  14. package/dist/{shared/remote → host/defaults}/pages.cjs +2 -2
  15. package/dist/host/defaults/pages.cjs.map +1 -0
  16. package/dist/host/defaults/pages.js +8 -0
  17. package/dist/host/defaults/pages.js.map +1 -0
  18. package/dist/{html/host.cjs → host/html.cjs} +1270 -1201
  19. package/dist/host/html.cjs.map +1 -0
  20. package/dist/{html/host.d.ts → host/html.d.ts} +0 -2
  21. package/dist/{html/host.js → host/html.js} +1266 -1196
  22. package/dist/host/html.js.map +1 -0
  23. package/dist/{next/host/client/index.cjs → host/nextjs/app/client-only.cjs} +690 -518
  24. package/dist/host/nextjs/app/client-only.cjs.map +1 -0
  25. package/dist/host/nextjs/app/client-only.d.ts +16 -0
  26. package/dist/{next/host/client/index.js → host/nextjs/app/client-only.js} +693 -514
  27. package/dist/host/nextjs/app/client-only.js.map +1 -0
  28. package/dist/{next/host/app-router-server.cjs → host/nextjs/app.cjs} +11 -10
  29. package/dist/host/nextjs/app.cjs.map +1 -0
  30. package/dist/host/nextjs/app.d.ts +29 -0
  31. package/dist/{next/host/app-router-server.js → host/nextjs/app.js} +7 -6
  32. package/dist/host/nextjs/app.js.map +1 -0
  33. package/dist/{next/host/pages-router-client.cjs → host/nextjs/pages/client-only.cjs} +8 -8
  34. package/dist/host/nextjs/pages/client-only.cjs.map +1 -0
  35. package/dist/host/nextjs/pages/client-only.d.ts +31 -0
  36. package/dist/{next/host/pages-router-client.js → host/nextjs/pages/client-only.js} +4 -4
  37. package/dist/host/nextjs/pages/client-only.js.map +1 -0
  38. package/dist/{next/host/pages-router-server.cjs → host/nextjs/pages.cjs} +44 -55
  39. package/dist/host/nextjs/pages.cjs.map +1 -0
  40. package/dist/host/nextjs/pages.d.ts +77 -0
  41. package/dist/{next/host/pages-router-server.js → host/nextjs/pages.js} +38 -49
  42. package/dist/host/nextjs/pages.js.map +1 -0
  43. package/dist/{internal/shared/client/proxy-through-host.cjs → host/proxy/client.cjs} +19 -13
  44. package/dist/host/proxy/client.cjs.map +1 -0
  45. package/dist/host/proxy/client.d.ts +31 -0
  46. package/dist/host/proxy/client.js +30 -0
  47. package/dist/host/proxy/client.js.map +1 -0
  48. package/dist/{shared/host/proxy.cjs → host/proxy/protected-fetch.cjs} +6 -6
  49. package/dist/host/proxy/protected-fetch.cjs.map +1 -0
  50. package/dist/{shared/host/proxy.js → host/proxy/protected-fetch.js} +3 -3
  51. package/dist/host/proxy/protected-fetch.js.map +1 -0
  52. package/dist/{next → host}/proxy.cjs +12 -92
  53. package/dist/host/proxy.cjs.map +1 -0
  54. package/dist/host/proxy.d.ts +30 -0
  55. package/dist/{next → host}/proxy.js +11 -88
  56. package/dist/host/proxy.js.map +1 -0
  57. package/dist/{react/index.cjs → host/react.cjs} +552 -477
  58. package/dist/host/react.cjs.map +1 -0
  59. package/dist/host/react.d.ts +366 -0
  60. package/dist/{react/index.js → host/react.js} +551 -474
  61. package/dist/host/react.js.map +1 -0
  62. package/dist/internal/{webpack/shared-modules.cjs → config/webpack/apply-shared-modules.cjs} +12 -15
  63. package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -0
  64. package/dist/internal/{webpack/shared-modules.js → config/webpack/apply-shared-modules.js} +9 -12
  65. package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -0
  66. package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.cjs +1 -1
  67. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -0
  68. package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.js +1 -1
  69. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -0
  70. package/dist/internal/{next/host/app-router-client.cjs → host/nextjs/app-client.cjs} +36 -29
  71. package/dist/internal/host/nextjs/app-client.cjs.map +1 -0
  72. package/dist/internal/host/nextjs/app-client.d.ts +25 -0
  73. package/dist/internal/{next/host/app-router-client.js → host/nextjs/app-client.js} +27 -25
  74. package/dist/internal/host/nextjs/app-client.js.map +1 -0
  75. package/dist/internal/{next/host/app-router-compat.cjs → host/nextjs/app-compat.cjs} +5 -22
  76. package/dist/internal/host/nextjs/app-compat.cjs.map +1 -0
  77. package/dist/internal/{next/host/app-router-compat.d.ts → host/nextjs/app-compat.d.ts} +1 -7
  78. package/dist/internal/{next/host/app-router-compat.js → host/nextjs/app-compat.js} +2 -18
  79. package/dist/internal/host/nextjs/app-compat.js.map +1 -0
  80. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -0
  81. package/dist/internal/host/nextjs/dom-flight.d.ts +39 -0
  82. package/dist/internal/host/nextjs/dom-flight.js.map +1 -0
  83. package/dist/internal/host/nextjs/image-impl.cjs +60 -0
  84. package/dist/internal/host/nextjs/image-impl.cjs.map +1 -0
  85. package/dist/internal/host/nextjs/image-impl.d.ts +10 -0
  86. package/dist/internal/host/nextjs/image-impl.js +36 -0
  87. package/dist/internal/host/nextjs/image-impl.js.map +1 -0
  88. package/dist/internal/host/nextjs/image-shared.cjs +43 -0
  89. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -0
  90. package/dist/internal/host/nextjs/image-shared.d.ts +9 -0
  91. package/dist/internal/host/nextjs/image-shared.js +19 -0
  92. package/dist/internal/host/nextjs/image-shared.js.map +1 -0
  93. package/dist/internal/{next/host → host/nextjs}/remote-component-links.cjs +2 -2
  94. package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -0
  95. package/dist/internal/{next/host → host/nextjs}/remote-component-links.d.ts +1 -1
  96. package/dist/internal/{next/host → host/nextjs}/remote-component-links.js +2 -2
  97. package/dist/internal/host/nextjs/remote-component-links.js.map +1 -0
  98. package/dist/internal/host/nextjs/skeleton.cjs.map +1 -0
  99. package/dist/internal/host/nextjs/skeleton.js.map +1 -0
  100. package/dist/internal/{react → host/react}/context.cjs +3 -3
  101. package/dist/internal/host/react/context.cjs.map +1 -0
  102. package/dist/internal/{react → host/react}/context.d.ts +4 -4
  103. package/dist/internal/{react → host/react}/context.js +2 -2
  104. package/dist/internal/host/react/context.js.map +1 -0
  105. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.cjs +2 -2
  106. package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -0
  107. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.d.ts +1 -1
  108. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.js +2 -2
  109. package/dist/internal/host/react/hooks/use-resolve-client-url.js.map +1 -0
  110. package/dist/internal/host/server/fetch-headers.cjs.map +1 -0
  111. package/dist/internal/host/server/fetch-headers.js.map +1 -0
  112. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.cjs +6 -6
  113. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -0
  114. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.d.ts +6 -1
  115. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.js +9 -9
  116. package/dist/internal/host/server/fetch-remote-component.js.map +1 -0
  117. package/dist/internal/{shared/ssr → host/server}/fetch-with-hooks.cjs +11 -15
  118. package/dist/internal/host/server/fetch-with-hooks.cjs.map +1 -0
  119. package/dist/internal/host/server/fetch-with-hooks.d.ts +21 -0
  120. package/dist/internal/{shared/ssr → host/server}/fetch-with-hooks.js +11 -15
  121. package/dist/internal/host/server/fetch-with-hooks.js.map +1 -0
  122. package/dist/internal/host/server/get-client-or-server-url.cjs.map +1 -0
  123. package/dist/internal/host/server/get-client-or-server-url.js.map +1 -0
  124. package/dist/internal/{shared/client → host/server}/get-client-src.cjs +1 -1
  125. package/dist/internal/host/server/get-client-src.cjs.map +1 -0
  126. package/dist/internal/{shared/client → host/server}/get-client-src.js +1 -1
  127. package/dist/internal/host/server/get-client-src.js.map +1 -0
  128. package/dist/internal/host/server/get-ssr-relative-path-base-url.cjs.map +1 -0
  129. package/dist/internal/host/server/get-ssr-relative-path-base-url.js.map +1 -0
  130. package/dist/internal/host/server/types.cjs +17 -0
  131. package/dist/internal/host/server/types.cjs.map +1 -0
  132. package/dist/internal/host/server/types.d.ts +33 -0
  133. package/dist/internal/host/server/types.js +1 -0
  134. package/dist/internal/host/server/types.js.map +1 -0
  135. package/dist/internal/host/shared/asset-descriptors.cjs +17 -0
  136. package/dist/internal/host/shared/asset-descriptors.cjs.map +1 -0
  137. package/dist/internal/host/shared/asset-descriptors.d.ts +21 -0
  138. package/dist/internal/host/shared/asset-descriptors.js +1 -0
  139. package/dist/internal/host/shared/asset-descriptors.js.map +1 -0
  140. package/dist/internal/host/shared/config.cjs +17 -0
  141. package/dist/internal/host/shared/config.cjs.map +1 -0
  142. package/dist/internal/host/shared/config.d.ts +100 -0
  143. package/dist/internal/host/shared/config.js +1 -0
  144. package/dist/internal/host/shared/config.js.map +1 -0
  145. package/dist/internal/host/shared/fetch-interceptors.cjs +17 -0
  146. package/dist/internal/host/shared/fetch-interceptors.cjs.map +1 -0
  147. package/dist/{types-cbe44b51.d.ts → internal/host/shared/fetch-interceptors.d.ts} +7 -73
  148. package/dist/internal/host/shared/fetch-interceptors.js +1 -0
  149. package/dist/internal/host/shared/fetch-interceptors.js.map +1 -0
  150. package/dist/internal/{shared/client → host/shared}/polyfill.cjs +7 -6
  151. package/dist/internal/host/shared/polyfill.cjs.map +1 -0
  152. package/dist/internal/{shared/client → host/shared}/polyfill.d.ts +2 -1
  153. package/dist/internal/{shared/client → host/shared}/polyfill.js +7 -6
  154. package/dist/internal/host/shared/polyfill.js.map +1 -0
  155. package/dist/internal/host/shared/resolved-data.cjs +17 -0
  156. package/dist/internal/host/shared/resolved-data.cjs.map +1 -0
  157. package/dist/internal/host/shared/resolved-data.d.ts +48 -0
  158. package/dist/internal/host/shared/resolved-data.js +1 -0
  159. package/dist/internal/host/shared/resolved-data.js.map +1 -0
  160. package/dist/{next/remote/server.cjs → internal/host/shared/state.cjs} +16 -7
  161. package/dist/internal/host/shared/state.cjs.map +1 -0
  162. package/dist/internal/host/shared/state.d.ts +53 -0
  163. package/dist/internal/host/shared/state.js +14 -0
  164. package/dist/internal/host/shared/state.js.map +1 -0
  165. package/dist/internal/host/utils/resolve-name-from-src.cjs +40 -0
  166. package/dist/internal/host/utils/resolve-name-from-src.cjs.map +1 -0
  167. package/dist/internal/host/utils/resolve-name-from-src.d.ts +13 -0
  168. package/dist/internal/host/utils/resolve-name-from-src.js +16 -0
  169. package/dist/internal/host/utils/resolve-name-from-src.js.map +1 -0
  170. package/dist/internal/{next/remote/render-client.cjs → remote/nextjs/app-client.cjs} +8 -8
  171. package/dist/internal/remote/nextjs/app-client.cjs.map +1 -0
  172. package/dist/internal/{next/remote/render-client.js → remote/nextjs/app-client.js} +4 -4
  173. package/dist/internal/remote/nextjs/app-client.js.map +1 -0
  174. package/dist/internal/runtime/constants.cjs +50 -0
  175. package/dist/internal/runtime/constants.cjs.map +1 -0
  176. package/dist/internal/runtime/constants.d.ts +10 -0
  177. package/dist/internal/runtime/constants.js +20 -0
  178. package/dist/internal/runtime/constants.js.map +1 -0
  179. package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs.map +1 -1
  180. package/dist/internal/{shared/client → runtime/html}/apply-origin.d.ts +1 -1
  181. package/dist/internal/{shared/client → runtime/html}/apply-origin.js.map +1 -1
  182. package/dist/internal/runtime/html/parse-remote-html.cjs +140 -0
  183. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -0
  184. package/dist/internal/runtime/html/parse-remote-html.d.ts +88 -0
  185. package/dist/internal/runtime/html/parse-remote-html.js +110 -0
  186. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -0
  187. package/dist/internal/runtime/html/set-attributes-from-props.cjs +68 -0
  188. package/dist/internal/runtime/html/set-attributes-from-props.cjs.map +1 -0
  189. package/dist/internal/runtime/html/set-attributes-from-props.d.ts +3 -0
  190. package/dist/internal/runtime/html/set-attributes-from-props.js +44 -0
  191. package/dist/internal/runtime/html/set-attributes-from-props.js.map +1 -0
  192. package/dist/internal/runtime/loaders/component-loader.cjs +184 -0
  193. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -0
  194. package/dist/internal/runtime/loaders/component-loader.d.ts +31 -0
  195. package/dist/internal/runtime/loaders/component-loader.js +150 -0
  196. package/dist/internal/runtime/loaders/component-loader.js.map +1 -0
  197. package/dist/internal/runtime/loaders/script-loader.cjs +69 -0
  198. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -0
  199. package/dist/internal/runtime/loaders/script-loader.d.ts +10 -0
  200. package/dist/internal/runtime/loaders/script-loader.js +48 -0
  201. package/dist/internal/runtime/loaders/script-loader.js.map +1 -0
  202. package/dist/internal/runtime/loaders/static-loader.cjs +177 -0
  203. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -0
  204. package/dist/internal/runtime/loaders/static-loader.d.ts +10 -0
  205. package/dist/internal/runtime/loaders/static-loader.js +153 -0
  206. package/dist/internal/runtime/loaders/static-loader.js.map +1 -0
  207. package/dist/internal/runtime/metadata.cjs +17 -0
  208. package/dist/internal/runtime/metadata.cjs.map +1 -0
  209. package/dist/internal/runtime/metadata.d.ts +16 -0
  210. package/dist/internal/runtime/metadata.js +1 -0
  211. package/dist/internal/runtime/metadata.js.map +1 -0
  212. package/dist/internal/runtime/rsc.cjs +92 -0
  213. package/dist/internal/runtime/rsc.cjs.map +1 -0
  214. package/dist/internal/runtime/rsc.d.ts +8 -0
  215. package/dist/internal/runtime/rsc.js +68 -0
  216. package/dist/internal/runtime/rsc.js.map +1 -0
  217. package/dist/internal/runtime/turbopack/chunk-loader.cjs +244 -0
  218. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -0
  219. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +11 -0
  220. package/dist/internal/runtime/turbopack/chunk-loader.js +227 -0
  221. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -0
  222. package/dist/internal/runtime/turbopack/module.cjs +257 -0
  223. package/dist/internal/runtime/turbopack/module.cjs.map +1 -0
  224. package/dist/internal/runtime/turbopack/module.d.ts +61 -0
  225. package/dist/internal/runtime/turbopack/module.js +233 -0
  226. package/dist/internal/runtime/turbopack/module.js.map +1 -0
  227. package/dist/internal/runtime/turbopack/patterns.cjs +44 -0
  228. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -0
  229. package/dist/internal/runtime/turbopack/patterns.d.ts +109 -0
  230. package/dist/internal/runtime/turbopack/patterns.js +15 -0
  231. package/dist/internal/runtime/turbopack/patterns.js.map +1 -0
  232. package/dist/internal/runtime/turbopack/shared-modules.cjs +152 -0
  233. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -0
  234. package/dist/internal/runtime/turbopack/shared-modules.d.ts +17 -0
  235. package/dist/internal/runtime/turbopack/shared-modules.js +133 -0
  236. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -0
  237. package/dist/internal/runtime/turbopack/webpack-runtime.cjs +137 -0
  238. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -0
  239. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +20 -0
  240. package/dist/internal/runtime/turbopack/webpack-runtime.js +107 -0
  241. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -0
  242. package/dist/internal/runtime/types.cjs +17 -0
  243. package/dist/internal/runtime/types.cjs.map +1 -0
  244. package/dist/internal/runtime/types.d.ts +40 -0
  245. package/dist/internal/runtime/types.js +1 -0
  246. package/dist/internal/runtime/types.js.map +1 -0
  247. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.cjs +2 -2
  248. package/dist/internal/runtime/url/default-resolve-client-url.cjs.map +1 -0
  249. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.d.ts +1 -1
  250. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.js +1 -1
  251. package/dist/internal/runtime/url/default-resolve-client-url.js.map +1 -0
  252. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.cjs +1 -1
  253. package/dist/internal/runtime/url/protected-rc-fallback.cjs.map +1 -0
  254. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.js +1 -1
  255. package/dist/internal/runtime/url/protected-rc-fallback.js.map +1 -0
  256. package/dist/internal/runtime/url/resolve-client-url.cjs +45 -0
  257. package/dist/internal/runtime/url/resolve-client-url.cjs.map +1 -0
  258. package/dist/internal/{shared/client/proxy-through-host.d.ts → runtime/url/resolve-client-url.d.ts} +6 -25
  259. package/dist/internal/runtime/url/resolve-client-url.js +21 -0
  260. package/dist/internal/runtime/url/resolve-client-url.js.map +1 -0
  261. package/dist/internal/utils/abort.cjs.map +1 -0
  262. package/dist/internal/utils/abort.js.map +1 -0
  263. package/dist/internal/{shared → utils}/constants.cjs +3 -0
  264. package/dist/internal/utils/constants.cjs.map +1 -0
  265. package/dist/internal/utils/constants.d.ts +5 -0
  266. package/dist/internal/{shared → utils}/constants.js +2 -0
  267. package/dist/internal/utils/constants.js.map +1 -0
  268. package/dist/internal/{shared → utils}/error.cjs +4 -4
  269. package/dist/internal/utils/error.cjs.map +1 -0
  270. package/dist/internal/{shared → utils}/error.js +4 -4
  271. package/dist/internal/utils/error.js.map +1 -0
  272. package/dist/internal/{shared/utils → utils}/logger.cjs +3 -3
  273. package/dist/internal/utils/logger.cjs.map +1 -0
  274. package/dist/internal/{shared/utils → utils}/logger.d.ts +2 -2
  275. package/dist/internal/{shared/utils → utils}/logger.js +3 -3
  276. package/dist/internal/utils/logger.js.map +1 -0
  277. package/dist/internal/utils.cjs.map +1 -0
  278. package/dist/internal/utils.js.map +1 -0
  279. package/dist/{shared/host → remote/defaults}/app.cjs +2 -6
  280. package/dist/remote/defaults/app.cjs.map +1 -0
  281. package/dist/remote/defaults/app.js +8 -0
  282. package/dist/remote/defaults/app.js.map +1 -0
  283. package/dist/{shared/host → remote/defaults}/pages.cjs +2 -6
  284. package/dist/remote/defaults/pages.cjs.map +1 -0
  285. package/dist/remote/defaults/pages.js +8 -0
  286. package/dist/remote/defaults/pages.js.map +1 -0
  287. package/dist/{shared/remote → remote/defaults}/wrapper.cjs +12 -10
  288. package/dist/remote/defaults/wrapper.cjs.map +1 -0
  289. package/dist/remote/defaults/wrapper.js +27 -0
  290. package/dist/remote/defaults/wrapper.js.map +1 -0
  291. package/dist/{html/remote.cjs → remote/html.cjs} +16 -16
  292. package/dist/remote/html.cjs.map +1 -0
  293. package/dist/{html/remote.js → remote/html.js} +16 -16
  294. package/dist/remote/html.js.map +1 -0
  295. package/dist/{shared/remote/proxy.cjs → remote/middleware.cjs} +37 -12
  296. package/dist/remote/middleware.cjs.map +1 -0
  297. package/dist/remote/middleware.d.ts +27 -0
  298. package/dist/{shared/remote/proxy.js → remote/middleware.js} +32 -5
  299. package/dist/remote/middleware.js.map +1 -0
  300. package/dist/{internal/next/remote/render-server.cjs → remote/nextjs/app.cjs} +14 -16
  301. package/dist/remote/nextjs/app.cjs.map +1 -0
  302. package/dist/remote/nextjs/app.d.ts +45 -0
  303. package/dist/{internal/next/remote/render-server.js → remote/nextjs/app.js} +9 -11
  304. package/dist/remote/nextjs/app.js.map +1 -0
  305. package/dist/{next/remote/pages-router.cjs → remote/nextjs/pages.cjs} +8 -8
  306. package/dist/remote/nextjs/pages.cjs.map +1 -0
  307. package/dist/{next/remote/pages-router.d.ts → remote/nextjs/pages.d.ts} +8 -8
  308. package/dist/{next/remote/pages-router.js → remote/nextjs/pages.js} +4 -4
  309. package/dist/remote/nextjs/pages.js.map +1 -0
  310. package/dist/server-handoff-8c89b856.d.ts +46 -0
  311. package/package.json +126 -157
  312. package/dist/component-loader-76eb1b8b.d.ts +0 -200
  313. package/dist/html/host.cjs.map +0 -1
  314. package/dist/html/host.js.map +0 -1
  315. package/dist/html/remote.cjs.map +0 -1
  316. package/dist/html/remote.js.map +0 -1
  317. package/dist/internal/next/host/app-router-client.cjs.map +0 -1
  318. package/dist/internal/next/host/app-router-client.d.ts +0 -66
  319. package/dist/internal/next/host/app-router-client.js.map +0 -1
  320. package/dist/internal/next/host/app-router-compat.cjs.map +0 -1
  321. package/dist/internal/next/host/app-router-compat.js.map +0 -1
  322. package/dist/internal/next/host/remote-component-links.cjs.map +0 -1
  323. package/dist/internal/next/host/remote-component-links.js.map +0 -1
  324. package/dist/internal/next/remote/render-client.cjs.map +0 -1
  325. package/dist/internal/next/remote/render-client.js.map +0 -1
  326. package/dist/internal/next/remote/render-server.cjs.map +0 -1
  327. package/dist/internal/next/remote/render-server.d.ts +0 -47
  328. package/dist/internal/next/remote/render-server.js.map +0 -1
  329. package/dist/internal/react/context.cjs.map +0 -1
  330. package/dist/internal/react/context.js.map +0 -1
  331. package/dist/internal/react/hooks/use-resolve-client-url.cjs.map +0 -1
  332. package/dist/internal/react/hooks/use-resolve-client-url.js.map +0 -1
  333. package/dist/internal/shared/client/default-resolve-client-url.cjs.map +0 -1
  334. package/dist/internal/shared/client/default-resolve-client-url.js.map +0 -1
  335. package/dist/internal/shared/client/get-client-src.cjs.map +0 -1
  336. package/dist/internal/shared/client/get-client-src.js.map +0 -1
  337. package/dist/internal/shared/client/polyfill.cjs.map +0 -1
  338. package/dist/internal/shared/client/polyfill.js.map +0 -1
  339. package/dist/internal/shared/client/protected-rc-fallback.cjs.map +0 -1
  340. package/dist/internal/shared/client/protected-rc-fallback.js.map +0 -1
  341. package/dist/internal/shared/client/proxy-through-host.cjs.map +0 -1
  342. package/dist/internal/shared/client/proxy-through-host.js +0 -26
  343. package/dist/internal/shared/client/proxy-through-host.js.map +0 -1
  344. package/dist/internal/shared/client/remote-component.cjs +0 -1436
  345. package/dist/internal/shared/client/remote-component.cjs.map +0 -1
  346. package/dist/internal/shared/client/remote-component.d.ts +0 -62
  347. package/dist/internal/shared/client/remote-component.js +0 -1385
  348. package/dist/internal/shared/client/remote-component.js.map +0 -1
  349. package/dist/internal/shared/constants.cjs.map +0 -1
  350. package/dist/internal/shared/constants.d.ts +0 -4
  351. package/dist/internal/shared/constants.js.map +0 -1
  352. package/dist/internal/shared/error.cjs.map +0 -1
  353. package/dist/internal/shared/error.js.map +0 -1
  354. package/dist/internal/shared/ssr/dom-flight.cjs.map +0 -1
  355. package/dist/internal/shared/ssr/dom-flight.d.ts +0 -2
  356. package/dist/internal/shared/ssr/dom-flight.js.map +0 -1
  357. package/dist/internal/shared/ssr/fetch-headers.cjs.map +0 -1
  358. package/dist/internal/shared/ssr/fetch-headers.js.map +0 -1
  359. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +0 -1
  360. package/dist/internal/shared/ssr/fetch-remote-component.js.map +0 -1
  361. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +0 -1
  362. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +0 -56
  363. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +0 -1
  364. package/dist/internal/shared/ssr/get-client-or-server-url.cjs.map +0 -1
  365. package/dist/internal/shared/ssr/get-client-or-server-url.js.map +0 -1
  366. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs.map +0 -1
  367. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js.map +0 -1
  368. package/dist/internal/shared/ssr/skeleton.cjs.map +0 -1
  369. package/dist/internal/shared/ssr/skeleton.js.map +0 -1
  370. package/dist/internal/shared/utils/abort.cjs.map +0 -1
  371. package/dist/internal/shared/utils/abort.js.map +0 -1
  372. package/dist/internal/shared/utils/logger.cjs.map +0 -1
  373. package/dist/internal/shared/utils/logger.js.map +0 -1
  374. package/dist/internal/shared/utils.cjs.map +0 -1
  375. package/dist/internal/shared/utils.js.map +0 -1
  376. package/dist/internal/webpack/next-client-pages-loader.cjs.map +0 -1
  377. package/dist/internal/webpack/next-client-pages-loader.js.map +0 -1
  378. package/dist/internal/webpack/shared-modules.cjs.map +0 -1
  379. package/dist/internal/webpack/shared-modules.js.map +0 -1
  380. package/dist/next/config.cjs.map +0 -1
  381. package/dist/next/config.js.map +0 -1
  382. package/dist/next/host/app-router-server.cjs.map +0 -1
  383. package/dist/next/host/app-router-server.d.ts +0 -60
  384. package/dist/next/host/app-router-server.js.map +0 -1
  385. package/dist/next/host/client/index.cjs.map +0 -1
  386. package/dist/next/host/client/index.d.ts +0 -19
  387. package/dist/next/host/client/index.js.map +0 -1
  388. package/dist/next/host/pages-router-client.cjs.map +0 -1
  389. package/dist/next/host/pages-router-client.d.ts +0 -56
  390. package/dist/next/host/pages-router-client.js.map +0 -1
  391. package/dist/next/host/pages-router-server.cjs.map +0 -1
  392. package/dist/next/host/pages-router-server.d.ts +0 -104
  393. package/dist/next/host/pages-router-server.js.map +0 -1
  394. package/dist/next/index.cjs +0 -53
  395. package/dist/next/index.cjs.map +0 -1
  396. package/dist/next/index.d.ts +0 -56
  397. package/dist/next/index.js +0 -19
  398. package/dist/next/index.js.map +0 -1
  399. package/dist/next/proxy.cjs.map +0 -1
  400. package/dist/next/proxy.d.ts +0 -56
  401. package/dist/next/proxy.js.map +0 -1
  402. package/dist/next/remote/pages-router.cjs.map +0 -1
  403. package/dist/next/remote/pages-router.js.map +0 -1
  404. package/dist/next/remote/server.cjs.map +0 -1
  405. package/dist/next/remote/server.d.ts +0 -1
  406. package/dist/next/remote/server.js +0 -5
  407. package/dist/next/remote/server.js.map +0 -1
  408. package/dist/proxy-through-host-a676a522.d.ts +0 -52
  409. package/dist/react/index.cjs.map +0 -1
  410. package/dist/react/index.d.ts +0 -123
  411. package/dist/react/index.js.map +0 -1
  412. package/dist/shared/host/app.cjs.map +0 -1
  413. package/dist/shared/host/app.js +0 -12
  414. package/dist/shared/host/app.js.map +0 -1
  415. package/dist/shared/host/pages.cjs.map +0 -1
  416. package/dist/shared/host/pages.js +0 -12
  417. package/dist/shared/host/pages.js.map +0 -1
  418. package/dist/shared/host/proxy.cjs.map +0 -1
  419. package/dist/shared/host/proxy.js.map +0 -1
  420. package/dist/shared/remote/app.cjs.map +0 -1
  421. package/dist/shared/remote/app.js +0 -8
  422. package/dist/shared/remote/app.js.map +0 -1
  423. package/dist/shared/remote/pages.cjs.map +0 -1
  424. package/dist/shared/remote/pages.js +0 -8
  425. package/dist/shared/remote/pages.js.map +0 -1
  426. package/dist/shared/remote/proxy.cjs.map +0 -1
  427. package/dist/shared/remote/proxy.d.ts +0 -44
  428. package/dist/shared/remote/proxy.js.map +0 -1
  429. package/dist/shared/remote/wrapper.cjs.map +0 -1
  430. package/dist/shared/remote/wrapper.js +0 -25
  431. package/dist/shared/remote/wrapper.js.map +0 -1
  432. package/dist/webpack.cjs.map +0 -1
  433. package/dist/webpack.js.map +0 -1
  434. /package/dist/{webpack.d.ts → config/webpack.d.ts} +0 -0
  435. /package/dist/{shared/host → host/defaults}/app.d.ts +0 -0
  436. /package/dist/{shared/host → host/defaults}/pages.d.ts +0 -0
  437. /package/dist/{shared/host/proxy.d.ts → host/proxy/protected-fetch.d.ts} +0 -0
  438. /package/dist/internal/{webpack/shared-modules.d.ts → config/webpack/apply-shared-modules.d.ts} +0 -0
  439. /package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.d.ts +0 -0
  440. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.cjs +0 -0
  441. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.js +0 -0
  442. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.cjs +0 -0
  443. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.d.ts +0 -0
  444. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.js +0 -0
  445. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.cjs +0 -0
  446. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.d.ts +0 -0
  447. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.js +0 -0
  448. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.cjs +0 -0
  449. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.d.ts +0 -0
  450. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.js +0 -0
  451. /package/dist/internal/{shared/client → host/server}/get-client-src.d.ts +0 -0
  452. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.cjs +0 -0
  453. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.d.ts +0 -0
  454. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.js +0 -0
  455. /package/dist/internal/{next/remote/render-client.d.ts → remote/nextjs/app-client.d.ts} +0 -0
  456. /package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs +0 -0
  457. /package/dist/internal/{shared/client → runtime/html}/apply-origin.js +0 -0
  458. /package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.d.ts +0 -0
  459. /package/dist/internal/{shared/utils → utils}/abort.cjs +0 -0
  460. /package/dist/internal/{shared/utils → utils}/abort.d.ts +0 -0
  461. /package/dist/internal/{shared/utils → utils}/abort.js +0 -0
  462. /package/dist/internal/{shared → utils}/error.d.ts +0 -0
  463. /package/dist/internal/{shared/utils.cjs → utils.cjs} +0 -0
  464. /package/dist/internal/{shared/utils.d.ts → utils.d.ts} +0 -0
  465. /package/dist/internal/{shared/utils.js → utils.js} +0 -0
  466. /package/dist/{shared/remote → remote/defaults}/app.d.ts +0 -0
  467. /package/dist/{shared/remote → remote/defaults}/pages.d.ts +0 -0
  468. /package/dist/{shared/remote → remote/defaults}/wrapper.d.ts +0 -0
  469. /package/dist/{html/remote.d.ts → remote/html.d.ts} +0 -0
@@ -8,20 +8,17 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
 
11
- // src/shared/constants.ts
11
+ // src/utils/constants.ts
12
12
  var RC_PROTECTED_REMOTE_FETCH_PATHNAME, CORS_DOCS_URL;
13
13
  var init_constants = __esm({
14
- "src/shared/constants.ts"() {
14
+ "src/utils/constants.ts"() {
15
15
  "use strict";
16
16
  RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
17
17
  CORS_DOCS_URL = "https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components";
18
18
  }
19
19
  });
20
20
 
21
- // src/shared/client/protected-rc-fallback.ts
22
- function generateProtectedRcFallbackSrc(url) {
23
- return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
24
- }
21
+ // src/runtime/url/protected-rc-fallback.ts
25
22
  function isProxiedUrl(url) {
26
23
  try {
27
24
  return new URL(url, location.href).pathname === RC_PROTECTED_REMOTE_FETCH_PATHNAME;
@@ -30,13 +27,13 @@ function isProxiedUrl(url) {
30
27
  }
31
28
  }
32
29
  var init_protected_rc_fallback = __esm({
33
- "src/shared/client/protected-rc-fallback.ts"() {
30
+ "src/runtime/url/protected-rc-fallback.ts"() {
34
31
  "use strict";
35
32
  init_constants();
36
33
  }
37
34
  });
38
35
 
39
- // src/shared/utils/abort.ts
36
+ // src/utils/abort.ts
40
37
  function isAbortError(error) {
41
38
  if (error instanceof DOMException && error.name === "AbortError") {
42
39
  return true;
@@ -48,12 +45,12 @@ function isAbortError(error) {
48
45
  return false;
49
46
  }
50
47
  var init_abort = __esm({
51
- "src/shared/utils/abort.ts"() {
48
+ "src/utils/abort.ts"() {
52
49
  "use strict";
53
50
  }
54
51
  });
55
52
 
56
- // src/shared/error.ts
53
+ // src/utils/error.ts
57
54
  function multipleRemoteComponentsError(url) {
58
55
  return new RemoteComponentsError(
59
56
  `Multiple Remote Components found at "${url}". When a page exposes multiple Remote Components you must specify the "name" prop to select which one to load.`
@@ -112,7 +109,7 @@ function failedProxyFetchError(originalUrl, proxyUrl, status, responseBody) {
112
109
  The host server needs middleware or a route that handles "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}".
113
110
 
114
111
  Proxying requires two pieces:
115
- 1. resolveClientUrl={proxyClientRequestsThroughHost} on <RemoteComponent>
112
+ 1. resolveClientUrl={routeThroughHostProxy} on <RemoteComponent>
116
113
  2. Middleware or a route for "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" on the host server
117
114
 
118
115
  Docs: ${CORS_DOCS_URL}`
@@ -130,11 +127,11 @@ Docs: ${CORS_DOCS_URL}`
130
127
  }
131
128
  var RemoteComponentsError;
132
129
  var init_error = __esm({
133
- "src/shared/error.ts"() {
130
+ "src/utils/error.ts"() {
134
131
  "use strict";
135
132
  init_protected_rc_fallback();
136
- init_constants();
137
133
  init_abort();
134
+ init_constants();
138
135
  RemoteComponentsError = class extends Error {
139
136
  code = "REMOTE_COMPONENTS_ERROR";
140
137
  constructor(message, options) {
@@ -145,7 +142,7 @@ var init_error = __esm({
145
142
  }
146
143
  });
147
144
 
148
- // src/shared/utils/logger.ts
145
+ // src/utils/logger.ts
149
146
  function logDebug(location2, message) {
150
147
  if (DEBUG) {
151
148
  console.debug(`[${PREFIX}:${location2}]: ${message}`);
@@ -169,14 +166,14 @@ function warnCrossOriginFetchError(logLocation, url) {
169
166
  }
170
167
  logWarn(
171
168
  logLocation,
172
- `Failed to fetch cross-origin resource "${parsed.href}". If this is a protected deployment, ensure withRemoteComponentsHost middleware is configured in your host and that the remote URL is included in allowedProxyUrls. See: ${CORS_DOCS_URL}`
169
+ `Failed to fetch cross-origin resource "${parsed.href}". If this is a protected deployment, ensure withRemoteComponentsHostProxy middleware is configured in your host and that the remote URL is included in allowedProxyUrls. See: ${CORS_DOCS_URL}`
173
170
  );
174
171
  } catch {
175
172
  }
176
173
  }
177
174
  var PREFIX, DEBUG;
178
175
  var init_logger = __esm({
179
- "src/shared/utils/logger.ts"() {
176
+ "src/utils/logger.ts"() {
180
177
  "use strict";
181
178
  init_constants();
182
179
  init_error();
@@ -185,7 +182,99 @@ var init_logger = __esm({
185
182
  }
186
183
  });
187
184
 
188
- // src/shared/webpack/next-client-pages-loader.ts
185
+ // src/utils/index.ts
186
+ function escapeString(str) {
187
+ return str.replace(/[^a-z0-9]/g, "_");
188
+ }
189
+ var init_utils = __esm({
190
+ "src/utils/index.ts"() {
191
+ "use strict";
192
+ }
193
+ });
194
+
195
+ // src/runtime/constants.ts
196
+ function getBundleKey(bundle) {
197
+ return escapeString(bundle);
198
+ }
199
+ var DEFAULT_ROUTE, RUNTIME_WEBPACK, RUNTIME_TURBOPACK, RUNTIME_SCRIPT, REMOTE_COMPONENT_REGEX, NEXT_BUNDLE_PATH_RE;
200
+ var init_constants2 = __esm({
201
+ "src/runtime/constants.ts"() {
202
+ "use strict";
203
+ init_utils();
204
+ DEFAULT_ROUTE = "/";
205
+ RUNTIME_WEBPACK = "webpack";
206
+ RUNTIME_TURBOPACK = "turbopack";
207
+ RUNTIME_SCRIPT = "script";
208
+ REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
209
+ NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
210
+ }
211
+ });
212
+
213
+ // src/config/webpack/apply-shared-modules.ts
214
+ function applySharedModules(bundle, resolve) {
215
+ logDebug(
216
+ "SharedModules",
217
+ `applySharedModules called for bundle: "${bundle}"`
218
+ );
219
+ logDebug(
220
+ "SharedModules",
221
+ `Shared modules to resolve: ${Object.keys(resolve)}`
222
+ );
223
+ const self = globalThis;
224
+ if (self.__remote_webpack_require__?.[bundle]) {
225
+ const modulePaths = Object.keys(
226
+ self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
227
+ );
228
+ logDebug(
229
+ "SharedModules",
230
+ `Available module paths in __remote_webpack_require__[${bundle}]: ${modulePaths}`
231
+ );
232
+ for (const [key, value] of Object.entries(resolve)) {
233
+ const exactIds = modulePaths.filter((p) => p === key);
234
+ const ids = exactIds.length > 0 ? exactIds : modulePaths.filter((p) => p.includes(key));
235
+ if (ids.length === 0) {
236
+ logDebug(
237
+ "SharedModules",
238
+ `No matching module path found for shared module "${key}"`
239
+ );
240
+ }
241
+ for (const id of ids) {
242
+ const webpackBundle = self.__remote_webpack_require__[bundle];
243
+ if (webpackBundle.m) {
244
+ const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id] ? `${self.__remote_webpack_module_map__[bundle][id]}` : id;
245
+ if (resolvedId !== id) {
246
+ logDebug(
247
+ "SharedModules",
248
+ `Mapped module id: "${id}" -> "${resolvedId}"`
249
+ );
250
+ }
251
+ webpackBundle.m[resolvedId] = (module) => {
252
+ module.exports = value;
253
+ };
254
+ } else {
255
+ logWarn(
256
+ "SharedModules",
257
+ `webpackBundle.m is not available for bundle "${bundle}"`
258
+ );
259
+ }
260
+ }
261
+ }
262
+ } else {
263
+ logWarn("SharedModules", `No webpack require found for bundle "${bundle}"`);
264
+ logDebug(
265
+ "SharedModules",
266
+ `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
267
+ );
268
+ }
269
+ }
270
+ var init_apply_shared_modules = __esm({
271
+ "src/config/webpack/apply-shared-modules.ts"() {
272
+ "use strict";
273
+ init_logger();
274
+ }
275
+ });
276
+
277
+ // src/config/webpack/next-client-pages-loader.ts
189
278
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
190
279
  const self = globalThis;
191
280
  const nextCssOriginal = document.querySelector(
@@ -297,213 +386,416 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
297
386
  return { Component: null, App: null };
298
387
  }
299
388
  var init_next_client_pages_loader = __esm({
300
- "src/shared/webpack/next-client-pages-loader.ts"() {
389
+ "src/config/webpack/next-client-pages-loader.ts"() {
301
390
  "use strict";
302
391
  init_error();
303
392
  }
304
393
  });
305
394
 
306
- // src/shared/webpack/shared-modules.ts
307
- function applySharedModules(bundle, resolve) {
308
- logDebug(
309
- "SharedModules",
310
- `applySharedModules called for bundle: "${bundle}"`
311
- );
312
- logDebug(
313
- "SharedModules",
314
- `Shared modules to resolve: ${Object.keys(resolve)}`
315
- );
395
+ // src/host/shared/polyfill.tsx
396
+ import { jsx } from "react/jsx-runtime";
397
+ function applyBundleUrlToSrc(bundle, src) {
316
398
  const self = globalThis;
317
- if (self.__remote_webpack_require__?.[bundle]) {
318
- const modulePaths = Object.keys(
319
- self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
320
- );
321
- logDebug(
322
- "SharedModules",
323
- `Available module paths in __remote_webpack_require__[${bundle}]: ${modulePaths}`
324
- );
325
- for (const [key, value] of Object.entries(resolve)) {
326
- let ids = modulePaths.filter((p) => p === key);
327
- if (ids.length === 0) {
328
- ids = modulePaths.filter((p) => p.includes(key));
329
- }
330
- if (ids.length === 0) {
331
- logDebug(
332
- "SharedModules",
333
- `No matching module path found for shared module "${key}"`
334
- );
335
- }
336
- for (let id of ids) {
337
- const webpackBundle = self.__remote_webpack_require__[bundle];
338
- if (webpackBundle.m) {
339
- if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
340
- const mappedId = `${self.__remote_webpack_module_map__[bundle][id]}`;
341
- logDebug(
342
- "SharedModules",
343
- `Mapped module id: "${id}" -> "${mappedId}"`
344
- );
345
- id = mappedId;
346
- }
347
- webpackBundle.m[id] = (module) => {
348
- module.exports = value;
349
- };
350
- } else {
351
- logWarn(
352
- "SharedModules",
353
- `webpackBundle.m is not available for bundle "${bundle}"`
354
- );
355
- }
356
- }
357
- }
358
- } else {
359
- logWarn("SharedModules", `No webpack require found for bundle "${bundle}"`);
360
- logDebug(
361
- "SharedModules",
362
- `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
363
- );
364
- }
365
- }
366
- var init_shared_modules = __esm({
367
- "src/shared/webpack/shared-modules.ts"() {
368
- "use strict";
369
- init_logger();
370
- }
371
- });
372
-
373
- // src/shared/client/webpack-patterns.ts
374
- var NEXT_BUNDLE_PATH_RE;
375
- var init_webpack_patterns = __esm({
376
- "src/shared/client/webpack-patterns.ts"() {
377
- "use strict";
378
- NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
399
+ if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
400
+ return src;
379
401
  }
380
- });
381
-
382
- // src/shared/client/script-loader.ts
383
- async function loadScripts(scripts, resolveClientUrl) {
384
- await Promise.all(
385
- scripts.map((script) => {
386
- return new Promise((resolve, reject) => {
387
- const newSrc = new URL(
388
- // remove the remote component bundle name identifier from the script src
389
- script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
390
- location.origin
391
- ).href;
392
- const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
393
- const newScript = document.createElement("script");
394
- newScript.onload = () => resolve();
395
- newScript.onerror = () => {
396
- const isProxied = isProxiedUrl(resolvedSrc);
397
- if (isProxied) {
398
- reject(
399
- new RemoteComponentsError(
400
- `Failed to load script "${newSrc}" via proxy "${resolvedSrc}". Ensure withRemoteComponentsHost middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
401
- )
402
- );
403
- } else {
404
- warnCrossOriginFetchError("ScriptLoader", newSrc);
405
- reject(
406
- new RemoteComponentsError(
407
- `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
408
- )
409
- );
410
- }
411
- };
412
- newScript.src = resolvedSrc;
413
- newScript.async = true;
414
- document.head.appendChild(newScript);
415
- });
416
- })
417
- );
418
- }
419
- var init_script_loader = __esm({
420
- "src/shared/client/script-loader.ts"() {
421
- "use strict";
422
- init_constants();
423
- init_error();
424
- init_logger();
425
- init_protected_rc_fallback();
426
- init_webpack_patterns();
402
+ const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
403
+ if (!path) {
404
+ return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
427
405
  }
428
- });
429
-
430
- // src/shared/utils/index.ts
431
- function escapeString(str) {
432
- return str.replace(/[^a-z0-9]/g, "_");
406
+ return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
433
407
  }
434
- var init_utils = __esm({
435
- "src/shared/utils/index.ts"() {
436
- "use strict";
408
+ function applyBundleUrlToImagePropsSrc(bundle, src) {
409
+ if (typeof src === "string") {
410
+ return applyBundleUrlToSrc(bundle, src);
437
411
  }
438
- });
439
-
440
- // src/shared/client/const.ts
441
- function getBundleKey(bundle) {
442
- return escapeString(bundle);
412
+ const propSrc = src;
413
+ return applyBundleUrlToSrc(bundle, propSrc.src);
443
414
  }
444
- var RUNTIME_WEBPACK, RUNTIME_TURBOPACK, REMOTE_COMPONENT_REGEX;
445
- var init_const = __esm({
446
- "src/shared/client/const.ts"() {
447
- "use strict";
448
- init_utils();
449
- RUNTIME_WEBPACK = "webpack";
450
- RUNTIME_TURBOPACK = "turbopack";
451
- REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
452
- }
453
- });
454
-
455
- // src/shared/client/turbopack-patterns.ts
456
- var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, TURBOPACK_GLOBAL_RE;
457
- var init_turbopack_patterns = __esm({
458
- "src/shared/client/turbopack-patterns.ts"() {
459
- "use strict";
460
- REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
461
- REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
462
- ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
463
- ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
464
- ASYNC_MODULE_ALL_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<vCb>parentImport|t)=>Promise\.all\(\["[^"]+"\]\.map\((?<mapCb>chunk|t)=>\k<ctx>\.l\(\k<mapCb>\)\)\)\.then\(\(\)=>\k<vCb>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
465
- TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
466
- }
467
- });
468
-
469
- // src/shared/client/chunk-loader.ts
470
- function createChunkLoader(runtime, resolveClientUrl) {
471
- return function __turbopack_chunk_load__(chunkId, scriptBundle) {
472
- logDebug("ChunkLoader", `Loading chunk: "${chunkId}"`);
473
- const self = globalThis;
474
- const {
475
- bundle,
476
- id: path,
477
- prefix
478
- } = REMOTE_COMPONENT_REGEX.exec(chunkId)?.groups ?? {
479
- bundle: scriptBundle ?? "",
480
- id: chunkId
481
- };
482
- logDebug(
483
- "ChunkLoader",
484
- `Parsed chunk - bundle: "${bundle}", path: "${path}", prefix: "${prefix}"`
485
- );
486
- const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
487
- logDebug("ChunkLoader", `Remote runtime: "${remoteRuntime}"`);
488
- if (remoteRuntime === RUNTIME_WEBPACK) {
489
- logDebug("ChunkLoader", "Skipping chunk load - webpack runtime detected");
490
- return Promise.resolve(void 0);
491
- }
492
- const url = new URL(
493
- path ? `${prefix ?? ""}${path}`.replace(
494
- /(?<char>[^:])(?<double>\/\/)/g,
495
- "$1/"
496
- ) : "/",
497
- self.__remote_bundle_url__?.[bundle ?? "default"] ?? new URL(location.origin)
498
- ).href;
499
- if (url.endsWith(".css")) {
500
- logDebug("ChunkLoader", `Skipping CSS file: "${url}"`);
501
- return;
502
- }
503
- if (!self.__remote_components_turbopack_chunk_loader_promise__) {
504
- self.__remote_components_turbopack_chunk_loader_promise__ = {};
505
- }
506
- if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {
415
+ function sharedPolyfills(shared, resolveClientUrl) {
416
+ const self = globalThis;
417
+ const polyfill = {
418
+ "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
419
+ useRouter() {
420
+ return {
421
+ push: (routerUrl) => {
422
+ history.pushState({}, "", routerUrl);
423
+ },
424
+ replace: (routerUrl) => {
425
+ history.replaceState({}, "", routerUrl);
426
+ },
427
+ back: () => {
428
+ history.back();
429
+ }
430
+ };
431
+ },
432
+ usePathname() {
433
+ return location.pathname;
434
+ },
435
+ useParams() {
436
+ return {};
437
+ },
438
+ useSearchParams() {
439
+ return new URLSearchParams(location.search);
440
+ },
441
+ useSelectedLayoutSegment() {
442
+ return null;
443
+ },
444
+ useSelectedLayoutSegments() {
445
+ return [];
446
+ },
447
+ __esModule: true
448
+ })),
449
+ "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
450
+ default: ({
451
+ scroll: _,
452
+ replace,
453
+ prefetch,
454
+ onNavigate,
455
+ children,
456
+ ...props
457
+ }) => {
458
+ if (prefetch) {
459
+ logWarn(
460
+ "Polyfill",
461
+ "Next.js Link prefetch is not supported in remote components"
462
+ );
463
+ }
464
+ return /* @__PURE__ */ jsx(
465
+ "a",
466
+ {
467
+ ...props,
468
+ href: props.href,
469
+ onClick: (e) => {
470
+ e.preventDefault();
471
+ let preventDefaulted = false;
472
+ e.preventDefault = () => {
473
+ preventDefaulted = true;
474
+ e.defaultPrevented = true;
475
+ };
476
+ if (typeof props.onClick === "function") {
477
+ props.onClick(e);
478
+ }
479
+ onNavigate?.(e);
480
+ if (preventDefaulted) {
481
+ return;
482
+ }
483
+ if (replace) {
484
+ history.replaceState({}, "", props.href);
485
+ } else {
486
+ history.pushState({}, "", props.href);
487
+ }
488
+ },
489
+ suppressHydrationWarning: true,
490
+ children: children ?? null
491
+ }
492
+ );
493
+ },
494
+ useLinkStatus() {
495
+ return { pending: false };
496
+ },
497
+ __esModule: true
498
+ })),
499
+ "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
500
+ default: () => {
501
+ throw new Error("Next.js <Form> component not implemented");
502
+ },
503
+ __esModule: true
504
+ })),
505
+ "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
506
+ Image: imageImpl(bundle, resolveClientUrl),
507
+ __esModule: true
508
+ })),
509
+ "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
510
+ default: imageImpl(bundle, resolveClientUrl),
511
+ getImageProps: (_imgProps) => {
512
+ throw new Error(
513
+ "Next.js getImageProps() is not implemented in remote components"
514
+ );
515
+ },
516
+ __esModule: true
517
+ })),
518
+ "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
519
+ // TODO: implement <Script> component for non-Next.js host applications
520
+ // do not throw an error for now
521
+ default: () => null,
522
+ __esModule: true
523
+ })),
524
+ "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
525
+ // TODO: incomplete implementation
526
+ Promise.resolve({
527
+ useRouter() {
528
+ return {
529
+ push: (routerUrl) => {
530
+ history.pushState({}, "", routerUrl);
531
+ },
532
+ replace: (routerUrl) => {
533
+ history.replaceState({}, "", routerUrl);
534
+ },
535
+ back: () => {
536
+ history.back();
537
+ }
538
+ };
539
+ },
540
+ __esModule: true
541
+ })
542
+ )),
543
+ "next/dist/build/polyfills/process": () => Promise.resolve({
544
+ default: {
545
+ env: {
546
+ NODE_ENV: "production"
547
+ }
548
+ },
549
+ __esModule: true
550
+ })
551
+ };
552
+ polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
553
+ polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
554
+ polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
555
+ polyfill["next/dist/api/image"] = polyfill["next/dist/client/image-component"];
556
+ polyfill["next/script"] = polyfill["next/dist/client/script"];
557
+ return polyfill;
558
+ }
559
+ var imageImpl;
560
+ var init_polyfill = __esm({
561
+ "src/host/shared/polyfill.tsx"() {
562
+ "use strict";
563
+ init_logger();
564
+ imageImpl = (bundle, resolveClientUrl) => function RemoteImage({
565
+ fill: _fill,
566
+ loader: _loader,
567
+ quality: _quality,
568
+ priority: _priority,
569
+ loading: _loading,
570
+ placeholder: _placeholder,
571
+ blurDataURL: _blurDataURL,
572
+ unoptimized: _unoptimized,
573
+ overrideSrc: _overrideSrc,
574
+ src,
575
+ ...props
576
+ }) {
577
+ const newSrc = applyBundleUrlToImagePropsSrc(
578
+ bundle,
579
+ typeof src === "string" ? src : src.src
580
+ );
581
+ const proxiedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
582
+ return (
583
+ // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
584
+ /* @__PURE__ */ jsx(
585
+ "img",
586
+ {
587
+ decoding: "async",
588
+ style: { color: "transparent" },
589
+ ...props,
590
+ src: proxiedSrc,
591
+ suppressHydrationWarning: true
592
+ }
593
+ )
594
+ );
595
+ };
596
+ }
597
+ });
598
+
599
+ // src/runtime/loaders/script-loader.ts
600
+ async function loadScripts(scripts, resolveClientUrl) {
601
+ await Promise.all(
602
+ scripts.map((script) => {
603
+ return new Promise((resolve, reject) => {
604
+ const newSrc = new URL(
605
+ // remove the remote component bundle name identifier from the script src
606
+ script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
607
+ location.origin
608
+ ).href;
609
+ const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
610
+ const newScript = document.createElement("script");
611
+ newScript.onload = () => resolve();
612
+ newScript.onerror = () => {
613
+ const isProxied = isProxiedUrl(resolvedSrc);
614
+ if (isProxied) {
615
+ reject(
616
+ new RemoteComponentsError(
617
+ `Failed to load script "${newSrc}" via proxy "${resolvedSrc}". Ensure withRemoteComponentsHostProxy middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
618
+ )
619
+ );
620
+ } else {
621
+ warnCrossOriginFetchError("ScriptLoader", newSrc);
622
+ reject(
623
+ new RemoteComponentsError(
624
+ `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
625
+ )
626
+ );
627
+ }
628
+ };
629
+ newScript.src = resolvedSrc;
630
+ newScript.async = true;
631
+ document.head.appendChild(newScript);
632
+ });
633
+ })
634
+ );
635
+ }
636
+ var init_script_loader = __esm({
637
+ "src/runtime/loaders/script-loader.ts"() {
638
+ "use strict";
639
+ init_constants2();
640
+ init_protected_rc_fallback();
641
+ init_constants();
642
+ init_error();
643
+ init_logger();
644
+ }
645
+ });
646
+
647
+ // src/host/html/runtime/webpack.ts
648
+ var webpack_exports = {};
649
+ __export(webpack_exports, {
650
+ webpackRuntime: () => webpackRuntime
651
+ });
652
+ async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
653
+ const self = globalThis;
654
+ if (!self.__DISABLE_WEBPACK_EXEC__) {
655
+ self.__DISABLE_WEBPACK_EXEC__ = {};
656
+ }
657
+ self.__DISABLE_WEBPACK_EXEC__[bundle] = true;
658
+ if (typeof self.__webpack_require__ !== "function" && self.__webpack_require_type__ !== "turbopack") {
659
+ self.__webpack_require__ = (remoteId) => {
660
+ const re = /\[(?<bundle>[^\]]+)\] (?<id>.*)/;
661
+ const match = re.exec(remoteId);
662
+ const remoteBundle = match?.groups?.bundle;
663
+ const id = match?.groups?.id;
664
+ if (!(id && remoteBundle)) {
665
+ throw new RemoteComponentsError(
666
+ `Remote Component module "${remoteId}" not found. Did you forget to wrap the Next.js config with \`withRemoteComponentsConfig\` on both host and remote?`
667
+ );
668
+ }
669
+ if (typeof self.__remote_webpack_require__?.[remoteBundle] !== "function") {
670
+ throw new RemoteComponentsError(
671
+ `Remote Components are not available in "${remoteBundle}". Did you forget to wrap the Next.js config with \`withRemoteComponentsConfig\` on both host and remote?`
672
+ );
673
+ }
674
+ return self.__remote_webpack_require__[remoteBundle](id);
675
+ };
676
+ self.__webpack_chunk_load__ = () => {
677
+ return Promise.resolve([]);
678
+ };
679
+ }
680
+ const {
681
+ default: { createFromReadableStream }
682
+ } = await import("react-server-dom-webpack/client.browser");
683
+ async function preloadScripts(scripts, url, remoteBundle, _) {
684
+ const scriptSrcs = scripts.flatMap((script) => {
685
+ const scriptSrc = script.getAttribute("src") || script.getAttribute("data-src");
686
+ script.parentElement?.removeChild(script);
687
+ if (!scriptSrc)
688
+ return [];
689
+ return [
690
+ {
691
+ src: new URL(scriptSrc.replace(NEXT_BUNDLE_PATH_RE, "/_next/"), url).href
692
+ }
693
+ ];
694
+ });
695
+ await loadScripts(scriptSrcs, resolveClientUrl);
696
+ const hostShared = {
697
+ ...sharedPolyfills(shared, resolveClientUrl),
698
+ ...self.__remote_component_host_shared_modules__,
699
+ ...shared
700
+ };
701
+ const resolve = {
702
+ "/react/index.js": (await import("react")).default,
703
+ "/react/jsx-dev-runtime.js": (await import("react/jsx-dev-runtime")).default,
704
+ "/react/jsx-runtime.js": (await import("react/jsx-runtime")).default,
705
+ "/react-dom/index.js": (await import("react-dom")).default,
706
+ "/react-dom/client.js": (await import("react-dom/client")).default,
707
+ ...Object.entries(remoteShared ?? {}).reduce(
708
+ (acc, [key, value]) => {
709
+ if (typeof hostShared[value] !== "undefined") {
710
+ acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
711
+ }
712
+ return acc;
713
+ },
714
+ {}
715
+ )
716
+ };
717
+ await Promise.all(
718
+ Object.entries(resolve).map(async ([key, value]) => {
719
+ if (typeof value === "function") {
720
+ resolve[key] = await value(remoteBundle);
721
+ }
722
+ return Promise.resolve(value);
723
+ })
724
+ );
725
+ applySharedModules(remoteBundle, resolve);
726
+ }
727
+ return {
728
+ self,
729
+ createFromReadableStream,
730
+ applySharedModules,
731
+ nextClientPagesLoader,
732
+ preloadScripts
733
+ };
734
+ }
735
+ var init_webpack = __esm({
736
+ "src/host/html/runtime/webpack.ts"() {
737
+ "use strict";
738
+ init_apply_shared_modules();
739
+ init_next_client_pages_loader();
740
+ init_polyfill();
741
+ init_constants2();
742
+ init_script_loader();
743
+ init_error();
744
+ }
745
+ });
746
+
747
+ // src/runtime/turbopack/patterns.ts
748
+ var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, TURBOPACK_GLOBAL_RE;
749
+ var init_patterns = __esm({
750
+ "src/runtime/turbopack/patterns.ts"() {
751
+ "use strict";
752
+ REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
753
+ REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|[a-z])\.A\((?<sharedModuleId>[0-9]+)\)/;
754
+ ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
755
+ ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
756
+ ASYNC_MODULE_ALL_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<vCb>parentImport|t)=>Promise\.all\(\["[^"]+"\]\.map\((?<mapCb>chunk|t)=>\k<ctx>\.l\(\k<mapCb>\)\)\)\.then\(\(\)=>\k<vCb>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
757
+ TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
758
+ }
759
+ });
760
+
761
+ // src/runtime/turbopack/chunk-loader.ts
762
+ function createChunkLoader(runtime, resolveClientUrl) {
763
+ return function __turbopack_chunk_load__(chunkId, scriptBundle) {
764
+ logDebug("ChunkLoader", `Loading chunk: "${chunkId}"`);
765
+ const self = globalThis;
766
+ const {
767
+ bundle,
768
+ id: path,
769
+ prefix
770
+ } = REMOTE_COMPONENT_REGEX.exec(chunkId)?.groups ?? {
771
+ bundle: scriptBundle ?? "",
772
+ id: chunkId
773
+ };
774
+ logDebug(
775
+ "ChunkLoader",
776
+ `Parsed chunk - bundle: "${bundle}", path: "${path}", prefix: "${prefix}"`
777
+ );
778
+ const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
779
+ logDebug("ChunkLoader", `Remote runtime: "${remoteRuntime}"`);
780
+ if (remoteRuntime === RUNTIME_WEBPACK) {
781
+ logDebug("ChunkLoader", "Skipping chunk load - webpack runtime detected");
782
+ return Promise.resolve(void 0);
783
+ }
784
+ const url = new URL(
785
+ path ? `${prefix ?? ""}${path}`.replace(
786
+ /(?<char>[^:])(?<double>\/\/)/g,
787
+ "$1/"
788
+ ) : "/",
789
+ self.__remote_bundle_url__?.[bundle ?? "default"] ?? new URL(location.origin)
790
+ ).href;
791
+ if (url.endsWith(".css")) {
792
+ logDebug("ChunkLoader", `Skipping CSS file: "${url}"`);
793
+ return;
794
+ }
795
+ if (!self.__remote_components_turbopack_chunk_loader_promise__) {
796
+ self.__remote_components_turbopack_chunk_loader_promise__ = {};
797
+ }
798
+ if (self.__remote_components_turbopack_chunk_loader_promise__[url]) {
507
799
  logDebug("ChunkLoader", `Returning cached promise for: "${url}"`);
508
800
  return self.__remote_components_turbopack_chunk_loader_promise__[url];
509
801
  }
@@ -528,7 +820,7 @@ function createChunkLoader(runtime, resolveClientUrl) {
528
820
  if (isProxied) {
529
821
  reject(
530
822
  new RemoteComponentsError(
531
- `Failed to load chunk "${url}" via proxy "${resolvedUrl}". Ensure withRemoteComponentsHost middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
823
+ `Failed to load chunk "${url}" via proxy "${resolvedUrl}". Ensure withRemoteComponentsHostProxy middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
532
824
  )
533
825
  );
534
826
  } else {
@@ -678,18 +970,18 @@ async function handleTurbopackChunk(code, bundle, url) {
678
970
  }
679
971
  }
680
972
  var init_chunk_loader = __esm({
681
- "src/shared/client/chunk-loader.ts"() {
973
+ "src/runtime/turbopack/chunk-loader.ts"() {
682
974
  "use strict";
975
+ init_constants2();
976
+ init_protected_rc_fallback();
683
977
  init_constants();
684
978
  init_error();
685
979
  init_logger();
686
- init_const();
687
- init_protected_rc_fallback();
688
- init_turbopack_patterns();
980
+ init_patterns();
689
981
  }
690
982
  });
691
983
 
692
- // src/shared/client/turbopack-module.ts
984
+ // src/runtime/turbopack/module.ts
693
985
  function handleTurbopackModule(bundle, moduleId, id) {
694
986
  const self = globalThis;
695
987
  const bundleKey = getBundleKey(bundle);
@@ -858,768 +1150,309 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
858
1150
  }
859
1151
  return mod;
860
1152
  },
861
- // require
862
- r(requireId) {
863
- return self.__webpack_require__?.(`[${bundle}] ${requireId}`);
864
- },
865
- // value exports
866
- v(value) {
867
- if (typeof value === "function") {
868
- exports.default = value((vid) => {
869
- return self.__webpack_require__?.(`[${bundle}] ${vid}`);
870
- });
871
- } else {
872
- moduleExports.exports = value;
873
- }
874
- },
875
- // async module initializer
876
- async a(mod) {
877
- let result;
878
- await mod(
879
- () => {
880
- },
881
- (value) => result = value
882
- );
883
- exports.default = result;
884
- },
885
- // async module loader
886
- async A(Aid) {
887
- const mod = self.__webpack_require__?.(`[${bundle}] ${Aid}`);
888
- return mod.default(
889
- (parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
890
- );
891
- },
892
- // dynamic import tracking — no-op for remote components
893
- j() {
894
- },
895
- // chunk loader
896
- l(url) {
897
- const flatModules = Array.isArray(modules) ? modules : [];
898
- const moduleInitIndex = flatModules.indexOf(moduleInit);
899
- if (moduleInitIndex !== -1) {
900
- const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
901
- if (scriptIndex !== -1) {
902
- const script = flatModules[scriptIndex];
903
- const scriptSrc = script.getAttribute("data-turbopack-src") || "";
904
- const nextIndex = scriptSrc.indexOf("/_next");
905
- const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
906
- const bundleUrl = `[${bundle}] ${baseUrl}/_next/${url}`;
907
- return self.__webpack_chunk_load__?.(bundleUrl, bundle);
908
- }
909
- }
910
- throw new Error(
911
- `Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
912
- );
913
- },
914
- // global object for this bundle
915
- g: self.__remote_components_turbopack_global__?.[bundle],
916
- m: moduleExports,
917
- e: exports
918
- };
919
- }
920
- var init_turbopack_module = __esm({
921
- "src/shared/client/turbopack-module.ts"() {
922
- "use strict";
923
- init_logger();
924
- init_const();
925
- }
926
- });
927
-
928
- // src/shared/client/shared-modules.ts
929
- async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {}) {
930
- const self = globalThis;
931
- self.__remote_shared_modules__ = self.__remote_shared_modules__ ?? {};
932
- if (!self.__remote_shared_modules__[bundle]) {
933
- self.__remote_shared_modules__[bundle] = {};
934
- }
935
- const bundleKey = getBundleKey(bundle);
936
- let modules = self[`TURBOPACK_${bundleKey}`];
937
- if (modules && typeof modules === "object" && "__chunks__" in modules) {
938
- const chunks = modules.__chunks__;
939
- modules = chunks.flat();
940
- }
941
- let sharedModuleInitializer = null;
942
- if (modules) {
943
- const allModules = Array.isArray(modules) ? modules.flat() : Object.entries(modules).flat();
944
- const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {
945
- if (typeof idOrFunc !== "function") {
946
- return false;
947
- }
948
- const funcCode = idOrFunc.toString();
949
- return REMOTE_SHARED_MARKER_RE.test(funcCode);
950
- });
951
- if (sharedModuleInitializerIndex > 0) {
952
- const sharedModuleInitializerCode = allModules[sharedModuleInitializerIndex].toString();
953
- const sharedModuleInitializerId = allModules[sharedModuleInitializerIndex - 1];
954
- const { sharedModuleId } = REMOTE_SHARED_ASSIGNMENT_RE.exec(sharedModuleInitializerCode)?.groups ?? {};
955
- if (sharedModuleId) {
956
- const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
957
- bundle,
958
- sharedModuleId,
959
- `[${bundle}] ${sharedModuleInitializerId}`
960
- );
961
- sharedModuleInitializer = sharedModuleInitializerInstance;
962
- }
963
- }
964
- if (sharedModuleInitializer) {
965
- const { shared } = await sharedModuleInitializer;
966
- const sharedModuleIds = extractSharedModuleIds(
967
- shared,
968
- bundleKey,
969
- self
970
- );
971
- return Promise.all(
972
- Object.entries(sharedModuleIds).map(async ([id, module]) => {
973
- if (self.__remote_shared_modules__?.[bundle]) {
974
- if (hostShared[module]) {
975
- self.__remote_shared_modules__[bundle][id] = await hostShared[module](bundle);
976
- } else {
977
- logError(
978
- "SharedModules",
979
- `Host shared module "${module}" not found for ID ${id}`
980
- );
981
- }
982
- }
983
- })
984
- );
985
- }
986
- }
987
- return Promise.all(
988
- Object.entries(remoteShared).map(async ([id, module]) => {
989
- if (self.__remote_shared_modules__?.[bundle]) {
990
- if (hostShared[module]) {
991
- const normalizedId = id.replace("[app-ssr]", "[app-client]");
992
- self.__remote_shared_modules__[bundle][normalizedId] = await hostShared[module](bundle);
993
- } else {
994
- logError(
995
- "SharedModules",
996
- `Shared module "${module}" not found for "${bundle}"`
997
- );
998
- }
999
- }
1000
- })
1001
- );
1002
- }
1003
- function extractSharedModuleIds(shared, bundleKey, self) {
1004
- return Object.entries(shared).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
1005
- const { asyncSharedModuleId } = ASYNC_MODULE_LOADER_RE.exec(value.toString())?.groups ?? {};
1006
- if (asyncSharedModuleId) {
1007
- const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
1008
- let asyncSharedModule;
1009
- let turbopackModules = self[`TURBOPACK_${bundleKey}`];
1010
- if (turbopackModules && typeof turbopackModules === "object" && "__chunks__" in turbopackModules) {
1011
- const chunks = turbopackModules.__chunks__;
1012
- turbopackModules = chunks.flat();
1013
- }
1014
- const newAllModules = Array.isArray(turbopackModules) ? turbopackModules.flat() : turbopackModules ? Object.entries(turbopackModules).flatMap(([key2, value2]) => [
1015
- key2,
1016
- value2
1017
- ]) : [];
1018
- const asyncSharedModuleIdIndex = newAllModules.indexOf(
1019
- asyncSharedModuleIdNumber
1020
- );
1021
- if (asyncSharedModuleIdIndex !== -1 && typeof newAllModules[asyncSharedModuleIdIndex + 1] === "function") {
1022
- asyncSharedModule = newAllModules[asyncSharedModuleIdIndex + 1];
1023
- }
1024
- if (asyncSharedModule) {
1025
- const asyncSharedModuleCode = asyncSharedModule.toString();
1026
- const { sharedModuleId } = ASYNC_MODULE_RESOLVE_RE.exec(asyncSharedModuleCode)?.groups ?? ASYNC_MODULE_ALL_RE.exec(asyncSharedModuleCode)?.groups ?? {};
1027
- acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(
1028
- "__remote_shared_module_",
1029
- ""
1030
- );
1031
- }
1032
- }
1033
- return acc;
1034
- }, {});
1035
- }
1036
- function getSharedModule(bundle, id) {
1037
- const self = globalThis;
1038
- for (const [key, value] of Object.entries(
1039
- self.__remote_shared_modules__?.[bundle] ?? {}
1040
- )) {
1041
- if (typeof value !== "undefined" && (typeof id === "string" && id.includes(key) || id === key)) {
1042
- return value;
1043
- }
1044
- }
1045
- return null;
1046
- }
1047
- var init_shared_modules2 = __esm({
1048
- "src/shared/client/shared-modules.ts"() {
1049
- "use strict";
1050
- init_logger();
1051
- init_const();
1052
- init_turbopack_module();
1053
- init_turbopack_patterns();
1054
- }
1055
- });
1056
-
1057
- // src/shared/client/webpack-adapter.ts
1058
- async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
1059
- const self = globalThis;
1060
- if (!self.__remote_bundle_url__) {
1061
- self.__remote_bundle_url__ = {};
1062
- }
1063
- self.__remote_bundle_url__[bundle ?? "default"] = url;
1064
- self.__webpack_get_script_filename__ = () => null;
1065
- if (typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack") {
1066
- if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
1067
- self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
1068
- self.__original_webpack_require__ = self.__webpack_require__;
1069
- }
1070
- self.__webpack_chunk_load__ = createChunkLoader(runtime, resolveClientUrl);
1071
- self.__webpack_require__ = createModuleRequire(runtime);
1072
- self.__webpack_require_type__ = runtime;
1073
- if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
1074
- const remoteBundle = bundle ?? "default";
1075
- self.__remote_webpack_require__[remoteBundle] = self.__webpack_require__;
1076
- self.__remote_webpack_require__[remoteBundle].type = "turbopack";
1077
- }
1078
- }
1079
- if (runtime === RUNTIME_TURBOPACK) {
1080
- await Promise.all(
1081
- scripts.map((script) => {
1082
- if (script.src) {
1083
- return self.__webpack_chunk_load__?.(script.src, bundle);
1084
- }
1085
- return Promise.resolve(void 0);
1086
- })
1087
- );
1088
- }
1089
- const coreShared = {
1090
- react: async () => (await import("react")).default,
1091
- "react-dom": async () => (await import("react-dom")).default,
1092
- "react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
1093
- "react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
1094
- "react-dom/client": async () => (await import("react-dom/client")).default,
1095
- ...shared
1096
- };
1097
- await initializeSharedModules(
1098
- bundle ?? "default",
1099
- // include all core modules as shared
1100
- coreShared,
1101
- remoteShared
1102
- );
1103
- }
1104
- function createModuleRequire(runtime) {
1105
- return (id) => {
1106
- const self = globalThis;
1107
- const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
1108
- bundle: "default",
1109
- id
1110
- };
1111
- const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
1112
- logDebug("WebpackAdapter", `remoteRuntime: "${remoteRuntime}"`);
1113
- try {
1114
- if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
1115
- return self.__remote_webpack_require__?.[bundle]?.(moduleId);
1116
- }
1117
- const sharedModuleId = moduleId ?? id;
1118
- const sharedModule = getSharedModule(bundle ?? "default", sharedModuleId);
1119
- if (sharedModule) {
1120
- return sharedModule;
1121
- }
1122
- if (bundle && moduleId) {
1123
- return handleTurbopackModule(bundle, moduleId, id);
1153
+ // require
1154
+ r(requireId) {
1155
+ return self.__webpack_require__?.(`[${bundle}] ${requireId}`);
1156
+ },
1157
+ // value exports
1158
+ v(value) {
1159
+ if (typeof value === "function") {
1160
+ exports.default = value((vid) => {
1161
+ return self.__webpack_require__?.(`[${bundle}] ${vid}`);
1162
+ });
1163
+ } else {
1164
+ moduleExports.exports = value;
1124
1165
  }
1125
- throw new Error(`Module "${id}" not found.`);
1126
- } catch (requireError) {
1127
- logWarn(
1128
- "WebpackAdapter",
1129
- `Module require failed: ${String(requireError)}`
1166
+ },
1167
+ // async module initializer
1168
+ async a(mod) {
1169
+ let result;
1170
+ await mod(
1171
+ () => {
1172
+ },
1173
+ (value) => result = value
1130
1174
  );
1131
- if (typeof self.__original_webpack_require__ !== "function") {
1132
- throw new RemoteComponentsError(
1133
- `Module "${id}" not found in remote component bundle "${bundle}".`,
1134
- {
1135
- cause: requireError instanceof Error ? requireError : void 0
1136
- }
1137
- );
1138
- }
1139
- try {
1140
- logDebug("WebpackAdapter", "Falling back to original webpack require");
1141
- return self.__original_webpack_require__(id);
1142
- } catch (originalError) {
1143
- throw new RemoteComponentsError(
1144
- `Module "${id}" not found in remote component bundle "${bundle}".`,
1145
- { cause: originalError instanceof Error ? originalError : void 0 }
1146
- );
1175
+ exports.default = result;
1176
+ },
1177
+ // async module loader
1178
+ async A(Aid) {
1179
+ const mod = self.__webpack_require__?.(`[${bundle}] ${Aid}`);
1180
+ return mod.default(
1181
+ (parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
1182
+ );
1183
+ },
1184
+ // dynamic import tracking no-op for remote components
1185
+ j() {
1186
+ },
1187
+ // chunk loader
1188
+ l(url) {
1189
+ const flatModules = Array.isArray(modules) ? modules : [];
1190
+ const moduleInitIndex = flatModules.indexOf(moduleInit);
1191
+ if (moduleInitIndex !== -1) {
1192
+ const scriptIndex = flatModules.slice(0, moduleInitIndex).findLastIndex((bundleEntry) => bundleEntry instanceof Element);
1193
+ if (scriptIndex !== -1) {
1194
+ const script = flatModules[scriptIndex];
1195
+ const scriptSrc = script.getAttribute("data-turbopack-src") || "";
1196
+ const nextIndex = scriptSrc.indexOf("/_next");
1197
+ const baseUrl = nextIndex !== -1 ? scriptSrc.slice(0, nextIndex) : "";
1198
+ const bundleUrl = `[${bundle}] ${baseUrl}/_next/${url}`;
1199
+ return self.__webpack_chunk_load__?.(bundleUrl, bundle);
1200
+ }
1147
1201
  }
1148
- }
1202
+ throw new Error(
1203
+ `Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
1204
+ );
1205
+ },
1206
+ // global object for this bundle
1207
+ g: self.__remote_components_turbopack_global__?.[bundle],
1208
+ m: moduleExports,
1209
+ e: exports
1149
1210
  };
1150
1211
  }
1151
- var init_webpack_adapter = __esm({
1152
- "src/shared/client/webpack-adapter.ts"() {
1212
+ var init_module = __esm({
1213
+ "src/runtime/turbopack/module.ts"() {
1153
1214
  "use strict";
1154
- init_error();
1215
+ init_constants2();
1155
1216
  init_logger();
1156
- init_chunk_loader();
1157
- init_const();
1158
- init_shared_modules2();
1159
- init_turbopack_module();
1160
1217
  }
1161
1218
  });
1162
1219
 
1163
- // src/shared/client/static-loader.ts
1164
- async function importViaCallback(absoluteSrc, resolveClientUrl) {
1165
- const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
1166
- const fetchUrl = new URL(resolvedUrl, location.href).href;
1167
- const response = await fetch(fetchUrl);
1168
- if (!response.ok)
1169
- throw new Error(`Proxied fetch failed: ${response.status}`);
1170
- const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
1171
- /\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
1172
- (_, keyword, quote, relativePath) => {
1173
- const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
1174
- const resolvedImportUrl = new URL(
1175
- resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
1176
- location.href
1177
- ).href;
1178
- return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
1179
- }
1180
- );
1181
- const moduleBlobUrl = URL.createObjectURL(
1182
- new Blob([content], { type: "text/javascript" })
1183
- );
1184
- const wrapperContent = [
1185
- `import*as m from${JSON.stringify(moduleBlobUrl)};`,
1186
- `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
1187
- `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
1188
- ].join("");
1189
- const wrapperBlobUrl = URL.createObjectURL(
1190
- new Blob([wrapperContent], { type: "text/javascript" })
1191
- );
1192
- const scriptEl = document.createElement("script");
1193
- scriptEl.type = "module";
1194
- scriptEl.src = wrapperBlobUrl;
1195
- try {
1196
- await new Promise((resolve, reject) => {
1197
- scriptEl.onload = () => resolve();
1198
- scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
1199
- document.head.appendChild(scriptEl);
1200
- });
1201
- } finally {
1202
- scriptEl.remove();
1203
- URL.revokeObjectURL(moduleBlobUrl);
1204
- URL.revokeObjectURL(wrapperBlobUrl);
1205
- }
1206
- const registry = globalThis.__rc_module_registry__;
1207
- const mod = registry?.[absoluteSrc] ?? {};
1208
- if (registry)
1209
- delete registry[absoluteSrc];
1210
- return mod;
1211
- }
1212
- async function importDirectly(absoluteSrc) {
1213
- try {
1214
- return await import(
1215
- /* @vite-ignore */
1216
- /* webpackIgnore: true */
1217
- absoluteSrc
1218
- );
1219
- } catch (importError) {
1220
- if (!absoluteSrc.startsWith("blob:")) {
1221
- warnCrossOriginFetchError("StaticLoader", absoluteSrc);
1222
- }
1223
- throw importError;
1224
- }
1225
- }
1226
- function resolveScriptSrc(script, url) {
1227
- const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1228
- if (!rawSrc && script.textContent) {
1229
- return URL.createObjectURL(
1230
- new Blob(
1231
- [script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
1232
- { type: "text/javascript" }
1233
- )
1234
- );
1235
- }
1236
- return rawSrc;
1237
- }
1238
- async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
1220
+ // src/runtime/turbopack/shared-modules.ts
1221
+ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {}) {
1239
1222
  const self = globalThis;
1240
- if (self.__remote_script_entrypoint_mount__?.[url.href]) {
1241
- self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
1223
+ self.__remote_shared_modules__ = self.__remote_shared_modules__ ?? {};
1224
+ if (!self.__remote_shared_modules__[bundle]) {
1225
+ self.__remote_shared_modules__[bundle] = {};
1242
1226
  }
1243
- if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
1244
- self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
1227
+ const bundleKey = getBundleKey(bundle);
1228
+ let modules = self[`TURBOPACK_${bundleKey}`];
1229
+ if (modules && typeof modules === "object" && "__chunks__" in modules) {
1230
+ const chunks = modules.__chunks__;
1231
+ modules = chunks.flat();
1245
1232
  }
1246
- const mountUnmountSets = await Promise.all(
1247
- scripts.map(async (script) => {
1248
- try {
1249
- const src = resolveScriptSrc(script, url);
1250
- const absoluteSrc = new URL(src, url).href;
1251
- const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
1252
- if (src.startsWith("blob:")) {
1253
- URL.revokeObjectURL(src);
1254
- }
1255
- if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
1256
- if (!self.__remote_script_entrypoint_mount__) {
1257
- self.__remote_script_entrypoint_mount__ = {};
1258
- }
1259
- if (!self.__remote_script_entrypoint_mount__[url.href]) {
1260
- self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
1261
- }
1262
- self.__remote_script_entrypoint_mount__[url.href]?.add(
1263
- mod.mount || mod.default?.mount || (() => {
1264
- })
1265
- );
1266
- }
1267
- if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
1268
- if (!self.__remote_script_entrypoint_unmount__) {
1269
- self.__remote_script_entrypoint_unmount__ = {};
1270
- }
1271
- if (!self.__remote_script_entrypoint_unmount__[url.href]) {
1272
- self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
1273
- }
1274
- self.__remote_script_entrypoint_unmount__[url.href]?.add(
1275
- mod.unmount || mod.default?.unmount || (() => {
1276
- })
1277
- );
1278
- }
1279
- return {
1280
- mount: mod.mount || mod.default?.mount,
1281
- unmount: mod.unmount || mod.default?.unmount
1282
- };
1283
- } catch (e) {
1284
- logError(
1285
- "StaticLoader",
1286
- `Error loading remote component script from "${script.src || url.href}".`,
1287
- e
1233
+ let sharedModuleInitializer = null;
1234
+ if (modules) {
1235
+ const allModules = Array.isArray(modules) ? modules.flat() : Object.entries(modules).flat();
1236
+ const sharedModuleInitializerIndex = allModules.findIndex((idOrFunc) => {
1237
+ if (typeof idOrFunc !== "function") {
1238
+ return false;
1239
+ }
1240
+ const funcCode = idOrFunc.toString();
1241
+ return REMOTE_SHARED_MARKER_RE.test(funcCode);
1242
+ });
1243
+ if (sharedModuleInitializerIndex > 0) {
1244
+ const sharedModuleInitializerCode = allModules[sharedModuleInitializerIndex].toString();
1245
+ const sharedModuleInitializerId = allModules[sharedModuleInitializerIndex - 1];
1246
+ const { sharedModuleId } = REMOTE_SHARED_ASSIGNMENT_RE.exec(sharedModuleInitializerCode)?.groups ?? {};
1247
+ if (sharedModuleId) {
1248
+ const { default: sharedModuleInitializerInstance } = handleTurbopackModule(
1249
+ bundle,
1250
+ sharedModuleId,
1251
+ `[${bundle}] ${sharedModuleInitializerId}`
1288
1252
  );
1289
- return {
1290
- mount: void 0,
1291
- unmount: void 0
1292
- };
1253
+ sharedModuleInitializer = sharedModuleInitializerInstance;
1254
+ }
1255
+ }
1256
+ if (sharedModuleInitializer) {
1257
+ const { shared } = await sharedModuleInitializer;
1258
+ const sharedModuleIds = extractSharedModuleIds(
1259
+ shared,
1260
+ bundleKey,
1261
+ self
1262
+ );
1263
+ return Promise.all(
1264
+ Object.entries(sharedModuleIds).map(async ([id, module]) => {
1265
+ if (self.__remote_shared_modules__?.[bundle]) {
1266
+ if (hostShared[module]) {
1267
+ self.__remote_shared_modules__[bundle][id] = await hostShared[module](bundle);
1268
+ } else {
1269
+ logError(
1270
+ "SharedModules",
1271
+ `Host shared module "${module}" not found for ID ${id}`
1272
+ );
1273
+ }
1274
+ }
1275
+ })
1276
+ );
1277
+ }
1278
+ }
1279
+ return Promise.all(
1280
+ Object.entries(remoteShared).map(async ([id, module]) => {
1281
+ if (self.__remote_shared_modules__?.[bundle]) {
1282
+ if (hostShared[module]) {
1283
+ const normalizedId = id.replace("[app-ssr]", "[app-client]");
1284
+ self.__remote_shared_modules__[bundle][normalizedId] = await hostShared[module](bundle);
1285
+ } else {
1286
+ logError(
1287
+ "SharedModules",
1288
+ `Shared module "${module}" not found for "${bundle}"`
1289
+ );
1290
+ }
1293
1291
  }
1294
1292
  })
1295
1293
  );
1296
- return mountUnmountSets.reduce(
1297
- (acc, { mount, unmount }) => {
1298
- if (typeof mount === "function") {
1299
- acc.mount.add(mount);
1294
+ }
1295
+ function extractSharedModuleIds(shared, bundleKey, self) {
1296
+ return Object.entries(shared).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
1297
+ const { asyncSharedModuleId } = ASYNC_MODULE_LOADER_RE.exec(value.toString())?.groups ?? {};
1298
+ if (asyncSharedModuleId) {
1299
+ const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
1300
+ let asyncSharedModule;
1301
+ let turbopackModules = self[`TURBOPACK_${bundleKey}`];
1302
+ if (turbopackModules && typeof turbopackModules === "object" && "__chunks__" in turbopackModules) {
1303
+ const chunks = turbopackModules.__chunks__;
1304
+ turbopackModules = chunks.flat();
1300
1305
  }
1301
- if (typeof unmount === "function") {
1302
- acc.unmount.add(unmount);
1306
+ const newAllModules = Array.isArray(turbopackModules) ? turbopackModules.flat() : turbopackModules ? Object.entries(turbopackModules).flatMap(([key2, value2]) => [
1307
+ key2,
1308
+ value2
1309
+ ]) : [];
1310
+ const asyncSharedModuleIdIndex = newAllModules.indexOf(
1311
+ asyncSharedModuleIdNumber
1312
+ );
1313
+ if (asyncSharedModuleIdIndex !== -1 && typeof newAllModules[asyncSharedModuleIdIndex + 1] === "function") {
1314
+ asyncSharedModule = newAllModules[asyncSharedModuleIdIndex + 1];
1315
+ }
1316
+ if (asyncSharedModule) {
1317
+ const asyncSharedModuleCode = asyncSharedModule.toString();
1318
+ const { sharedModuleId } = ASYNC_MODULE_RESOLVE_RE.exec(asyncSharedModuleCode)?.groups ?? ASYNC_MODULE_ALL_RE.exec(asyncSharedModuleCode)?.groups ?? {};
1319
+ acc[sharedModuleId ?? asyncSharedModuleId] = key.replace(
1320
+ "__remote_shared_module_",
1321
+ ""
1322
+ );
1303
1323
  }
1304
- return acc;
1305
- },
1306
- {
1307
- mount: /* @__PURE__ */ new Set(),
1308
- unmount: /* @__PURE__ */ new Set()
1309
1324
  }
1310
- );
1325
+ return acc;
1326
+ }, {});
1311
1327
  }
1312
- var init_static_loader = __esm({
1313
- "src/shared/client/static-loader.ts"() {
1314
- "use strict";
1315
- init_logger();
1316
- }
1317
- });
1318
-
1319
- // src/shared/client/polyfill.tsx
1320
- import { jsx } from "react/jsx-runtime";
1321
- function applyBundleUrlToSrc(bundle, src) {
1328
+ function getSharedModule(bundle, id) {
1322
1329
  const self = globalThis;
1323
- if (self.__remote_bundle_url__?.[bundle]?.origin === location.origin) {
1324
- return src;
1325
- }
1326
- const { assetPrefix, path } = /^(?<assetPrefix>.*?)\/_next\/(?<path>.*)/.exec(src)?.groups ?? {};
1327
- if (!path) {
1328
- return new URL(src, self.__remote_bundle_url__?.[bundle]?.origin).href;
1329
- }
1330
- return `${self.__remote_bundle_url__?.[bundle]?.origin ?? ""}${assetPrefix}/_next/${path}`;
1331
- }
1332
- function applyBundleUrlToImagePropsSrc(bundle, src) {
1333
- if (typeof src === "string") {
1334
- return applyBundleUrlToSrc(bundle, src);
1330
+ for (const [key, value] of Object.entries(
1331
+ self.__remote_shared_modules__?.[bundle] ?? {}
1332
+ )) {
1333
+ if (typeof value !== "undefined" && (typeof id === "string" && id.includes(key) || id === key)) {
1334
+ return value;
1335
+ }
1335
1336
  }
1336
- const propSrc = src;
1337
- return applyBundleUrlToSrc(bundle, propSrc.src);
1338
- }
1339
- function sharedPolyfills(shared) {
1340
- const self = globalThis;
1341
- const polyfill = {
1342
- "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
1343
- useRouter() {
1344
- return {
1345
- push: (routerUrl) => {
1346
- history.pushState({}, "", routerUrl);
1347
- },
1348
- replace: (routerUrl) => {
1349
- history.replaceState({}, "", routerUrl);
1350
- },
1351
- back: () => {
1352
- history.back();
1353
- }
1354
- };
1355
- },
1356
- usePathname() {
1357
- return location.pathname;
1358
- },
1359
- useParams() {
1360
- return {};
1361
- },
1362
- useSearchParams() {
1363
- return new URLSearchParams(location.search);
1364
- },
1365
- useSelectedLayoutSegment() {
1366
- return null;
1367
- },
1368
- useSelectedLayoutSegments() {
1369
- return [];
1370
- },
1371
- __esModule: true
1372
- })),
1373
- "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
1374
- default: ({
1375
- scroll: _,
1376
- replace,
1377
- prefetch,
1378
- onNavigate,
1379
- children,
1380
- ...props
1381
- }) => {
1382
- if (prefetch) {
1383
- logWarn(
1384
- "Polyfill",
1385
- "Next.js Link prefetch is not supported in remote components"
1386
- );
1387
- }
1388
- return /* @__PURE__ */ jsx(
1389
- "a",
1390
- {
1391
- ...props,
1392
- href: props.href,
1393
- onClick: (e) => {
1394
- e.preventDefault();
1395
- let preventDefaulted = false;
1396
- e.preventDefault = () => {
1397
- preventDefaulted = true;
1398
- e.defaultPrevented = true;
1399
- };
1400
- if (typeof props.onClick === "function") {
1401
- props.onClick(e);
1402
- }
1403
- onNavigate?.(e);
1404
- if (preventDefaulted) {
1405
- return;
1406
- }
1407
- if (replace) {
1408
- history.replaceState({}, "", props.href);
1409
- } else {
1410
- history.pushState({}, "", props.href);
1411
- }
1412
- },
1413
- suppressHydrationWarning: true,
1414
- children: children ?? null
1415
- }
1416
- );
1417
- },
1418
- useLinkStatus() {
1419
- return { pending: false };
1420
- },
1421
- __esModule: true
1422
- })),
1423
- "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
1424
- default: () => {
1425
- throw new Error("Next.js <Form> component not implemented");
1426
- },
1427
- __esModule: true
1428
- })),
1429
- "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
1430
- Image: imageImpl(bundle),
1431
- __esModule: true
1432
- })),
1433
- "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
1434
- default: imageImpl(bundle),
1435
- getImageProps: (_imgProps) => {
1436
- throw new Error(
1437
- "Next.js getImageProps() is not implemented in remote components"
1438
- );
1439
- },
1440
- __esModule: true
1441
- })),
1442
- "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
1443
- // TODO: implement <Script> component for non-Next.js host applications
1444
- // do not throw an error for now
1445
- default: () => null,
1446
- __esModule: true
1447
- })),
1448
- "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
1449
- // TODO: incomplete implementation
1450
- Promise.resolve({
1451
- useRouter() {
1452
- return {
1453
- push: (routerUrl) => {
1454
- history.pushState({}, "", routerUrl);
1455
- },
1456
- replace: (routerUrl) => {
1457
- history.replaceState({}, "", routerUrl);
1458
- },
1459
- back: () => {
1460
- history.back();
1461
- }
1462
- };
1463
- },
1464
- __esModule: true
1465
- })
1466
- )),
1467
- "next/dist/build/polyfills/process": () => Promise.resolve({
1468
- default: {
1469
- env: {
1470
- NODE_ENV: "production"
1471
- }
1472
- },
1473
- __esModule: true
1474
- })
1475
- };
1476
- polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
1477
- polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
1478
- polyfill["next/form"] = polyfill["next/dist/client/app-dir/form"];
1479
- polyfill["next/dist/api/image"] = polyfill["next/dist/client/image-component"];
1480
- polyfill["next/script"] = polyfill["next/dist/client/script"];
1481
- return polyfill;
1337
+ return null;
1482
1338
  }
1483
- var imageImpl;
1484
- var init_polyfill = __esm({
1485
- "src/shared/client/polyfill.tsx"() {
1339
+ var init_shared_modules = __esm({
1340
+ "src/runtime/turbopack/shared-modules.ts"() {
1486
1341
  "use strict";
1342
+ init_constants2();
1487
1343
  init_logger();
1488
- imageImpl = (bundle) => function RemoteImage({
1489
- fill: _fill,
1490
- loader: _loader,
1491
- quality: _quality,
1492
- priority: _priority,
1493
- loading: _loading,
1494
- placeholder: _placeholder,
1495
- blurDataURL: _blurDataURL,
1496
- unoptimized: _unoptimized,
1497
- overrideSrc: _overrideSrc,
1498
- src,
1499
- ...props
1500
- }) {
1501
- const newSrc = applyBundleUrlToImagePropsSrc(
1502
- bundle,
1503
- typeof src === "string" ? src : src.src
1504
- );
1505
- return (
1506
- // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
1507
- /* @__PURE__ */ jsx(
1508
- "img",
1509
- {
1510
- decoding: "async",
1511
- style: { color: "transparent" },
1512
- ...props,
1513
- src: newSrc,
1514
- suppressHydrationWarning: true
1515
- }
1516
- )
1517
- );
1518
- };
1344
+ init_module();
1345
+ init_patterns();
1519
1346
  }
1520
1347
  });
1521
1348
 
1522
- // src/html/host/runtime/webpack.ts
1523
- var webpack_exports = {};
1524
- __export(webpack_exports, {
1525
- webpackRuntime: () => webpackRuntime
1526
- });
1527
- async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
1349
+ // src/runtime/turbopack/webpack-runtime.ts
1350
+ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
1528
1351
  const self = globalThis;
1529
- if (!self.__DISABLE_WEBPACK_EXEC__) {
1530
- self.__DISABLE_WEBPACK_EXEC__ = {};
1352
+ if (!self.__remote_bundle_url__) {
1353
+ self.__remote_bundle_url__ = {};
1531
1354
  }
1532
- self.__DISABLE_WEBPACK_EXEC__[bundle] = true;
1533
- if (typeof self.__webpack_require__ !== "function" && self.__webpack_require_type__ !== "turbopack") {
1534
- self.__webpack_require__ = (remoteId) => {
1535
- const re = /\[(?<bundle>[^\]]+)\] (?<id>.*)/;
1536
- const match = re.exec(remoteId);
1537
- const remoteBundle = match?.groups?.bundle;
1538
- const id = match?.groups?.id;
1539
- if (!(id && remoteBundle)) {
1540
- throw new RemoteComponentsError(
1541
- `Remote Component module "${remoteId}" not found. Did you forget to wrap the Next.js config with \`withRemoteComponents\` on both host and remote?`
1542
- );
1543
- }
1544
- if (typeof self.__remote_webpack_require__?.[remoteBundle] !== "function") {
1545
- throw new RemoteComponentsError(
1546
- `Remote Components are not available in "${remoteBundle}". Did you forget to wrap the Next.js config with \`withRemoteComponents\` on both host and remote?`
1547
- );
1548
- }
1549
- return self.__remote_webpack_require__[remoteBundle](id);
1550
- };
1551
- self.__webpack_chunk_load__ = () => {
1552
- return Promise.resolve([]);
1553
- };
1355
+ self.__remote_bundle_url__[bundle ?? "default"] = url;
1356
+ self.__webpack_get_script_filename__ = () => null;
1357
+ if (typeof self.__webpack_require__ !== "function" || self.__webpack_require_type__ !== "turbopack") {
1358
+ if (!self.__original_webpack_require__ && !self.__original_webpack_chunk_load__) {
1359
+ self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
1360
+ self.__original_webpack_require__ = self.__webpack_require__;
1361
+ }
1362
+ self.__webpack_chunk_load__ = createChunkLoader(runtime, resolveClientUrl);
1363
+ self.__webpack_require__ = createModuleRequire(runtime);
1364
+ self.__webpack_require_type__ = runtime;
1365
+ if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
1366
+ const remoteBundle = bundle ?? "default";
1367
+ self.__remote_webpack_require__[remoteBundle] = self.__webpack_require__;
1368
+ self.__remote_webpack_require__[remoteBundle].type = "turbopack";
1369
+ }
1554
1370
  }
1555
- const {
1556
- default: { createFromReadableStream }
1557
- } = await import("react-server-dom-webpack/client.browser");
1558
- async function preloadScripts(scripts, url, remoteBundle, _) {
1559
- const scriptSrcs = scripts.flatMap((script) => {
1560
- const scriptSrc = script.getAttribute("src") || script.getAttribute("data-src");
1561
- script.parentElement?.removeChild(script);
1562
- if (!scriptSrc)
1563
- return [];
1564
- return [
1565
- {
1566
- src: new URL(scriptSrc.replace(NEXT_BUNDLE_PATH_RE, "/_next/"), url).href
1567
- }
1568
- ];
1569
- });
1570
- await loadScripts(scriptSrcs, resolveClientUrl);
1571
- const hostShared = {
1572
- ...sharedPolyfills(shared),
1573
- ...self.__remote_component_host_shared_modules__,
1574
- ...shared
1575
- };
1576
- const resolve = {
1577
- "/react/index.js": (await import("react")).default,
1578
- "/react/jsx-dev-runtime.js": (await import("react/jsx-dev-runtime")).default,
1579
- "/react/jsx-runtime.js": (await import("react/jsx-runtime")).default,
1580
- "/react-dom/index.js": (await import("react-dom")).default,
1581
- "/react-dom/client.js": (await import("react-dom/client")).default,
1582
- ...Object.entries(remoteShared ?? {}).reduce(
1583
- (acc, [key, value]) => {
1584
- if (typeof hostShared[value] !== "undefined") {
1585
- acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
1586
- }
1587
- return acc;
1588
- },
1589
- {}
1590
- )
1591
- };
1371
+ if (runtime === RUNTIME_TURBOPACK) {
1592
1372
  await Promise.all(
1593
- Object.entries(resolve).map(async ([key, value]) => {
1594
- if (typeof value === "function") {
1595
- resolve[key] = await value(remoteBundle);
1373
+ scripts.map((script) => {
1374
+ if (script.src) {
1375
+ return self.__webpack_chunk_load__?.(script.src, bundle);
1596
1376
  }
1597
- return Promise.resolve(value);
1377
+ return Promise.resolve(void 0);
1598
1378
  })
1599
1379
  );
1600
- applySharedModules(remoteBundle, resolve);
1601
1380
  }
1602
- return {
1603
- self,
1604
- createFromReadableStream,
1605
- applySharedModules,
1606
- nextClientPagesLoader,
1607
- preloadScripts
1381
+ const coreShared = {
1382
+ react: async () => (await import("react")).default,
1383
+ "react-dom": async () => (await import("react-dom")).default,
1384
+ "react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
1385
+ "react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
1386
+ "react-dom/client": async () => (await import("react-dom/client")).default,
1387
+ ...shared
1608
1388
  };
1389
+ await initializeSharedModules(
1390
+ bundle ?? "default",
1391
+ // include all core modules as shared
1392
+ coreShared,
1393
+ remoteShared
1394
+ );
1609
1395
  }
1610
- var init_webpack = __esm({
1611
- "src/html/host/runtime/webpack.ts"() {
1396
+ function createModuleRequire(runtime) {
1397
+ return (id) => {
1398
+ const self = globalThis;
1399
+ const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
1400
+ bundle: "default",
1401
+ id
1402
+ };
1403
+ const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
1404
+ logDebug("WebpackRuntime", `remoteRuntime: "${remoteRuntime}"`);
1405
+ try {
1406
+ if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
1407
+ return self.__remote_webpack_require__?.[bundle]?.(moduleId);
1408
+ }
1409
+ const sharedModuleId = moduleId ?? id;
1410
+ const sharedModule = getSharedModule(bundle ?? "default", sharedModuleId);
1411
+ if (sharedModule) {
1412
+ return sharedModule;
1413
+ }
1414
+ if (bundle && moduleId) {
1415
+ return handleTurbopackModule(bundle, moduleId, id);
1416
+ }
1417
+ throw new Error(`Module "${id}" not found.`);
1418
+ } catch (requireError) {
1419
+ logWarn(
1420
+ "WebpackRuntime",
1421
+ `Module require failed: ${String(requireError)}`
1422
+ );
1423
+ if (typeof self.__original_webpack_require__ !== "function") {
1424
+ throw new RemoteComponentsError(
1425
+ `Module "${id}" not found in remote component bundle "${bundle}".`,
1426
+ {
1427
+ cause: requireError instanceof Error ? requireError : void 0
1428
+ }
1429
+ );
1430
+ }
1431
+ try {
1432
+ logDebug("WebpackRuntime", "Falling back to original webpack require");
1433
+ return self.__original_webpack_require__(id);
1434
+ } catch (originalError) {
1435
+ throw new RemoteComponentsError(
1436
+ `Module "${id}" not found in remote component bundle "${bundle}".`,
1437
+ { cause: originalError instanceof Error ? originalError : void 0 }
1438
+ );
1439
+ }
1440
+ }
1441
+ };
1442
+ }
1443
+ var init_webpack_runtime = __esm({
1444
+ "src/runtime/turbopack/webpack-runtime.ts"() {
1612
1445
  "use strict";
1613
- init_polyfill();
1614
- init_script_loader();
1615
- init_webpack_patterns();
1446
+ init_constants2();
1616
1447
  init_error();
1617
- init_next_client_pages_loader();
1448
+ init_logger();
1449
+ init_chunk_loader();
1450
+ init_module();
1618
1451
  init_shared_modules();
1619
1452
  }
1620
1453
  });
1621
1454
 
1622
- // src/html/host/runtime/turbopack.ts
1455
+ // src/host/html/runtime/turbopack.ts
1623
1456
  var turbopack_exports = {};
1624
1457
  __export(turbopack_exports, {
1625
1458
  turbopackRuntime: () => turbopackRuntime
@@ -1627,7 +1460,7 @@ __export(turbopack_exports, {
1627
1460
  async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClientUrl) {
1628
1461
  const self = globalThis;
1629
1462
  const hostShared = {
1630
- ...sharedPolyfills(shared),
1463
+ ...sharedPolyfills(shared, resolveClientUrl),
1631
1464
  ...self.__remote_component_host_shared_modules__,
1632
1465
  ...shared,
1633
1466
  ...self.__remote_component_shared__
@@ -1657,25 +1490,181 @@ async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClient
1657
1490
  resolveClientUrl
1658
1491
  );
1659
1492
  }
1660
- return {
1661
- self,
1662
- createFromReadableStream,
1663
- applySharedModules,
1664
- nextClientPagesLoader,
1665
- preloadScripts
1666
- };
1493
+ return {
1494
+ self,
1495
+ createFromReadableStream,
1496
+ applySharedModules,
1497
+ nextClientPagesLoader,
1498
+ preloadScripts
1499
+ };
1500
+ }
1501
+ var init_turbopack = __esm({
1502
+ "src/host/html/runtime/turbopack.ts"() {
1503
+ "use strict";
1504
+ init_apply_shared_modules();
1505
+ init_next_client_pages_loader();
1506
+ init_polyfill();
1507
+ init_webpack_runtime();
1508
+ }
1509
+ });
1510
+
1511
+ // src/runtime/loaders/static-loader.ts
1512
+ async function importViaCallback(absoluteSrc, resolveClientUrl) {
1513
+ const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
1514
+ const fetchUrl = new URL(resolvedUrl, location.href).href;
1515
+ const response = await fetch(fetchUrl);
1516
+ if (!response.ok)
1517
+ throw new Error(`Proxied fetch failed: ${response.status}`);
1518
+ const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
1519
+ /\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
1520
+ (_, keyword, quote, relativePath) => {
1521
+ const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
1522
+ const resolvedImportUrl = new URL(
1523
+ resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
1524
+ location.href
1525
+ ).href;
1526
+ return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
1527
+ }
1528
+ );
1529
+ const moduleBlobUrl = URL.createObjectURL(
1530
+ new Blob([content], { type: "text/javascript" })
1531
+ );
1532
+ const wrapperContent = [
1533
+ `import*as m from${JSON.stringify(moduleBlobUrl)};`,
1534
+ `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
1535
+ `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
1536
+ ].join("");
1537
+ const wrapperBlobUrl = URL.createObjectURL(
1538
+ new Blob([wrapperContent], { type: "text/javascript" })
1539
+ );
1540
+ const scriptEl = document.createElement("script");
1541
+ scriptEl.type = "module";
1542
+ scriptEl.src = wrapperBlobUrl;
1543
+ try {
1544
+ await new Promise((resolve, reject) => {
1545
+ scriptEl.onload = () => resolve();
1546
+ scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
1547
+ document.head.appendChild(scriptEl);
1548
+ });
1549
+ } finally {
1550
+ scriptEl.remove();
1551
+ URL.revokeObjectURL(moduleBlobUrl);
1552
+ URL.revokeObjectURL(wrapperBlobUrl);
1553
+ }
1554
+ const registry = globalThis.__rc_module_registry__;
1555
+ const mod = registry?.[absoluteSrc] ?? {};
1556
+ if (registry)
1557
+ delete registry[absoluteSrc];
1558
+ return mod;
1559
+ }
1560
+ async function importDirectly(absoluteSrc) {
1561
+ try {
1562
+ return await import(
1563
+ /* @vite-ignore */
1564
+ /* webpackIgnore: true */
1565
+ absoluteSrc
1566
+ );
1567
+ } catch (importError) {
1568
+ if (!absoluteSrc.startsWith("blob:")) {
1569
+ warnCrossOriginFetchError("StaticLoader", absoluteSrc);
1570
+ }
1571
+ throw importError;
1572
+ }
1573
+ }
1574
+ function resolveScriptSrc(script, url) {
1575
+ const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
1576
+ if (!rawSrc && script.textContent) {
1577
+ return URL.createObjectURL(
1578
+ new Blob(
1579
+ [script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
1580
+ { type: "text/javascript" }
1581
+ )
1582
+ );
1583
+ }
1584
+ return rawSrc;
1585
+ }
1586
+ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
1587
+ const self = globalThis;
1588
+ if (self.__remote_script_entrypoint_mount__?.[url.href]) {
1589
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
1590
+ }
1591
+ if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
1592
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
1593
+ }
1594
+ const mountUnmountSets = await Promise.all(
1595
+ scripts.map(async (script) => {
1596
+ try {
1597
+ const src = resolveScriptSrc(script, url);
1598
+ const absoluteSrc = new URL(src, url).href;
1599
+ const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
1600
+ if (src.startsWith("blob:")) {
1601
+ URL.revokeObjectURL(src);
1602
+ }
1603
+ if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
1604
+ if (!self.__remote_script_entrypoint_mount__) {
1605
+ self.__remote_script_entrypoint_mount__ = {};
1606
+ }
1607
+ if (!self.__remote_script_entrypoint_mount__[url.href]) {
1608
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
1609
+ }
1610
+ self.__remote_script_entrypoint_mount__[url.href]?.add(
1611
+ mod.mount || mod.default?.mount || (() => {
1612
+ })
1613
+ );
1614
+ }
1615
+ if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
1616
+ if (!self.__remote_script_entrypoint_unmount__) {
1617
+ self.__remote_script_entrypoint_unmount__ = {};
1618
+ }
1619
+ if (!self.__remote_script_entrypoint_unmount__[url.href]) {
1620
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
1621
+ }
1622
+ self.__remote_script_entrypoint_unmount__[url.href]?.add(
1623
+ mod.unmount || mod.default?.unmount || (() => {
1624
+ })
1625
+ );
1626
+ }
1627
+ return {
1628
+ mount: mod.mount || mod.default?.mount,
1629
+ unmount: mod.unmount || mod.default?.unmount
1630
+ };
1631
+ } catch (e) {
1632
+ logError(
1633
+ "StaticLoader",
1634
+ `Error loading remote component script from "${script.src || url.href}".`,
1635
+ e
1636
+ );
1637
+ return {
1638
+ mount: void 0,
1639
+ unmount: void 0
1640
+ };
1641
+ }
1642
+ })
1643
+ );
1644
+ return mountUnmountSets.reduce(
1645
+ (acc, { mount, unmount }) => {
1646
+ if (typeof mount === "function") {
1647
+ acc.mount.add(mount);
1648
+ }
1649
+ if (typeof unmount === "function") {
1650
+ acc.unmount.add(unmount);
1651
+ }
1652
+ return acc;
1653
+ },
1654
+ {
1655
+ mount: /* @__PURE__ */ new Set(),
1656
+ unmount: /* @__PURE__ */ new Set()
1657
+ }
1658
+ );
1667
1659
  }
1668
- var init_turbopack = __esm({
1669
- "src/html/host/runtime/turbopack.ts"() {
1660
+ var init_static_loader = __esm({
1661
+ "src/runtime/loaders/static-loader.ts"() {
1670
1662
  "use strict";
1671
- init_polyfill();
1672
- init_webpack_adapter();
1673
- init_next_client_pages_loader();
1674
- init_shared_modules();
1663
+ init_logger();
1675
1664
  }
1676
1665
  });
1677
1666
 
1678
- // src/html/host/runtime/script.ts
1667
+ // src/host/html/runtime/script.ts
1679
1668
  var script_exports = {};
1680
1669
  __export(script_exports, {
1681
1670
  scriptRuntime: () => scriptRuntime
@@ -1694,17 +1683,101 @@ function scriptRuntime(resolveClientUrl) {
1694
1683
  };
1695
1684
  }
1696
1685
  var init_script = __esm({
1697
- "src/html/host/runtime/script.ts"() {
1686
+ "src/host/html/runtime/script.ts"() {
1698
1687
  "use strict";
1699
1688
  init_static_loader();
1700
1689
  }
1701
1690
  });
1702
1691
 
1703
- // src/html/host/index.tsx
1692
+ // src/host/html/index.tsx
1704
1693
  import { startTransition, useLayoutEffect } from "react";
1705
1694
  import { hydrateRoot } from "react-dom/client";
1706
1695
 
1707
- // src/shared/client/apply-origin.ts
1696
+ // src/host/server/fetch-with-hooks.ts
1697
+ init_logger();
1698
+
1699
+ // src/host/server/fetch-headers.ts
1700
+ function remoteFetchHeaders() {
1701
+ return {
1702
+ /**
1703
+ * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
1704
+ * If the remote component uses vercel deployment protection, ensure the host and remote vercel
1705
+ * projects share a common automation bypass secret, and the shared secret is used as the
1706
+ * VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
1707
+ */
1708
+ ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
1709
+ "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
1710
+ } : {},
1711
+ Accept: "text/html"
1712
+ };
1713
+ }
1714
+
1715
+ // src/host/server/fetch-with-hooks.ts
1716
+ async function fetchWithWarning(url, init) {
1717
+ try {
1718
+ return await fetch(url, init);
1719
+ } catch (error) {
1720
+ warnCrossOriginFetchError("FetchRemoteComponent", url);
1721
+ throw error;
1722
+ }
1723
+ }
1724
+ async function fetchWithHooks(url, additionalInit, options = {}) {
1725
+ const {
1726
+ onRequest,
1727
+ onResponse,
1728
+ abortController = new AbortController()
1729
+ } = options;
1730
+ const signal = abortController.signal;
1731
+ const hookOptions = {
1732
+ signal,
1733
+ abort: (reason) => abortController.abort(reason)
1734
+ };
1735
+ const init = {
1736
+ method: "GET",
1737
+ headers: remoteFetchHeaders(),
1738
+ signal,
1739
+ ...additionalInit
1740
+ };
1741
+ const res = await onRequest?.(url, init, hookOptions) ?? await fetchWithWarning(url, init);
1742
+ return await onResponse?.(url, res, hookOptions) ?? res;
1743
+ }
1744
+
1745
+ // src/host/server/get-client-or-server-url.ts
1746
+ function getClientOrServerUrl(src, serverFallback) {
1747
+ const fallback = typeof location !== "undefined" ? location.href : serverFallback;
1748
+ if (!src) {
1749
+ return new URL(fallback);
1750
+ }
1751
+ return typeof src === "string" ? new URL(src, fallback) : src;
1752
+ }
1753
+
1754
+ // src/host/shared/state.ts
1755
+ function createHostState() {
1756
+ return {
1757
+ stage: "idle",
1758
+ prevSrc: void 0,
1759
+ prevUrl: void 0,
1760
+ prevName: void 0,
1761
+ prevIsRemoteComponent: false,
1762
+ abortController: void 0
1763
+ };
1764
+ }
1765
+
1766
+ // src/host/utils/resolve-name-from-src.ts
1767
+ function resolveNameFromSrc(src, defaultName) {
1768
+ if (!src) {
1769
+ return defaultName;
1770
+ }
1771
+ const hash = typeof src === "string" ? src : src.hash;
1772
+ const hashIndex = hash.indexOf("#");
1773
+ if (hashIndex < 0) {
1774
+ return defaultName;
1775
+ }
1776
+ const name = hash.slice(hashIndex + 1);
1777
+ return name || defaultName;
1778
+ }
1779
+
1780
+ // src/runtime/html/apply-origin.ts
1708
1781
  var tagNames = [
1709
1782
  "img",
1710
1783
  "source",
@@ -1766,49 +1839,103 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
1766
1839
  }
1767
1840
  }
1768
1841
 
1769
- // src/shared/client/proxy-through-host.ts
1770
- init_protected_rc_fallback();
1771
- function withRemoteSrc(resolveClientUrl, remoteSrc) {
1772
- return (url) => resolveClientUrl(remoteSrc, url);
1773
- }
1774
- var proxyClientRequestsThroughHost = (remoteSrc, url) => {
1775
- if (typeof location === "undefined") {
1776
- return void 0;
1777
- }
1778
- const remoteOrigin = new URL(remoteSrc, location.href).origin;
1779
- if (remoteOrigin === location.origin) {
1780
- return void 0;
1842
+ // src/runtime/html/parse-remote-html.ts
1843
+ init_constants2();
1844
+ init_error();
1845
+ function validateSingleComponent(doc, name, url) {
1846
+ if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
1847
+ throw multipleRemoteComponentsError(url);
1781
1848
  }
1782
- try {
1783
- const parsed = new URL(url, location.href);
1784
- if (parsed.origin === remoteOrigin) {
1785
- return generateProtectedRcFallbackSrc(url);
1786
- }
1787
- } catch {
1849
+ }
1850
+ function findComponentElement(doc, name) {
1851
+ return doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) ?? doc.querySelector("div[data-bundle][data-route]") ?? doc.querySelector("div#__next") ?? doc.querySelector(`remote-component[name="${name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
1852
+ }
1853
+ function parseNextData(doc) {
1854
+ return JSON.parse(
1855
+ (doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
1856
+ );
1857
+ }
1858
+ function resolveComponentName(component, nextData, fallbackName) {
1859
+ const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
1860
+ const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
1861
+ return { name, isRemoteComponent };
1862
+ }
1863
+ function extractComponentMetadata(component, nextData, name, url) {
1864
+ return {
1865
+ name,
1866
+ bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
1867
+ route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
1868
+ runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
1869
+ };
1870
+ }
1871
+ function extractRemoteShared(doc, name, nextData) {
1872
+ const remoteSharedEl = doc.querySelector(
1873
+ `#${name}_shared[data-remote-components-shared]`
1874
+ );
1875
+ const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
1876
+ remoteSharedEl?.remove();
1877
+ return remoteShared;
1878
+ }
1879
+ function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
1880
+ if (!component || !(rsc || nextData || isRemoteComponent)) {
1881
+ throw new RemoteComponentsError(
1882
+ `Remote Component not found on ${url}.${name !== "__vercel_remote_component" ? ` The name for the <RemoteComponent> is "${name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
1883
+ );
1788
1884
  }
1789
- return void 0;
1790
- };
1791
-
1792
- // src/shared/client/default-resolve-client-url.ts
1793
- function bindResolveClientUrl(prop, remoteSrc) {
1794
- return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
1885
+ }
1886
+ function extractLinks(doc, component) {
1887
+ return Array.from(doc.querySelectorAll("link[href]")).filter(
1888
+ (link) => !component.contains(link)
1889
+ );
1890
+ }
1891
+ function extractScripts(doc, component, isRemoteComponent) {
1892
+ return Array.from(
1893
+ (isRemoteComponent ? component : doc).querySelectorAll(
1894
+ "script[src],script[data-src]"
1895
+ )
1896
+ );
1897
+ }
1898
+ function parseRemoteComponentDocument(doc, name, url) {
1899
+ validateSingleComponent(doc, name, url.href);
1900
+ const component = findComponentElement(doc, name);
1901
+ const nextData = parseNextData(doc);
1902
+ const { name: resolvedName, isRemoteComponent } = resolveComponentName(
1903
+ component,
1904
+ nextData,
1905
+ name
1906
+ );
1907
+ const rsc = doc.querySelector(`#${resolvedName}_rsc`);
1908
+ const metadata = extractComponentMetadata(
1909
+ component,
1910
+ nextData,
1911
+ resolvedName,
1912
+ url
1913
+ );
1914
+ const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
1915
+ validateComponentFound(
1916
+ component,
1917
+ rsc,
1918
+ nextData,
1919
+ isRemoteComponent,
1920
+ url.href,
1921
+ resolvedName
1922
+ );
1923
+ const links = extractLinks(doc, component);
1924
+ const scripts = extractScripts(doc, component, isRemoteComponent);
1925
+ return {
1926
+ component,
1927
+ name: resolvedName,
1928
+ isRemoteComponent,
1929
+ metadata,
1930
+ nextData,
1931
+ rsc,
1932
+ remoteShared,
1933
+ links,
1934
+ scripts
1935
+ };
1795
1936
  }
1796
1937
 
1797
- // src/shared/client/remote-component.ts
1798
- init_error();
1799
-
1800
- // src/shared/client/component-loader.ts
1801
- init_error();
1802
- init_logger();
1803
- init_next_client_pages_loader();
1804
- init_shared_modules();
1805
- import * as React from "react";
1806
- import * as JSXDevRuntime from "react/jsx-dev-runtime";
1807
- import * as JSXRuntime from "react/jsx-runtime";
1808
- import * as ReactDOM from "react-dom";
1809
- import * as ReactDOMClient from "react-dom/client";
1810
-
1811
- // src/shared/client/rsc.ts
1938
+ // src/runtime/rsc.ts
1812
1939
  import { ReadableStream } from "web-streams-polyfill";
1813
1940
  function fixPayload(payload) {
1814
1941
  if (Array.isArray(payload)) {
@@ -1874,78 +2001,37 @@ function createRSCStream(rscName, data) {
1874
2001
  });
1875
2002
  }
1876
2003
 
1877
- // src/shared/client/component-loader.ts
1878
- init_script_loader();
1879
- init_webpack_adapter();
1880
-
1881
- // src/shared/client/remote-component.ts
1882
- init_const();
1883
- init_script_loader();
1884
- init_static_loader();
1885
- init_webpack_adapter();
1886
-
1887
- // src/html/host/index.tsx
1888
- init_error();
1889
-
1890
- // src/shared/ssr/fetch-with-hooks.ts
1891
- init_logger();
1892
-
1893
- // src/shared/ssr/fetch-headers.ts
1894
- function remoteFetchHeaders() {
1895
- return {
1896
- /**
1897
- * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
1898
- * If the remote component uses vercel deployment protection, ensure the host and remote vercel
1899
- * projects share a common automation bypass secret, and the shared secret is used as the
1900
- * VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
1901
- */
1902
- ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
1903
- "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
1904
- } : {},
1905
- Accept: "text/html"
2004
+ // src/runtime/url/resolve-client-url.ts
2005
+ function withRemoteSrc(resolveClientUrl, remoteSrc) {
2006
+ const remoteOrigin = parseOrigin(remoteSrc);
2007
+ return (url) => {
2008
+ const urlOrigin = parseOrigin(url);
2009
+ if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
2010
+ return void 0;
2011
+ }
2012
+ return resolveClientUrl(remoteSrc, url);
1906
2013
  };
1907
2014
  }
1908
-
1909
- // src/shared/ssr/fetch-with-hooks.ts
1910
- async function fetchWithHooks(url, additionalInit, options = {}) {
1911
- const {
1912
- onRequest,
1913
- onResponse,
1914
- abortController = new AbortController()
1915
- } = options;
1916
- const signal = abortController.signal;
1917
- const hookOptions = {
1918
- signal,
1919
- abort: (reason) => abortController.abort(reason)
1920
- };
1921
- const init = {
1922
- method: "GET",
1923
- headers: remoteFetchHeaders(),
1924
- signal,
1925
- ...additionalInit
1926
- };
1927
- let res = await onRequest?.(url, init, hookOptions);
1928
- if (!res) {
1929
- try {
1930
- res = await fetch(url, init);
1931
- } catch (error) {
1932
- warnCrossOriginFetchError("FetchRemoteComponent", url);
1933
- throw error;
1934
- }
1935
- }
1936
- const transformedRes = await onResponse?.(url, res, hookOptions);
1937
- if (transformedRes) {
1938
- res = transformedRes;
2015
+ function parseOrigin(url) {
2016
+ try {
2017
+ return new URL(url).origin;
2018
+ } catch {
2019
+ return void 0;
1939
2020
  }
1940
- return res;
1941
2021
  }
1942
2022
 
1943
- // src/html/host/index.tsx
2023
+ // src/runtime/url/default-resolve-client-url.ts
2024
+ function bindResolveClientUrl(prop, remoteSrc) {
2025
+ return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
2026
+ }
2027
+
2028
+ // src/host/html/index.tsx
1944
2029
  init_utils();
1945
2030
  init_abort();
2031
+ init_error();
1946
2032
  init_logger();
1947
2033
 
1948
- // src/html/host/attach-styles.ts
2034
+ // src/host/html/attach-styles.ts
1949
2035
  init_error();
1950
2036
  async function attachStyles({
1951
2037
  doc,
@@ -2028,7 +2114,7 @@ async function attachStyles({
2028
2114
  }
2029
2115
  }
2030
2116
 
2031
- // src/html/host/runtime/index.ts
2117
+ // src/host/html/runtime/index.ts
2032
2118
  init_error();
2033
2119
  async function getRuntime(type, url, bundle, shared, remoteShared, resolveClientUrl) {
2034
2120
  if (typeof globalThis.process === "undefined") {
@@ -2062,7 +2148,7 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
2062
2148
  );
2063
2149
  }
2064
2150
 
2065
- // src/html/host/index.tsx
2151
+ // src/host/html/index.tsx
2066
2152
  import { jsx as jsx2 } from "react/jsx-runtime";
2067
2153
  if (typeof HTMLElement !== "undefined") {
2068
2154
  class RemoteComponent extends HTMLElement {
@@ -2071,42 +2157,76 @@ if (typeof HTMLElement !== "undefined") {
2071
2157
  fallbackSlot;
2072
2158
  __next = null;
2073
2159
  fouc = null;
2074
- isLoading = false;
2075
- prevIsRemoteComponent = false;
2076
- prevUrl;
2077
- prevSrc = null;
2078
- prevName;
2160
+ hostState = createHostState();
2079
2161
  root = null;
2080
2162
  reactRoot;
2081
2163
  onRequest;
2082
2164
  onResponse;
2083
2165
  resolveClientUrl;
2084
- /** Current AbortController for the loading operation - can be used to cancel loading via controller.abort() */
2085
- abortController;
2166
+ // -- ConsumeServerConfig property accessors (attribute-reflected) --
2167
+ get src() {
2168
+ return this.getAttribute("src") ?? void 0;
2169
+ }
2170
+ set src(value) {
2171
+ if (value == null) {
2172
+ this.removeAttribute("src");
2173
+ } else {
2174
+ this.setAttribute("src", String(value));
2175
+ }
2176
+ }
2177
+ /** Always `true` — the HTML host always isolates via Shadow DOM. */
2178
+ get isolate() {
2179
+ return true;
2180
+ }
2181
+ get mode() {
2182
+ const attr = this.getAttribute("mode");
2183
+ return attr === "closed" ? "closed" : "open";
2184
+ }
2185
+ set mode(value) {
2186
+ if (value) {
2187
+ this.setAttribute("mode", value);
2188
+ }
2189
+ }
2190
+ get reset() {
2191
+ return this.getAttribute("reset") !== null;
2192
+ }
2193
+ set reset(value) {
2194
+ if (value) {
2195
+ this.setAttribute("reset", "");
2196
+ } else {
2197
+ this.removeAttribute("reset");
2198
+ }
2199
+ }
2200
+ get credentials() {
2201
+ return this.getAttribute("credentials") || "same-origin";
2202
+ }
2203
+ set credentials(value) {
2204
+ if (value) {
2205
+ this.setAttribute("credentials", value);
2206
+ } else {
2207
+ this.removeAttribute("credentials");
2208
+ }
2209
+ }
2086
2210
  static get observedAttributes() {
2087
2211
  return ["src", "name", "mode"];
2088
2212
  }
2089
- // watch for src attribute changes
2090
- // this is required to reload the remote component when the src attribute is added later
2091
- // this is for rendering the custom element using React
2213
+ dispatchLifecycleEvent(type, detail) {
2214
+ const event = new Event(type, { bubbles: true, composed: true });
2215
+ if (detail) {
2216
+ Object.assign(event, detail);
2217
+ }
2218
+ this.dispatchEvent(event);
2219
+ }
2092
2220
  attributeChangedCallback(name, oldValue, newValue) {
2093
2221
  if ((name === "src" || name === "name") && oldValue !== newValue) {
2094
- if (this.getAttribute("src")) {
2222
+ if (this.src) {
2095
2223
  this.load().catch((e) => {
2096
2224
  if (isAbortError(e)) {
2097
2225
  return;
2098
2226
  }
2099
2227
  logError("HtmlHost", "Error loading remote component.", e);
2100
- const errorEvent = new Event("error", {
2101
- bubbles: true,
2102
- composed: true
2103
- });
2104
- Object.assign(errorEvent, {
2105
- error: e,
2106
- src: this.getAttribute("src")
2107
- });
2108
- this.dispatchEvent(errorEvent);
2109
- this.isLoading = false;
2228
+ this.dispatchLifecycleEvent("error", { error: e, src: this.src });
2229
+ this.hostState.stage = "error";
2110
2230
  });
2111
2231
  }
2112
2232
  } else if (name === "mode" && oldValue !== newValue && this.root) {
@@ -2122,15 +2242,7 @@ if (typeof HTMLElement !== "undefined") {
2122
2242
  return;
2123
2243
  }
2124
2244
  logError("HtmlHost", "Error reloading remote component.", e);
2125
- const errorEvent = new Event("error", {
2126
- bubbles: true,
2127
- composed: true
2128
- });
2129
- Object.assign(errorEvent, {
2130
- error: e,
2131
- src: this.getAttribute("src")
2132
- });
2133
- this.dispatchEvent(errorEvent);
2245
+ this.dispatchLifecycleEvent("error", { error: e, src: this.src });
2134
2246
  });
2135
2247
  }
2136
2248
  }
@@ -2140,9 +2252,9 @@ if (typeof HTMLElement !== "undefined") {
2140
2252
  resolve(void 0);
2141
2253
  });
2142
2254
  });
2143
- if (this.isLoading) {
2144
- this.abortController?.abort();
2145
- this.isLoading = false;
2255
+ if (this.hostState.stage === "loading") {
2256
+ this.hostState.abortController?.abort();
2257
+ this.hostState.stage = "idle";
2146
2258
  if (this.root && !this.reactRoot) {
2147
2259
  this.root.innerHTML = "";
2148
2260
  this.fouc = null;
@@ -2152,29 +2264,24 @@ if (typeof HTMLElement !== "undefined") {
2152
2264
  }
2153
2265
  if (!this.root) {
2154
2266
  this.root = this.attachShadow({
2155
- mode: this.getAttribute("mode") === "closed" ? "closed" : "open"
2267
+ mode: this.mode === "closed" ? "closed" : "open"
2156
2268
  });
2157
2269
  this.fallbackSlot = document.createElement("slot");
2158
2270
  this.root.appendChild(this.fallbackSlot);
2159
2271
  }
2160
2272
  this.name = this.getAttribute("name") || "__vercel_remote_component";
2161
2273
  this.bundle = "default";
2162
- this.isLoading = true;
2163
- const src = this.getAttribute("src");
2164
- this.abortController = new AbortController();
2165
- const signal = this.abortController.signal;
2166
- const isCurrentLoad = () => !signal.aborted && this.getAttribute("src") === src;
2274
+ this.hostState.stage = "loading";
2275
+ const src = this.src;
2276
+ this.hostState.abortController = new AbortController();
2277
+ const signal = this.hostState.abortController.signal;
2278
+ const isCurrentLoad = () => !signal.aborted && this.src === src;
2167
2279
  const abandonLoad = () => {
2168
- if (this.abortController?.signal === signal && this.isLoading) {
2169
- this.isLoading = false;
2280
+ if (this.hostState.abortController?.signal === signal && this.hostState.stage === "loading") {
2281
+ this.hostState.stage = "idle";
2170
2282
  }
2171
2283
  };
2172
- const beforeLoadEvent = new Event("beforeload", {
2173
- bubbles: true,
2174
- composed: true
2175
- });
2176
- Object.assign(beforeLoadEvent, { src });
2177
- this.dispatchEvent(beforeLoadEvent);
2284
+ this.dispatchLifecycleEvent("beforeload", { src });
2178
2285
  const remoteComponentChild = this.querySelector("div#__REMOTE_COMPONENT__") || this.querySelector("div[data-bundle][data-route]");
2179
2286
  if (!src && !remoteComponentChild) {
2180
2287
  throw new RemoteComponentsError('"src" attribute is required');
@@ -2182,15 +2289,16 @@ if (typeof HTMLElement !== "undefined") {
2182
2289
  let url = null;
2183
2290
  let html = this.innerHTML;
2184
2291
  if (src) {
2185
- url = new URL(src, window.location.href);
2186
- if (url.hash) {
2187
- this.name = url.hash.slice(1);
2188
- }
2292
+ url = getClientOrServerUrl(src, window.location.href);
2293
+ this.name = resolveNameFromSrc(
2294
+ src,
2295
+ this.name ?? "__vercel_remote_component"
2296
+ );
2189
2297
  }
2190
2298
  const resolveClientUrl = url ? bindResolveClientUrl(this.resolveClientUrl, url.href) : void 0;
2191
2299
  if (!remoteComponentChild && url) {
2192
2300
  const fetchInit = {
2193
- credentials: this.getAttribute("credentials") || "same-origin"
2301
+ credentials: this.credentials || "same-origin"
2194
2302
  };
2195
2303
  const resolvedUrl = new URL(
2196
2304
  resolveClientUrl?.(url.href) ?? url.href,
@@ -2201,7 +2309,7 @@ if (typeof HTMLElement !== "undefined") {
2201
2309
  res = await fetchWithHooks(resolvedUrl, fetchInit, {
2202
2310
  onRequest: this.onRequest,
2203
2311
  onResponse: this.onResponse,
2204
- abortController: this.abortController
2312
+ abortController: this.hostState.abortController
2205
2313
  });
2206
2314
  } catch (e) {
2207
2315
  if (isAbortError(e)) {
@@ -2226,29 +2334,27 @@ if (typeof HTMLElement !== "undefined") {
2226
2334
  }
2227
2335
  const parser = new DOMParser();
2228
2336
  const doc = parser.parseFromString(html, "text/html");
2229
- if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
2230
- `div[data-bundle][data-route][id^="${this.name}"]`
2231
- ) || doc.querySelectorAll("remote-component").length > 1 && !doc.querySelector(`remote-component[name="${this.name}"]`)) {
2232
- throw multipleRemoteComponentsError(
2233
- url?.href ?? (this.getAttribute("src") || "unknown")
2234
- );
2235
- }
2236
- const component = doc.querySelector(`div[data-bundle][data-route][id^="${this.name}"]`) ?? // fallback to the first element with the data-bundle and data-route attributes when not using a named remote component
2237
- doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
2238
- doc.querySelector("div#__next") ?? // fallback to a <remote-component> element
2239
- doc.querySelector(`remote-component[name="${this.name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
2240
- const nextData = JSON.parse(
2241
- (doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
2337
+ const parsed = parseRemoteComponentDocument(
2338
+ doc,
2339
+ this.name ?? "__vercel_remote_component",
2340
+ url ?? new URL(window.location.href)
2242
2341
  );
2243
- const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
2342
+ const {
2343
+ component,
2344
+ name: resolvedName,
2345
+ isRemoteComponent,
2346
+ metadata: parsedMetadata,
2347
+ nextData,
2348
+ rsc,
2349
+ remoteShared
2350
+ } = parsed;
2244
2351
  if (nextData && nextData.buildId === "development" && !this.reactRoot) {
2245
2352
  this.fouc = document.createElement("style");
2246
2353
  this.fouc.textContent = `:host { display: none; }`;
2247
2354
  this.root.appendChild(this.fouc);
2248
2355
  }
2249
- this.name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component.getAttribute("name") || (nextData ? "__next" : this.name);
2250
- const rsc = doc.querySelector(`#${this.name}_rsc`);
2251
- this.bundle = component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || this.bundle;
2356
+ this.name = resolvedName;
2357
+ this.bundle = parsedMetadata.bundle;
2252
2358
  if (url) {
2253
2359
  const self2 = globalThis;
2254
2360
  if (!self2.__remote_bundle_url__) {
@@ -2256,38 +2362,28 @@ if (typeof HTMLElement !== "undefined") {
2256
2362
  }
2257
2363
  self2.__remote_bundle_url__[this.bundle ?? "default"] = url;
2258
2364
  }
2259
- const metadata = document.createElement("script");
2260
- metadata.type = "application/json";
2261
- metadata.setAttribute("data-remote-component", "");
2365
+ const metadataEl = document.createElement("script");
2366
+ metadataEl.type = "application/json";
2367
+ metadataEl.setAttribute("data-remote-component", "");
2262
2368
  const metadataObj = {
2263
2369
  name: this.name,
2264
2370
  bundle: this.bundle,
2265
- route: component?.getAttribute("data-route") ?? nextData?.page ?? url?.pathname ?? "/",
2266
- runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? "script"
2371
+ route: parsedMetadata.route,
2372
+ runtime: parsedMetadata.runtime
2267
2373
  };
2268
- metadata.textContent = JSON.stringify(metadataObj);
2374
+ metadataEl.textContent = JSON.stringify(metadataObj);
2269
2375
  if (this.previousElementSibling?.getAttribute("data-remote-component") !== null) {
2270
2376
  this.previousElementSibling?.remove();
2271
2377
  }
2272
- this.parentElement?.insertBefore(metadata, this);
2273
- const remoteSharedEl = doc.querySelector(
2274
- `#${this.name}_shared[data-remote-components-shared]`
2275
- );
2276
- const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
2277
- remoteSharedEl?.parentElement?.removeChild(remoteSharedEl);
2378
+ this.parentElement?.insertBefore(metadataEl, this);
2278
2379
  if ("__remote_components_missing_shared__" in remoteShared) {
2279
2380
  throw new RemoteComponentsError(
2280
2381
  remoteShared.__remote_components_missing_shared__
2281
2382
  );
2282
2383
  }
2283
- if (!component || !(rsc || nextData || isRemoteComponent)) {
2284
- throw new RemoteComponentsError(
2285
- `Remote Component not found on ${src}.${this.name !== "__vercel_remote_component" ? ` The name for the <RemoteComponent> is "${this.name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
2286
- );
2287
- }
2288
- if (this.prevIsRemoteComponent) {
2289
- if (this.prevUrl) {
2290
- const prevUrl = this.prevUrl;
2384
+ if (this.hostState.prevIsRemoteComponent) {
2385
+ if (this.hostState.prevUrl) {
2386
+ const prevUrl = this.hostState.prevUrl;
2291
2387
  const self2 = globalThis;
2292
2388
  if (self2.__remote_script_entrypoint_unmount__?.[prevUrl.href]) {
2293
2389
  await Promise.all(
@@ -2312,26 +2408,21 @@ if (typeof HTMLElement !== "undefined") {
2312
2408
  }
2313
2409
  this.root.innerHTML = "";
2314
2410
  }
2315
- if (this.prevSrc !== null) {
2316
- const changeEvent = new Event("change", {
2317
- bubbles: true,
2318
- composed: true
2319
- });
2320
- Object.assign(changeEvent, {
2321
- previousSrc: this.prevSrc,
2411
+ if (this.hostState.prevSrc !== void 0) {
2412
+ this.dispatchLifecycleEvent("change", {
2413
+ previousSrc: this.hostState.prevSrc,
2322
2414
  nextSrc: src,
2323
- previousName: this.prevName,
2415
+ previousName: this.hostState.prevName,
2324
2416
  nextName: this.name
2325
2417
  });
2326
- this.dispatchEvent(changeEvent);
2327
2418
  }
2328
- this.prevUrl = url ?? new URL(window.location.href);
2329
- this.prevIsRemoteComponent = isRemoteComponent;
2330
- this.prevSrc = src;
2331
- this.prevName = this.name;
2419
+ this.hostState.prevUrl = url ?? new URL(window.location.href);
2420
+ this.hostState.prevIsRemoteComponent = isRemoteComponent;
2421
+ this.hostState.prevSrc = src;
2422
+ this.hostState.prevName = this.name;
2332
2423
  const removable = Array.from(this.childNodes);
2333
2424
  const links = doc.querySelectorAll("link[href]");
2334
- const remoteComponentSrc = this.getAttribute("src");
2425
+ const remoteComponentSrc = this.src ? String(this.src) : null;
2335
2426
  const doAttachStyles = () => attachStyles({
2336
2427
  doc,
2337
2428
  component,
@@ -2405,7 +2496,7 @@ if (typeof HTMLElement !== "undefined") {
2405
2496
  }
2406
2497
  this.fallbackSlot?.remove();
2407
2498
  const applyReset = () => {
2408
- if (this.getAttribute("reset") !== null && !this.root?.querySelector("link[data-remote-components-reset]")) {
2499
+ if (this.reset && !this.root?.querySelector("link[data-remote-components-reset]")) {
2409
2500
  const allInitial = document.createElement("link");
2410
2501
  allInitial.setAttribute("data-remote-components-reset", "");
2411
2502
  const css = `:host { all: initial; }`;
@@ -2423,7 +2514,7 @@ if (typeof HTMLElement !== "undefined") {
2423
2514
  allInitial.removeAttribute("onload");
2424
2515
  };
2425
2516
  this.root?.prepend(allInitial);
2426
- } else if (this.getAttribute("reset") === null && this.root?.querySelector("link[data-remote-components-reset]")) {
2517
+ } else if (!this.reset && this.root?.querySelector("link[data-remote-components-reset]")) {
2427
2518
  this.root.querySelector("link[data-remote-components-reset]")?.remove();
2428
2519
  }
2429
2520
  };
@@ -2531,14 +2622,9 @@ if (typeof HTMLElement !== "undefined") {
2531
2622
  });
2532
2623
  }
2533
2624
  if (isCurrentLoad()) {
2534
- this.isLoading = false;
2625
+ this.hostState.stage = "loaded";
2535
2626
  }
2536
- const loadEvent = new Event("load", {
2537
- bubbles: true,
2538
- composed: true
2539
- });
2540
- Object.assign(loadEvent, { src: this.getAttribute("src") });
2541
- this.dispatchEvent(loadEvent);
2627
+ this.dispatchLifecycleEvent("load", { src: this.src });
2542
2628
  }, [initial, name]);
2543
2629
  return Component;
2544
2630
  };
@@ -2572,7 +2658,7 @@ if (typeof HTMLElement !== "undefined") {
2572
2658
  } else if (nextData) {
2573
2659
  const { Component, App } = nextClientPagesLoader2(
2574
2660
  this.bundle ?? "default",
2575
- nextData.page,
2661
+ nextData.page ?? "/",
2576
2662
  this.root
2577
2663
  );
2578
2664
  if (Component) {
@@ -2586,16 +2672,11 @@ if (typeof HTMLElement !== "undefined") {
2586
2672
  });
2587
2673
  }
2588
2674
  if (isCurrentLoad()) {
2589
- remoteComponent.isLoading = false;
2675
+ remoteComponent.hostState.stage = "loaded";
2590
2676
  }
2591
- const loadEvent = new Event("load", {
2592
- bubbles: true,
2593
- composed: true
2594
- });
2595
- Object.assign(loadEvent, {
2596
- src: remoteComponent.getAttribute("src")
2677
+ remoteComponent.dispatchLifecycleEvent("load", {
2678
+ src: remoteComponent.src
2597
2679
  });
2598
- remoteComponent.dispatchEvent(loadEvent);
2599
2680
  }, [initial, remoteComponent]);
2600
2681
  return NextApp ? /* @__PURE__ */ jsx2(NextApp, { Component: NextComponent, ...nextData.props }) : /* @__PURE__ */ jsx2(NextComponent, { ...nextData.props });
2601
2682
  })(App, Component, this);
@@ -2605,7 +2686,7 @@ if (typeof HTMLElement !== "undefined") {
2605
2686
  root.render(/* @__PURE__ */ jsx2(RemoteComponentFromNext, { initial: false }));
2606
2687
  doCleanup();
2607
2688
  if (isCurrentLoad()) {
2608
- this.isLoading = false;
2689
+ this.hostState.stage = "loaded";
2609
2690
  }
2610
2691
  });
2611
2692
  return;
@@ -2636,22 +2717,12 @@ if (typeof HTMLElement !== "undefined") {
2636
2717
  }
2637
2718
  })
2638
2719
  );
2639
- const loadEvent = new Event("load", {
2640
- bubbles: true,
2641
- composed: true
2642
- });
2643
- Object.assign(loadEvent, { src: this.getAttribute("src") });
2644
- this.dispatchEvent(loadEvent);
2720
+ this.dispatchLifecycleEvent("load", { src: this.src });
2645
2721
  } else {
2646
- const loadEvent = new Event("load", {
2647
- bubbles: true,
2648
- composed: true
2649
- });
2650
- Object.assign(loadEvent, { src: this.getAttribute("src") });
2651
- this.dispatchEvent(loadEvent);
2722
+ this.dispatchLifecycleEvent("load", { src: this.src });
2652
2723
  }
2653
2724
  if (isCurrentLoad()) {
2654
- this.isLoading = false;
2725
+ this.hostState.stage = "loaded";
2655
2726
  }
2656
2727
  }
2657
2728
  }
@@ -2669,7 +2740,6 @@ function registerSharedModules(modules = {}) {
2669
2740
  });
2670
2741
  }
2671
2742
  export {
2672
- proxyClientRequestsThroughHost,
2673
2743
  registerSharedModules
2674
2744
  };
2675
- //# sourceMappingURL=host.js.map
2745
+ //# sourceMappingURL=html.js.map