remote-components 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (469) hide show
  1. package/dist/{next/config.cjs → config/nextjs.cjs} +76 -101
  2. package/dist/config/nextjs.cjs.map +1 -0
  3. package/dist/{next/config.d.ts → config/nextjs.d.ts} +4 -4
  4. package/dist/{next/config.js → config/nextjs.js} +72 -97
  5. package/dist/config/nextjs.js.map +1 -0
  6. package/dist/{webpack.cjs → config/webpack.cjs} +13 -29
  7. package/dist/config/webpack.cjs.map +1 -0
  8. package/dist/{webpack.js → config/webpack.js} +12 -28
  9. package/dist/config/webpack.js.map +1 -0
  10. package/dist/{shared/remote → host/defaults}/app.cjs +2 -2
  11. package/dist/host/defaults/app.cjs.map +1 -0
  12. package/dist/host/defaults/app.js +8 -0
  13. package/dist/host/defaults/app.js.map +1 -0
  14. package/dist/{shared/remote → host/defaults}/pages.cjs +2 -2
  15. package/dist/host/defaults/pages.cjs.map +1 -0
  16. package/dist/host/defaults/pages.js +8 -0
  17. package/dist/host/defaults/pages.js.map +1 -0
  18. package/dist/{html/host.cjs → host/html.cjs} +1270 -1201
  19. package/dist/host/html.cjs.map +1 -0
  20. package/dist/{html/host.d.ts → host/html.d.ts} +0 -2
  21. package/dist/{html/host.js → host/html.js} +1266 -1196
  22. package/dist/host/html.js.map +1 -0
  23. package/dist/{next/host/client/index.cjs → host/nextjs/app/client-only.cjs} +690 -518
  24. package/dist/host/nextjs/app/client-only.cjs.map +1 -0
  25. package/dist/host/nextjs/app/client-only.d.ts +16 -0
  26. package/dist/{next/host/client/index.js → host/nextjs/app/client-only.js} +693 -514
  27. package/dist/host/nextjs/app/client-only.js.map +1 -0
  28. package/dist/{next/host/app-router-server.cjs → host/nextjs/app.cjs} +11 -10
  29. package/dist/host/nextjs/app.cjs.map +1 -0
  30. package/dist/host/nextjs/app.d.ts +29 -0
  31. package/dist/{next/host/app-router-server.js → host/nextjs/app.js} +7 -6
  32. package/dist/host/nextjs/app.js.map +1 -0
  33. package/dist/{next/host/pages-router-client.cjs → host/nextjs/pages/client-only.cjs} +8 -8
  34. package/dist/host/nextjs/pages/client-only.cjs.map +1 -0
  35. package/dist/host/nextjs/pages/client-only.d.ts +31 -0
  36. package/dist/{next/host/pages-router-client.js → host/nextjs/pages/client-only.js} +4 -4
  37. package/dist/host/nextjs/pages/client-only.js.map +1 -0
  38. package/dist/{next/host/pages-router-server.cjs → host/nextjs/pages.cjs} +44 -55
  39. package/dist/host/nextjs/pages.cjs.map +1 -0
  40. package/dist/host/nextjs/pages.d.ts +77 -0
  41. package/dist/{next/host/pages-router-server.js → host/nextjs/pages.js} +38 -49
  42. package/dist/host/nextjs/pages.js.map +1 -0
  43. package/dist/{internal/shared/client/proxy-through-host.cjs → host/proxy/client.cjs} +19 -13
  44. package/dist/host/proxy/client.cjs.map +1 -0
  45. package/dist/host/proxy/client.d.ts +31 -0
  46. package/dist/host/proxy/client.js +30 -0
  47. package/dist/host/proxy/client.js.map +1 -0
  48. package/dist/{shared/host/proxy.cjs → host/proxy/protected-fetch.cjs} +6 -6
  49. package/dist/host/proxy/protected-fetch.cjs.map +1 -0
  50. package/dist/{shared/host/proxy.js → host/proxy/protected-fetch.js} +3 -3
  51. package/dist/host/proxy/protected-fetch.js.map +1 -0
  52. package/dist/{next → host}/proxy.cjs +12 -92
  53. package/dist/host/proxy.cjs.map +1 -0
  54. package/dist/host/proxy.d.ts +30 -0
  55. package/dist/{next → host}/proxy.js +11 -88
  56. package/dist/host/proxy.js.map +1 -0
  57. package/dist/{react/index.cjs → host/react.cjs} +552 -477
  58. package/dist/host/react.cjs.map +1 -0
  59. package/dist/host/react.d.ts +366 -0
  60. package/dist/{react/index.js → host/react.js} +551 -474
  61. package/dist/host/react.js.map +1 -0
  62. package/dist/internal/{webpack/shared-modules.cjs → config/webpack/apply-shared-modules.cjs} +12 -15
  63. package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -0
  64. package/dist/internal/{webpack/shared-modules.js → config/webpack/apply-shared-modules.js} +9 -12
  65. package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -0
  66. package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.cjs +1 -1
  67. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -0
  68. package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.js +1 -1
  69. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -0
  70. package/dist/internal/{next/host/app-router-client.cjs → host/nextjs/app-client.cjs} +36 -29
  71. package/dist/internal/host/nextjs/app-client.cjs.map +1 -0
  72. package/dist/internal/host/nextjs/app-client.d.ts +25 -0
  73. package/dist/internal/{next/host/app-router-client.js → host/nextjs/app-client.js} +27 -25
  74. package/dist/internal/host/nextjs/app-client.js.map +1 -0
  75. package/dist/internal/{next/host/app-router-compat.cjs → host/nextjs/app-compat.cjs} +5 -22
  76. package/dist/internal/host/nextjs/app-compat.cjs.map +1 -0
  77. package/dist/internal/{next/host/app-router-compat.d.ts → host/nextjs/app-compat.d.ts} +1 -7
  78. package/dist/internal/{next/host/app-router-compat.js → host/nextjs/app-compat.js} +2 -18
  79. package/dist/internal/host/nextjs/app-compat.js.map +1 -0
  80. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -0
  81. package/dist/internal/host/nextjs/dom-flight.d.ts +39 -0
  82. package/dist/internal/host/nextjs/dom-flight.js.map +1 -0
  83. package/dist/internal/host/nextjs/image-impl.cjs +60 -0
  84. package/dist/internal/host/nextjs/image-impl.cjs.map +1 -0
  85. package/dist/internal/host/nextjs/image-impl.d.ts +10 -0
  86. package/dist/internal/host/nextjs/image-impl.js +36 -0
  87. package/dist/internal/host/nextjs/image-impl.js.map +1 -0
  88. package/dist/internal/host/nextjs/image-shared.cjs +43 -0
  89. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -0
  90. package/dist/internal/host/nextjs/image-shared.d.ts +9 -0
  91. package/dist/internal/host/nextjs/image-shared.js +19 -0
  92. package/dist/internal/host/nextjs/image-shared.js.map +1 -0
  93. package/dist/internal/{next/host → host/nextjs}/remote-component-links.cjs +2 -2
  94. package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -0
  95. package/dist/internal/{next/host → host/nextjs}/remote-component-links.d.ts +1 -1
  96. package/dist/internal/{next/host → host/nextjs}/remote-component-links.js +2 -2
  97. package/dist/internal/host/nextjs/remote-component-links.js.map +1 -0
  98. package/dist/internal/host/nextjs/skeleton.cjs.map +1 -0
  99. package/dist/internal/host/nextjs/skeleton.js.map +1 -0
  100. package/dist/internal/{react → host/react}/context.cjs +3 -3
  101. package/dist/internal/host/react/context.cjs.map +1 -0
  102. package/dist/internal/{react → host/react}/context.d.ts +4 -4
  103. package/dist/internal/{react → host/react}/context.js +2 -2
  104. package/dist/internal/host/react/context.js.map +1 -0
  105. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.cjs +2 -2
  106. package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -0
  107. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.d.ts +1 -1
  108. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.js +2 -2
  109. package/dist/internal/host/react/hooks/use-resolve-client-url.js.map +1 -0
  110. package/dist/internal/host/server/fetch-headers.cjs.map +1 -0
  111. package/dist/internal/host/server/fetch-headers.js.map +1 -0
  112. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.cjs +6 -6
  113. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -0
  114. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.d.ts +6 -1
  115. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.js +9 -9
  116. package/dist/internal/host/server/fetch-remote-component.js.map +1 -0
  117. package/dist/internal/{shared/ssr → host/server}/fetch-with-hooks.cjs +11 -15
  118. package/dist/internal/host/server/fetch-with-hooks.cjs.map +1 -0
  119. package/dist/internal/host/server/fetch-with-hooks.d.ts +21 -0
  120. package/dist/internal/{shared/ssr → host/server}/fetch-with-hooks.js +11 -15
  121. package/dist/internal/host/server/fetch-with-hooks.js.map +1 -0
  122. package/dist/internal/host/server/get-client-or-server-url.cjs.map +1 -0
  123. package/dist/internal/host/server/get-client-or-server-url.js.map +1 -0
  124. package/dist/internal/{shared/client → host/server}/get-client-src.cjs +1 -1
  125. package/dist/internal/host/server/get-client-src.cjs.map +1 -0
  126. package/dist/internal/{shared/client → host/server}/get-client-src.js +1 -1
  127. package/dist/internal/host/server/get-client-src.js.map +1 -0
  128. package/dist/internal/host/server/get-ssr-relative-path-base-url.cjs.map +1 -0
  129. package/dist/internal/host/server/get-ssr-relative-path-base-url.js.map +1 -0
  130. package/dist/internal/host/server/types.cjs +17 -0
  131. package/dist/internal/host/server/types.cjs.map +1 -0
  132. package/dist/internal/host/server/types.d.ts +33 -0
  133. package/dist/internal/host/server/types.js +1 -0
  134. package/dist/internal/host/server/types.js.map +1 -0
  135. package/dist/internal/host/shared/asset-descriptors.cjs +17 -0
  136. package/dist/internal/host/shared/asset-descriptors.cjs.map +1 -0
  137. package/dist/internal/host/shared/asset-descriptors.d.ts +21 -0
  138. package/dist/internal/host/shared/asset-descriptors.js +1 -0
  139. package/dist/internal/host/shared/asset-descriptors.js.map +1 -0
  140. package/dist/internal/host/shared/config.cjs +17 -0
  141. package/dist/internal/host/shared/config.cjs.map +1 -0
  142. package/dist/internal/host/shared/config.d.ts +100 -0
  143. package/dist/internal/host/shared/config.js +1 -0
  144. package/dist/internal/host/shared/config.js.map +1 -0
  145. package/dist/internal/host/shared/fetch-interceptors.cjs +17 -0
  146. package/dist/internal/host/shared/fetch-interceptors.cjs.map +1 -0
  147. package/dist/{types-cbe44b51.d.ts → internal/host/shared/fetch-interceptors.d.ts} +7 -73
  148. package/dist/internal/host/shared/fetch-interceptors.js +1 -0
  149. package/dist/internal/host/shared/fetch-interceptors.js.map +1 -0
  150. package/dist/internal/{shared/client → host/shared}/polyfill.cjs +7 -6
  151. package/dist/internal/host/shared/polyfill.cjs.map +1 -0
  152. package/dist/internal/{shared/client → host/shared}/polyfill.d.ts +2 -1
  153. package/dist/internal/{shared/client → host/shared}/polyfill.js +7 -6
  154. package/dist/internal/host/shared/polyfill.js.map +1 -0
  155. package/dist/internal/host/shared/resolved-data.cjs +17 -0
  156. package/dist/internal/host/shared/resolved-data.cjs.map +1 -0
  157. package/dist/internal/host/shared/resolved-data.d.ts +48 -0
  158. package/dist/internal/host/shared/resolved-data.js +1 -0
  159. package/dist/internal/host/shared/resolved-data.js.map +1 -0
  160. package/dist/{next/remote/server.cjs → internal/host/shared/state.cjs} +16 -7
  161. package/dist/internal/host/shared/state.cjs.map +1 -0
  162. package/dist/internal/host/shared/state.d.ts +53 -0
  163. package/dist/internal/host/shared/state.js +14 -0
  164. package/dist/internal/host/shared/state.js.map +1 -0
  165. package/dist/internal/host/utils/resolve-name-from-src.cjs +40 -0
  166. package/dist/internal/host/utils/resolve-name-from-src.cjs.map +1 -0
  167. package/dist/internal/host/utils/resolve-name-from-src.d.ts +13 -0
  168. package/dist/internal/host/utils/resolve-name-from-src.js +16 -0
  169. package/dist/internal/host/utils/resolve-name-from-src.js.map +1 -0
  170. package/dist/internal/{next/remote/render-client.cjs → remote/nextjs/app-client.cjs} +8 -8
  171. package/dist/internal/remote/nextjs/app-client.cjs.map +1 -0
  172. package/dist/internal/{next/remote/render-client.js → remote/nextjs/app-client.js} +4 -4
  173. package/dist/internal/remote/nextjs/app-client.js.map +1 -0
  174. package/dist/internal/runtime/constants.cjs +50 -0
  175. package/dist/internal/runtime/constants.cjs.map +1 -0
  176. package/dist/internal/runtime/constants.d.ts +10 -0
  177. package/dist/internal/runtime/constants.js +20 -0
  178. package/dist/internal/runtime/constants.js.map +1 -0
  179. package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs.map +1 -1
  180. package/dist/internal/{shared/client → runtime/html}/apply-origin.d.ts +1 -1
  181. package/dist/internal/{shared/client → runtime/html}/apply-origin.js.map +1 -1
  182. package/dist/internal/runtime/html/parse-remote-html.cjs +140 -0
  183. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -0
  184. package/dist/internal/runtime/html/parse-remote-html.d.ts +88 -0
  185. package/dist/internal/runtime/html/parse-remote-html.js +110 -0
  186. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -0
  187. package/dist/internal/runtime/html/set-attributes-from-props.cjs +68 -0
  188. package/dist/internal/runtime/html/set-attributes-from-props.cjs.map +1 -0
  189. package/dist/internal/runtime/html/set-attributes-from-props.d.ts +3 -0
  190. package/dist/internal/runtime/html/set-attributes-from-props.js +44 -0
  191. package/dist/internal/runtime/html/set-attributes-from-props.js.map +1 -0
  192. package/dist/internal/runtime/loaders/component-loader.cjs +184 -0
  193. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -0
  194. package/dist/internal/runtime/loaders/component-loader.d.ts +31 -0
  195. package/dist/internal/runtime/loaders/component-loader.js +150 -0
  196. package/dist/internal/runtime/loaders/component-loader.js.map +1 -0
  197. package/dist/internal/runtime/loaders/script-loader.cjs +69 -0
  198. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -0
  199. package/dist/internal/runtime/loaders/script-loader.d.ts +10 -0
  200. package/dist/internal/runtime/loaders/script-loader.js +48 -0
  201. package/dist/internal/runtime/loaders/script-loader.js.map +1 -0
  202. package/dist/internal/runtime/loaders/static-loader.cjs +177 -0
  203. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -0
  204. package/dist/internal/runtime/loaders/static-loader.d.ts +10 -0
  205. package/dist/internal/runtime/loaders/static-loader.js +153 -0
  206. package/dist/internal/runtime/loaders/static-loader.js.map +1 -0
  207. package/dist/internal/runtime/metadata.cjs +17 -0
  208. package/dist/internal/runtime/metadata.cjs.map +1 -0
  209. package/dist/internal/runtime/metadata.d.ts +16 -0
  210. package/dist/internal/runtime/metadata.js +1 -0
  211. package/dist/internal/runtime/metadata.js.map +1 -0
  212. package/dist/internal/runtime/rsc.cjs +92 -0
  213. package/dist/internal/runtime/rsc.cjs.map +1 -0
  214. package/dist/internal/runtime/rsc.d.ts +8 -0
  215. package/dist/internal/runtime/rsc.js +68 -0
  216. package/dist/internal/runtime/rsc.js.map +1 -0
  217. package/dist/internal/runtime/turbopack/chunk-loader.cjs +244 -0
  218. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -0
  219. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +11 -0
  220. package/dist/internal/runtime/turbopack/chunk-loader.js +227 -0
  221. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -0
  222. package/dist/internal/runtime/turbopack/module.cjs +257 -0
  223. package/dist/internal/runtime/turbopack/module.cjs.map +1 -0
  224. package/dist/internal/runtime/turbopack/module.d.ts +61 -0
  225. package/dist/internal/runtime/turbopack/module.js +233 -0
  226. package/dist/internal/runtime/turbopack/module.js.map +1 -0
  227. package/dist/internal/runtime/turbopack/patterns.cjs +44 -0
  228. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -0
  229. package/dist/internal/runtime/turbopack/patterns.d.ts +109 -0
  230. package/dist/internal/runtime/turbopack/patterns.js +15 -0
  231. package/dist/internal/runtime/turbopack/patterns.js.map +1 -0
  232. package/dist/internal/runtime/turbopack/shared-modules.cjs +152 -0
  233. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -0
  234. package/dist/internal/runtime/turbopack/shared-modules.d.ts +17 -0
  235. package/dist/internal/runtime/turbopack/shared-modules.js +133 -0
  236. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -0
  237. package/dist/internal/runtime/turbopack/webpack-runtime.cjs +137 -0
  238. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -0
  239. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +20 -0
  240. package/dist/internal/runtime/turbopack/webpack-runtime.js +107 -0
  241. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -0
  242. package/dist/internal/runtime/types.cjs +17 -0
  243. package/dist/internal/runtime/types.cjs.map +1 -0
  244. package/dist/internal/runtime/types.d.ts +40 -0
  245. package/dist/internal/runtime/types.js +1 -0
  246. package/dist/internal/runtime/types.js.map +1 -0
  247. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.cjs +2 -2
  248. package/dist/internal/runtime/url/default-resolve-client-url.cjs.map +1 -0
  249. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.d.ts +1 -1
  250. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.js +1 -1
  251. package/dist/internal/runtime/url/default-resolve-client-url.js.map +1 -0
  252. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.cjs +1 -1
  253. package/dist/internal/runtime/url/protected-rc-fallback.cjs.map +1 -0
  254. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.js +1 -1
  255. package/dist/internal/runtime/url/protected-rc-fallback.js.map +1 -0
  256. package/dist/internal/runtime/url/resolve-client-url.cjs +45 -0
  257. package/dist/internal/runtime/url/resolve-client-url.cjs.map +1 -0
  258. package/dist/internal/{shared/client/proxy-through-host.d.ts → runtime/url/resolve-client-url.d.ts} +6 -25
  259. package/dist/internal/runtime/url/resolve-client-url.js +21 -0
  260. package/dist/internal/runtime/url/resolve-client-url.js.map +1 -0
  261. package/dist/internal/utils/abort.cjs.map +1 -0
  262. package/dist/internal/utils/abort.js.map +1 -0
  263. package/dist/internal/{shared → utils}/constants.cjs +3 -0
  264. package/dist/internal/utils/constants.cjs.map +1 -0
  265. package/dist/internal/utils/constants.d.ts +5 -0
  266. package/dist/internal/{shared → utils}/constants.js +2 -0
  267. package/dist/internal/utils/constants.js.map +1 -0
  268. package/dist/internal/{shared → utils}/error.cjs +4 -4
  269. package/dist/internal/utils/error.cjs.map +1 -0
  270. package/dist/internal/{shared → utils}/error.js +4 -4
  271. package/dist/internal/utils/error.js.map +1 -0
  272. package/dist/internal/{shared/utils → utils}/logger.cjs +3 -3
  273. package/dist/internal/utils/logger.cjs.map +1 -0
  274. package/dist/internal/{shared/utils → utils}/logger.d.ts +2 -2
  275. package/dist/internal/{shared/utils → utils}/logger.js +3 -3
  276. package/dist/internal/utils/logger.js.map +1 -0
  277. package/dist/internal/utils.cjs.map +1 -0
  278. package/dist/internal/utils.js.map +1 -0
  279. package/dist/{shared/host → remote/defaults}/app.cjs +2 -6
  280. package/dist/remote/defaults/app.cjs.map +1 -0
  281. package/dist/remote/defaults/app.js +8 -0
  282. package/dist/remote/defaults/app.js.map +1 -0
  283. package/dist/{shared/host → remote/defaults}/pages.cjs +2 -6
  284. package/dist/remote/defaults/pages.cjs.map +1 -0
  285. package/dist/remote/defaults/pages.js +8 -0
  286. package/dist/remote/defaults/pages.js.map +1 -0
  287. package/dist/{shared/remote → remote/defaults}/wrapper.cjs +12 -10
  288. package/dist/remote/defaults/wrapper.cjs.map +1 -0
  289. package/dist/remote/defaults/wrapper.js +27 -0
  290. package/dist/remote/defaults/wrapper.js.map +1 -0
  291. package/dist/{html/remote.cjs → remote/html.cjs} +16 -16
  292. package/dist/remote/html.cjs.map +1 -0
  293. package/dist/{html/remote.js → remote/html.js} +16 -16
  294. package/dist/remote/html.js.map +1 -0
  295. package/dist/{shared/remote/proxy.cjs → remote/middleware.cjs} +37 -12
  296. package/dist/remote/middleware.cjs.map +1 -0
  297. package/dist/remote/middleware.d.ts +27 -0
  298. package/dist/{shared/remote/proxy.js → remote/middleware.js} +32 -5
  299. package/dist/remote/middleware.js.map +1 -0
  300. package/dist/{internal/next/remote/render-server.cjs → remote/nextjs/app.cjs} +14 -16
  301. package/dist/remote/nextjs/app.cjs.map +1 -0
  302. package/dist/remote/nextjs/app.d.ts +45 -0
  303. package/dist/{internal/next/remote/render-server.js → remote/nextjs/app.js} +9 -11
  304. package/dist/remote/nextjs/app.js.map +1 -0
  305. package/dist/{next/remote/pages-router.cjs → remote/nextjs/pages.cjs} +8 -8
  306. package/dist/remote/nextjs/pages.cjs.map +1 -0
  307. package/dist/{next/remote/pages-router.d.ts → remote/nextjs/pages.d.ts} +8 -8
  308. package/dist/{next/remote/pages-router.js → remote/nextjs/pages.js} +4 -4
  309. package/dist/remote/nextjs/pages.js.map +1 -0
  310. package/dist/server-handoff-8c89b856.d.ts +46 -0
  311. package/package.json +126 -157
  312. package/dist/component-loader-76eb1b8b.d.ts +0 -200
  313. package/dist/html/host.cjs.map +0 -1
  314. package/dist/html/host.js.map +0 -1
  315. package/dist/html/remote.cjs.map +0 -1
  316. package/dist/html/remote.js.map +0 -1
  317. package/dist/internal/next/host/app-router-client.cjs.map +0 -1
  318. package/dist/internal/next/host/app-router-client.d.ts +0 -66
  319. package/dist/internal/next/host/app-router-client.js.map +0 -1
  320. package/dist/internal/next/host/app-router-compat.cjs.map +0 -1
  321. package/dist/internal/next/host/app-router-compat.js.map +0 -1
  322. package/dist/internal/next/host/remote-component-links.cjs.map +0 -1
  323. package/dist/internal/next/host/remote-component-links.js.map +0 -1
  324. package/dist/internal/next/remote/render-client.cjs.map +0 -1
  325. package/dist/internal/next/remote/render-client.js.map +0 -1
  326. package/dist/internal/next/remote/render-server.cjs.map +0 -1
  327. package/dist/internal/next/remote/render-server.d.ts +0 -47
  328. package/dist/internal/next/remote/render-server.js.map +0 -1
  329. package/dist/internal/react/context.cjs.map +0 -1
  330. package/dist/internal/react/context.js.map +0 -1
  331. package/dist/internal/react/hooks/use-resolve-client-url.cjs.map +0 -1
  332. package/dist/internal/react/hooks/use-resolve-client-url.js.map +0 -1
  333. package/dist/internal/shared/client/default-resolve-client-url.cjs.map +0 -1
  334. package/dist/internal/shared/client/default-resolve-client-url.js.map +0 -1
  335. package/dist/internal/shared/client/get-client-src.cjs.map +0 -1
  336. package/dist/internal/shared/client/get-client-src.js.map +0 -1
  337. package/dist/internal/shared/client/polyfill.cjs.map +0 -1
  338. package/dist/internal/shared/client/polyfill.js.map +0 -1
  339. package/dist/internal/shared/client/protected-rc-fallback.cjs.map +0 -1
  340. package/dist/internal/shared/client/protected-rc-fallback.js.map +0 -1
  341. package/dist/internal/shared/client/proxy-through-host.cjs.map +0 -1
  342. package/dist/internal/shared/client/proxy-through-host.js +0 -26
  343. package/dist/internal/shared/client/proxy-through-host.js.map +0 -1
  344. package/dist/internal/shared/client/remote-component.cjs +0 -1436
  345. package/dist/internal/shared/client/remote-component.cjs.map +0 -1
  346. package/dist/internal/shared/client/remote-component.d.ts +0 -62
  347. package/dist/internal/shared/client/remote-component.js +0 -1385
  348. package/dist/internal/shared/client/remote-component.js.map +0 -1
  349. package/dist/internal/shared/constants.cjs.map +0 -1
  350. package/dist/internal/shared/constants.d.ts +0 -4
  351. package/dist/internal/shared/constants.js.map +0 -1
  352. package/dist/internal/shared/error.cjs.map +0 -1
  353. package/dist/internal/shared/error.js.map +0 -1
  354. package/dist/internal/shared/ssr/dom-flight.cjs.map +0 -1
  355. package/dist/internal/shared/ssr/dom-flight.d.ts +0 -2
  356. package/dist/internal/shared/ssr/dom-flight.js.map +0 -1
  357. package/dist/internal/shared/ssr/fetch-headers.cjs.map +0 -1
  358. package/dist/internal/shared/ssr/fetch-headers.js.map +0 -1
  359. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +0 -1
  360. package/dist/internal/shared/ssr/fetch-remote-component.js.map +0 -1
  361. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +0 -1
  362. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +0 -56
  363. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +0 -1
  364. package/dist/internal/shared/ssr/get-client-or-server-url.cjs.map +0 -1
  365. package/dist/internal/shared/ssr/get-client-or-server-url.js.map +0 -1
  366. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs.map +0 -1
  367. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js.map +0 -1
  368. package/dist/internal/shared/ssr/skeleton.cjs.map +0 -1
  369. package/dist/internal/shared/ssr/skeleton.js.map +0 -1
  370. package/dist/internal/shared/utils/abort.cjs.map +0 -1
  371. package/dist/internal/shared/utils/abort.js.map +0 -1
  372. package/dist/internal/shared/utils/logger.cjs.map +0 -1
  373. package/dist/internal/shared/utils/logger.js.map +0 -1
  374. package/dist/internal/shared/utils.cjs.map +0 -1
  375. package/dist/internal/shared/utils.js.map +0 -1
  376. package/dist/internal/webpack/next-client-pages-loader.cjs.map +0 -1
  377. package/dist/internal/webpack/next-client-pages-loader.js.map +0 -1
  378. package/dist/internal/webpack/shared-modules.cjs.map +0 -1
  379. package/dist/internal/webpack/shared-modules.js.map +0 -1
  380. package/dist/next/config.cjs.map +0 -1
  381. package/dist/next/config.js.map +0 -1
  382. package/dist/next/host/app-router-server.cjs.map +0 -1
  383. package/dist/next/host/app-router-server.d.ts +0 -60
  384. package/dist/next/host/app-router-server.js.map +0 -1
  385. package/dist/next/host/client/index.cjs.map +0 -1
  386. package/dist/next/host/client/index.d.ts +0 -19
  387. package/dist/next/host/client/index.js.map +0 -1
  388. package/dist/next/host/pages-router-client.cjs.map +0 -1
  389. package/dist/next/host/pages-router-client.d.ts +0 -56
  390. package/dist/next/host/pages-router-client.js.map +0 -1
  391. package/dist/next/host/pages-router-server.cjs.map +0 -1
  392. package/dist/next/host/pages-router-server.d.ts +0 -104
  393. package/dist/next/host/pages-router-server.js.map +0 -1
  394. package/dist/next/index.cjs +0 -53
  395. package/dist/next/index.cjs.map +0 -1
  396. package/dist/next/index.d.ts +0 -56
  397. package/dist/next/index.js +0 -19
  398. package/dist/next/index.js.map +0 -1
  399. package/dist/next/proxy.cjs.map +0 -1
  400. package/dist/next/proxy.d.ts +0 -56
  401. package/dist/next/proxy.js.map +0 -1
  402. package/dist/next/remote/pages-router.cjs.map +0 -1
  403. package/dist/next/remote/pages-router.js.map +0 -1
  404. package/dist/next/remote/server.cjs.map +0 -1
  405. package/dist/next/remote/server.d.ts +0 -1
  406. package/dist/next/remote/server.js +0 -5
  407. package/dist/next/remote/server.js.map +0 -1
  408. package/dist/proxy-through-host-a676a522.d.ts +0 -52
  409. package/dist/react/index.cjs.map +0 -1
  410. package/dist/react/index.d.ts +0 -123
  411. package/dist/react/index.js.map +0 -1
  412. package/dist/shared/host/app.cjs.map +0 -1
  413. package/dist/shared/host/app.js +0 -12
  414. package/dist/shared/host/app.js.map +0 -1
  415. package/dist/shared/host/pages.cjs.map +0 -1
  416. package/dist/shared/host/pages.js +0 -12
  417. package/dist/shared/host/pages.js.map +0 -1
  418. package/dist/shared/host/proxy.cjs.map +0 -1
  419. package/dist/shared/host/proxy.js.map +0 -1
  420. package/dist/shared/remote/app.cjs.map +0 -1
  421. package/dist/shared/remote/app.js +0 -8
  422. package/dist/shared/remote/app.js.map +0 -1
  423. package/dist/shared/remote/pages.cjs.map +0 -1
  424. package/dist/shared/remote/pages.js +0 -8
  425. package/dist/shared/remote/pages.js.map +0 -1
  426. package/dist/shared/remote/proxy.cjs.map +0 -1
  427. package/dist/shared/remote/proxy.d.ts +0 -44
  428. package/dist/shared/remote/proxy.js.map +0 -1
  429. package/dist/shared/remote/wrapper.cjs.map +0 -1
  430. package/dist/shared/remote/wrapper.js +0 -25
  431. package/dist/shared/remote/wrapper.js.map +0 -1
  432. package/dist/webpack.cjs.map +0 -1
  433. package/dist/webpack.js.map +0 -1
  434. /package/dist/{webpack.d.ts → config/webpack.d.ts} +0 -0
  435. /package/dist/{shared/host → host/defaults}/app.d.ts +0 -0
  436. /package/dist/{shared/host → host/defaults}/pages.d.ts +0 -0
  437. /package/dist/{shared/host/proxy.d.ts → host/proxy/protected-fetch.d.ts} +0 -0
  438. /package/dist/internal/{webpack/shared-modules.d.ts → config/webpack/apply-shared-modules.d.ts} +0 -0
  439. /package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.d.ts +0 -0
  440. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.cjs +0 -0
  441. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.js +0 -0
  442. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.cjs +0 -0
  443. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.d.ts +0 -0
  444. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.js +0 -0
  445. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.cjs +0 -0
  446. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.d.ts +0 -0
  447. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.js +0 -0
  448. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.cjs +0 -0
  449. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.d.ts +0 -0
  450. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.js +0 -0
  451. /package/dist/internal/{shared/client → host/server}/get-client-src.d.ts +0 -0
  452. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.cjs +0 -0
  453. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.d.ts +0 -0
  454. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.js +0 -0
  455. /package/dist/internal/{next/remote/render-client.d.ts → remote/nextjs/app-client.d.ts} +0 -0
  456. /package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs +0 -0
  457. /package/dist/internal/{shared/client → runtime/html}/apply-origin.js +0 -0
  458. /package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.d.ts +0 -0
  459. /package/dist/internal/{shared/utils → utils}/abort.cjs +0 -0
  460. /package/dist/internal/{shared/utils → utils}/abort.d.ts +0 -0
  461. /package/dist/internal/{shared/utils → utils}/abort.js +0 -0
  462. /package/dist/internal/{shared → utils}/error.d.ts +0 -0
  463. /package/dist/internal/{shared/utils.cjs → utils.cjs} +0 -0
  464. /package/dist/internal/{shared/utils.d.ts → utils.d.ts} +0 -0
  465. /package/dist/internal/{shared/utils.js → utils.js} +0 -0
  466. /package/dist/{shared/remote → remote/defaults}/app.d.ts +0 -0
  467. /package/dist/{shared/remote → remote/defaults}/pages.d.ts +0 -0
  468. /package/dist/{shared/remote → remote/defaults}/wrapper.d.ts +0 -0
  469. /package/dist/{html/remote.d.ts → remote/html.d.ts} +0 -0
@@ -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) {
@@ -168,7 +131,7 @@ function failedProxyFetchError(originalUrl, proxyUrl, status, responseBody) {
168
131
  The host server needs middleware or a route that handles "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}".
169
132
 
170
133
  Proxying requires two pieces:
171
- 1. resolveClientUrl={proxyClientRequestsThroughHost} on <RemoteComponent>
134
+ 1. resolveClientUrl={routeThroughHostProxy} on <RemoteComponent>
172
135
  2. Middleware or a route for "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" on the host server
173
136
 
174
137
  Docs: ${CORS_DOCS_URL}`
@@ -185,7 +148,7 @@ Docs: ${CORS_DOCS_URL}`
185
148
  );
186
149
  }
187
150
 
188
- // src/shared/utils/logger.ts
151
+ // src/utils/logger.ts
189
152
  var PREFIX = "remote-components";
190
153
  var DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
191
154
  function logDebug(location2, message) {
@@ -211,13 +174,13 @@ function warnCrossOriginFetchError(logLocation, url) {
211
174
  }
212
175
  logWarn(
213
176
  logLocation,
214
- `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}`
177
+ `Failed to fetch cross-origin resource "${parsed.href}". If this is a protected deployment, ensure withRemoteComponentsHostProxy middleware is configured in your host and that the remote URL is included in allowedProxyUrls. See: ${CORS_DOCS_URL}`
215
178
  );
216
179
  } catch {
217
180
  }
218
181
  }
219
182
 
220
- // src/shared/client/polyfill.tsx
183
+ // src/host/shared/polyfill.tsx
221
184
  import { jsx } from "react/jsx-runtime";
222
185
  function applyBundleUrlToSrc(bundle, src) {
223
186
  const self = globalThis;
@@ -237,7 +200,7 @@ function applyBundleUrlToImagePropsSrc(bundle, src) {
237
200
  const propSrc = src;
238
201
  return applyBundleUrlToSrc(bundle, propSrc.src);
239
202
  }
240
- var imageImpl = (bundle) => function RemoteImage({
203
+ var imageImpl = (bundle, resolveClientUrl) => function RemoteImage({
241
204
  fill: _fill,
242
205
  loader: _loader,
243
206
  quality: _quality,
@@ -254,6 +217,7 @@ var imageImpl = (bundle) => function RemoteImage({
254
217
  bundle,
255
218
  typeof src === "string" ? src : src.src
256
219
  );
220
+ const proxiedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
257
221
  return (
258
222
  // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
259
223
  /* @__PURE__ */ jsx(
@@ -262,16 +226,16 @@ var imageImpl = (bundle) => function RemoteImage({
262
226
  decoding: "async",
263
227
  style: { color: "transparent" },
264
228
  ...props,
265
- src: newSrc,
229
+ src: proxiedSrc,
266
230
  suppressHydrationWarning: true
267
231
  }
268
232
  )
269
233
  );
270
234
  };
271
- function sharedPolyfills(shared) {
235
+ function sharedPolyfills(shared2, resolveClientUrl) {
272
236
  const self = globalThis;
273
237
  const polyfill = {
274
- "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared?.["next/navigation"] ?? (() => Promise.resolve({
238
+ "next/dist/client/components/navigation": self.__remote_component_host_shared_modules__?.["next/navigation"] ?? shared2?.["next/navigation"] ?? (() => Promise.resolve({
275
239
  useRouter() {
276
240
  return {
277
241
  push: (routerUrl) => {
@@ -302,7 +266,7 @@ function sharedPolyfills(shared) {
302
266
  },
303
267
  __esModule: true
304
268
  })),
305
- "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared?.["next/link"] ?? (() => Promise.resolve({
269
+ "next/dist/client/app-dir/link": self.__remote_component_host_shared_modules__?.["next/link"] ?? shared2?.["next/link"] ?? (() => Promise.resolve({
306
270
  default: ({
307
271
  scroll: _,
308
272
  replace,
@@ -352,18 +316,18 @@ function sharedPolyfills(shared) {
352
316
  },
353
317
  __esModule: true
354
318
  })),
355
- "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared?.["next/form"] ?? (() => Promise.resolve({
319
+ "next/dist/client/app-dir/form": self.__remote_component_host_shared_modules__?.["next/form"] ?? shared2?.["next/form"] ?? (() => Promise.resolve({
356
320
  default: () => {
357
321
  throw new Error("Next.js <Form> component not implemented");
358
322
  },
359
323
  __esModule: true
360
324
  })),
361
- "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
362
- Image: imageImpl(bundle),
325
+ "next/dist/client/image-component": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared2?.["next/image"] ?? ((bundle) => Promise.resolve({
326
+ Image: imageImpl(bundle, resolveClientUrl),
363
327
  __esModule: true
364
328
  })),
365
- "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared?.["next/image"] ?? ((bundle) => Promise.resolve({
366
- default: imageImpl(bundle),
329
+ "next/image": self.__remote_component_host_shared_modules__?.["next/image"] ?? shared2?.["next/image"] ?? ((bundle) => Promise.resolve({
330
+ default: imageImpl(bundle, resolveClientUrl),
367
331
  getImageProps: (_imgProps) => {
368
332
  throw new Error(
369
333
  "Next.js getImageProps() is not implemented in remote components"
@@ -371,13 +335,13 @@ function sharedPolyfills(shared) {
371
335
  },
372
336
  __esModule: true
373
337
  })),
374
- "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared?.["next/script"] ?? (() => Promise.resolve({
338
+ "next/dist/client/script": self.__remote_component_host_shared_modules__?.["next/script"] ?? shared2?.["next/script"] ?? (() => Promise.resolve({
375
339
  // TODO: implement <Script> component for non-Next.js host applications
376
340
  // do not throw an error for now
377
341
  default: () => null,
378
342
  __esModule: true
379
343
  })),
380
- "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared?.["next/router"] ?? (() => (
344
+ "next/router": self.__remote_component_host_shared_modules__?.["next/router"] ?? shared2?.["next/router"] ?? (() => (
381
345
  // TODO: incomplete implementation
382
346
  Promise.resolve({
383
347
  useRouter() {
@@ -413,14 +377,443 @@ function sharedPolyfills(shared) {
413
377
  return polyfill;
414
378
  }
415
379
 
416
- // src/shared/client/component-loader.ts
380
+ // src/host/nextjs/image-impl.tsx
381
+ import { jsx as jsx2 } from "react/jsx-runtime";
382
+ function createRemoteLoader(bundle, resolveClientUrl) {
383
+ return ({ src, width, quality }) => {
384
+ const self = globalThis;
385
+ const origin = self.__remote_bundle_url__?.[bundle]?.origin ?? "";
386
+ let imageUrl = src;
387
+ try {
388
+ const parsed = new URL(src);
389
+ if (origin && parsed.origin === origin) {
390
+ imageUrl = parsed.pathname + parsed.search;
391
+ }
392
+ } catch {
393
+ }
394
+ const { assetPrefix } = /^(?<assetPrefix>.*?)\/_next\//.exec(imageUrl)?.groups ?? {};
395
+ const url = `${origin}${assetPrefix ?? ""}/_next/image?url=${encodeURIComponent(imageUrl)}&w=${width}&q=${quality ?? 75}`;
396
+ return resolveClientUrl?.(url) ?? url;
397
+ };
398
+ }
399
+ function imageImpl2(ImageComponent, bundle, resolveClientUrl, useRemoteLoader) {
400
+ const remoteLoader = useRemoteLoader ? createRemoteLoader(bundle, resolveClientUrl) : void 0;
401
+ const component = function RemoteImage(props) {
402
+ if (remoteLoader) {
403
+ return /* @__PURE__ */ jsx2(ImageComponent, { loader: remoteLoader, ...props });
404
+ }
405
+ const rawSrc = applyBundleUrlToImagePropsSrc(bundle, props.src);
406
+ const src = resolveClientUrl?.(rawSrc) ?? rawSrc;
407
+ return /* @__PURE__ */ jsx2(ImageComponent, { ...props, src });
408
+ };
409
+ component.default = component;
410
+ return component;
411
+ }
412
+
413
+ // src/runtime/url/resolve-client-url.ts
414
+ function withRemoteSrc(resolveClientUrl, remoteSrc) {
415
+ const remoteOrigin = parseOrigin(remoteSrc);
416
+ return (url) => {
417
+ const urlOrigin = parseOrigin(url);
418
+ if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
419
+ return void 0;
420
+ }
421
+ return resolveClientUrl(remoteSrc, url);
422
+ };
423
+ }
424
+ function parseOrigin(url) {
425
+ try {
426
+ return new URL(url).origin;
427
+ } catch {
428
+ return void 0;
429
+ }
430
+ }
431
+
432
+ // src/runtime/url/default-resolve-client-url.ts
433
+ function bindResolveClientUrl(prop, remoteSrc) {
434
+ return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
435
+ }
436
+
437
+ // src/host/react/index.tsx
438
+ import {
439
+ startTransition,
440
+ useEffect,
441
+ useId,
442
+ useLayoutEffect as useLayoutEffect2,
443
+ useMemo as useMemo2,
444
+ useRef as useRef2,
445
+ useState as useState2
446
+ } from "react";
447
+ import { createPortal } from "react-dom";
448
+
449
+ // src/host/server/fetch-headers.ts
450
+ function remoteFetchHeaders() {
451
+ return {
452
+ /**
453
+ * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
454
+ * If the remote component uses vercel deployment protection, ensure the host and remote vercel
455
+ * projects share a common automation bypass secret, and the shared secret is used as the
456
+ * VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
457
+ */
458
+ ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
459
+ "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
460
+ } : {},
461
+ Accept: "text/html"
462
+ };
463
+ }
464
+
465
+ // src/host/server/fetch-with-hooks.ts
466
+ async function fetchWithWarning(url, init) {
467
+ try {
468
+ return await fetch(url, init);
469
+ } catch (error) {
470
+ warnCrossOriginFetchError("FetchRemoteComponent", url);
471
+ throw error;
472
+ }
473
+ }
474
+ async function fetchWithHooks(url, additionalInit, options = {}) {
475
+ const {
476
+ onRequest,
477
+ onResponse,
478
+ abortController = new AbortController()
479
+ } = options;
480
+ const signal = abortController.signal;
481
+ const hookOptions = {
482
+ signal,
483
+ abort: (reason) => abortController.abort(reason)
484
+ };
485
+ const init = {
486
+ method: "GET",
487
+ headers: remoteFetchHeaders(),
488
+ signal,
489
+ ...additionalInit
490
+ };
491
+ const res = await onRequest?.(url, init, hookOptions) ?? await fetchWithWarning(url, init);
492
+ return await onResponse?.(url, res, hookOptions) ?? res;
493
+ }
494
+
495
+ // src/host/server/get-client-or-server-url.ts
496
+ function getClientOrServerUrl(src, serverFallback) {
497
+ const fallback = typeof location !== "undefined" ? location.href : serverFallback;
498
+ if (!src) {
499
+ return new URL(fallback);
500
+ }
501
+ return typeof src === "string" ? new URL(src, fallback) : src;
502
+ }
503
+
504
+ // src/host/shared/state.ts
505
+ function createHostState() {
506
+ return {
507
+ stage: "idle",
508
+ prevSrc: void 0,
509
+ prevUrl: void 0,
510
+ prevName: void 0,
511
+ prevIsRemoteComponent: false,
512
+ abortController: void 0
513
+ };
514
+ }
515
+
516
+ // src/host/utils/resolve-name-from-src.ts
517
+ function resolveNameFromSrc(src, defaultName) {
518
+ if (!src) {
519
+ return defaultName;
520
+ }
521
+ const hash = typeof src === "string" ? src : src.hash;
522
+ const hashIndex = hash.indexOf("#");
523
+ if (hashIndex < 0) {
524
+ return defaultName;
525
+ }
526
+ const name = hash.slice(hashIndex + 1);
527
+ return name || defaultName;
528
+ }
529
+
530
+ // src/utils/index.ts
531
+ function escapeString(str) {
532
+ return str.replace(/[^a-z0-9]/g, "_");
533
+ }
534
+ var attrToProp = {
535
+ fetchpriority: "fetchPriority",
536
+ crossorigin: "crossOrigin",
537
+ imagesrcset: "imageSrcSet",
538
+ imagesizes: "imageSizes",
539
+ srcset: "srcSet"
540
+ };
541
+
542
+ // src/runtime/constants.ts
543
+ var DEFAULT_ROUTE = "/";
544
+ var RUNTIME_WEBPACK = "webpack";
545
+ var RUNTIME_TURBOPACK = "turbopack";
546
+ var RUNTIME_SCRIPT = "script";
547
+ var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
548
+ var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
549
+ function getBundleKey(bundle) {
550
+ return escapeString(bundle);
551
+ }
552
+
553
+ // src/runtime/html/apply-origin.ts
554
+ var tagNames = [
555
+ "img",
556
+ "source",
557
+ "video",
558
+ "audio",
559
+ "track",
560
+ "iframe",
561
+ "embed",
562
+ "script",
563
+ "link"
564
+ ];
565
+ function applyOriginToNodes(doc, url, resolveClientUrl) {
566
+ if (url.origin !== location.origin) {
567
+ const nodes = doc.querySelectorAll(
568
+ tagNames.map(
569
+ (type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
570
+ ).join(",")
571
+ );
572
+ nodes.forEach((node) => {
573
+ if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
574
+ const absoluteSrc = new URL(node.getAttribute("src") ?? "/", url).href;
575
+ const isScript = node.tagName.toLowerCase() === "script";
576
+ node.src = isScript ? absoluteSrc : resolveClientUrl?.(absoluteSrc) ?? absoluteSrc;
577
+ }
578
+ if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
579
+ const absoluteHref = new URL(node.getAttribute("href") ?? "/", url).href;
580
+ node.setAttribute(
581
+ "href",
582
+ resolveClientUrl?.(absoluteHref) ?? absoluteHref
583
+ );
584
+ }
585
+ if (node.hasAttribute("srcset")) {
586
+ const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
587
+ const [urlPart, descriptor] = entry.trim().split(/\s+/);
588
+ if (!urlPart)
589
+ return entry;
590
+ const absoluteUrl = new URL(urlPart, url).href;
591
+ const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
592
+ return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
593
+ }).join(", ");
594
+ if (srcSet) {
595
+ node.setAttribute("srcset", srcSet);
596
+ }
597
+ }
598
+ if (node.hasAttribute("imagesrcset")) {
599
+ const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
600
+ const [urlPart, descriptor] = entry.trim().split(/\s+/);
601
+ if (!urlPart)
602
+ return entry;
603
+ const absoluteUrl = new URL(urlPart, url).href;
604
+ const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
605
+ return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
606
+ }).join(", ");
607
+ if (srcSet) {
608
+ node.setAttribute("imagesrcset", srcSet);
609
+ }
610
+ }
611
+ });
612
+ }
613
+ }
614
+
615
+ // src/runtime/html/parse-remote-html.ts
616
+ function validateSingleComponent(doc, name, url) {
617
+ 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}"]`)) {
618
+ throw multipleRemoteComponentsError(url);
619
+ }
620
+ }
621
+ function findComponentElement(doc, name) {
622
+ 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])");
623
+ }
624
+ function parseNextData(doc) {
625
+ return JSON.parse(
626
+ (doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
627
+ );
628
+ }
629
+ function resolveComponentName(component, nextData, fallbackName) {
630
+ const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
631
+ const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
632
+ return { name, isRemoteComponent };
633
+ }
634
+ function extractComponentMetadata(component, nextData, name, url) {
635
+ return {
636
+ name,
637
+ bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
638
+ route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
639
+ runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
640
+ };
641
+ }
642
+ function extractRemoteShared(doc, name, nextData) {
643
+ const remoteSharedEl = doc.querySelector(
644
+ `#${name}_shared[data-remote-components-shared]`
645
+ );
646
+ const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
647
+ remoteSharedEl?.remove();
648
+ return remoteShared;
649
+ }
650
+ function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
651
+ if (!component || !(rsc || nextData || isRemoteComponent)) {
652
+ throw new RemoteComponentsError(
653
+ `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>?`
654
+ );
655
+ }
656
+ }
657
+ function extractLinks(doc, component) {
658
+ return Array.from(doc.querySelectorAll("link[href]")).filter(
659
+ (link) => !component.contains(link)
660
+ );
661
+ }
662
+ function extractScripts(doc, component, isRemoteComponent) {
663
+ return Array.from(
664
+ (isRemoteComponent ? component : doc).querySelectorAll(
665
+ "script[src],script[data-src]"
666
+ )
667
+ );
668
+ }
669
+ function parseRemoteComponentDocument(doc, name, url) {
670
+ validateSingleComponent(doc, name, url.href);
671
+ const component = findComponentElement(doc, name);
672
+ const nextData = parseNextData(doc);
673
+ const { name: resolvedName, isRemoteComponent } = resolveComponentName(
674
+ component,
675
+ nextData,
676
+ name
677
+ );
678
+ const rsc = doc.querySelector(`#${resolvedName}_rsc`);
679
+ const metadata = extractComponentMetadata(
680
+ component,
681
+ nextData,
682
+ resolvedName,
683
+ url
684
+ );
685
+ const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
686
+ validateComponentFound(
687
+ component,
688
+ rsc,
689
+ nextData,
690
+ isRemoteComponent,
691
+ url.href,
692
+ resolvedName
693
+ );
694
+ const links = extractLinks(doc, component);
695
+ const scripts = extractScripts(doc, component, isRemoteComponent);
696
+ return {
697
+ component,
698
+ name: resolvedName,
699
+ isRemoteComponent,
700
+ metadata,
701
+ nextData,
702
+ rsc,
703
+ remoteShared,
704
+ links,
705
+ scripts
706
+ };
707
+ }
708
+
709
+ // src/runtime/html/set-attributes-from-props.ts
710
+ var DOMAttributeNames = {
711
+ acceptCharset: "accept-charset",
712
+ className: "class",
713
+ htmlFor: "for",
714
+ httpEquiv: "http-equiv",
715
+ noModule: "noModule"
716
+ };
717
+ var ignoreProps = [
718
+ "onLoad",
719
+ "onReady",
720
+ "dangerouslySetInnerHTML",
721
+ "children",
722
+ "onError",
723
+ "strategy",
724
+ "stylesheets"
725
+ ];
726
+ function isBooleanScriptAttribute(attr) {
727
+ return ["async", "defer", "noModule"].includes(attr);
728
+ }
729
+ function setAttributesFromProps(el, props) {
730
+ for (const [p, value] of Object.entries(props)) {
731
+ if (!Object.hasOwn(props, p))
732
+ continue;
733
+ if (ignoreProps.includes(p))
734
+ continue;
735
+ if (value === void 0) {
736
+ continue;
737
+ }
738
+ const attr = DOMAttributeNames[p] || p.toLowerCase();
739
+ if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
740
+ el[attr] = Boolean(value);
741
+ } else {
742
+ el.setAttribute(attr, String(value));
743
+ }
744
+ if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
745
+ el.setAttribute(attr, "");
746
+ el.removeAttribute(attr);
747
+ }
748
+ }
749
+ }
750
+
751
+ // src/runtime/loaders/component-loader.ts
417
752
  import * as React from "react";
418
753
  import * as JSXDevRuntime from "react/jsx-dev-runtime";
419
754
  import * as JSXRuntime from "react/jsx-runtime";
420
755
  import * as ReactDOM from "react-dom";
421
756
  import * as ReactDOMClient from "react-dom/client";
422
757
 
423
- // src/shared/webpack/next-client-pages-loader.ts
758
+ // src/config/webpack/apply-shared-modules.ts
759
+ function applySharedModules(bundle, resolve) {
760
+ logDebug(
761
+ "SharedModules",
762
+ `applySharedModules called for bundle: "${bundle}"`
763
+ );
764
+ logDebug(
765
+ "SharedModules",
766
+ `Shared modules to resolve: ${Object.keys(resolve)}`
767
+ );
768
+ const self = globalThis;
769
+ if (self.__remote_webpack_require__?.[bundle]) {
770
+ const modulePaths = Object.keys(
771
+ self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
772
+ );
773
+ logDebug(
774
+ "SharedModules",
775
+ `Available module paths in __remote_webpack_require__[${bundle}]: ${modulePaths}`
776
+ );
777
+ for (const [key, value] of Object.entries(resolve)) {
778
+ const exactIds = modulePaths.filter((p) => p === key);
779
+ const ids = exactIds.length > 0 ? exactIds : modulePaths.filter((p) => p.includes(key));
780
+ if (ids.length === 0) {
781
+ logDebug(
782
+ "SharedModules",
783
+ `No matching module path found for shared module "${key}"`
784
+ );
785
+ }
786
+ for (const id of ids) {
787
+ const webpackBundle = self.__remote_webpack_require__[bundle];
788
+ if (webpackBundle.m) {
789
+ const resolvedId = self.__remote_webpack_module_map__?.[bundle]?.[id] ? `${self.__remote_webpack_module_map__[bundle][id]}` : id;
790
+ if (resolvedId !== id) {
791
+ logDebug(
792
+ "SharedModules",
793
+ `Mapped module id: "${id}" -> "${resolvedId}"`
794
+ );
795
+ }
796
+ webpackBundle.m[resolvedId] = (module) => {
797
+ module.exports = value;
798
+ };
799
+ } else {
800
+ logWarn(
801
+ "SharedModules",
802
+ `webpackBundle.m is not available for bundle "${bundle}"`
803
+ );
804
+ }
805
+ }
806
+ }
807
+ } else {
808
+ logWarn("SharedModules", `No webpack require found for bundle "${bundle}"`);
809
+ logDebug(
810
+ "SharedModules",
811
+ `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
812
+ );
813
+ }
814
+ }
815
+
816
+ // src/config/webpack/next-client-pages-loader.ts
424
817
  function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
425
818
  const self = globalThis;
426
819
  const nextCssOriginal = document.querySelector(
@@ -503,97 +896,36 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
503
896
  const elements = [];
504
897
  let node = nextCss.previousSibling;
505
898
  while (node && node !== nextCssEnd) {
506
- elements.push(node);
507
- node.remove();
508
- node = nextCss.previousSibling;
509
- }
510
- self.__remote_next_css__[bundle] = elements;
511
- }
512
- if (styleContainer) {
513
- const elements = self.__remote_next_css__[bundle];
514
- elements.forEach((el) => {
515
- styleContainer.appendChild(el.cloneNode(true));
516
- });
517
- } else {
518
- const elements = self.__remote_next_css__[bundle];
519
- elements.forEach((el) => {
520
- document.head.appendChild(el);
521
- });
522
- }
523
- delete self.__NEXT_P;
524
- self.__NEXT_P = __NEXT_P_ORIGINAL;
525
- if (nextCssOriginal) {
526
- nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
527
- }
528
- nextCss.remove();
529
- nextCssEnd.remove();
530
- return { Component, App };
531
- }
532
- return { Component: null, App: null };
533
- }
534
-
535
- // src/shared/webpack/shared-modules.ts
536
- function applySharedModules(bundle, resolve) {
537
- logDebug(
538
- "SharedModules",
539
- `applySharedModules called for bundle: "${bundle}"`
540
- );
541
- logDebug(
542
- "SharedModules",
543
- `Shared modules to resolve: ${Object.keys(resolve)}`
544
- );
545
- const self = globalThis;
546
- if (self.__remote_webpack_require__?.[bundle]) {
547
- const modulePaths = Object.keys(
548
- self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
549
- );
550
- logDebug(
551
- "SharedModules",
552
- `Available module paths in __remote_webpack_require__[${bundle}]: ${modulePaths}`
553
- );
554
- for (const [key, value] of Object.entries(resolve)) {
555
- let ids = modulePaths.filter((p) => p === key);
556
- if (ids.length === 0) {
557
- ids = modulePaths.filter((p) => p.includes(key));
558
- }
559
- if (ids.length === 0) {
560
- logDebug(
561
- "SharedModules",
562
- `No matching module path found for shared module "${key}"`
563
- );
564
- }
565
- for (let id of ids) {
566
- const webpackBundle = self.__remote_webpack_require__[bundle];
567
- if (webpackBundle.m) {
568
- if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
569
- const mappedId = `${self.__remote_webpack_module_map__[bundle][id]}`;
570
- logDebug(
571
- "SharedModules",
572
- `Mapped module id: "${id}" -> "${mappedId}"`
573
- );
574
- id = mappedId;
575
- }
576
- webpackBundle.m[id] = (module) => {
577
- module.exports = value;
578
- };
579
- } else {
580
- logWarn(
581
- "SharedModules",
582
- `webpackBundle.m is not available for bundle "${bundle}"`
583
- );
584
- }
899
+ elements.push(node);
900
+ node.remove();
901
+ node = nextCss.previousSibling;
585
902
  }
903
+ self.__remote_next_css__[bundle] = elements;
586
904
  }
587
- } else {
588
- logWarn("SharedModules", `No webpack require found for bundle "${bundle}"`);
589
- logDebug(
590
- "SharedModules",
591
- `Available bundles: ${Object.keys(self.__remote_webpack_require__ ?? {})}`
592
- );
905
+ if (styleContainer) {
906
+ const elements = self.__remote_next_css__[bundle];
907
+ elements.forEach((el) => {
908
+ styleContainer.appendChild(el.cloneNode(true));
909
+ });
910
+ } else {
911
+ const elements = self.__remote_next_css__[bundle];
912
+ elements.forEach((el) => {
913
+ document.head.appendChild(el);
914
+ });
915
+ }
916
+ delete self.__NEXT_P;
917
+ self.__NEXT_P = __NEXT_P_ORIGINAL;
918
+ if (nextCssOriginal) {
919
+ nextCssOriginal.parentNode?.appendChild(nextCssOriginal);
920
+ }
921
+ nextCss.remove();
922
+ nextCssEnd.remove();
923
+ return { Component, App };
593
924
  }
925
+ return { Component: null, App: null };
594
926
  }
595
927
 
596
- // src/shared/client/rsc.ts
928
+ // src/runtime/rsc.ts
597
929
  import { ReadableStream } from "web-streams-polyfill";
598
930
  function fixPayload(payload) {
599
931
  if (Array.isArray(payload)) {
@@ -659,78 +991,18 @@ function createRSCStream(rscName, data) {
659
991
  });
660
992
  }
661
993
 
662
- // src/shared/client/webpack-patterns.ts
663
- var NEXT_BUNDLE_PATH_RE = /\/_next\/\[.+\](?:%20| )/;
664
-
665
- // src/shared/client/script-loader.ts
666
- async function loadScripts(scripts, resolveClientUrl) {
667
- await Promise.all(
668
- scripts.map((script) => {
669
- return new Promise((resolve, reject) => {
670
- const newSrc = new URL(
671
- // remove the remote component bundle name identifier from the script src
672
- script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
673
- location.origin
674
- ).href;
675
- const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
676
- const newScript = document.createElement("script");
677
- newScript.onload = () => resolve();
678
- newScript.onerror = () => {
679
- const isProxied = isProxiedUrl(resolvedSrc);
680
- if (isProxied) {
681
- reject(
682
- new RemoteComponentsError(
683
- `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}`
684
- )
685
- );
686
- } else {
687
- warnCrossOriginFetchError("ScriptLoader", newSrc);
688
- reject(
689
- new RemoteComponentsError(
690
- `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
691
- )
692
- );
693
- }
694
- };
695
- newScript.src = resolvedSrc;
696
- newScript.async = true;
697
- document.head.appendChild(newScript);
698
- });
699
- })
700
- );
701
- }
702
-
703
- // src/shared/utils/index.ts
704
- function escapeString(str) {
705
- return str.replace(/[^a-z0-9]/g, "_");
706
- }
707
- var attrToProp = {
708
- fetchpriority: "fetchPriority",
709
- crossorigin: "crossOrigin",
710
- imagesrcset: "imageSrcSet",
711
- imagesizes: "imageSizes",
712
- srcset: "srcSet"
713
- };
714
-
715
- // src/shared/client/const.ts
716
- var DEFAULT_ROUTE = "/";
717
- var RUNTIME_WEBPACK = "webpack";
718
- var RUNTIME_TURBOPACK = "turbopack";
719
- var RUNTIME_SCRIPT = "script";
720
- var REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
721
- function getBundleKey(bundle) {
722
- return escapeString(bundle);
723
- }
994
+ // src/runtime/turbopack/chunk-loader.ts
995
+ init_constants();
724
996
 
725
- // src/shared/client/turbopack-patterns.ts
997
+ // src/runtime/turbopack/patterns.ts
726
998
  var REMOTE_SHARED_MARKER_RE = /(?:self|[a-z])\.TURBOPACK_REMOTE_SHARED/;
727
- var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|e)\.A\((?<sharedModuleId>[0-9]+)\)/;
999
+ var REMOTE_SHARED_ASSIGNMENT_RE = /\.TURBOPACK_REMOTE_SHARED=await (?:__turbopack_context__|[a-z])\.A\((?<sharedModuleId>[0-9]+)\)/;
728
1000
  var ASYNC_MODULE_LOADER_RE = /(?:__turbopack_context__|e)\.A\((?<asyncSharedModuleId>[0-9]+)\)/;
729
1001
  var ASYNC_MODULE_RESOLVE_RE = /(?<ctx>__turbopack_context__|e)=>\{\k<ctx>\.v\((?<inner>parentImport|e)=>Promise\.resolve\(\)\.then\(\(\)=>\k<inner>\((?<sharedModuleId>[0-9]+)\)\)\)\}/;
730
1002
  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]+)\)\)\)\}/;
731
1003
  var TURBOPACK_GLOBAL_RE = /(?:globalThis|self)\s*(?:\.TURBOPACK|\[\s*["']TURBOPACK["']\s*\])/;
732
1004
 
733
- // src/shared/client/chunk-loader.ts
1005
+ // src/runtime/turbopack/chunk-loader.ts
734
1006
  function createChunkLoader(runtime, resolveClientUrl) {
735
1007
  return function __turbopack_chunk_load__(chunkId, scriptBundle) {
736
1008
  logDebug("ChunkLoader", `Loading chunk: "${chunkId}"`);
@@ -792,7 +1064,7 @@ function createChunkLoader(runtime, resolveClientUrl) {
792
1064
  if (isProxied) {
793
1065
  reject(
794
1066
  new RemoteComponentsError(
795
- `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}`
1067
+ `Failed to load chunk "${url}" via proxy "${resolvedUrl}". Ensure withRemoteComponentsHostProxy middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
796
1068
  )
797
1069
  );
798
1070
  } else {
@@ -942,7 +1214,7 @@ async function handleTurbopackChunk(code, bundle, url) {
942
1214
  }
943
1215
  }
944
1216
 
945
- // src/shared/client/turbopack-module.ts
1217
+ // src/runtime/turbopack/module.ts
946
1218
  function handleTurbopackModule(bundle, moduleId, id) {
947
1219
  const self = globalThis;
948
1220
  const bundleKey = getBundleKey(bundle);
@@ -1171,7 +1443,7 @@ function createTurbopackContext(bundle, exports, moduleExports, modules, moduleI
1171
1443
  };
1172
1444
  }
1173
1445
 
1174
- // src/shared/client/shared-modules.ts
1446
+ // src/runtime/turbopack/shared-modules.ts
1175
1447
  async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {}) {
1176
1448
  const self = globalThis;
1177
1449
  self.__remote_shared_modules__ = self.__remote_shared_modules__ ?? {};
@@ -1208,9 +1480,9 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
1208
1480
  }
1209
1481
  }
1210
1482
  if (sharedModuleInitializer) {
1211
- const { shared } = await sharedModuleInitializer;
1483
+ const { shared: shared2 } = await sharedModuleInitializer;
1212
1484
  const sharedModuleIds = extractSharedModuleIds(
1213
- shared,
1485
+ shared2,
1214
1486
  bundleKey,
1215
1487
  self
1216
1488
  );
@@ -1246,8 +1518,8 @@ async function initializeSharedModules(bundle, hostShared = {}, remoteShared = {
1246
1518
  })
1247
1519
  );
1248
1520
  }
1249
- function extractSharedModuleIds(shared, bundleKey, self) {
1250
- return Object.entries(shared).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
1521
+ function extractSharedModuleIds(shared2, bundleKey, self) {
1522
+ return Object.entries(shared2).filter(([, value]) => typeof value === "function").reduce((acc, [key, value]) => {
1251
1523
  const { asyncSharedModuleId } = ASYNC_MODULE_LOADER_RE.exec(value.toString())?.groups ?? {};
1252
1524
  if (asyncSharedModuleId) {
1253
1525
  const asyncSharedModuleIdNumber = Number(asyncSharedModuleId);
@@ -1291,8 +1563,8 @@ function getSharedModule(bundle, id) {
1291
1563
  return null;
1292
1564
  }
1293
1565
 
1294
- // src/shared/client/webpack-adapter.ts
1295
- async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
1566
+ // src/runtime/turbopack/webpack-runtime.ts
1567
+ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared2 = {}, remoteShared = {}, resolveClientUrl) {
1296
1568
  const self = globalThis;
1297
1569
  if (!self.__remote_bundle_url__) {
1298
1570
  self.__remote_bundle_url__ = {};
@@ -1329,7 +1601,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
1329
1601
  "react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
1330
1602
  "react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
1331
1603
  "react-dom/client": async () => (await import("react-dom/client")).default,
1332
- ...shared
1604
+ ...shared2
1333
1605
  };
1334
1606
  await initializeSharedModules(
1335
1607
  bundle ?? "default",
@@ -1346,7 +1618,7 @@ function createModuleRequire(runtime) {
1346
1618
  id
1347
1619
  };
1348
1620
  const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
1349
- logDebug("WebpackAdapter", `remoteRuntime: "${remoteRuntime}"`);
1621
+ logDebug("WebpackRuntime", `remoteRuntime: "${remoteRuntime}"`);
1350
1622
  try {
1351
1623
  if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
1352
1624
  return self.__remote_webpack_require__?.[bundle]?.(moduleId);
@@ -1362,7 +1634,7 @@ function createModuleRequire(runtime) {
1362
1634
  throw new Error(`Module "${id}" not found.`);
1363
1635
  } catch (requireError) {
1364
1636
  logWarn(
1365
- "WebpackAdapter",
1637
+ "WebpackRuntime",
1366
1638
  `Module require failed: ${String(requireError)}`
1367
1639
  );
1368
1640
  if (typeof self.__original_webpack_require__ !== "function") {
@@ -1374,7 +1646,7 @@ function createModuleRequire(runtime) {
1374
1646
  );
1375
1647
  }
1376
1648
  try {
1377
- logDebug("WebpackAdapter", "Falling back to original webpack require");
1649
+ logDebug("WebpackRuntime", "Falling back to original webpack require");
1378
1650
  return self.__original_webpack_require__(id);
1379
1651
  } catch (originalError) {
1380
1652
  throw new RemoteComponentsError(
@@ -1386,7 +1658,46 @@ function createModuleRequire(runtime) {
1386
1658
  };
1387
1659
  }
1388
1660
 
1389
- // src/shared/client/component-loader.ts
1661
+ // src/runtime/loaders/script-loader.ts
1662
+ init_constants();
1663
+ async function loadScripts(scripts, resolveClientUrl) {
1664
+ await Promise.all(
1665
+ scripts.map((script) => {
1666
+ return new Promise((resolve, reject) => {
1667
+ const newSrc = new URL(
1668
+ // remove the remote component bundle name identifier from the script src
1669
+ script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
1670
+ location.origin
1671
+ ).href;
1672
+ const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
1673
+ const newScript = document.createElement("script");
1674
+ newScript.onload = () => resolve();
1675
+ newScript.onerror = () => {
1676
+ const isProxied = isProxiedUrl(resolvedSrc);
1677
+ if (isProxied) {
1678
+ reject(
1679
+ new RemoteComponentsError(
1680
+ `Failed to load script "${newSrc}" via proxy "${resolvedSrc}". Ensure withRemoteComponentsHostProxy middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
1681
+ )
1682
+ );
1683
+ } else {
1684
+ warnCrossOriginFetchError("ScriptLoader", newSrc);
1685
+ reject(
1686
+ new RemoteComponentsError(
1687
+ `Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
1688
+ )
1689
+ );
1690
+ }
1691
+ };
1692
+ newScript.src = resolvedSrc;
1693
+ newScript.async = true;
1694
+ document.head.appendChild(newScript);
1695
+ });
1696
+ })
1697
+ );
1698
+ }
1699
+
1700
+ // src/runtime/loaders/component-loader.ts
1390
1701
  async function loadRemoteComponent({
1391
1702
  url,
1392
1703
  name,
@@ -1397,7 +1708,7 @@ async function loadRemoteComponent({
1397
1708
  data,
1398
1709
  nextData,
1399
1710
  scripts = [],
1400
- shared = Promise.resolve({}),
1711
+ shared: shared2 = Promise.resolve({}),
1401
1712
  remoteShared = {},
1402
1713
  container,
1403
1714
  resolveClientUrl
@@ -1411,7 +1722,7 @@ async function loadRemoteComponent({
1411
1722
  self.__DISABLE_WEBPACK_EXEC__[bundle] = true;
1412
1723
  await loadScripts(scripts, resolveClientUrl);
1413
1724
  }
1414
- const hostShared = await shared;
1725
+ const hostShared = await shared2;
1415
1726
  logDebug(
1416
1727
  "ComponentLoader",
1417
1728
  `loadRemoteComponent: bundle="${bundle}", name="${name}"`
@@ -1489,17 +1800,19 @@ async function loadRemoteComponent({
1489
1800
  };
1490
1801
  }
1491
1802
  }
1492
- async function loadRSCComponent(rscName, data) {
1493
- let createFromReadableStream;
1803
+ async function importCreateFromReadableStream() {
1494
1804
  try {
1495
- const { createFromReadableStream: _createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.browser");
1496
- createFromReadableStream = _createFromReadableStream;
1805
+ const { createFromReadableStream } = await import("next/dist/compiled/react-server-dom-webpack/client.browser");
1806
+ return createFromReadableStream;
1497
1807
  } catch {
1498
1808
  const {
1499
- default: { createFromReadableStream: _createFromReadableStream }
1809
+ default: { createFromReadableStream }
1500
1810
  } = await import("react-server-dom-webpack/client.browser");
1501
- createFromReadableStream = _createFromReadableStream;
1811
+ return createFromReadableStream;
1502
1812
  }
1813
+ }
1814
+ async function loadRSCComponent(rscName, data) {
1815
+ const createFromReadableStream = await importCreateFromReadableStream();
1503
1816
  if (typeof createFromReadableStream !== "function") {
1504
1817
  throw new RemoteComponentsError(
1505
1818
  'Failed to import "react-server-dom-webpack". Is Next.js installed correctly?'
@@ -1520,54 +1833,7 @@ function loadNextPagesComponent(bundle, route, nextData, name, container) {
1520
1833
  return { component };
1521
1834
  }
1522
1835
 
1523
- // src/shared/client/proxy-through-host.ts
1524
- function withRemoteSrc(resolveClientUrl, remoteSrc) {
1525
- return (url) => resolveClientUrl(remoteSrc, url);
1526
- }
1527
-
1528
- // src/shared/client/set-attributes-from-props.ts
1529
- var DOMAttributeNames = {
1530
- acceptCharset: "accept-charset",
1531
- className: "class",
1532
- htmlFor: "for",
1533
- httpEquiv: "http-equiv",
1534
- noModule: "noModule"
1535
- };
1536
- var ignoreProps = [
1537
- "onLoad",
1538
- "onReady",
1539
- "dangerouslySetInnerHTML",
1540
- "children",
1541
- "onError",
1542
- "strategy",
1543
- "stylesheets"
1544
- ];
1545
- function isBooleanScriptAttribute(attr) {
1546
- return ["async", "defer", "noModule"].includes(attr);
1547
- }
1548
- function setAttributesFromProps(el, props) {
1549
- for (const [p, value] of Object.entries(props)) {
1550
- if (!Object.hasOwn(props, p))
1551
- continue;
1552
- if (ignoreProps.includes(p))
1553
- continue;
1554
- if (value === void 0) {
1555
- continue;
1556
- }
1557
- const attr = DOMAttributeNames[p] || p.toLowerCase();
1558
- if (el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr)) {
1559
- el[attr] = Boolean(value);
1560
- } else {
1561
- el.setAttribute(attr, String(value));
1562
- }
1563
- if (value === false || el.tagName === "SCRIPT" && isBooleanScriptAttribute(attr) && (!value || value === "false")) {
1564
- el.setAttribute(attr, "");
1565
- el.removeAttribute(attr);
1566
- }
1567
- }
1568
- }
1569
-
1570
- // src/shared/client/static-loader.ts
1836
+ // src/runtime/loaders/static-loader.ts
1571
1837
  async function importViaCallback(absoluteSrc, resolveClientUrl) {
1572
1838
  const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
1573
1839
  const fetchUrl = new URL(resolvedUrl, location.href).href;
@@ -1717,75 +1983,9 @@ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
1717
1983
  );
1718
1984
  }
1719
1985
 
1720
- // src/shared/ssr/fetch-headers.ts
1721
- function remoteFetchHeaders() {
1722
- return {
1723
- /**
1724
- * Authenticates deployment protection for the remote. Needed for SSR and SSG clients.
1725
- * If the remote component uses vercel deployment protection, ensure the host and remote vercel
1726
- * projects share a common automation bypass secret, and the shared secret is used as the
1727
- * VERCEL_AUTOMATION_BYPASS_SECRET env var in the host project.
1728
- */
1729
- ...typeof process === "object" && typeof process.env === "object" && typeof process.env.VERCEL_AUTOMATION_BYPASS_SECRET === "string" ? {
1730
- "x-vercel-protection-bypass": process.env.VERCEL_AUTOMATION_BYPASS_SECRET
1731
- } : {},
1732
- Accept: "text/html"
1733
- };
1734
- }
1735
-
1736
- // src/shared/ssr/fetch-with-hooks.ts
1737
- async function fetchWithHooks(url, additionalInit, options = {}) {
1738
- const {
1739
- onRequest,
1740
- onResponse,
1741
- abortController = new AbortController()
1742
- } = options;
1743
- const signal = abortController.signal;
1744
- const hookOptions = {
1745
- signal,
1746
- abort: (reason) => abortController.abort(reason)
1747
- };
1748
- const init = {
1749
- method: "GET",
1750
- headers: remoteFetchHeaders(),
1751
- signal,
1752
- ...additionalInit
1753
- };
1754
- let res = await onRequest?.(url, init, hookOptions);
1755
- if (!res) {
1756
- try {
1757
- res = await fetch(url, init);
1758
- } catch (error) {
1759
- warnCrossOriginFetchError("FetchRemoteComponent", url);
1760
- throw error;
1761
- }
1762
- }
1763
- const transformedRes = await onResponse?.(url, res, hookOptions);
1764
- if (transformedRes) {
1765
- res = transformedRes;
1766
- }
1767
- return res;
1768
- }
1769
-
1770
- // src/shared/ssr/get-client-or-server-url.ts
1771
- function getClientOrServerUrl(src, serverFallback) {
1772
- const fallback = typeof location !== "undefined" ? location.href : serverFallback;
1773
- if (!src) {
1774
- return new URL(fallback);
1775
- }
1776
- return typeof src === "string" ? new URL(src, fallback) : src;
1777
- }
1778
-
1779
- // src/react/hooks/use-resolve-client-url.ts
1986
+ // src/host/react/hooks/use-resolve-client-url.ts
1780
1987
  import { useMemo } from "react";
1781
- import { useRemoteComponentsContext } from "#internal/react/context";
1782
-
1783
- // src/shared/client/default-resolve-client-url.ts
1784
- function bindResolveClientUrl(prop, remoteSrc) {
1785
- return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
1786
- }
1787
-
1788
- // src/react/hooks/use-resolve-client-url.ts
1988
+ import { useRemoteComponentsContext } from "#internal/host/react/context";
1789
1989
  function useResolveClientUrl(prop, urlHref) {
1790
1990
  const { resolveClientUrl: contextValue } = useRemoteComponentsContext();
1791
1991
  const resolveClientUrl = prop ?? contextValue;
@@ -1795,7 +1995,7 @@ function useResolveClientUrl(prop, urlHref) {
1795
1995
  );
1796
1996
  }
1797
1997
 
1798
- // src/react/hooks/use-shadow-root.ts
1998
+ // src/host/react/hooks/use-shadow-root.ts
1799
1999
  import { useLayoutEffect, useRef, useState } from "react";
1800
2000
  function useShadowRoot({
1801
2001
  isolate,
@@ -1844,7 +2044,7 @@ function useShadowRoot({
1844
2044
  return { shadowRoot, shadowRootContainerRef };
1845
2045
  }
1846
2046
 
1847
- // src/react/utils/parse-remote-html.ts
2047
+ // src/host/react/utils/extract-remote-html.ts
1848
2048
  var DUMMY_FALLBACK = "http://remote-components-dummy-fallback";
1849
2049
  function getRemoteComponentHtml(html) {
1850
2050
  if (typeof document === "undefined")
@@ -1866,18 +2066,17 @@ function getRemoteComponentHtml(html) {
1866
2066
  return "";
1867
2067
  }
1868
2068
 
1869
- // src/react/index.tsx
1870
- import { RemoteComponentsProvider } from "#internal/react/context";
1871
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
2069
+ // src/host/react/index.tsx
2070
+ import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
1872
2071
  import { createElement as createElement2 } from "react";
1873
- function RemoteComponent({
2072
+ function ConsumeRemoteComponent({
1874
2073
  src,
1875
2074
  isolate,
1876
2075
  mode = "open",
1877
2076
  reset,
1878
2077
  credentials = "same-origin",
1879
2078
  name: nameProp = "__vercel_remote_component",
1880
- shared = {},
2079
+ shared: shared2 = {},
1881
2080
  children,
1882
2081
  onBeforeLoad,
1883
2082
  onLoad,
@@ -1888,21 +2087,13 @@ function RemoteComponent({
1888
2087
  resolveClientUrl: _resolveClientUrl
1889
2088
  }) {
1890
2089
  const instanceId = useId();
1891
- const name = useMemo2(() => {
1892
- if (typeof src === "string") {
1893
- const url2 = new URL(
1894
- src,
1895
- typeof document !== "undefined" ? location.href : DUMMY_FALLBACK
1896
- );
1897
- if (url2.hash) {
1898
- return url2.hash.slice(1);
1899
- }
1900
- } else if (typeof src === "object" && "hash" in src && src.hash) {
1901
- return src.hash.slice(1) || nameProp;
1902
- }
1903
- return nameProp;
1904
- }, [src, nameProp]);
1905
- const [data, setData] = useState2(null);
2090
+ const name = useMemo2(
2091
+ () => resolveNameFromSrc(src, nameProp),
2092
+ [src, nameProp]
2093
+ );
2094
+ const [data, setData] = useState2(
2095
+ null
2096
+ );
1906
2097
  const url = useMemo2(() => getClientOrServerUrl(src, DUMMY_FALLBACK), [src]);
1907
2098
  const resolveClientUrl = useResolveClientUrl(_resolveClientUrl, url.href);
1908
2099
  const id = url.origin === (typeof location !== "undefined" ? location.origin : DUMMY_FALLBACK) ? url.pathname : url.href;
@@ -1934,13 +2125,10 @@ function RemoteComponent({
1934
2125
  return elements;
1935
2126
  })() : []
1936
2127
  );
1937
- const prevSrcRef = useRef2(null);
2128
+ const hostStateRef = useRef2(createHostState());
1938
2129
  const componentHydrationHtml = useRef2(null);
1939
- const prevIsRemoteComponentRef = useRef2(false);
1940
- const prevUrlRef = useRef2(null);
1941
2130
  const prevRemoteComponentContainerRef = useRef2(null);
1942
2131
  const unmountRef = useRef2(null);
1943
- const prevNameRef = useRef2(void 0);
1944
2132
  useLayoutEffect2(() => {
1945
2133
  const shadowRootKey = `__remote_components_shadowroot_${keySuffix}`;
1946
2134
  return () => {
@@ -1979,14 +2167,18 @@ function RemoteComponent({
1979
2167
  }
1980
2168
  }, [shadowRoot, remoteComponent, name]);
1981
2169
  useEffect(() => {
1982
- if (src && src !== prevSrcRef.current) {
1983
- const previousSrc = prevSrcRef.current;
1984
- const previousName = prevNameRef.current;
1985
- prevSrcRef.current = src;
2170
+ if (src && src !== hostStateRef.current.prevSrc) {
2171
+ const previousSrc = hostStateRef.current.prevSrc;
2172
+ const previousName = hostStateRef.current.prevName;
2173
+ hostStateRef.current.prevSrc = src;
1986
2174
  if (previousSrc !== null) {
1987
2175
  htmlRef.current = null;
1988
2176
  }
2177
+ hostStateRef.current.abortController?.abort();
2178
+ hostStateRef.current.abortController = new AbortController();
2179
+ const { signal } = hostStateRef.current.abortController;
1989
2180
  onBeforeLoad?.(src);
2181
+ hostStateRef.current.stage = "loading";
1990
2182
  startTransition(async () => {
1991
2183
  try {
1992
2184
  let html = getRemoteComponentHtml(
@@ -2000,59 +2192,41 @@ function RemoteComponent({
2000
2192
  resolveClientUrl?.(url.href) ?? url.href,
2001
2193
  location.href
2002
2194
  );
2003
- const abortController = new AbortController();
2004
2195
  const res = await fetchWithHooks(resolvedUrl, fetchInit, {
2005
2196
  onRequest,
2006
2197
  onResponse,
2007
- abortController
2198
+ abortController: hostStateRef.current.abortController
2008
2199
  });
2009
2200
  if (!res || !res.ok) {
2010
2201
  throw await errorFromFailedFetch(url.href, resolvedUrl, res);
2011
2202
  }
2012
2203
  const remoteHtml = await res.text();
2204
+ if (signal.aborted)
2205
+ return;
2013
2206
  htmlRef.current = remoteHtml;
2014
2207
  html = getRemoteComponentHtml(remoteHtml);
2015
2208
  }
2209
+ if (signal.aborted)
2210
+ return;
2016
2211
  const parser = new DOMParser();
2017
2212
  const doc = parser.parseFromString(html, "text/html");
2018
- if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
2019
- `div[data-bundle][data-route][id^="${name}"]`
2020
- ) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
2021
- throw multipleRemoteComponentsError(url.href);
2022
- }
2023
- const component = doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) ?? // fallback to the first element with the data-bundle and data-route attributes when not using a named remote component
2024
- doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
2025
- doc.querySelector("div#__next") ?? // fallback to the remote-component web component
2026
- doc.querySelector(`remote-component[name="${name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
2027
- const nextData = JSON.parse(
2028
- (doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
2029
- );
2030
- const remoteName = component?.getAttribute("id")?.replace(/_ssr$/, "") || (nextData ? "__next" : name);
2031
- const rsc = doc.querySelector(`#${remoteName}_rsc`);
2032
- const bundle = component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default";
2033
- const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
2034
- const metadata = {
2213
+ const {
2214
+ component,
2035
2215
  name: remoteName,
2036
- bundle,
2037
- route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
2038
- runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
2039
- };
2040
- const remoteSharedEl = doc.querySelector(
2041
- `#${remoteName}_shared[data-remote-components-shared]`
2042
- );
2043
- const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
2044
- remoteSharedEl?.remove();
2045
- if (!component || !(rsc || nextData || isRemoteComponent)) {
2046
- throw new RemoteComponentsError(
2047
- `Remote Component not found on ${url.href}.${remoteName !== "__vercel_remote_component" ? `The name for the <RemoteComponent> is "${remoteName}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
2048
- );
2049
- }
2050
- if (prevIsRemoteComponentRef.current) {
2216
+ isRemoteComponent,
2217
+ metadata,
2218
+ nextData,
2219
+ rsc,
2220
+ remoteShared,
2221
+ links: linkElements,
2222
+ scripts: scriptElements
2223
+ } = parseRemoteComponentDocument(doc, name, url);
2224
+ if (hostStateRef.current.prevIsRemoteComponent) {
2051
2225
  if (shadowRoot) {
2052
2226
  shadowRoot.innerHTML = "";
2053
2227
  }
2054
2228
  const self = globalThis;
2055
- const prevUrl = prevUrlRef.current;
2229
+ const prevUrl = hostStateRef.current.prevUrl;
2056
2230
  if (prevUrl && self.__remote_script_entrypoint_unmount__?.[prevUrl.href]) {
2057
2231
  const unmountPromises = Promise.all(
2058
2232
  Array.from(unmountRef.current ?? []).map(
@@ -2065,15 +2239,11 @@ function RemoteComponent({
2065
2239
  await unmountPromises;
2066
2240
  }
2067
2241
  }
2068
- prevIsRemoteComponentRef.current = isRemoteComponent;
2069
- prevUrlRef.current = url;
2070
- prevNameRef.current = remoteName;
2242
+ hostStateRef.current.prevIsRemoteComponent = isRemoteComponent;
2243
+ hostStateRef.current.prevUrl = url;
2244
+ hostStateRef.current.prevName = remoteName;
2071
2245
  applyOriginToNodes(doc, url, resolveClientUrl);
2072
- const links = Array.from(
2073
- doc.querySelectorAll("link[href]")
2074
- ).filter((link) => {
2075
- return !component.contains(link);
2076
- }).map((link) => ({
2246
+ const links = linkElements.map((link) => ({
2077
2247
  href: new URL(link.getAttribute("href") ?? link.href, url).href,
2078
2248
  ...link.getAttributeNames().reduce((acc, key) => {
2079
2249
  if (key !== "href") {
@@ -2082,7 +2252,7 @@ function RemoteComponent({
2082
2252
  return acc;
2083
2253
  }, {})
2084
2254
  }));
2085
- const scripts = (isRemoteComponent ? component : doc).querySelectorAll("script[src],script[data-src]");
2255
+ const scripts = scriptElements;
2086
2256
  const inlineScripts = (isRemoteComponent ? component : doc).querySelectorAll(
2087
2257
  "script:not([src]):not([data-src]):not([id*='_rsc']):not([id='__NEXT_DATA__']):not([id='__REMOTE_NEXT_DATA__'])"
2088
2258
  );
@@ -2140,11 +2310,10 @@ function RemoteComponent({
2140
2310
  });
2141
2311
  self.__next_s = prevNextScripts;
2142
2312
  }
2143
- let rscName;
2313
+ const rscName = rsc ? `__remote_component_rsc_${escapeString(id)}_${escapeString(
2314
+ remoteName
2315
+ )}` : void 0;
2144
2316
  if (rsc) {
2145
- rscName = `__remote_component_rsc_${escapeString(
2146
- id
2147
- )}_${escapeString(remoteName)}`;
2148
2317
  rsc.textContent = rsc.textContent?.replace(
2149
2318
  new RegExp(`self\\["${remoteName}"\\]`, "g"),
2150
2319
  `self["${rscName}"]`
@@ -2162,7 +2331,7 @@ function RemoteComponent({
2162
2331
  componentHydrationHtml.current = `${Array.from(
2163
2332
  doc.querySelectorAll("link,style")
2164
2333
  ).map((link) => link.outerHTML).join("")}${reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>` : ""}${component.innerHTML}`;
2165
- const userShared = await shared;
2334
+ const userShared = await shared2;
2166
2335
  if ("__remote_components_missing_shared__" in userShared) {
2167
2336
  userShared.__remote_components_missing_shared__().catch((e) => {
2168
2337
  throw e;
@@ -2173,7 +2342,7 @@ function RemoteComponent({
2173
2342
  );
2174
2343
  }
2175
2344
  if (isRemoteComponent) {
2176
- if (previousSrc !== null) {
2345
+ if (previousSrc !== void 0) {
2177
2346
  onChange?.({
2178
2347
  previousSrc,
2179
2348
  nextSrc: src,
@@ -2183,10 +2352,7 @@ function RemoteComponent({
2183
2352
  }
2184
2353
  setData(newData);
2185
2354
  if (shadowRoot) {
2186
- let shadowRootHtml = component.innerHTML;
2187
- if (reset) {
2188
- shadowRootHtml = `<style data-remote-components-reset="">:host { all: initial; }</style>${shadowRootHtml}`;
2189
- }
2355
+ const shadowRootHtml = reset ? `<style data-remote-components-reset="">:host { all: initial; }</style>${component.innerHTML}` : component.innerHTML;
2190
2356
  shadowRoot.innerHTML = shadowRootHtml;
2191
2357
  htmlRef.current = null;
2192
2358
  setRemoteComponent(null);
@@ -2203,7 +2369,7 @@ function RemoteComponent({
2203
2369
  } else if (isolate === false) {
2204
2370
  setRemoteComponent(
2205
2371
  // TODO: remove wrapper div by converting HTML to RSC or React tree
2206
- /* @__PURE__ */ jsx2(
2372
+ /* @__PURE__ */ jsx3(
2207
2373
  "div",
2208
2374
  {
2209
2375
  dangerouslySetInnerHTML: { __html: component.innerHTML },
@@ -2225,12 +2391,13 @@ function RemoteComponent({
2225
2391
  );
2226
2392
  onLoad?.(src);
2227
2393
  }
2394
+ hostStateRef.current.stage = "loaded";
2228
2395
  } else {
2229
2396
  const result = await loadRemoteComponent({
2230
2397
  url,
2231
2398
  name: remoteName,
2232
2399
  rscName,
2233
- bundle,
2400
+ bundle: metadata.bundle,
2234
2401
  route: metadata.route,
2235
2402
  runtime: metadata.runtime,
2236
2403
  data: newData.data,
@@ -2254,7 +2421,7 @@ function RemoteComponent({
2254
2421
  };
2255
2422
  }),
2256
2423
  shared: {
2257
- ...sharedPolyfills(userShared),
2424
+ ...sharedPolyfills(userShared, resolveClientUrl),
2258
2425
  ...userShared
2259
2426
  },
2260
2427
  remoteShared,
@@ -2265,7 +2432,7 @@ function RemoteComponent({
2265
2432
  rsc.remove();
2266
2433
  }
2267
2434
  setData(newData);
2268
- if (previousSrc !== null) {
2435
+ if (previousSrc !== void 0) {
2269
2436
  onChange?.({
2270
2437
  previousSrc,
2271
2438
  nextSrc: src,
@@ -2274,17 +2441,21 @@ function RemoteComponent({
2274
2441
  });
2275
2442
  }
2276
2443
  if (result.error) {
2444
+ hostStateRef.current.stage = "error";
2277
2445
  setRemoteComponent(result.error);
2278
2446
  onError?.(result.error);
2279
2447
  } else {
2448
+ hostStateRef.current.stage = "loaded";
2280
2449
  setRemoteComponent(result.component);
2281
2450
  onLoad?.(src);
2282
2451
  }
2283
2452
  }
2284
2453
  } catch (error) {
2285
2454
  if (isAbortError(error)) {
2455
+ hostStateRef.current.stage = "idle";
2286
2456
  return;
2287
2457
  }
2458
+ hostStateRef.current.stage = "error";
2288
2459
  setRemoteComponent(error);
2289
2460
  onError?.(error);
2290
2461
  }
@@ -2296,7 +2467,7 @@ function RemoteComponent({
2296
2467
  isolate,
2297
2468
  credentials,
2298
2469
  name,
2299
- shared,
2470
+ shared2,
2300
2471
  shadowRoot,
2301
2472
  reset,
2302
2473
  id,
@@ -2311,13 +2482,13 @@ function RemoteComponent({
2311
2482
  if (remoteComponent instanceof Error) {
2312
2483
  throw remoteComponent;
2313
2484
  }
2314
- const metadataJson = /* @__PURE__ */ jsx2("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
2485
+ const metadataJson = /* @__PURE__ */ jsx3("script", { "data-remote-component": true, type: "application/json", children: JSON.stringify({
2315
2486
  name: data?.name || name,
2316
2487
  bundle: data?.bundle || "default",
2317
2488
  route: data?.route || DEFAULT_ROUTE,
2318
- runtime: prevIsRemoteComponentRef.current ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
2489
+ runtime: hostStateRef.current.prevIsRemoteComponent ? RUNTIME_SCRIPT : data?.runtime || RUNTIME_WEBPACK
2319
2490
  }) });
2320
- const resetStyle = reset ? /* @__PURE__ */ jsx2("style", { "data-remote-components-reset": "react", children: `:host { all: initial; }` }) : null;
2491
+ const resetStyle = reset ? /* @__PURE__ */ jsx3("style", { "data-remote-components-reset": "react", children: `:host { all: initial; }` }) : null;
2321
2492
  const linksToRender = data?.links?.map((link) => /* @__PURE__ */ createElement2(
2322
2493
  "link",
2323
2494
  {
@@ -2334,7 +2505,7 @@ function RemoteComponent({
2334
2505
  if (componentHydrationHtml.current && shadowRoot && !shadowRoot.innerHTML) {
2335
2506
  shadowRoot.innerHTML = componentHydrationHtml.current;
2336
2507
  componentHydrationHtml.current = null;
2337
- if (prevIsRemoteComponentRef.current) {
2508
+ if (hostStateRef.current.prevIsRemoteComponent) {
2338
2509
  loadStaticRemoteComponent(
2339
2510
  Array.from(shadowRoot.querySelectorAll("script")),
2340
2511
  url,
@@ -2376,7 +2547,7 @@ function RemoteComponent({
2376
2547
  typeof document === "undefined" ? (
2377
2548
  // eslint-disable-next-line react/no-unknown-property
2378
2549
  /* @__PURE__ */ jsxs("template", { shadowrootmode: mode, children: [
2379
- typeof document === "undefined" ? /* @__PURE__ */ jsx2(
2550
+ typeof document === "undefined" ? /* @__PURE__ */ jsx3(
2380
2551
  "div",
2381
2552
  {
2382
2553
  dangerouslySetInnerHTML: {
@@ -2399,11 +2570,11 @@ function RemoteComponent({
2399
2570
  ) : null,
2400
2571
  shadowRoot && remoteComponent ? createPortal(
2401
2572
  /* @__PURE__ */ jsxs(Fragment, { children: [
2402
- /* @__PURE__ */ jsx2("template", { id: `${name}_start` }),
2573
+ /* @__PURE__ */ jsx3("template", { id: `${name}_start` }),
2403
2574
  resetStyle,
2404
2575
  linksToRender,
2405
2576
  remoteComponent,
2406
- /* @__PURE__ */ jsx2("template", { id: `${name}_end`, ref: endTemplateRef })
2577
+ /* @__PURE__ */ jsx3("template", { id: `${name}_end`, ref: endTemplateRef })
2407
2578
  ] }),
2408
2579
  shadowRoot
2409
2580
  ) : null
@@ -2414,32 +2585,15 @@ function RemoteComponent({
2414
2585
  }
2415
2586
  htmlRef.current = null;
2416
2587
  return /* @__PURE__ */ jsxs(Fragment, { children: [
2417
- /* @__PURE__ */ jsx2("template", { id: `${name}_start` }),
2588
+ /* @__PURE__ */ jsx3("template", { id: `${name}_start` }),
2418
2589
  metadataJson,
2419
2590
  componentToRender,
2420
- /* @__PURE__ */ jsx2("template", { id: `${name}_end`, ref: endTemplateRef })
2591
+ /* @__PURE__ */ jsx3("template", { id: `${name}_end`, ref: endTemplateRef })
2421
2592
  ] });
2422
2593
  }
2423
2594
 
2424
- // src/next/host/client/index.tsx
2425
- import { RemoteComponentsProvider as RemoteComponentsProvider2 } from "#internal/react/context";
2426
-
2427
- // src/next/host/app-router-compat.tsx
2595
+ // src/host/nextjs/app-compat.tsx
2428
2596
  import { usePathname, useSearchParams } from "next/navigation";
2429
- import { jsx as jsx3 } from "react/jsx-runtime";
2430
- function imageImpl2(ImageComponent, bundle) {
2431
- const component = function RemoteImage(props) {
2432
- return /* @__PURE__ */ jsx3(
2433
- ImageComponent,
2434
- {
2435
- ...props,
2436
- src: applyBundleUrlToImagePropsSrc(bundle, props.src)
2437
- }
2438
- );
2439
- };
2440
- component.default = component;
2441
- return component;
2442
- }
2443
2597
  var routerImpl = async () => {
2444
2598
  const { useRouter } = await import("next/navigation");
2445
2599
  return Promise.resolve({
@@ -2503,17 +2657,34 @@ var routerImpl = async () => {
2503
2657
  });
2504
2658
  };
2505
2659
 
2506
- // src/next/host/client/index.tsx
2660
+ // src/host/nextjs/image-shared.ts
2661
+ function createNextImageSharedEntries(getWrappedImage, options) {
2662
+ const entries = {
2663
+ "next/image": (bundle) => Promise.resolve(getWrappedImage(bundle)),
2664
+ "next/dist/client/image-component": (bundle) => Promise.resolve({
2665
+ Image: getWrappedImage(bundle)
2666
+ })
2667
+ };
2668
+ if (options?.getImageProps) {
2669
+ entries["next/dist/api/image"] = (bundle) => Promise.resolve({
2670
+ default: getWrappedImage(bundle),
2671
+ getImageProps: options.getImageProps
2672
+ });
2673
+ }
2674
+ return entries;
2675
+ }
2676
+
2677
+ // src/host/nextjs/app-client-only.tsx
2507
2678
  import { jsx as jsx4 } from "react/jsx-runtime";
2508
2679
  async function tryImportShared() {
2509
2680
  try {
2510
- const { shared } = await import("remote-components/shared/host/app");
2511
- return shared;
2681
+ const { shared: shared2 } = await Promise.resolve().then(() => (init_app(), app_exports));
2682
+ return shared2;
2512
2683
  } catch {
2513
2684
  return {};
2514
2685
  }
2515
2686
  }
2516
- var sharedModules = async (userShared) => {
2687
+ var sharedModules = async (userShared, resolveClientUrl) => {
2517
2688
  const [resolvedShared, resolvedUserShared] = await Promise.all([
2518
2689
  tryImportShared(),
2519
2690
  userShared ?? Promise.resolve({})
@@ -2521,19 +2692,27 @@ var sharedModules = async (userShared) => {
2521
2692
  return {
2522
2693
  ...resolvedShared,
2523
2694
  "next/router": routerImpl,
2524
- "next/image": (bundle) => Promise.resolve(imageImpl2(Image.default, bundle ?? "default")),
2525
- "next/dist/client/image-component": (bundle) => Promise.resolve({ Image: imageImpl2(Image.default, bundle ?? "default") }),
2695
+ ...createNextImageSharedEntries(
2696
+ (bundle) => imageImpl2(Image.default, bundle ?? "default", resolveClientUrl)
2697
+ ),
2526
2698
  ...resolvedUserShared
2527
2699
  };
2528
2700
  };
2529
- function RemoteComponent2(props) {
2701
+ function ConsumeRemoteComponent2(props) {
2530
2702
  if (typeof props.src !== "string" && !(props.src instanceof URL)) {
2531
2703
  return props.children ?? null;
2532
2704
  }
2533
- return /* @__PURE__ */ jsx4(RemoteComponent, { ...props, shared: sharedModules(props.shared) });
2705
+ const src = typeof props.src === "string" ? props.src : props.src.href;
2706
+ const resolveClientUrl = props.resolveClientUrl ? bindResolveClientUrl(props.resolveClientUrl, src) : void 0;
2707
+ return /* @__PURE__ */ jsx4(
2708
+ ConsumeRemoteComponent,
2709
+ {
2710
+ ...props,
2711
+ shared: sharedModules(props.shared, resolveClientUrl)
2712
+ }
2713
+ );
2534
2714
  }
2535
2715
  export {
2536
- RemoteComponent2 as RemoteComponent,
2537
- RemoteComponentsProvider2 as RemoteComponentsProvider
2716
+ ConsumeRemoteComponent2 as ConsumeRemoteComponent
2538
2717
  };
2539
- //# sourceMappingURL=index.js.map
2718
+ //# sourceMappingURL=client-only.js.map