remote-components 0.1.2 → 0.2.1

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 (470) hide show
  1. package/dist/{next/config.cjs → config/nextjs.cjs} +77 -102
  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} +73 -98
  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} +1019 -1080
  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} +1016 -1076
  22. package/dist/host/html.js.map +1 -0
  23. package/dist/{next/host/client/index.cjs → host/nextjs/app/client-only.cjs} +685 -623
  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} +687 -618
  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/{next/host/pages-router-server.d.ts → host/nextjs/pages.d.ts} +11 -13
  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/host/proxy/client.cjs +57 -0
  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} +524 -555
  58. package/dist/host/react.cjs.map +1 -0
  59. package/dist/{component-loader-21865da3.d.ts → host/react.d.ts} +141 -99
  60. package/dist/{react/index.js → host/react.js} +523 -552
  61. package/dist/host/react.js.map +1 -0
  62. package/dist/internal/{webpack/shared-modules.cjs → config/webpack/apply-shared-modules.cjs} +18 -17
  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} +15 -14
  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} +29 -24
  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} +19 -19
  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/{next/remote/server.cjs → internal/host/server/types.cjs} +3 -15
  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/{host-config-58cdccea.d.ts → internal/host/shared/config.d.ts} +32 -19
  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-2b26a246.d.ts → internal/host/shared/fetch-interceptors.d.ts} +4 -87
  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/internal/{shared/contract/host-state.cjs → host/shared/state.cjs} +4 -4
  161. package/dist/internal/host/shared/state.cjs.map +1 -0
  162. package/dist/internal/{shared/contract/host-state.js → host/shared/state.js} +1 -1
  163. package/dist/internal/host/shared/state.js.map +1 -0
  164. package/dist/internal/host/utils/resolve-name-from-src.cjs.map +1 -0
  165. package/dist/internal/host/utils/resolve-name-from-src.js.map +1 -0
  166. package/dist/internal/{next/remote/render-client.cjs → remote/nextjs/app-client.cjs} +8 -8
  167. package/dist/internal/remote/nextjs/app-client.cjs.map +1 -0
  168. package/dist/internal/{next/remote/render-client.js → remote/nextjs/app-client.js} +4 -4
  169. package/dist/internal/remote/nextjs/app-client.js.map +1 -0
  170. package/dist/internal/runtime/constants.cjs +50 -0
  171. package/dist/internal/runtime/constants.cjs.map +1 -0
  172. package/dist/internal/runtime/constants.d.ts +10 -0
  173. package/dist/internal/runtime/constants.js +20 -0
  174. package/dist/internal/runtime/constants.js.map +1 -0
  175. package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs.map +1 -1
  176. package/dist/internal/{shared/client → runtime/html}/apply-origin.d.ts +1 -1
  177. package/dist/internal/{shared/client → runtime/html}/apply-origin.js.map +1 -1
  178. package/dist/internal/runtime/html/parse-remote-html.cjs +140 -0
  179. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -0
  180. package/dist/internal/runtime/html/parse-remote-html.d.ts +88 -0
  181. package/dist/internal/runtime/html/parse-remote-html.js +110 -0
  182. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -0
  183. package/dist/internal/runtime/html/set-attributes-from-props.cjs +68 -0
  184. package/dist/internal/runtime/html/set-attributes-from-props.cjs.map +1 -0
  185. package/dist/internal/runtime/html/set-attributes-from-props.d.ts +3 -0
  186. package/dist/internal/runtime/html/set-attributes-from-props.js +44 -0
  187. package/dist/internal/runtime/html/set-attributes-from-props.js.map +1 -0
  188. package/dist/internal/runtime/loaders/component-loader.cjs +184 -0
  189. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -0
  190. package/dist/internal/runtime/loaders/component-loader.d.ts +31 -0
  191. package/dist/internal/runtime/loaders/component-loader.js +150 -0
  192. package/dist/internal/runtime/loaders/component-loader.js.map +1 -0
  193. package/dist/internal/runtime/loaders/script-loader.cjs +64 -0
  194. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -0
  195. package/dist/internal/runtime/loaders/script-loader.d.ts +10 -0
  196. package/dist/internal/runtime/loaders/script-loader.js +43 -0
  197. package/dist/internal/runtime/loaders/script-loader.js.map +1 -0
  198. package/dist/internal/runtime/loaders/static-loader.cjs +177 -0
  199. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -0
  200. package/dist/internal/runtime/loaders/static-loader.d.ts +10 -0
  201. package/dist/internal/runtime/loaders/static-loader.js +153 -0
  202. package/dist/internal/runtime/loaders/static-loader.js.map +1 -0
  203. package/dist/internal/runtime/metadata.cjs +17 -0
  204. package/dist/internal/runtime/metadata.cjs.map +1 -0
  205. package/dist/internal/runtime/metadata.d.ts +16 -0
  206. package/dist/internal/runtime/metadata.js +1 -0
  207. package/dist/internal/runtime/metadata.js.map +1 -0
  208. package/dist/internal/runtime/rsc.cjs +92 -0
  209. package/dist/internal/runtime/rsc.cjs.map +1 -0
  210. package/dist/internal/runtime/rsc.d.ts +8 -0
  211. package/dist/internal/runtime/rsc.js +68 -0
  212. package/dist/internal/runtime/rsc.js.map +1 -0
  213. package/dist/internal/runtime/turbopack/chunk-loader.cjs +239 -0
  214. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -0
  215. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +11 -0
  216. package/dist/internal/runtime/turbopack/chunk-loader.js +222 -0
  217. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -0
  218. package/dist/internal/runtime/turbopack/module.cjs +257 -0
  219. package/dist/internal/runtime/turbopack/module.cjs.map +1 -0
  220. package/dist/internal/runtime/turbopack/module.d.ts +61 -0
  221. package/dist/internal/runtime/turbopack/module.js +233 -0
  222. package/dist/internal/runtime/turbopack/module.js.map +1 -0
  223. package/dist/internal/runtime/turbopack/patterns.cjs +44 -0
  224. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -0
  225. package/dist/internal/runtime/turbopack/patterns.d.ts +109 -0
  226. package/dist/internal/runtime/turbopack/patterns.js +15 -0
  227. package/dist/internal/runtime/turbopack/patterns.js.map +1 -0
  228. package/dist/internal/runtime/turbopack/shared-modules.cjs +153 -0
  229. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -0
  230. package/dist/internal/runtime/turbopack/shared-modules.d.ts +17 -0
  231. package/dist/internal/runtime/turbopack/shared-modules.js +134 -0
  232. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -0
  233. package/dist/internal/runtime/turbopack/webpack-runtime.cjs +137 -0
  234. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -0
  235. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +20 -0
  236. package/dist/internal/runtime/turbopack/webpack-runtime.js +107 -0
  237. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -0
  238. package/dist/internal/runtime/types.cjs +17 -0
  239. package/dist/internal/runtime/types.cjs.map +1 -0
  240. package/dist/internal/runtime/types.d.ts +40 -0
  241. package/dist/internal/runtime/types.js +1 -0
  242. package/dist/internal/runtime/types.js.map +1 -0
  243. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.cjs +2 -2
  244. package/dist/internal/runtime/url/default-resolve-client-url.cjs.map +1 -0
  245. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.d.ts +1 -1
  246. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.js +1 -1
  247. package/dist/internal/runtime/url/default-resolve-client-url.js.map +1 -0
  248. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.cjs +1 -1
  249. package/dist/internal/runtime/url/protected-rc-fallback.cjs.map +1 -0
  250. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.js +1 -1
  251. package/dist/internal/runtime/url/protected-rc-fallback.js.map +1 -0
  252. package/dist/internal/{shared/client/proxy-through-host.cjs → runtime/url/resolve-client-url.cjs} +4 -24
  253. package/dist/internal/runtime/url/resolve-client-url.cjs.map +1 -0
  254. package/dist/internal/{shared/client/proxy-through-host.d.ts → runtime/url/resolve-client-url.d.ts} +1 -25
  255. package/dist/internal/runtime/url/resolve-client-url.js +21 -0
  256. package/dist/internal/runtime/url/resolve-client-url.js.map +1 -0
  257. package/dist/internal/utils/abort.cjs.map +1 -0
  258. package/dist/internal/utils/abort.js.map +1 -0
  259. package/dist/internal/{shared → utils}/constants.cjs +3 -0
  260. package/dist/internal/utils/constants.cjs.map +1 -0
  261. package/dist/internal/utils/constants.d.ts +5 -0
  262. package/dist/internal/{shared → utils}/constants.js +2 -0
  263. package/dist/internal/utils/constants.js.map +1 -0
  264. package/dist/internal/{shared → utils}/error.cjs +11 -4
  265. package/dist/internal/utils/error.cjs.map +1 -0
  266. package/dist/internal/{shared → utils}/error.d.ts +2 -1
  267. package/dist/internal/{shared → utils}/error.js +10 -4
  268. package/dist/internal/utils/error.js.map +1 -0
  269. package/dist/internal/{shared/utils → utils}/logger.cjs +3 -3
  270. package/dist/internal/utils/logger.cjs.map +1 -0
  271. package/dist/internal/{shared/utils → utils}/logger.d.ts +2 -2
  272. package/dist/internal/{shared/utils → utils}/logger.js +3 -3
  273. package/dist/internal/utils/logger.js.map +1 -0
  274. package/dist/internal/utils.cjs.map +1 -0
  275. package/dist/internal/utils.js.map +1 -0
  276. package/dist/{shared/host → remote/defaults}/app.cjs +2 -6
  277. package/dist/remote/defaults/app.cjs.map +1 -0
  278. package/dist/remote/defaults/app.js +8 -0
  279. package/dist/remote/defaults/app.js.map +1 -0
  280. package/dist/{shared/host → remote/defaults}/pages.cjs +2 -6
  281. package/dist/remote/defaults/pages.cjs.map +1 -0
  282. package/dist/remote/defaults/pages.js +8 -0
  283. package/dist/remote/defaults/pages.js.map +1 -0
  284. package/dist/{shared/remote → remote/defaults}/wrapper.cjs +12 -10
  285. package/dist/remote/defaults/wrapper.cjs.map +1 -0
  286. package/dist/remote/defaults/wrapper.js +27 -0
  287. package/dist/remote/defaults/wrapper.js.map +1 -0
  288. package/dist/{html/remote.cjs → remote/html.cjs} +16 -16
  289. package/dist/remote/html.cjs.map +1 -0
  290. package/dist/{html/remote.js → remote/html.js} +16 -16
  291. package/dist/remote/html.js.map +1 -0
  292. package/dist/{shared/remote/proxy.cjs → remote/middleware.cjs} +37 -12
  293. package/dist/remote/middleware.cjs.map +1 -0
  294. package/dist/remote/middleware.d.ts +27 -0
  295. package/dist/{shared/remote/proxy.js → remote/middleware.js} +32 -5
  296. package/dist/remote/middleware.js.map +1 -0
  297. package/dist/{internal/next/remote/render-server.cjs → remote/nextjs/app.cjs} +14 -16
  298. package/dist/remote/nextjs/app.cjs.map +1 -0
  299. package/dist/{internal/next/remote/render-server.d.ts → remote/nextjs/app.d.ts} +12 -13
  300. package/dist/{internal/next/remote/render-server.js → remote/nextjs/app.js} +9 -11
  301. package/dist/remote/nextjs/app.js.map +1 -0
  302. package/dist/{next/remote/pages-router.cjs → remote/nextjs/pages.cjs} +8 -8
  303. package/dist/remote/nextjs/pages.cjs.map +1 -0
  304. package/dist/{next/remote/pages-router.d.ts → remote/nextjs/pages.d.ts} +8 -8
  305. package/dist/{next/remote/pages-router.js → remote/nextjs/pages.js} +4 -4
  306. package/dist/remote/nextjs/pages.js.map +1 -0
  307. package/dist/server-handoff-8c89b856.d.ts +46 -0
  308. package/package.json +126 -157
  309. package/dist/html/host.cjs.map +0 -1
  310. package/dist/html/host.js.map +0 -1
  311. package/dist/html/remote.cjs.map +0 -1
  312. package/dist/html/remote.js.map +0 -1
  313. package/dist/internal/next/host/app-router-client.cjs.map +0 -1
  314. package/dist/internal/next/host/app-router-client.d.ts +0 -79
  315. package/dist/internal/next/host/app-router-client.js.map +0 -1
  316. package/dist/internal/next/host/app-router-compat.cjs.map +0 -1
  317. package/dist/internal/next/host/app-router-compat.js.map +0 -1
  318. package/dist/internal/next/host/remote-component-links.cjs.map +0 -1
  319. package/dist/internal/next/host/remote-component-links.js.map +0 -1
  320. package/dist/internal/next/remote/render-client.cjs.map +0 -1
  321. package/dist/internal/next/remote/render-client.js.map +0 -1
  322. package/dist/internal/next/remote/render-server.cjs.map +0 -1
  323. package/dist/internal/next/remote/render-server.js.map +0 -1
  324. package/dist/internal/react/context.cjs.map +0 -1
  325. package/dist/internal/react/context.js.map +0 -1
  326. package/dist/internal/react/hooks/use-resolve-client-url.cjs.map +0 -1
  327. package/dist/internal/react/hooks/use-resolve-client-url.js.map +0 -1
  328. package/dist/internal/shared/client/default-resolve-client-url.cjs.map +0 -1
  329. package/dist/internal/shared/client/default-resolve-client-url.js.map +0 -1
  330. package/dist/internal/shared/client/get-client-src.cjs.map +0 -1
  331. package/dist/internal/shared/client/get-client-src.js.map +0 -1
  332. package/dist/internal/shared/client/polyfill.cjs.map +0 -1
  333. package/dist/internal/shared/client/polyfill.js.map +0 -1
  334. package/dist/internal/shared/client/protected-rc-fallback.cjs.map +0 -1
  335. package/dist/internal/shared/client/protected-rc-fallback.js.map +0 -1
  336. package/dist/internal/shared/client/proxy-through-host.cjs.map +0 -1
  337. package/dist/internal/shared/client/proxy-through-host.js +0 -40
  338. package/dist/internal/shared/client/proxy-through-host.js.map +0 -1
  339. package/dist/internal/shared/client/remote-component.cjs +0 -1436
  340. package/dist/internal/shared/client/remote-component.cjs.map +0 -1
  341. package/dist/internal/shared/client/remote-component.d.ts +0 -62
  342. package/dist/internal/shared/client/remote-component.js +0 -1385
  343. package/dist/internal/shared/client/remote-component.js.map +0 -1
  344. package/dist/internal/shared/constants.cjs.map +0 -1
  345. package/dist/internal/shared/constants.d.ts +0 -4
  346. package/dist/internal/shared/constants.js.map +0 -1
  347. package/dist/internal/shared/contract/host-state.cjs.map +0 -1
  348. package/dist/internal/shared/contract/host-state.js.map +0 -1
  349. package/dist/internal/shared/contract/resolve-name-from-src.cjs.map +0 -1
  350. package/dist/internal/shared/contract/resolve-name-from-src.js.map +0 -1
  351. package/dist/internal/shared/error.cjs.map +0 -1
  352. package/dist/internal/shared/error.js.map +0 -1
  353. package/dist/internal/shared/ssr/dom-flight.cjs.map +0 -1
  354. package/dist/internal/shared/ssr/dom-flight.d.ts +0 -2
  355. package/dist/internal/shared/ssr/dom-flight.js.map +0 -1
  356. package/dist/internal/shared/ssr/fetch-headers.cjs.map +0 -1
  357. package/dist/internal/shared/ssr/fetch-headers.js.map +0 -1
  358. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +0 -1
  359. package/dist/internal/shared/ssr/fetch-remote-component.js.map +0 -1
  360. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +0 -1
  361. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +0 -56
  362. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +0 -1
  363. package/dist/internal/shared/ssr/get-client-or-server-url.cjs.map +0 -1
  364. package/dist/internal/shared/ssr/get-client-or-server-url.js.map +0 -1
  365. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs.map +0 -1
  366. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js.map +0 -1
  367. package/dist/internal/shared/ssr/skeleton.cjs.map +0 -1
  368. package/dist/internal/shared/ssr/skeleton.js.map +0 -1
  369. package/dist/internal/shared/utils/abort.cjs.map +0 -1
  370. package/dist/internal/shared/utils/abort.js.map +0 -1
  371. package/dist/internal/shared/utils/logger.cjs.map +0 -1
  372. package/dist/internal/shared/utils/logger.js.map +0 -1
  373. package/dist/internal/shared/utils.cjs.map +0 -1
  374. package/dist/internal/shared/utils.js.map +0 -1
  375. package/dist/internal/webpack/next-client-pages-loader.cjs.map +0 -1
  376. package/dist/internal/webpack/next-client-pages-loader.js.map +0 -1
  377. package/dist/internal/webpack/shared-modules.cjs.map +0 -1
  378. package/dist/internal/webpack/shared-modules.js.map +0 -1
  379. package/dist/next/config.cjs.map +0 -1
  380. package/dist/next/config.js.map +0 -1
  381. package/dist/next/host/app-router-server.cjs.map +0 -1
  382. package/dist/next/host/app-router-server.d.ts +0 -30
  383. package/dist/next/host/app-router-server.js.map +0 -1
  384. package/dist/next/host/client/index.cjs.map +0 -1
  385. package/dist/next/host/client/index.d.ts +0 -19
  386. package/dist/next/host/client/index.js.map +0 -1
  387. package/dist/next/host/pages-router-client.cjs.map +0 -1
  388. package/dist/next/host/pages-router-client.d.ts +0 -33
  389. package/dist/next/host/pages-router-client.js.map +0 -1
  390. package/dist/next/host/pages-router-server.cjs.map +0 -1
  391. package/dist/next/host/pages-router-server.js.map +0 -1
  392. package/dist/next/index.cjs +0 -53
  393. package/dist/next/index.cjs.map +0 -1
  394. package/dist/next/index.d.ts +0 -30
  395. package/dist/next/index.js +0 -19
  396. package/dist/next/index.js.map +0 -1
  397. package/dist/next/proxy.cjs.map +0 -1
  398. package/dist/next/proxy.d.ts +0 -56
  399. package/dist/next/proxy.js.map +0 -1
  400. package/dist/next/remote/pages-router.cjs.map +0 -1
  401. package/dist/next/remote/pages-router.js.map +0 -1
  402. package/dist/next/remote/server.cjs.map +0 -1
  403. package/dist/next/remote/server.d.ts +0 -5
  404. package/dist/next/remote/server.js +0 -5
  405. package/dist/next/remote/server.js.map +0 -1
  406. package/dist/proxy-through-host-a676a522.d.ts +0 -52
  407. package/dist/react/index.cjs.map +0 -1
  408. package/dist/react/index.d.ts +0 -86
  409. package/dist/react/index.js.map +0 -1
  410. package/dist/shared/host/app.cjs.map +0 -1
  411. package/dist/shared/host/app.js +0 -12
  412. package/dist/shared/host/app.js.map +0 -1
  413. package/dist/shared/host/pages.cjs.map +0 -1
  414. package/dist/shared/host/pages.js +0 -12
  415. package/dist/shared/host/pages.js.map +0 -1
  416. package/dist/shared/host/proxy.cjs.map +0 -1
  417. package/dist/shared/host/proxy.js.map +0 -1
  418. package/dist/shared/remote/app.cjs.map +0 -1
  419. package/dist/shared/remote/app.js +0 -8
  420. package/dist/shared/remote/app.js.map +0 -1
  421. package/dist/shared/remote/pages.cjs.map +0 -1
  422. package/dist/shared/remote/pages.js +0 -8
  423. package/dist/shared/remote/pages.js.map +0 -1
  424. package/dist/shared/remote/proxy.cjs.map +0 -1
  425. package/dist/shared/remote/proxy.d.ts +0 -44
  426. package/dist/shared/remote/proxy.js.map +0 -1
  427. package/dist/shared/remote/wrapper.cjs.map +0 -1
  428. package/dist/shared/remote/wrapper.js +0 -25
  429. package/dist/shared/remote/wrapper.js.map +0 -1
  430. package/dist/webpack.cjs.map +0 -1
  431. package/dist/webpack.js.map +0 -1
  432. /package/dist/{webpack.d.ts → config/webpack.d.ts} +0 -0
  433. /package/dist/{shared/host → host/defaults}/app.d.ts +0 -0
  434. /package/dist/{shared/host → host/defaults}/pages.d.ts +0 -0
  435. /package/dist/{shared/host/proxy.d.ts → host/proxy/protected-fetch.d.ts} +0 -0
  436. /package/dist/internal/{webpack/shared-modules.d.ts → config/webpack/apply-shared-modules.d.ts} +0 -0
  437. /package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.d.ts +0 -0
  438. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.cjs +0 -0
  439. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.js +0 -0
  440. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.cjs +0 -0
  441. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.d.ts +0 -0
  442. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.js +0 -0
  443. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.cjs +0 -0
  444. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.d.ts +0 -0
  445. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.js +0 -0
  446. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.cjs +0 -0
  447. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.d.ts +0 -0
  448. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.js +0 -0
  449. /package/dist/internal/{shared/client → host/server}/get-client-src.d.ts +0 -0
  450. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.cjs +0 -0
  451. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.d.ts +0 -0
  452. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.js +0 -0
  453. /package/dist/internal/{shared/contract/host-state.d.ts → host/shared/state.d.ts} +0 -0
  454. /package/dist/internal/{shared/contract → host/utils}/resolve-name-from-src.cjs +0 -0
  455. /package/dist/internal/{shared/contract → host/utils}/resolve-name-from-src.d.ts +0 -0
  456. /package/dist/internal/{shared/contract → host/utils}/resolve-name-from-src.js +0 -0
  457. /package/dist/internal/{next/remote/render-client.d.ts → remote/nextjs/app-client.d.ts} +0 -0
  458. /package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs +0 -0
  459. /package/dist/internal/{shared/client → runtime/html}/apply-origin.js +0 -0
  460. /package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.d.ts +0 -0
  461. /package/dist/internal/{shared/utils → utils}/abort.cjs +0 -0
  462. /package/dist/internal/{shared/utils → utils}/abort.d.ts +0 -0
  463. /package/dist/internal/{shared/utils → utils}/abort.js +0 -0
  464. /package/dist/internal/{shared/utils.cjs → utils.cjs} +0 -0
  465. /package/dist/internal/{shared/utils.d.ts → utils.d.ts} +0 -0
  466. /package/dist/internal/{shared/utils.js → utils.js} +0 -0
  467. /package/dist/{shared/remote → remote/defaults}/app.d.ts +0 -0
  468. /package/dist/{shared/remote → remote/defaults}/pages.d.ts +0 -0
  469. /package/dist/{shared/remote → remote/defaults}/wrapper.d.ts +0 -0
  470. /package/dist/{html/remote.d.ts → remote/html.d.ts} +0 -0
@@ -1,87 +1,49 @@
1
1
  "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
2
11
 
3
- // src/next/host/client/index.tsx
4
- import * as Image from "next/image";
5
-
6
- // src/react/index.tsx
7
- import {
8
- startTransition,
9
- useEffect,
10
- useId,
11
- useLayoutEffect as useLayoutEffect2,
12
- useMemo as useMemo2,
13
- useRef as useRef2,
14
- useState as useState2
15
- } from "react";
16
- import { createPortal } from "react-dom";
12
+ // src/utils/constants.ts
13
+ var RC_PROTECTED_REMOTE_FETCH_PATHNAME, MISSING_SHARED_MODULES_MESSAGE, CORS_DOCS_URL;
14
+ var init_constants = __esm({
15
+ "src/utils/constants.ts"() {
16
+ "use strict";
17
+ RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
18
+ MISSING_SHARED_MODULES_MESSAGE = "Remote Components shared modules not found. Did you forget to wrap your config with `withRemoteComponentsConfig` on both host and remote?";
19
+ CORS_DOCS_URL = "https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components";
20
+ }
21
+ });
17
22
 
18
- // src/shared/client/apply-origin.ts
19
- var tagNames = [
20
- "img",
21
- "source",
22
- "video",
23
- "audio",
24
- "track",
25
- "iframe",
26
- "embed",
27
- "script",
28
- "link"
29
- ];
30
- function applyOriginToNodes(doc, url, resolveClientUrl) {
31
- if (url.origin !== location.origin) {
32
- const nodes = doc.querySelectorAll(
33
- tagNames.map(
34
- (type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
35
- ).join(",")
36
- );
37
- nodes.forEach((node) => {
38
- if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
39
- const absoluteSrc = new URL(node.getAttribute("src") ?? "/", url).href;
40
- const isScript = node.tagName.toLowerCase() === "script";
41
- node.src = isScript ? absoluteSrc : resolveClientUrl?.(absoluteSrc) ?? absoluteSrc;
42
- }
43
- if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
44
- const absoluteHref = new URL(node.getAttribute("href") ?? "/", url).href;
45
- node.setAttribute(
46
- "href",
47
- resolveClientUrl?.(absoluteHref) ?? absoluteHref
48
- );
49
- }
50
- if (node.hasAttribute("srcset")) {
51
- const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
52
- const [urlPart, descriptor] = entry.trim().split(/\s+/);
53
- if (!urlPart)
54
- return entry;
55
- const absoluteUrl = new URL(urlPart, url).href;
56
- const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
57
- return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
58
- }).join(", ");
59
- if (srcSet) {
60
- node.setAttribute("srcset", srcSet);
61
- }
62
- }
63
- if (node.hasAttribute("imagesrcset")) {
64
- const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
65
- const [urlPart, descriptor] = entry.trim().split(/\s+/);
66
- if (!urlPart)
67
- return entry;
68
- const absoluteUrl = new URL(urlPart, url).href;
69
- const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
70
- return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
71
- }).join(", ");
72
- if (srcSet) {
73
- node.setAttribute("imagesrcset", srcSet);
74
- }
75
- }
76
- });
23
+ // src/host/defaults/app.ts
24
+ var app_exports = {};
25
+ __export(app_exports, {
26
+ shared: () => shared
27
+ });
28
+ var shared;
29
+ var init_app = __esm({
30
+ "src/host/defaults/app.ts"() {
31
+ "use strict";
32
+ init_constants();
33
+ shared = {
34
+ __remote_components_missing_shared__: () => Promise.reject(new Error(MISSING_SHARED_MODULES_MESSAGE))
35
+ };
77
36
  }
78
- }
37
+ });
38
+
39
+ // src/host/nextjs/app-client-only.tsx
40
+ import * as Image from "next/image";
79
41
 
80
- // src/shared/constants.ts
81
- var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
82
- var CORS_DOCS_URL = "https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components";
42
+ // src/utils/logger.ts
43
+ init_constants();
83
44
 
84
- // src/shared/client/protected-rc-fallback.ts
45
+ // src/runtime/url/protected-rc-fallback.ts
46
+ init_constants();
85
47
  function isProxiedUrl(url) {
86
48
  try {
87
49
  return new URL(url, location.href).pathname === RC_PROTECTED_REMOTE_FETCH_PATHNAME;
@@ -90,7 +52,7 @@ function isProxiedUrl(url) {
90
52
  }
91
53
  }
92
54
 
93
- // src/shared/utils/abort.ts
55
+ // src/utils/abort.ts
94
56
  function isAbortError(error) {
95
57
  if (error instanceof DOMException && error.name === "AbortError") {
96
58
  return true;
@@ -102,7 +64,8 @@ function isAbortError(error) {
102
64
  return false;
103
65
  }
104
66
 
105
- // src/shared/error.ts
67
+ // src/utils/error.ts
68
+ init_constants();
106
69
  var RemoteComponentsError = class extends Error {
107
70
  code = "REMOTE_COMPONENTS_ERROR";
108
71
  constructor(message, options) {
@@ -160,6 +123,11 @@ async function errorFromFailedFetch(originalUrl, resolvedUrl, res) {
160
123
  }
161
124
  return fallback;
162
125
  }
126
+ function failedProxiedAssetError(kind, url, resolvedUrl) {
127
+ return new RemoteComponentsError(
128
+ `Failed to load ${kind} "${url}" via proxy "${resolvedUrl}". Ensure withRemoteComponentsHostProxy middleware is configured, "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher, and the remote URL is included in allowedProxyUrls. See: ${CORS_DOCS_URL}`
129
+ );
130
+ }
163
131
  function failedProxyFetchError(originalUrl, proxyUrl, status, responseBody) {
164
132
  if (status === 404) {
165
133
  return new RemoteComponentsError(
@@ -168,7 +136,7 @@ function failedProxyFetchError(originalUrl, proxyUrl, status, responseBody) {
168
136
  The host server needs middleware or a route that handles "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}".
169
137
 
170
138
  Proxying requires two pieces:
171
- 1. resolveClientUrl={proxyClientRequestsThroughHost} on <RemoteComponent>
139
+ 1. resolveClientUrl={routeThroughHostProxy} on <RemoteComponent>
172
140
  2. Middleware or a route for "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" on the host server
173
141
 
174
142
  Docs: ${CORS_DOCS_URL}`
@@ -185,123 +153,7 @@ Docs: ${CORS_DOCS_URL}`
185
153
  );
186
154
  }
187
155
 
188
- // src/shared/utils/index.ts
189
- function escapeString(str) {
190
- return str.replace(/[^a-z0-9]/g, "_");
191
- }
192
- var attrToProp = {
193
- fetchpriority: "fetchPriority",
194
- crossorigin: "crossOrigin",
195
- imagesrcset: "imageSrcSet",
196
- imagesizes: "imageSizes",
197
- srcset: "srcSet"
198
- };
199
-
200
- // src/shared/client/const.ts
201
- var DEFAULT_ROUTE = "/";
202
- var RUNTIME_WEBPACK = "webpack";
203
- var RUNTIME_TURBOPACK = "turbopack";
204
- var RUNTIME_SCRIPT = "script";
205
- var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
206
- function getBundleKey(bundle) {
207
- return escapeString(bundle);
208
- }
209
-
210
- // src/shared/client/parse-remote-html.ts
211
- function validateSingleComponent(doc, name, url) {
212
- 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}"]`)) {
213
- throw multipleRemoteComponentsError(url);
214
- }
215
- }
216
- function findComponentElement(doc, name) {
217
- 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])");
218
- }
219
- function parseNextData(doc) {
220
- return JSON.parse(
221
- (doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
222
- );
223
- }
224
- function resolveComponentName(component, nextData, fallbackName) {
225
- const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
226
- const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
227
- return { name, isRemoteComponent };
228
- }
229
- function extractComponentMetadata(component, nextData, name, url) {
230
- return {
231
- name,
232
- bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
233
- route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
234
- runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
235
- };
236
- }
237
- function extractRemoteShared(doc, name, nextData) {
238
- const remoteSharedEl = doc.querySelector(
239
- `#${name}_shared[data-remote-components-shared]`
240
- );
241
- const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
242
- remoteSharedEl?.remove();
243
- return remoteShared;
244
- }
245
- function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
246
- if (!component || !(rsc || nextData || isRemoteComponent)) {
247
- throw new RemoteComponentsError(
248
- `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>?`
249
- );
250
- }
251
- }
252
- function extractLinks(doc, component) {
253
- return Array.from(doc.querySelectorAll("link[href]")).filter(
254
- (link) => !component.contains(link)
255
- );
256
- }
257
- function extractScripts(doc, component, isRemoteComponent) {
258
- return Array.from(
259
- (isRemoteComponent ? component : doc).querySelectorAll(
260
- "script[src],script[data-src]"
261
- )
262
- );
263
- }
264
- function parseRemoteComponentDocument(doc, name, url) {
265
- validateSingleComponent(doc, name, url.href);
266
- const component = findComponentElement(doc, name);
267
- const nextData = parseNextData(doc);
268
- const { name: resolvedName, isRemoteComponent } = resolveComponentName(
269
- component,
270
- nextData,
271
- name
272
- );
273
- const rsc = doc.querySelector(`#${resolvedName}_rsc`);
274
- const metadata = extractComponentMetadata(
275
- component,
276
- nextData,
277
- resolvedName,
278
- url
279
- );
280
- const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
281
- validateComponentFound(
282
- component,
283
- rsc,
284
- nextData,
285
- isRemoteComponent,
286
- url.href,
287
- resolvedName
288
- );
289
- const links = extractLinks(doc, component);
290
- const scripts = extractScripts(doc, component, isRemoteComponent);
291
- return {
292
- component,
293
- name: resolvedName,
294
- isRemoteComponent,
295
- metadata,
296
- nextData,
297
- rsc,
298
- remoteShared,
299
- links,
300
- scripts
301
- };
302
- }
303
-
304
- // src/shared/utils/logger.ts
156
+ // src/utils/logger.ts
305
157
  var PREFIX = "remote-components";
306
158
  var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
307
159
  function logDebug(location2, message) {
@@ -327,13 +179,13 @@ function warnCrossOriginFetchError(logLocation, url) {
327
179
  }
328
180
  logWarn(
329
181
  logLocation,
330
- `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}`
182
+ `Failed to fetch cross-origin resource "${parsed.href}". To load assets from a protected deployment, two steps are required: (1) configure withRemoteComponentsHostProxy middleware in your host with the remote URL in allowedProxyUrls, and (2) provide a resolveClientUrl prop that rewrites cross-origin asset URLs to go through the proxy. See: ${CORS_DOCS_URL}`
331
183
  );
332
184
  } catch {
333
185
  }
334
186
  }
335
187
 
336
- // src/shared/client/polyfill.tsx
188
+ // src/host/shared/polyfill.tsx
337
189
  import { jsx } from "react/jsx-runtime";
338
190
  function applyBundleUrlToSrc(bundle, src) {
339
191
  const self = globalThis;
@@ -353,7 +205,7 @@ function applyBundleUrlToImagePropsSrc(bundle, src) {
353
205
  const propSrc = src;
354
206
  return applyBundleUrlToSrc(bundle, propSrc.src);
355
207
  }
356
- var imageImpl = (bundle) => function RemoteImage({
208
+ var imageImpl = (bundle, resolveClientUrl) => function RemoteImage({
357
209
  fill: _fill,
358
210
  loader: _loader,
359
211
  quality: _quality,
@@ -370,6 +222,7 @@ var imageImpl = (bundle) => function RemoteImage({
370
222
  bundle,
371
223
  typeof src === "string" ? src : src.src
372
224
  );
225
+ const proxiedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
373
226
  return (
374
227
  // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
375
228
  /* @__PURE__ */ jsx(
@@ -378,16 +231,16 @@ var imageImpl = (bundle) => function RemoteImage({
378
231
  decoding: "async",
379
232
  style: { color: "transparent" },
380
233
  ...props,
381
- src: newSrc,
234
+ src: proxiedSrc,
382
235
  suppressHydrationWarning: true
383
236
  }
384
237
  )
385
238
  );
386
239
  };
387
- function sharedPolyfills(shared) {
240
+ function sharedPolyfills(shared2, resolveClientUrl) {
388
241
  const self = globalThis;
389
242
  const polyfill = {
390
- "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
243
+ "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared2?.["next/navigation"] ?? (() => Promise.resolve({
391
244
  useRouter() {
392
245
  return {
393
246
  push: (routerUrl) => {
@@ -418,7 +271,7 @@ function sharedPolyfills(shared) {
418
271
  },
419
272
  __esModule: true
420
273
  })),
421
- "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
274
+ "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared2?.["next/link"] ?? (() => Promise.resolve({
422
275
  default: ({
423
276
  scroll: _,
424
277
  replace,
@@ -468,18 +321,18 @@ function sharedPolyfills(shared) {
468
321
  },
469
322
  __esModule: true
470
323
  })),
471
- "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
324
+ "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared2?.["next/form"] ?? (() => Promise.resolve({
472
325
  default: () => {
473
326
  throw new Error("Next.js <Form> component not implemented");
474
327
  },
475
328
  __esModule: true
476
329
  })),
477
- "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
478
- Image: imageImpl(bundle),
330
+ "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared2?.["next/image"] ?? ((bundle) => Promise.resolve({
331
+ Image: imageImpl(bundle, resolveClientUrl),
479
332
  __esModule: true
480
333
  })),
481
- "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
482
- default: imageImpl(bundle),
334
+ "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared2?.["next/image"] ?? ((bundle) => Promise.resolve({
335
+ default: imageImpl(bundle, resolveClientUrl),
483
336
  getImageProps: (_imgProps) => {
484
337
  throw new Error(
485
338
  "Next.js getImageProps() is not implemented in remote components"
@@ -487,13 +340,13 @@ function sharedPolyfills(shared) {
487
340
  },
488
341
  __esModule: true
489
342
  })),
490
- "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
343
+ "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared2?.["next/script"] ?? (() => Promise.resolve({
491
344
  // TODO: implement <Script> component for non-Next.js host applications
492
345
  // do not throw an error for now
493
346
  default: () => null,
494
347
  __esModule: true
495
348
  })),
496
- "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
349
+ "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared2?.["next/router"] ?? (() => (
497
350
  // TODO: incomplete implementation
498
351
  Promise.resolve({
499
352
  useRouter() {
@@ -529,47 +382,480 @@ function sharedPolyfills(shared) {
529
382
  return polyfill;
530
383
  }
531
384
 
532
- // src/shared/client/component-loader.ts
533
- import * as React from "react";
534
- import * as JSXDevRuntime from "react/jsx-dev-runtime";
535
- import * as JSXRuntime from "react/jsx-runtime";
536
- import * as ReactDOM from "react-dom";
537
- import * as ReactDOMClient from "react-dom/client";
385
+ // src/host/nextjs/image-impl.tsx
386
+ import { jsx as jsx2 } from "react/jsx-runtime";
387
+ function createRemoteLoader(bundle, resolveClientUrl) {
388
+ return ({ src, width, quality }) => {
389
+ const self = globalThis;
390
+ const origin = self.__remote_bundle_url__?.[bundle]?.origin ?? "";
391
+ let imageUrl = src;
392
+ try {
393
+ const parsed = new URL(src);
394
+ if (origin && parsed.origin === origin) {
395
+ imageUrl = parsed.pathname + parsed.search;
396
+ }
397
+ } catch {
398
+ }
399
+ const { assetPrefix } = /^(?<assetPrefix>.*?)\/_next\//.exec(imageUrl)?.groups ?? {};
400
+ const url = `${origin}${assetPrefix ?? ""}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${quality ?? 75}`;
401
+ return resolveClientUrl?.(url) ?? url;
402
+ };
403
+ }
404
+ function imageImpl2(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
405
+ const remoteLoader = useRemoteLoader ? createRemoteLoader(bundle, resolveClientUrl) : void 0;
406
+ const component = function RemoteImage(props) {
407
+ if (remoteLoader) {
408
+ return /* @__PURE__ */ jsx2(ImageComponent, { loader: remoteLoader, ...props });
409
+ }
410
+ const rawSrc = applyBundleUrlToImagePropsSrc(bundle, props.src);
411
+ const src = resolveClientUrl?.(rawSrc) ?? rawSrc;
412
+ return /* @__PURE__ */ jsx2(ImageComponent, { ...props, src });
413
+ };
414
+ component.default = component;
415
+ return component;
416
+ }
538
417
 
539
- // src/shared/webpack/next-client-pages-loader.ts
540
- function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
541
- const self = globalThis;
542
- const nextCssOriginal = document.querySelector(
543
- `[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
544
- );
545
- if (nextCssOriginal) {
546
- nextCssOriginal.parentNode?.removeChild(nextCssOriginal);
418
+ // src/runtime/url/resolve-client-url.ts
419
+ function withRemoteSrc(resolveClientUrl, remoteSrc) {
420
+ const remoteOrigin = parseOrigin(remoteSrc);
421
+ return (url) => {
422
+ const urlOrigin = parseOrigin(url);
423
+ if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
424
+ return void 0;
425
+ }
426
+ return resolveClientUrl(remoteSrc, url);
427
+ };
428
+ }
429
+ function parseOrigin(url) {
430
+ try {
431
+ return new URL(url).origin;
432
+ } catch {
433
+ return void 0;
547
434
  }
548
- const nextCss = document.createElement("noscript");
549
- nextCss.id = "__next_css__DO_NOT_USE__";
550
- nextCss.setAttribute("data-bundle", bundle);
551
- nextCss.setAttribute("data-route", route);
552
- const nextCssEnd = document.createElement("noscript");
553
- nextCssEnd.id = "__next_css__DO_NOT_USE_END__";
554
- nextCssEnd.setAttribute("data-bundle", bundle);
555
- nextCssEnd.setAttribute("data-route", route);
556
- document.head.appendChild(nextCssEnd);
557
- document.head.appendChild(nextCss);
558
- const componentLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
559
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
560
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
561
- (key) => key.includes("/next/dist/client/page-loader.js")
562
- ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
563
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
564
- ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
565
- (key) => key.includes("/next/dist/client/page-loader.js")
566
- ) ?? ""] ?? -1;
567
- const appLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
568
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
569
- ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
570
- (key) => key.includes("/next/dist/client/page-loader.js")
571
- ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
572
- (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
435
+ }
436
+
437
+ // src/runtime/url/default-resolve-client-url.ts
438
+ function bindResolveClientUrl(prop, remoteSrc) {
439
+ return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
440
+ }
441
+
442
+ // src/host/react/index.tsx
443
+ import {
444
+ startTransition,
445
+ useEffect,
446
+ useId,
447
+ useLayoutEffect as useLayoutEffect2,
448
+ useMemo as useMemo2,
449
+ useRef as useRef2,
450
+ useState as useState2
451
+ } from "react";
452
+ import { createPortal } from "react-dom";
453
+
454
+ // src/host/server/fetch-headers.ts
455
+ function remoteFetchHeaders() {
456
+ return {
457
+ /**
458
+ * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
459
+ * If the remote component uses vercel deployment protection, ensure the host and remote vercel
460
+ * projects share a common automation bypass secret, and the shared secret is used as the
461
+ * VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
462
+ */
463
+ ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
464
+ "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
465
+ } : {},
466
+ Accept: "text/html"
467
+ };
468
+ }
469
+
470
+ // src/host/server/fetch-with-hooks.ts
471
+ async function fetchWithWarning(url, init) {
472
+ try {
473
+ return await fetch(url, init);
474
+ } catch (error) {
475
+ warnCrossOriginFetchError("FetchRemoteComponent", url);
476
+ throw error;
477
+ }
478
+ }
479
+ async function fetchWithHooks(url, additionalInit, options = {}) {
480
+ const {
481
+ onRequest,
482
+ onResponse,
483
+ abortController = new AbortController()
484
+ } = options;
485
+ const signal = abortController.signal;
486
+ const hookOptions = {
487
+ signal,
488
+ abort: (reason) => abortController.abort(reason)
489
+ };
490
+ const init = {
491
+ method: "GET",
492
+ headers: remoteFetchHeaders(),
493
+ signal,
494
+ ...additionalInit
495
+ };
496
+ const res = await onRequest?.(url, init, hookOptions) ?? await fetchWithWarning(url, init);
497
+ return await onResponse?.(url, res, hookOptions) ?? res;
498
+ }
499
+
500
+ // src/host/server/get-client-or-server-url.ts
501
+ function getClientOrServerUrl(src, serverFallback) {
502
+ const fallback = typeof location !== "undefined" ? location.href : serverFallback;
503
+ if (!src) {
504
+ return new URL(fallback);
505
+ }
506
+ return typeof src === "string" ? new URL(src, fallback) : src;
507
+ }
508
+
509
+ // src/host/shared/state.ts
510
+ function createHostState() {
511
+ return {
512
+ stage: "idle",
513
+ prevSrc: void 0,
514
+ prevUrl: void 0,
515
+ prevName: void 0,
516
+ prevIsRemoteComponent: false,
517
+ abortController: void 0
518
+ };
519
+ }
520
+
521
+ // src/host/utils/resolve-name-from-src.ts
522
+ function resolveNameFromSrc(src, defaultName) {
523
+ if (!src) {
524
+ return defaultName;
525
+ }
526
+ const hash = typeof src === "string" ? src : src.hash;
527
+ const hashIndex = hash.indexOf("#");
528
+ if (hashIndex < 0) {
529
+ return defaultName;
530
+ }
531
+ const name = hash.slice(hashIndex + 1);
532
+ return name || defaultName;
533
+ }
534
+
535
+ // src/utils/index.ts
536
+ function escapeString(str) {
537
+ return str.replace(/[^a-z0-9]/g, "_");
538
+ }
539
+ var attrToProp = {
540
+ fetchpriority: "fetchPriority",
541
+ crossorigin: "crossOrigin",
542
+ imagesrcset: "imageSrcSet",
543
+ imagesizes: "imageSizes",
544
+ srcset: "srcSet"
545
+ };
546
+
547
+ // src/runtime/constants.ts
548
+ var DEFAULT_ROUTE = "/";
549
+ var RUNTIME_WEBPACK = "webpack";
550
+ var RUNTIME_TURBOPACK = "turbopack";
551
+ var RUNTIME_SCRIPT = "script";
552
+ var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
553
+ var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
554
+ function getBundleKey(bundle) {
555
+ return escapeString(bundle);
556
+ }
557
+
558
+ // src/runtime/html/apply-origin.ts
559
+ var tagNames = [
560
+ "img",
561
+ "source",
562
+ "video",
563
+ "audio",
564
+ "track",
565
+ "iframe",
566
+ "embed",
567
+ "script",
568
+ "link"
569
+ ];
570
+ function applyOriginToNodes(doc, url, resolveClientUrl) {
571
+ if (url.origin !== location.origin) {
572
+ const nodes = doc.querySelectorAll(
573
+ tagNames.map(
574
+ (type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
575
+ ).join(",")
576
+ );
577
+ nodes.forEach((node) => {
578
+ if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
579
+ const absoluteSrc = new URL(node.getAttribute("src") ?? "/", url).href;
580
+ const isScript = node.tagName.toLowerCase() === "script";
581
+ node.src = isScript ? absoluteSrc : resolveClientUrl?.(absoluteSrc) ?? absoluteSrc;
582
+ }
583
+ if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
584
+ const absoluteHref = new URL(node.getAttribute("href") ?? "/", url).href;
585
+ node.setAttribute(
586
+ "href",
587
+ resolveClientUrl?.(absoluteHref) ?? absoluteHref
588
+ );
589
+ }
590
+ if (node.hasAttribute("srcset")) {
591
+ const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
592
+ const [urlPart, descriptor] = entry.trim().split(/\s+/);
593
+ if (!urlPart)
594
+ return entry;
595
+ const absoluteUrl = new URL(urlPart, url).href;
596
+ const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
597
+ return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
598
+ }).join(", ");
599
+ if (srcSet) {
600
+ node.setAttribute("srcset", srcSet);
601
+ }
602
+ }
603
+ if (node.hasAttribute("imagesrcset")) {
604
+ const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
605
+ const [urlPart, descriptor] = entry.trim().split(/\s+/);
606
+ if (!urlPart)
607
+ return entry;
608
+ const absoluteUrl = new URL(urlPart, url).href;
609
+ const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
610
+ return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
611
+ }).join(", ");
612
+ if (srcSet) {
613
+ node.setAttribute("imagesrcset", srcSet);
614
+ }
615
+ }
616
+ });
617
+ }
618
+ }
619
+
620
+ // src/runtime/html/parse-remote-html.ts
621
+ function validateSingleComponent(doc, name, url) {
622
+ 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}"]`)) {
623
+ throw multipleRemoteComponentsError(url);
624
+ }
625
+ }
626
+ function findComponentElement(doc, name) {
627
+ 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])");
628
+ }
629
+ function parseNextData(doc) {
630
+ return JSON.parse(
631
+ (doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
632
+ );
633
+ }
634
+ function resolveComponentName(component, nextData, fallbackName) {
635
+ const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
636
+ const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
637
+ return { name, isRemoteComponent };
638
+ }
639
+ function extractComponentMetadata(component, nextData, name, url) {
640
+ return {
641
+ name,
642
+ bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
643
+ route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
644
+ runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
645
+ };
646
+ }
647
+ function extractRemoteShared(doc, name, nextData) {
648
+ const remoteSharedEl = doc.querySelector(
649
+ `#${name}_shared[data-remote-components-shared]`
650
+ );
651
+ const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
652
+ remoteSharedEl?.remove();
653
+ return remoteShared;
654
+ }
655
+ function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
656
+ if (!component || !(rsc || nextData || isRemoteComponent)) {
657
+ throw new RemoteComponentsError(
658
+ `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>?`
659
+ );
660
+ }
661
+ }
662
+ function extractLinks(doc, component) {
663
+ return Array.from(doc.querySelectorAll("link[href]")).filter(
664
+ (link) => !component.contains(link)
665
+ );
666
+ }
667
+ function extractScripts(doc, component, isRemoteComponent) {
668
+ return Array.from(
669
+ (isRemoteComponent ? component : doc).querySelectorAll(
670
+ "script[src],script[data-src]"
671
+ )
672
+ );
673
+ }
674
+ function parseRemoteComponentDocument(doc, name, url) {
675
+ validateSingleComponent(doc, name, url.href);
676
+ const component = findComponentElement(doc, name);
677
+ const nextData = parseNextData(doc);
678
+ const { name: resolvedName, isRemoteComponent } = resolveComponentName(
679
+ component,
680
+ nextData,
681
+ name
682
+ );
683
+ const rsc = doc.querySelector(`#${resolvedName}_rsc`);
684
+ const metadata = extractComponentMetadata(
685
+ component,
686
+ nextData,
687
+ resolvedName,
688
+ url
689
+ );
690
+ const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
691
+ validateComponentFound(
692
+ component,
693
+ rsc,
694
+ nextData,
695
+ isRemoteComponent,
696
+ url.href,
697
+ resolvedName
698
+ );
699
+ const links = extractLinks(doc, component);
700
+ const scripts = extractScripts(doc, component, isRemoteComponent);
701
+ return {
702
+ component,
703
+ name: resolvedName,
704
+ isRemoteComponent,
705
+ metadata,
706
+ nextData,
707
+ rsc,
708
+ remoteShared,
709
+ links,
710
+ scripts
711
+ };
712
+ }
713
+
714
+ // src/runtime/html/set-attributes-from-props.ts
715
+ var DOMAttributeNames = {
716
+ acceptCharset: "accept-charset",
717
+ className: "class",
718
+ htmlFor: "for",
719
+ httpEquiv: "http-equiv",
720
+ noModule: "noModule"
721
+ };
722
+ var ignoreProps = [
723
+ "onLoad",
724
+ "onReady",
725
+ "dangerouslySetInnerHTML",
726
+ "children",
727
+ "onError",
728
+ "strategy",
729
+ "stylesheets"
730
+ ];
731
+ function isBooleanScriptAttribute(attr) {
732
+ return ["async", "defer", "noModule"].includes(attr);
733
+ }
734
+ function setAttributesFromProps(el, props) {
735
+ for (const [p, value] of Object.entries(props)) {
736
+ if (!Object.hasOwn(props, p))
737
+ continue;
738
+ if (ignoreProps.includes(p))
739
+ continue;
740
+ if (value === void 0) {
741
+ continue;
742
+ }
743
+ const attr = DOMAttributeNames[p] || p.toLowerCase();
744
+ if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
745
+ el[attr] = Boolean(value);
746
+ } else {
747
+ el.setAttribute(attr, String(value));
748
+ }
749
+ if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
750
+ el.setAttribute(attr, "");
751
+ el.removeAttribute(attr);
752
+ }
753
+ }
754
+ }
755
+
756
+ // src/runtime/loaders/component-loader.ts
757
+ import * as React from "react";
758
+ import * as JSXDevRuntime from "react/jsx-dev-runtime";
759
+ import * as JSXRuntime from "react/jsx-runtime";
760
+ import * as ReactDOM from "react-dom";
761
+ import * as ReactDOMClient from "react-dom/client";
762
+
763
+ // src/config/webpack/apply-shared-modules.ts
764
+ var DEDUPLICATION_SKIPPED = "shared module deduplication skipped. The remote may load its own copy of shared dependencies.";
765
+ function applySharedModules(bundle, resolve) {
766
+ logDebug(
767
+ "SharedModules",
768
+ `applySharedModules called for bundle: "${bundle}"`
769
+ );
770
+ logDebug(
771
+ "SharedModules",
772
+ `Shared modules to resolve: ${Object.keys(resolve)}`
773
+ );
774
+ const self = globalThis;
775
+ if (self.__remote_webpack_require__?.[bundle]) {
776
+ const modulePaths = Object.keys(
777
+ self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
778
+ );
779
+ logDebug(
780
+ "SharedModules",
781
+ `Available module paths in __remote_webpack_require__[${bundle}]: ${modulePaths}`
782
+ );
783
+ for (const [key, value] of Object.entries(resolve)) {
784
+ const exactIds = modulePaths.filter((p) => p === key);
785
+ const ids = exactIds.length > 0 ? exactIds : modulePaths.filter((p) => p.includes(key));
786
+ if (ids.length === 0) {
787
+ logDebug(
788
+ "SharedModules",
789
+ `No matching module path found for shared module "${key}"`
790
+ );
791
+ }
792
+ for (const id of ids) {
793
+ const webpackBundle = self.__remote_webpack_require__[bundle];
794
+ if (webpackBundle.m) {
795
+ const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id] ? `${self.__remote_webpack_module_map__[bundle][id]}` : id;
796
+ if (resolvedId !== id) {
797
+ logDebug(
798
+ "SharedModules",
799
+ `Mapped module id: "${id}" -> "${resolvedId}"`
800
+ );
801
+ }
802
+ webpackBundle.m[resolvedId] = (module) => {
803
+ module.exports = value;
804
+ };
805
+ } else {
806
+ logWarn(
807
+ "SharedModules",
808
+ `webpackBundle.m is not available for bundle "${bundle}" \u2014 ${DEDUPLICATION_SKIPPED}`
809
+ );
810
+ }
811
+ }
812
+ }
813
+ } else {
814
+ logWarn(
815
+ "SharedModules",
816
+ `No webpack require found for bundle "${bundle}" \u2014 ${DEDUPLICATION_SKIPPED}`
817
+ );
818
+ logDebug(
819
+ "SharedModules",
820
+ `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
821
+ );
822
+ }
823
+ }
824
+
825
+ // src/config/webpack/next-client-pages-loader.ts
826
+ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
827
+ const self = globalThis;
828
+ const nextCssOriginal = document.querySelector(
829
+ `[id="__next_css__DO_NOT_USE__"]:not([data-bundle="${bundle}"][data-route="${route}"])`
830
+ );
831
+ if (nextCssOriginal) {
832
+ nextCssOriginal.parentNode?.removeChild(nextCssOriginal);
833
+ }
834
+ const nextCss = document.createElement("noscript");
835
+ nextCss.id = "__next_css__DO_NOT_USE__";
836
+ nextCss.setAttribute("data-bundle", bundle);
837
+ nextCss.setAttribute("data-route", route);
838
+ const nextCssEnd = document.createElement("noscript");
839
+ nextCssEnd.id = "__next_css__DO_NOT_USE_END__";
840
+ nextCssEnd.setAttribute("data-bundle", bundle);
841
+ nextCssEnd.setAttribute("data-route", route);
842
+ document.head.appendChild(nextCssEnd);
843
+ document.head.appendChild(nextCss);
844
+ const componentLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
845
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
846
+ ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
847
+ (key) => key.includes("/next/dist/client/page-loader.js")
848
+ ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
849
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=${encodeURIComponent(route)}!`)
850
+ ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
851
+ (key) => key.includes("/next/dist/client/page-loader.js")
852
+ ) ?? ""] ?? -1;
853
+ const appLoaderChunk = Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
854
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
855
+ ) ?? Object.keys(self.__remote_webpack_require__?.[bundle]?.m ?? {}).find(
856
+ (key) => key.includes("/next/dist/client/page-loader.js")
857
+ ) ?? self.__remote_webpack_module_map__?.[bundle]?.[Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
858
+ (key) => key.includes("/webpack/loaders/next-client-pages-loader.js") && key.includes(`page=%2F_app`)
573
859
  ) ?? Object.keys(self.__remote_webpack_module_map__[bundle] ?? {}).find(
574
860
  (key) => key.includes("/next/dist/client/page-loader.js")
575
861
  ) ?? ""] ?? -1;
@@ -623,93 +909,32 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
623
909
  node.remove();
624
910
  node = nextCss.previousSibling;
625
911
  }
626
- self.__remote_next_css__[bundle] = elements;
627
- }
628
- if (styleContainer) {
629
- const elements = self.__remote_next_css__[bundle];
630
- elements.forEach((el) => {
631
- styleContainer.appendChild(el.cloneNode(true));
632
- });
633
- } else {
634
- const elements = self.__remote_next_css__[bundle];
635
- elements.forEach((el) => {
636
- document.head.appendChild(el);
637
- });
638
- }
639
- delete self.__NEXT_P;
640
- self.__NEXT_P = __NEXT_P_ORIGINAL;
641
- if (nextCssOriginal) {
642
- nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
643
- }
644
- nextCss.remove();
645
- nextCssEnd.remove();
646
- return { Component, App };
647
- }
648
- return { Component: null, App: null };
649
- }
650
-
651
- // src/shared/webpack/shared-modules.ts
652
- function applySharedModules(bundle, resolve) {
653
- logDebug(
654
- "SharedModules",
655
- `applySharedModules called for bundle: "${bundle}"`
656
- );
657
- logDebug(
658
- "SharedModules",
659
- `Shared modules to resolve: ${Object.keys(resolve)}`
660
- );
661
- const self = globalThis;
662
- if (self.__remote_webpack_require__?.[bundle]) {
663
- const modulePaths = Object.keys(
664
- self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
665
- );
666
- logDebug(
667
- "SharedModules",
668
- `Available module paths in __remote_webpack_require__[${bundle}]: ${modulePaths}`
669
- );
670
- for (const [key, value] of Object.entries(resolve)) {
671
- let ids = modulePaths.filter((p) => p === key);
672
- if (ids.length === 0) {
673
- ids = modulePaths.filter((p) => p.includes(key));
674
- }
675
- if (ids.length === 0) {
676
- logDebug(
677
- "SharedModules",
678
- `No matching module path found for shared module "${key}"`
679
- );
680
- }
681
- for (let id of ids) {
682
- const webpackBundle = self.__remote_webpack_require__[bundle];
683
- if (webpackBundle.m) {
684
- if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
685
- const mappedId = `${self.__remote_webpack_module_map__[bundle][id]}`;
686
- logDebug(
687
- "SharedModules",
688
- `Mapped module id: "${id}" -> "${mappedId}"`
689
- );
690
- id = mappedId;
691
- }
692
- webpackBundle.m[id] = (module) => {
693
- module.exports = value;
694
- };
695
- } else {
696
- logWarn(
697
- "SharedModules",
698
- `webpackBundle.m is not available for bundle "${bundle}"`
699
- );
700
- }
701
- }
912
+ self.__remote_next_css__[bundle] = elements;
702
913
  }
703
- } else {
704
- logWarn("SharedModules", `No webpack require found for bundle "${bundle}"`);
705
- logDebug(
706
- "SharedModules",
707
- `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
708
- );
914
+ if (styleContainer) {
915
+ const elements = self.__remote_next_css__[bundle];
916
+ elements.forEach((el) => {
917
+ styleContainer.appendChild(el.cloneNode(true));
918
+ });
919
+ } else {
920
+ const elements = self.__remote_next_css__[bundle];
921
+ elements.forEach((el) => {
922
+ document.head.appendChild(el);
923
+ });
924
+ }
925
+ delete self.__NEXT_P;
926
+ self.__NEXT_P = __NEXT_P_ORIGINAL;
927
+ if (nextCssOriginal) {
928
+ nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
929
+ }
930
+ nextCss.remove();
931
+ nextCssEnd.remove();
932
+ return { Component, App };
709
933
  }
934
+ return { Component: null, App: null };
710
935
  }
711
936
 
712
- // src/shared/client/rsc.ts
937
+ // src/runtime/rsc.ts
713
938
  import { ReadableStream } from "web-streams-polyfill";
714
939
  function fixPayload(payload) {
715
940
  if (Array.isArray(payload)) {
@@ -775,56 +1000,15 @@ function createRSCStream(rscName, data) {
775
1000
  });
776
1001
  }
777
1002
 
778
- // src/shared/client/webpack-patterns.ts
779
- var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
780
-
781
- // src/shared/client/script-loader.ts
782
- async function loadScripts(scripts, resolveClientUrl) {
783
- await Promise.all(
784
- scripts.map((script) => {
785
- return new Promise((resolve, reject) => {
786
- const newSrc = new URL(
787
- // remove the remote component bundle name identifier from the script src
788
- script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
789
- location.origin
790
- ).href;
791
- const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
792
- const newScript = document.createElement("script");
793
- newScript.onload = () => resolve();
794
- newScript.onerror = () => {
795
- const isProxied = isProxiedUrl(resolvedSrc);
796
- if (isProxied) {
797
- reject(
798
- new RemoteComponentsError(
799
- `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}`
800
- )
801
- );
802
- } else {
803
- warnCrossOriginFetchError("ScriptLoader", newSrc);
804
- reject(
805
- new RemoteComponentsError(
806
- `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
807
- )
808
- );
809
- }
810
- };
811
- newScript.src = resolvedSrc;
812
- newScript.async = true;
813
- document.head.appendChild(newScript);
814
- });
815
- })
816
- );
817
- }
818
-
819
- // src/shared/client/turbopack-patterns.ts
1003
+ // src/runtime/turbopack/patterns.ts
820
1004
  var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
821
- var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
1005
+ var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|[a-z])\.A\((?<sharedModuleId>[0-9]+)\)/;
822
1006
  var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
823
1007
  var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
824
1008
  var 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]+)\)\)\)\}/;
825
1009
  var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
826
1010
 
827
- // src/shared/client/chunk-loader.ts
1011
+ // src/runtime/turbopack/chunk-loader.ts
828
1012
  function createChunkLoader(runtime, resolveClientUrl) {
829
1013
  return function __turbopack_chunk_load__(chunkId, scriptBundle) {
830
1014
  logDebug("ChunkLoader", `Loading chunk: "${chunkId}"`);
@@ -884,11 +1068,7 @@ function createChunkLoader(runtime, resolveClientUrl) {
884
1068
  }).then(resolve).catch((error) => {
885
1069
  const isProxied = isProxiedUrl(resolvedUrl);
886
1070
  if (isProxied) {
887
- reject(
888
- new RemoteComponentsError(
889
- `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}`
890
- )
891
- );
1071
+ reject(failedProxiedAssetError("chunk", url, resolvedUrl));
892
1072
  } else {
893
1073
  warnCrossOriginFetchError("ChunkLoader", url);
894
1074
  reject(error);
@@ -1036,7 +1216,7 @@ async function handleTurbopackChunk(code, bundle, url) {
1036
1216
  }
1037
1217
  }
1038
1218
 
1039
- // src/shared/client/turbopack-module.ts
1219
+ // src/runtime/turbopack/module.ts
1040
1220
  function handleTurbopackModule(bundle, moduleId, id) {
1041
1221
  const self = globalThis;
1042
1222
  const bundleKey = getBundleKey(bundle);
@@ -1265,7 +1445,8 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
1265
1445
  };
1266
1446
  }
1267
1447
 
1268
- // src/shared/client/shared-modules.ts
1448
+ // src/runtime/turbopack/shared-modules.ts
1449
+ var DEDUPLICATION_WARNING = "This module will not be deduplicated \u2014 the remote may load its own copy, which can cause duplicate instance errors (e.g. invalid hook calls if React is loaded twice).";
1269
1450
  async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {}) {
1270
1451
  const self = globalThis;
1271
1452
  self.__remote_shared_modules__ = self.__remote_shared_modules__ ?? {};
@@ -1302,9 +1483,9 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
1302
1483
  }
1303
1484
  }
1304
1485
  if (sharedModuleInitializer) {
1305
- const { shared } = await sharedModuleInitializer;
1486
+ const { shared: shared2 } = await sharedModuleInitializer;
1306
1487
  const sharedModuleIds = extractSharedModuleIds(
1307
- shared,
1488
+ shared2,
1308
1489
  bundleKey,
1309
1490
  self
1310
1491
  );
@@ -1316,7 +1497,7 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
1316
1497
  } else {
1317
1498
  logError(
1318
1499
  "SharedModules",
1319
- `Host shared module "${module}" not found for ID ${id}`
1500
+ `Host shared module "${module}" not found for ID ${id}. ${DEDUPLICATION_WARNING}`
1320
1501
  );
1321
1502
  }
1322
1503
  }
@@ -1333,15 +1514,15 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
1333
1514
  } else {
1334
1515
  logError(
1335
1516
  "SharedModules",
1336
- `Shared module "${module}" not found for "${bundle}"`
1517
+ `Shared module "${module}" not found for "${bundle}". ${DEDUPLICATION_WARNING}`
1337
1518
  );
1338
1519
  }
1339
1520
  }
1340
1521
  })
1341
1522
  );
1342
1523
  }
1343
- function extractSharedModuleIds(shared, bundleKey, self) {
1344
- return Object.entries(shared).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
1524
+ function extractSharedModuleIds(shared2, bundleKey, self) {
1525
+ return Object.entries(shared2).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
1345
1526
  const { asyncSharedModuleId } = ASYNC_MODULE_LOADER_RE.exec(value.toString())?.groups ?? {};
1346
1527
  if (asyncSharedModuleId) {
1347
1528
  const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
@@ -1385,8 +1566,8 @@ function getSharedModule(bundle, id) {
1385
1566
  return null;
1386
1567
  }
1387
1568
 
1388
- // src/shared/client/webpack-adapter.ts
1389
- async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
1569
+ // src/runtime/turbopack/webpack-runtime.ts
1570
+ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared2 = {}, remoteShared = {}, resolveClientUrl) {
1390
1571
  const self = globalThis;
1391
1572
  if (!self.__remote_bundle_url__) {
1392
1573
  self.__remote_bundle_url__ = {};
@@ -1423,7 +1604,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
1423
1604
  "react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
1424
1605
  "react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
1425
1606
  "react-dom/client": async () => (await import("react-dom/client")).default,
1426
- ...shared
1607
+ ...shared2
1427
1608
  };
1428
1609
  await initializeSharedModules(
1429
1610
  bundle ?? "default",
@@ -1440,7 +1621,7 @@ function createModuleRequire(runtime) {
1440
1621
  id
1441
1622
  };
1442
1623
  const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
1443
- logDebug("WebpackAdapter", `remoteRuntime: "${remoteRuntime}"`);
1624
+ logDebug("WebpackRuntime", `remoteRuntime: "${remoteRuntime}"`);
1444
1625
  try {
1445
1626
  if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
1446
1627
  return self.__remote_webpack_require__?.[bundle]?.(moduleId);
@@ -1456,7 +1637,7 @@ function createModuleRequire(runtime) {
1456
1637
  throw new Error(`Module "${id}" not found.`);
1457
1638
  } catch (requireError) {
1458
1639
  logWarn(
1459
- "WebpackAdapter",
1640
+ "WebpackRuntime",
1460
1641
  `Module require failed: ${String(requireError)}`
1461
1642
  );
1462
1643
  if (typeof self.__original_webpack_require__ !== "function") {
@@ -1468,7 +1649,7 @@ function createModuleRequire(runtime) {
1468
1649
  );
1469
1650
  }
1470
1651
  try {
1471
- logDebug("WebpackAdapter", "Falling back to original webpack require");
1652
+ logDebug("WebpackRuntime", "Falling back to original webpack require");
1472
1653
  return self.__original_webpack_require__(id);
1473
1654
  } catch (originalError) {
1474
1655
  throw new RemoteComponentsError(
@@ -1480,7 +1661,41 @@ function createModuleRequire(runtime) {
1480
1661
  };
1481
1662
  }
1482
1663
 
1483
- // src/shared/client/component-loader.ts
1664
+ // src/runtime/loaders/script-loader.ts
1665
+ async function loadScripts(scripts, resolveClientUrl) {
1666
+ await Promise.all(
1667
+ scripts.map((script) => {
1668
+ return new Promise((resolve, reject) => {
1669
+ const newSrc = new URL(
1670
+ // remove the remote component bundle name identifier from the script src
1671
+ script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
1672
+ location.origin
1673
+ ).href;
1674
+ const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
1675
+ const newScript = document.createElement("script");
1676
+ newScript.onload = () => resolve();
1677
+ newScript.onerror = () => {
1678
+ const isProxied = isProxiedUrl(resolvedSrc);
1679
+ if (isProxied) {
1680
+ reject(failedProxiedAssetError("script", newSrc, resolvedSrc));
1681
+ } else {
1682
+ warnCrossOriginFetchError("ScriptLoader", newSrc);
1683
+ reject(
1684
+ new RemoteComponentsError(
1685
+ `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
1686
+ )
1687
+ );
1688
+ }
1689
+ };
1690
+ newScript.src = resolvedSrc;
1691
+ newScript.async = true;
1692
+ document.head.appendChild(newScript);
1693
+ });
1694
+ })
1695
+ );
1696
+ }
1697
+
1698
+ // src/runtime/loaders/component-loader.ts
1484
1699
  async function loadRemoteComponent({
1485
1700
  url,
1486
1701
  name,
@@ -1491,7 +1706,7 @@ async function loadRemoteComponent({
1491
1706
  data,
1492
1707
  nextData,
1493
1708
  scripts = [],
1494
- shared = Promise.resolve({}),
1709
+ shared: shared2 = Promise.resolve({}),
1495
1710
  remoteShared = {},
1496
1711
  container,
1497
1712
  resolveClientUrl
@@ -1505,7 +1720,7 @@ async function loadRemoteComponent({
1505
1720
  self.__DISABLE_WEBPACK_EXEC__[bundle] = true;
1506
1721
  await loadScripts(scripts, resolveClientUrl);
1507
1722
  }
1508
- const hostShared = await shared;
1723
+ const hostShared = await shared2;
1509
1724
  logDebug(
1510
1725
  "ComponentLoader",
1511
1726
  `loadRemoteComponent: bundle="${bundle}", name="${name}"`
@@ -1583,17 +1798,19 @@ async function loadRemoteComponent({
1583
1798
  };
1584
1799
  }
1585
1800
  }
1586
- async function loadRSCComponent(rscName, data) {
1587
- let createFromReadableStream;
1801
+ async function importCreateFromReadableStream() {
1588
1802
  try {
1589
- const { createFromReadableStream: _createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.browser");
1590
- createFromReadableStream = _createFromReadableStream;
1803
+ const { createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.browser");
1804
+ return createFromReadableStream;
1591
1805
  } catch {
1592
1806
  const {
1593
- default: { createFromReadableStream: _createFromReadableStream }
1807
+ default: { createFromReadableStream }
1594
1808
  } = await import("react-server-dom-webpack/client.browser");
1595
- createFromReadableStream = _createFromReadableStream;
1809
+ return createFromReadableStream;
1596
1810
  }
1811
+ }
1812
+ async function loadRSCComponent(rscName, data) {
1813
+ const createFromReadableStream = await importCreateFromReadableStream();
1597
1814
  if (typeof createFromReadableStream !== "function") {
1598
1815
  throw new RemoteComponentsError(
1599
1816
  'Failed to import "react-server-dom-webpack". Is Next.js installed correctly?'
@@ -1614,68 +1831,7 @@ function loadNextPagesComponent(bundle, route, nextData, name, container) {
1614
1831
  return { component };
1615
1832
  }
1616
1833
 
1617
- // src/shared/client/proxy-through-host.ts
1618
- function withRemoteSrc(resolveClientUrl, remoteSrc) {
1619
- const remoteOrigin = parseOrigin(remoteSrc);
1620
- return (url) => {
1621
- const urlOrigin = parseOrigin(url);
1622
- if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
1623
- return void 0;
1624
- }
1625
- return resolveClientUrl(remoteSrc, url);
1626
- };
1627
- }
1628
- function parseOrigin(url) {
1629
- try {
1630
- return new URL(url).origin;
1631
- } catch {
1632
- return void 0;
1633
- }
1634
- }
1635
-
1636
- // src/shared/client/set-attributes-from-props.ts
1637
- var DOMAttributeNames = {
1638
- acceptCharset: "accept-charset",
1639
- className: "class",
1640
- htmlFor: "for",
1641
- httpEquiv: "http-equiv",
1642
- noModule: "noModule"
1643
- };
1644
- var ignoreProps = [
1645
- "onLoad",
1646
- "onReady",
1647
- "dangerouslySetInnerHTML",
1648
- "children",
1649
- "onError",
1650
- "strategy",
1651
- "stylesheets"
1652
- ];
1653
- function isBooleanScriptAttribute(attr) {
1654
- return ["async", "defer", "noModule"].includes(attr);
1655
- }
1656
- function setAttributesFromProps(el, props) {
1657
- for (const [p, value] of Object.entries(props)) {
1658
- if (!Object.hasOwn(props, p))
1659
- continue;
1660
- if (ignoreProps.includes(p))
1661
- continue;
1662
- if (value === void 0) {
1663
- continue;
1664
- }
1665
- const attr = DOMAttributeNames[p] || p.toLowerCase();
1666
- if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
1667
- el[attr] = Boolean(value);
1668
- } else {
1669
- el.setAttribute(attr, String(value));
1670
- }
1671
- if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
1672
- el.setAttribute(attr, "");
1673
- el.removeAttribute(attr);
1674
- }
1675
- }
1676
- }
1677
-
1678
- // src/shared/client/static-loader.ts
1834
+ // src/runtime/loaders/static-loader.ts
1679
1835
  async function importViaCallback(absoluteSrc, resolveClientUrl) {
1680
1836
  const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
1681
1837
  const fetchUrl = new URL(resolvedUrl, location.href).href;
@@ -1825,101 +1981,9 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
1825
1981
  );
1826
1982
  }
1827
1983
 
1828
- // src/shared/contract/host-state.ts
1829
- function createHostState() {
1830
- return {
1831
- stage: "idle",
1832
- prevSrc: void 0,
1833
- prevUrl: void 0,
1834
- prevName: void 0,
1835
- prevIsRemoteComponent: false,
1836
- abortController: void 0
1837
- };
1838
- }
1839
-
1840
- // src/shared/contract/resolve-name-from-src.ts
1841
- function resolveNameFromSrc(src, defaultName) {
1842
- if (!src) {
1843
- return defaultName;
1844
- }
1845
- const hash = typeof src === "string" ? src : src.hash;
1846
- const hashIndex = hash.indexOf("#");
1847
- if (hashIndex < 0) {
1848
- return defaultName;
1849
- }
1850
- const name = hash.slice(hashIndex + 1);
1851
- return name || defaultName;
1852
- }
1853
-
1854
- // src/shared/ssr/fetch-headers.ts
1855
- function remoteFetchHeaders() {
1856
- return {
1857
- /**
1858
- * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
1859
- * If the remote component uses vercel deployment protection, ensure the host and remote vercel
1860
- * projects share a common automation bypass secret, and the shared secret is used as the
1861
- * VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
1862
- */
1863
- ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
1864
- "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
1865
- } : {},
1866
- Accept: "text/html"
1867
- };
1868
- }
1869
-
1870
- // src/shared/ssr/fetch-with-hooks.ts
1871
- async function fetchWithHooks(url, additionalInit, options = {}) {
1872
- const {
1873
- onRequest,
1874
- onResponse,
1875
- abortController = new AbortController()
1876
- } = options;
1877
- const signal = abortController.signal;
1878
- const hookOptions = {
1879
- signal,
1880
- abort: (reason) => abortController.abort(reason)
1881
- };
1882
- const init = {
1883
- method: "GET",
1884
- headers: remoteFetchHeaders(),
1885
- signal,
1886
- ...additionalInit
1887
- };
1888
- let res = await onRequest?.(url, init, hookOptions);
1889
- if (!res) {
1890
- try {
1891
- res = await fetch(url, init);
1892
- } catch (error) {
1893
- warnCrossOriginFetchError("FetchRemoteComponent", url);
1894
- throw error;
1895
- }
1896
- }
1897
- const transformedRes = await onResponse?.(url, res, hookOptions);
1898
- if (transformedRes) {
1899
- res = transformedRes;
1900
- }
1901
- return res;
1902
- }
1903
-
1904
- // src/shared/ssr/get-client-or-server-url.ts
1905
- function getClientOrServerUrl(src, serverFallback) {
1906
- const fallback = typeof location !== "undefined" ? location.href : serverFallback;
1907
- if (!src) {
1908
- return new URL(fallback);
1909
- }
1910
- return typeof src === "string" ? new URL(src, fallback) : src;
1911
- }
1912
-
1913
- // src/react/hooks/use-resolve-client-url.ts
1984
+ // src/host/react/hooks/use-resolve-client-url.ts
1914
1985
  import { useMemo } from "react";
1915
- import { useRemoteComponentsContext } from "#internal/react/context";
1916
-
1917
- // src/shared/client/default-resolve-client-url.ts
1918
- function bindResolveClientUrl(prop, remoteSrc) {
1919
- return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
1920
- }
1921
-
1922
- // src/react/hooks/use-resolve-client-url.ts
1986
+ import { useRemoteComponentsContext } from "#internal/host/react/context";
1923
1987
  function useResolveClientUrl(prop, urlHref) {
1924
1988
  const { resolveClientUrl: contextValue } = useRemoteComponentsContext();
1925
1989
  const resolveClientUrl = prop ?? contextValue;
@@ -1929,7 +1993,7 @@ function useResolveClientUrl(prop, urlHref) {
1929
1993
  );
1930
1994
  }
1931
1995
 
1932
- // src/react/hooks/use-shadow-root.ts
1996
+ // src/host/react/hooks/use-shadow-root.ts
1933
1997
  import { useLayoutEffect, useRef, useState } from "react";
1934
1998
  function useShadowRoot({
1935
1999
  isolate,
@@ -1978,7 +2042,7 @@ function useShadowRoot({
1978
2042
  return { shadowRoot, shadowRootContainerRef };
1979
2043
  }
1980
2044
 
1981
- // src/react/utils/extract-remote-html.ts
2045
+ // src/host/react/utils/extract-remote-html.ts
1982
2046
  var DUMMY_FALLBACK = "http://remote-components-dummy-fallback";
1983
2047
  function getRemoteComponentHtml(html) {
1984
2048
  if (typeof document === "undefined")
@@ -2000,18 +2064,17 @@ function getRemoteComponentHtml(html) {
2000
2064
  return "";
2001
2065
  }
2002
2066
 
2003
- // src/react/index.tsx
2004
- import { RemoteComponentsProvider } from "#internal/react/context";
2005
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
2067
+ // src/host/react/index.tsx
2068
+ import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
2006
2069
  import { createElement as createElement2 } from "react";
2007
- function RemoteComponent({
2070
+ function ConsumeRemoteComponent({
2008
2071
  src,
2009
2072
  isolate,
2010
2073
  mode = "open",
2011
2074
  reset,
2012
2075
  credentials = "same-origin",
2013
2076
  name: nameProp = "__vercel_remote_component",
2014
- shared = {},
2077
+ shared: shared2 = {},
2015
2078
  children,
2016
2079
  onBeforeLoad,
2017
2080
  onLoad,
@@ -2026,7 +2089,9 @@ function RemoteComponent({
2026
2089
  () => resolveNameFromSrc(src, nameProp),
2027
2090
  [src, nameProp]
2028
2091
  );
2029
- const [data, setData] = useState2(null);
2092
+ const [data, setData] = useState2(
2093
+ null
2094
+ );
2030
2095
  const url = useMemo2(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
2031
2096
  const resolveClientUrl = useResolveClientUrl(_resolveClientUrl, url.href);
2032
2097
  const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
@@ -2243,11 +2308,10 @@ function RemoteComponent({
2243
2308
  });
2244
2309
  self.__next_s = prevNextScripts;
2245
2310
  }
2246
- let rscName;
2311
+ const rscName = rsc ? `__remote_component_rsc_${escapeString(id)}_${escapeString(
2312
+ remoteName
2313
+ )}` : void 0;
2247
2314
  if (rsc) {
2248
- rscName = `__remote_component_rsc_${escapeString(
2249
- id
2250
- )}_${escapeString(remoteName)}`;
2251
2315
  rsc.textContent = rsc.textContent?.replace(
2252
2316
  new RegExp(`self\\["${remoteName}"\\]`, "g"),
2253
2317
  `self["${rscName}"]`
@@ -2265,7 +2329,7 @@ function RemoteComponent({
2265
2329
  componentHydrationHtml.current = `${Array.from(
2266
2330
  doc.querySelectorAll("link,style")
2267
2331
  ).map((link) => link.outerHTML).join("")}${reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>` : ""}${component.innerHTML}`;
2268
- const userShared = await shared;
2332
+ const userShared = await shared2;
2269
2333
  if ("__remote_components_missing_shared__" in userShared) {
2270
2334
  userShared.__remote_components_missing_shared__().catch((e) => {
2271
2335
  throw e;
@@ -2286,10 +2350,7 @@ function RemoteComponent({
2286
2350
  }
2287
2351
  setData(newData);
2288
2352
  if (shadowRoot) {
2289
- let shadowRootHtml = component.innerHTML;
2290
- if (reset) {
2291
- shadowRootHtml = `<style data-remote-components-reset="">:host { all: initial; }</style>${shadowRootHtml}`;
2292
- }
2353
+ const shadowRootHtml = reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>${component.innerHTML}` : component.innerHTML;
2293
2354
  shadowRoot.innerHTML = shadowRootHtml;
2294
2355
  htmlRef.current = null;
2295
2356
  setRemoteComponent(null);
@@ -2306,7 +2367,7 @@ function RemoteComponent({
2306
2367
  } else if (isolate === false) {
2307
2368
  setRemoteComponent(
2308
2369
  // TODO: remove wrapper div by converting HTML to RSC or React tree
2309
- /* @__PURE__ */ jsx2(
2370
+ /* @__PURE__ */ jsx3(
2310
2371
  "div",
2311
2372
  {
2312
2373
  dangerouslySetInnerHTML: { __html: component.innerHTML },
@@ -2358,7 +2419,7 @@ function RemoteComponent({
2358
2419
  };
2359
2420
  }),
2360
2421
  shared: {
2361
- ...sharedPolyfills(userShared),
2422
+ ...sharedPolyfills(userShared, resolveClientUrl),
2362
2423
  ...userShared
2363
2424
  },
2364
2425
  remoteShared,
@@ -2404,7 +2465,7 @@ function RemoteComponent({
2404
2465
  isolate,
2405
2466
  credentials,
2406
2467
  name,
2407
- shared,
2468
+ shared2,
2408
2469
  shadowRoot,
2409
2470
  reset,
2410
2471
  id,
@@ -2419,13 +2480,13 @@ function RemoteComponent({
2419
2480
  if (remoteComponent instanceof Error) {
2420
2481
  throw remoteComponent;
2421
2482
  }
2422
- const metadataJson = /* @__PURE__ */ jsx2("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
2483
+ const metadataJson = /* @__PURE__ */ jsx3("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
2423
2484
  name: data?.name || name,
2424
2485
  bundle: data?.bundle || "default",
2425
2486
  route: data?.route || DEFAULT_ROUTE,
2426
2487
  runtime: hostStateRef.current.prevIsRemoteComponent ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
2427
2488
  }) });
2428
- const resetStyle = reset ? /* @__PURE__ */ jsx2("style", { "data-remote-components-reset": "react", children: `:host { all: initial; }` }) : null;
2489
+ const resetStyle = reset ? /* @__PURE__ */ jsx3("style", { "data-remote-components-reset": "react", children: `:host { all: initial; }` }) : null;
2429
2490
  const linksToRender = data?.links?.map((link) => /* @__PURE__ */ createElement2(
2430
2491
  "link",
2431
2492
  {
@@ -2484,7 +2545,7 @@ function RemoteComponent({
2484
2545
  typeof document === "undefined" ? (
2485
2546
  // eslint-disable-next-line react/no-unknown-property
2486
2547
  /* @__PURE__ */ jsxs("template", { shadowrootmode: mode, children: [
2487
- typeof document === "undefined" ? /* @__PURE__ */ jsx2(
2548
+ typeof document === "undefined" ? /* @__PURE__ */ jsx3(
2488
2549
  "div",
2489
2550
  {
2490
2551
  dangerouslySetInnerHTML: {
@@ -2507,11 +2568,11 @@ function RemoteComponent({
2507
2568
  ) : null,
2508
2569
  shadowRoot && remoteComponent ? createPortal(
2509
2570
  /* @__PURE__ */ jsxs(Fragment, { children: [
2510
- /* @__PURE__ */ jsx2("template", { id: `${name}_start` }),
2571
+ /* @__PURE__ */ jsx3("template", { id: `${name}_start` }),
2511
2572
  resetStyle,
2512
2573
  linksToRender,
2513
2574
  remoteComponent,
2514
- /* @__PURE__ */ jsx2("template", { id: `${name}_end`, ref: endTemplateRef })
2575
+ /* @__PURE__ */ jsx3("template", { id: `${name}_end`, ref: endTemplateRef })
2515
2576
  ] }),
2516
2577
  shadowRoot
2517
2578
  ) : null
@@ -2522,32 +2583,15 @@ function RemoteComponent({
2522
2583
  }
2523
2584
  htmlRef.current = null;
2524
2585
  return /* @__PURE__ */ jsxs(Fragment, { children: [
2525
- /* @__PURE__ */ jsx2("template", { id: `${name}_start` }),
2586
+ /* @__PURE__ */ jsx3("template", { id: `${name}_start` }),
2526
2587
  metadataJson,
2527
2588
  componentToRender,
2528
- /* @__PURE__ */ jsx2("template", { id: `${name}_end`, ref: endTemplateRef })
2589
+ /* @__PURE__ */ jsx3("template", { id: `${name}_end`, ref: endTemplateRef })
2529
2590
  ] });
2530
2591
  }
2531
2592
 
2532
- // src/next/host/client/index.tsx
2533
- import { RemoteComponentsProvider as RemoteComponentsProvider2 } from "#internal/react/context";
2534
-
2535
- // src/next/host/app-router-compat.tsx
2593
+ // src/host/nextjs/app-compat.tsx
2536
2594
  import { usePathname, useSearchParams } from "next/navigation";
2537
- import { jsx as jsx3 } from "react/jsx-runtime";
2538
- function imageImpl2(ImageComponent, bundle) {
2539
- const component = function RemoteImage(props) {
2540
- return /* @__PURE__ */ jsx3(
2541
- ImageComponent,
2542
- {
2543
- ...props,
2544
- src: applyBundleUrlToImagePropsSrc(bundle, props.src)
2545
- }
2546
- );
2547
- };
2548
- component.default = component;
2549
- return component;
2550
- }
2551
2595
  var routerImpl = async () => {
2552
2596
  const { useRouter } = await import("next/navigation");
2553
2597
  return Promise.resolve({
@@ -2611,17 +2655,34 @@ var routerImpl = async () => {
2611
2655
  });
2612
2656
  };
2613
2657
 
2614
- // src/next/host/client/index.tsx
2658
+ // src/host/nextjs/image-shared.ts
2659
+ function createNextImageSharedEntries(getWrappedImage, options) {
2660
+ const entries = {
2661
+ "next/image": (bundle) => Promise.resolve(getWrappedImage(bundle)),
2662
+ "next/dist/client/image-component": (bundle) => Promise.resolve({
2663
+ Image: getWrappedImage(bundle)
2664
+ })
2665
+ };
2666
+ if (options?.getImageProps) {
2667
+ entries["next/dist/api/image"] = (bundle) => Promise.resolve({
2668
+ default: getWrappedImage(bundle),
2669
+ getImageProps: options.getImageProps
2670
+ });
2671
+ }
2672
+ return entries;
2673
+ }
2674
+
2675
+ // src/host/nextjs/app-client-only.tsx
2615
2676
  import { jsx as jsx4 } from "react/jsx-runtime";
2616
2677
  async function tryImportShared() {
2617
2678
  try {
2618
- const { shared } = await import("remote-components/shared/host/app");
2619
- return shared;
2679
+ const { shared: shared2 } = await Promise.resolve().then(() => (init_app(), app_exports));
2680
+ return shared2;
2620
2681
  } catch {
2621
2682
  return {};
2622
2683
  }
2623
2684
  }
2624
- var sharedModules = async (userShared) => {
2685
+ var sharedModules = async (userShared, resolveClientUrl) => {
2625
2686
  const [resolvedShared, resolvedUserShared] = await Promise.all([
2626
2687
  tryImportShared(),
2627
2688
  userShared ?? Promise.resolve({})
@@ -2629,19 +2690,27 @@ var sharedModules = async (userShared) => {
2629
2690
  return {
2630
2691
  ...resolvedShared,
2631
2692
  "next/router": routerImpl,
2632
- "next/image": (bundle) => Promise.resolve(imageImpl2(Image.default, bundle ?? "default")),
2633
- "next/dist/client/image-component": (bundle) => Promise.resolve({ Image: imageImpl2(Image.default, bundle ?? "default") }),
2693
+ ...createNextImageSharedEntries(
2694
+ (bundle) => imageImpl2(Image.default, bundle ?? "default", resolveClientUrl)
2695
+ ),
2634
2696
  ...resolvedUserShared
2635
2697
  };
2636
2698
  };
2637
- function RemoteComponent2(props) {
2699
+ function ConsumeRemoteComponent2(props) {
2638
2700
  if (typeof props.src !== "string" && !(props.src instanceof URL)) {
2639
2701
  return props.children ?? null;
2640
2702
  }
2641
- return /* @__PURE__ */ jsx4(RemoteComponent, { ...props, shared: sharedModules(props.shared) });
2703
+ const src = typeof props.src === "string" ? props.src : props.src.href;
2704
+ const resolveClientUrl = props.resolveClientUrl ? bindResolveClientUrl(props.resolveClientUrl, src) : void 0;
2705
+ return /* @__PURE__ */ jsx4(
2706
+ ConsumeRemoteComponent,
2707
+ {
2708
+ ...props,
2709
+ shared: sharedModules(props.shared, resolveClientUrl)
2710
+ }
2711
+ );
2642
2712
  }
2643
2713
  export {
2644
- RemoteComponent2 as RemoteComponent,
2645
- RemoteComponentsProvider2 as RemoteComponentsProvider
2714
+ ConsumeRemoteComponent2 as ConsumeRemoteComponent
2646
2715
  };
2647
- //# sourceMappingURL=index.js.map
2716
+ //# sourceMappingURL=client-only.js.map