remote-components 0.1.2 → 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 (470) 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} +1012 -1075
  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} +1009 -1071
  22. package/dist/host/html.js.map +1 -0
  23. package/dist/{next/host/client/index.cjs → host/nextjs/app/client-only.cjs} +681 -617
  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} +682 -611
  27. package/dist/host/nextjs/app/client-only.js.map +1 -0
  28. package/dist/{next/host/app-router-server.cjs → host/nextjs/app.cjs} +11 -10
  29. package/dist/host/nextjs/app.cjs.map +1 -0
  30. package/dist/host/nextjs/app.d.ts +29 -0
  31. package/dist/{next/host/app-router-server.js → host/nextjs/app.js} +7 -6
  32. package/dist/host/nextjs/app.js.map +1 -0
  33. package/dist/{next/host/pages-router-client.cjs → host/nextjs/pages/client-only.cjs} +8 -8
  34. package/dist/host/nextjs/pages/client-only.cjs.map +1 -0
  35. package/dist/host/nextjs/pages/client-only.d.ts +31 -0
  36. package/dist/{next/host/pages-router-client.js → host/nextjs/pages/client-only.js} +4 -4
  37. package/dist/host/nextjs/pages/client-only.js.map +1 -0
  38. package/dist/{next/host/pages-router-server.cjs → host/nextjs/pages.cjs} +44 -55
  39. package/dist/host/nextjs/pages.cjs.map +1 -0
  40. package/dist/{next/host/pages-router-server.d.ts → host/nextjs/pages.d.ts} +11 -13
  41. package/dist/{next/host/pages-router-server.js → host/nextjs/pages.js} +38 -49
  42. package/dist/host/nextjs/pages.js.map +1 -0
  43. package/dist/host/proxy/client.cjs +57 -0
  44. package/dist/host/proxy/client.cjs.map +1 -0
  45. package/dist/host/proxy/client.d.ts +31 -0
  46. package/dist/host/proxy/client.js +30 -0
  47. package/dist/host/proxy/client.js.map +1 -0
  48. package/dist/{shared/host/proxy.cjs → host/proxy/protected-fetch.cjs} +6 -6
  49. package/dist/host/proxy/protected-fetch.cjs.map +1 -0
  50. package/dist/{shared/host/proxy.js → host/proxy/protected-fetch.js} +3 -3
  51. package/dist/host/proxy/protected-fetch.js.map +1 -0
  52. package/dist/{next → host}/proxy.cjs +12 -92
  53. package/dist/host/proxy.cjs.map +1 -0
  54. package/dist/host/proxy.d.ts +30 -0
  55. package/dist/{next → host}/proxy.js +11 -88
  56. package/dist/host/proxy.js.map +1 -0
  57. package/dist/{react/index.cjs → host/react.cjs} +515 -548
  58. package/dist/host/react.cjs.map +1 -0
  59. package/dist/{component-loader-21865da3.d.ts → host/react.d.ts} +141 -99
  60. package/dist/{react/index.js → host/react.js} +514 -545
  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} +29 -24
  71. package/dist/internal/host/nextjs/app-client.cjs.map +1 -0
  72. package/dist/internal/host/nextjs/app-client.d.ts +25 -0
  73. package/dist/internal/{next/host/app-router-client.js → host/nextjs/app-client.js} +19 -19
  74. package/dist/internal/host/nextjs/app-client.js.map +1 -0
  75. package/dist/internal/{next/host/app-router-compat.cjs → host/nextjs/app-compat.cjs} +5 -22
  76. package/dist/internal/host/nextjs/app-compat.cjs.map +1 -0
  77. package/dist/internal/{next/host/app-router-compat.d.ts → host/nextjs/app-compat.d.ts} +1 -7
  78. package/dist/internal/{next/host/app-router-compat.js → host/nextjs/app-compat.js} +2 -18
  79. package/dist/internal/host/nextjs/app-compat.js.map +1 -0
  80. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -0
  81. package/dist/internal/host/nextjs/dom-flight.d.ts +39 -0
  82. package/dist/internal/host/nextjs/dom-flight.js.map +1 -0
  83. package/dist/internal/host/nextjs/image-impl.cjs +60 -0
  84. package/dist/internal/host/nextjs/image-impl.cjs.map +1 -0
  85. package/dist/internal/host/nextjs/image-impl.d.ts +10 -0
  86. package/dist/internal/host/nextjs/image-impl.js +36 -0
  87. package/dist/internal/host/nextjs/image-impl.js.map +1 -0
  88. package/dist/internal/host/nextjs/image-shared.cjs +43 -0
  89. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -0
  90. package/dist/internal/host/nextjs/image-shared.d.ts +9 -0
  91. package/dist/internal/host/nextjs/image-shared.js +19 -0
  92. package/dist/internal/host/nextjs/image-shared.js.map +1 -0
  93. package/dist/internal/{next/host → host/nextjs}/remote-component-links.cjs +2 -2
  94. package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -0
  95. package/dist/internal/{next/host → host/nextjs}/remote-component-links.d.ts +1 -1
  96. package/dist/internal/{next/host → host/nextjs}/remote-component-links.js +2 -2
  97. package/dist/internal/host/nextjs/remote-component-links.js.map +1 -0
  98. package/dist/internal/host/nextjs/skeleton.cjs.map +1 -0
  99. package/dist/internal/host/nextjs/skeleton.js.map +1 -0
  100. package/dist/internal/{react → host/react}/context.cjs +3 -3
  101. package/dist/internal/host/react/context.cjs.map +1 -0
  102. package/dist/internal/{react → host/react}/context.d.ts +4 -4
  103. package/dist/internal/{react → host/react}/context.js +2 -2
  104. package/dist/internal/host/react/context.js.map +1 -0
  105. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.cjs +2 -2
  106. package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -0
  107. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.d.ts +1 -1
  108. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.js +2 -2
  109. package/dist/internal/host/react/hooks/use-resolve-client-url.js.map +1 -0
  110. package/dist/internal/host/server/fetch-headers.cjs.map +1 -0
  111. package/dist/internal/host/server/fetch-headers.js.map +1 -0
  112. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.cjs +6 -6
  113. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -0
  114. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.d.ts +6 -1
  115. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.js +9 -9
  116. package/dist/internal/host/server/fetch-remote-component.js.map +1 -0
  117. package/dist/internal/{shared/ssr → host/server}/fetch-with-hooks.cjs +11 -15
  118. package/dist/internal/host/server/fetch-with-hooks.cjs.map +1 -0
  119. package/dist/internal/host/server/fetch-with-hooks.d.ts +21 -0
  120. package/dist/internal/{shared/ssr → host/server}/fetch-with-hooks.js +11 -15
  121. package/dist/internal/host/server/fetch-with-hooks.js.map +1 -0
  122. package/dist/internal/host/server/get-client-or-server-url.cjs.map +1 -0
  123. package/dist/internal/host/server/get-client-or-server-url.js.map +1 -0
  124. package/dist/internal/{shared/client → host/server}/get-client-src.cjs +1 -1
  125. package/dist/internal/host/server/get-client-src.cjs.map +1 -0
  126. package/dist/internal/{shared/client → host/server}/get-client-src.js +1 -1
  127. package/dist/internal/host/server/get-client-src.js.map +1 -0
  128. package/dist/internal/host/server/get-ssr-relative-path-base-url.cjs.map +1 -0
  129. package/dist/internal/host/server/get-ssr-relative-path-base-url.js.map +1 -0
  130. package/dist/{next/remote/server.cjs → internal/host/server/types.cjs} +3 -15
  131. package/dist/internal/host/server/types.cjs.map +1 -0
  132. package/dist/internal/host/server/types.d.ts +33 -0
  133. package/dist/internal/host/server/types.js +1 -0
  134. package/dist/internal/host/server/types.js.map +1 -0
  135. package/dist/internal/host/shared/asset-descriptors.cjs +17 -0
  136. package/dist/internal/host/shared/asset-descriptors.cjs.map +1 -0
  137. package/dist/internal/host/shared/asset-descriptors.d.ts +21 -0
  138. package/dist/internal/host/shared/asset-descriptors.js +1 -0
  139. package/dist/internal/host/shared/asset-descriptors.js.map +1 -0
  140. package/dist/internal/host/shared/config.cjs +17 -0
  141. package/dist/internal/host/shared/config.cjs.map +1 -0
  142. package/dist/{host-config-58cdccea.d.ts → internal/host/shared/config.d.ts} +32 -19
  143. package/dist/internal/host/shared/config.js +1 -0
  144. package/dist/internal/host/shared/config.js.map +1 -0
  145. package/dist/internal/host/shared/fetch-interceptors.cjs +17 -0
  146. package/dist/internal/host/shared/fetch-interceptors.cjs.map +1 -0
  147. package/dist/{types-2b26a246.d.ts → internal/host/shared/fetch-interceptors.d.ts} +4 -87
  148. package/dist/internal/host/shared/fetch-interceptors.js +1 -0
  149. package/dist/internal/host/shared/fetch-interceptors.js.map +1 -0
  150. package/dist/internal/{shared/client → host/shared}/polyfill.cjs +7 -6
  151. package/dist/internal/host/shared/polyfill.cjs.map +1 -0
  152. package/dist/internal/{shared/client → host/shared}/polyfill.d.ts +2 -1
  153. package/dist/internal/{shared/client → host/shared}/polyfill.js +7 -6
  154. package/dist/internal/host/shared/polyfill.js.map +1 -0
  155. package/dist/internal/host/shared/resolved-data.cjs +17 -0
  156. package/dist/internal/host/shared/resolved-data.cjs.map +1 -0
  157. package/dist/internal/host/shared/resolved-data.d.ts +48 -0
  158. package/dist/internal/host/shared/resolved-data.js +1 -0
  159. package/dist/internal/host/shared/resolved-data.js.map +1 -0
  160. package/dist/internal/{shared/contract/host-state.cjs → host/shared/state.cjs} +4 -4
  161. package/dist/internal/host/shared/state.cjs.map +1 -0
  162. package/dist/internal/{shared/contract/host-state.js → host/shared/state.js} +1 -1
  163. package/dist/internal/host/shared/state.js.map +1 -0
  164. package/dist/internal/host/utils/resolve-name-from-src.cjs.map +1 -0
  165. package/dist/internal/host/utils/resolve-name-from-src.js.map +1 -0
  166. package/dist/internal/{next/remote/render-client.cjs → remote/nextjs/app-client.cjs} +8 -8
  167. package/dist/internal/remote/nextjs/app-client.cjs.map +1 -0
  168. package/dist/internal/{next/remote/render-client.js → remote/nextjs/app-client.js} +4 -4
  169. package/dist/internal/remote/nextjs/app-client.js.map +1 -0
  170. package/dist/internal/runtime/constants.cjs +50 -0
  171. package/dist/internal/runtime/constants.cjs.map +1 -0
  172. package/dist/internal/runtime/constants.d.ts +10 -0
  173. package/dist/internal/runtime/constants.js +20 -0
  174. package/dist/internal/runtime/constants.js.map +1 -0
  175. package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs.map +1 -1
  176. package/dist/internal/{shared/client → runtime/html}/apply-origin.d.ts +1 -1
  177. package/dist/internal/{shared/client → runtime/html}/apply-origin.js.map +1 -1
  178. package/dist/internal/runtime/html/parse-remote-html.cjs +140 -0
  179. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -0
  180. package/dist/internal/runtime/html/parse-remote-html.d.ts +88 -0
  181. package/dist/internal/runtime/html/parse-remote-html.js +110 -0
  182. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -0
  183. package/dist/internal/runtime/html/set-attributes-from-props.cjs +68 -0
  184. package/dist/internal/runtime/html/set-attributes-from-props.cjs.map +1 -0
  185. package/dist/internal/runtime/html/set-attributes-from-props.d.ts +3 -0
  186. package/dist/internal/runtime/html/set-attributes-from-props.js +44 -0
  187. package/dist/internal/runtime/html/set-attributes-from-props.js.map +1 -0
  188. package/dist/internal/runtime/loaders/component-loader.cjs +184 -0
  189. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -0
  190. package/dist/internal/runtime/loaders/component-loader.d.ts +31 -0
  191. package/dist/internal/runtime/loaders/component-loader.js +150 -0
  192. package/dist/internal/runtime/loaders/component-loader.js.map +1 -0
  193. package/dist/internal/runtime/loaders/script-loader.cjs +69 -0
  194. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -0
  195. package/dist/internal/runtime/loaders/script-loader.d.ts +10 -0
  196. package/dist/internal/runtime/loaders/script-loader.js +48 -0
  197. package/dist/internal/runtime/loaders/script-loader.js.map +1 -0
  198. package/dist/internal/runtime/loaders/static-loader.cjs +177 -0
  199. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -0
  200. package/dist/internal/runtime/loaders/static-loader.d.ts +10 -0
  201. package/dist/internal/runtime/loaders/static-loader.js +153 -0
  202. package/dist/internal/runtime/loaders/static-loader.js.map +1 -0
  203. package/dist/internal/runtime/metadata.cjs +17 -0
  204. package/dist/internal/runtime/metadata.cjs.map +1 -0
  205. package/dist/internal/runtime/metadata.d.ts +16 -0
  206. package/dist/internal/runtime/metadata.js +1 -0
  207. package/dist/internal/runtime/metadata.js.map +1 -0
  208. package/dist/internal/runtime/rsc.cjs +92 -0
  209. package/dist/internal/runtime/rsc.cjs.map +1 -0
  210. package/dist/internal/runtime/rsc.d.ts +8 -0
  211. package/dist/internal/runtime/rsc.js +68 -0
  212. package/dist/internal/runtime/rsc.js.map +1 -0
  213. package/dist/internal/runtime/turbopack/chunk-loader.cjs +244 -0
  214. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -0
  215. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +11 -0
  216. package/dist/internal/runtime/turbopack/chunk-loader.js +227 -0
  217. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -0
  218. package/dist/internal/runtime/turbopack/module.cjs +257 -0
  219. package/dist/internal/runtime/turbopack/module.cjs.map +1 -0
  220. package/dist/internal/runtime/turbopack/module.d.ts +61 -0
  221. package/dist/internal/runtime/turbopack/module.js +233 -0
  222. package/dist/internal/runtime/turbopack/module.js.map +1 -0
  223. package/dist/internal/runtime/turbopack/patterns.cjs +44 -0
  224. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -0
  225. package/dist/internal/runtime/turbopack/patterns.d.ts +109 -0
  226. package/dist/internal/runtime/turbopack/patterns.js +15 -0
  227. package/dist/internal/runtime/turbopack/patterns.js.map +1 -0
  228. package/dist/internal/runtime/turbopack/shared-modules.cjs +152 -0
  229. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -0
  230. package/dist/internal/runtime/turbopack/shared-modules.d.ts +17 -0
  231. package/dist/internal/runtime/turbopack/shared-modules.js +133 -0
  232. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -0
  233. package/dist/internal/runtime/turbopack/webpack-runtime.cjs +137 -0
  234. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -0
  235. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +20 -0
  236. package/dist/internal/runtime/turbopack/webpack-runtime.js +107 -0
  237. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -0
  238. package/dist/internal/runtime/types.cjs +17 -0
  239. package/dist/internal/runtime/types.cjs.map +1 -0
  240. package/dist/internal/runtime/types.d.ts +40 -0
  241. package/dist/internal/runtime/types.js +1 -0
  242. package/dist/internal/runtime/types.js.map +1 -0
  243. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.cjs +2 -2
  244. package/dist/internal/runtime/url/default-resolve-client-url.cjs.map +1 -0
  245. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.d.ts +1 -1
  246. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.js +1 -1
  247. package/dist/internal/runtime/url/default-resolve-client-url.js.map +1 -0
  248. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.cjs +1 -1
  249. package/dist/internal/runtime/url/protected-rc-fallback.cjs.map +1 -0
  250. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.js +1 -1
  251. package/dist/internal/runtime/url/protected-rc-fallback.js.map +1 -0
  252. package/dist/internal/{shared/client/proxy-through-host.cjs → runtime/url/resolve-client-url.cjs} +4 -24
  253. package/dist/internal/runtime/url/resolve-client-url.cjs.map +1 -0
  254. package/dist/internal/{shared/client/proxy-through-host.d.ts → runtime/url/resolve-client-url.d.ts} +1 -25
  255. package/dist/internal/runtime/url/resolve-client-url.js +21 -0
  256. package/dist/internal/runtime/url/resolve-client-url.js.map +1 -0
  257. package/dist/internal/utils/abort.cjs.map +1 -0
  258. package/dist/internal/utils/abort.js.map +1 -0
  259. package/dist/internal/{shared → utils}/constants.cjs +3 -0
  260. package/dist/internal/utils/constants.cjs.map +1 -0
  261. package/dist/internal/utils/constants.d.ts +5 -0
  262. package/dist/internal/{shared → utils}/constants.js +2 -0
  263. package/dist/internal/utils/constants.js.map +1 -0
  264. package/dist/internal/{shared → utils}/error.cjs +4 -4
  265. package/dist/internal/utils/error.cjs.map +1 -0
  266. package/dist/internal/{shared → utils}/error.js +4 -4
  267. package/dist/internal/utils/error.js.map +1 -0
  268. package/dist/internal/{shared/utils → utils}/logger.cjs +3 -3
  269. package/dist/internal/utils/logger.cjs.map +1 -0
  270. package/dist/internal/{shared/utils → utils}/logger.d.ts +2 -2
  271. package/dist/internal/{shared/utils → utils}/logger.js +3 -3
  272. package/dist/internal/utils/logger.js.map +1 -0
  273. package/dist/internal/utils.cjs.map +1 -0
  274. package/dist/internal/utils.js.map +1 -0
  275. package/dist/{shared/host → remote/defaults}/app.cjs +2 -6
  276. package/dist/remote/defaults/app.cjs.map +1 -0
  277. package/dist/remote/defaults/app.js +8 -0
  278. package/dist/remote/defaults/app.js.map +1 -0
  279. package/dist/{shared/host → remote/defaults}/pages.cjs +2 -6
  280. package/dist/remote/defaults/pages.cjs.map +1 -0
  281. package/dist/remote/defaults/pages.js +8 -0
  282. package/dist/remote/defaults/pages.js.map +1 -0
  283. package/dist/{shared/remote → remote/defaults}/wrapper.cjs +12 -10
  284. package/dist/remote/defaults/wrapper.cjs.map +1 -0
  285. package/dist/remote/defaults/wrapper.js +27 -0
  286. package/dist/remote/defaults/wrapper.js.map +1 -0
  287. package/dist/{html/remote.cjs → remote/html.cjs} +16 -16
  288. package/dist/remote/html.cjs.map +1 -0
  289. package/dist/{html/remote.js → remote/html.js} +16 -16
  290. package/dist/remote/html.js.map +1 -0
  291. package/dist/{shared/remote/proxy.cjs → remote/middleware.cjs} +37 -12
  292. package/dist/remote/middleware.cjs.map +1 -0
  293. package/dist/remote/middleware.d.ts +27 -0
  294. package/dist/{shared/remote/proxy.js → remote/middleware.js} +32 -5
  295. package/dist/remote/middleware.js.map +1 -0
  296. package/dist/{internal/next/remote/render-server.cjs → remote/nextjs/app.cjs} +14 -16
  297. package/dist/remote/nextjs/app.cjs.map +1 -0
  298. package/dist/{internal/next/remote/render-server.d.ts → remote/nextjs/app.d.ts} +12 -13
  299. package/dist/{internal/next/remote/render-server.js → remote/nextjs/app.js} +9 -11
  300. package/dist/remote/nextjs/app.js.map +1 -0
  301. package/dist/{next/remote/pages-router.cjs → remote/nextjs/pages.cjs} +8 -8
  302. package/dist/remote/nextjs/pages.cjs.map +1 -0
  303. package/dist/{next/remote/pages-router.d.ts → remote/nextjs/pages.d.ts} +8 -8
  304. package/dist/{next/remote/pages-router.js → remote/nextjs/pages.js} +4 -4
  305. package/dist/remote/nextjs/pages.js.map +1 -0
  306. package/dist/server-handoff-8c89b856.d.ts +46 -0
  307. package/package.json +126 -157
  308. package/dist/html/host.cjs.map +0 -1
  309. package/dist/html/host.js.map +0 -1
  310. package/dist/html/remote.cjs.map +0 -1
  311. package/dist/html/remote.js.map +0 -1
  312. package/dist/internal/next/host/app-router-client.cjs.map +0 -1
  313. package/dist/internal/next/host/app-router-client.d.ts +0 -79
  314. package/dist/internal/next/host/app-router-client.js.map +0 -1
  315. package/dist/internal/next/host/app-router-compat.cjs.map +0 -1
  316. package/dist/internal/next/host/app-router-compat.js.map +0 -1
  317. package/dist/internal/next/host/remote-component-links.cjs.map +0 -1
  318. package/dist/internal/next/host/remote-component-links.js.map +0 -1
  319. package/dist/internal/next/remote/render-client.cjs.map +0 -1
  320. package/dist/internal/next/remote/render-client.js.map +0 -1
  321. package/dist/internal/next/remote/render-server.cjs.map +0 -1
  322. package/dist/internal/next/remote/render-server.js.map +0 -1
  323. package/dist/internal/react/context.cjs.map +0 -1
  324. package/dist/internal/react/context.js.map +0 -1
  325. package/dist/internal/react/hooks/use-resolve-client-url.cjs.map +0 -1
  326. package/dist/internal/react/hooks/use-resolve-client-url.js.map +0 -1
  327. package/dist/internal/shared/client/default-resolve-client-url.cjs.map +0 -1
  328. package/dist/internal/shared/client/default-resolve-client-url.js.map +0 -1
  329. package/dist/internal/shared/client/get-client-src.cjs.map +0 -1
  330. package/dist/internal/shared/client/get-client-src.js.map +0 -1
  331. package/dist/internal/shared/client/polyfill.cjs.map +0 -1
  332. package/dist/internal/shared/client/polyfill.js.map +0 -1
  333. package/dist/internal/shared/client/protected-rc-fallback.cjs.map +0 -1
  334. package/dist/internal/shared/client/protected-rc-fallback.js.map +0 -1
  335. package/dist/internal/shared/client/proxy-through-host.cjs.map +0 -1
  336. package/dist/internal/shared/client/proxy-through-host.js +0 -40
  337. package/dist/internal/shared/client/proxy-through-host.js.map +0 -1
  338. package/dist/internal/shared/client/remote-component.cjs +0 -1436
  339. package/dist/internal/shared/client/remote-component.cjs.map +0 -1
  340. package/dist/internal/shared/client/remote-component.d.ts +0 -62
  341. package/dist/internal/shared/client/remote-component.js +0 -1385
  342. package/dist/internal/shared/client/remote-component.js.map +0 -1
  343. package/dist/internal/shared/constants.cjs.map +0 -1
  344. package/dist/internal/shared/constants.d.ts +0 -4
  345. package/dist/internal/shared/constants.js.map +0 -1
  346. package/dist/internal/shared/contract/host-state.cjs.map +0 -1
  347. package/dist/internal/shared/contract/host-state.js.map +0 -1
  348. package/dist/internal/shared/contract/resolve-name-from-src.cjs.map +0 -1
  349. package/dist/internal/shared/contract/resolve-name-from-src.js.map +0 -1
  350. package/dist/internal/shared/error.cjs.map +0 -1
  351. package/dist/internal/shared/error.js.map +0 -1
  352. package/dist/internal/shared/ssr/dom-flight.cjs.map +0 -1
  353. package/dist/internal/shared/ssr/dom-flight.d.ts +0 -2
  354. package/dist/internal/shared/ssr/dom-flight.js.map +0 -1
  355. package/dist/internal/shared/ssr/fetch-headers.cjs.map +0 -1
  356. package/dist/internal/shared/ssr/fetch-headers.js.map +0 -1
  357. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +0 -1
  358. package/dist/internal/shared/ssr/fetch-remote-component.js.map +0 -1
  359. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +0 -1
  360. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +0 -56
  361. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +0 -1
  362. package/dist/internal/shared/ssr/get-client-or-server-url.cjs.map +0 -1
  363. package/dist/internal/shared/ssr/get-client-or-server-url.js.map +0 -1
  364. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs.map +0 -1
  365. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js.map +0 -1
  366. package/dist/internal/shared/ssr/skeleton.cjs.map +0 -1
  367. package/dist/internal/shared/ssr/skeleton.js.map +0 -1
  368. package/dist/internal/shared/utils/abort.cjs.map +0 -1
  369. package/dist/internal/shared/utils/abort.js.map +0 -1
  370. package/dist/internal/shared/utils/logger.cjs.map +0 -1
  371. package/dist/internal/shared/utils/logger.js.map +0 -1
  372. package/dist/internal/shared/utils.cjs.map +0 -1
  373. package/dist/internal/shared/utils.js.map +0 -1
  374. package/dist/internal/webpack/next-client-pages-loader.cjs.map +0 -1
  375. package/dist/internal/webpack/next-client-pages-loader.js.map +0 -1
  376. package/dist/internal/webpack/shared-modules.cjs.map +0 -1
  377. package/dist/internal/webpack/shared-modules.js.map +0 -1
  378. package/dist/next/config.cjs.map +0 -1
  379. package/dist/next/config.js.map +0 -1
  380. package/dist/next/host/app-router-server.cjs.map +0 -1
  381. package/dist/next/host/app-router-server.d.ts +0 -30
  382. package/dist/next/host/app-router-server.js.map +0 -1
  383. package/dist/next/host/client/index.cjs.map +0 -1
  384. package/dist/next/host/client/index.d.ts +0 -19
  385. package/dist/next/host/client/index.js.map +0 -1
  386. package/dist/next/host/pages-router-client.cjs.map +0 -1
  387. package/dist/next/host/pages-router-client.d.ts +0 -33
  388. package/dist/next/host/pages-router-client.js.map +0 -1
  389. package/dist/next/host/pages-router-server.cjs.map +0 -1
  390. package/dist/next/host/pages-router-server.js.map +0 -1
  391. package/dist/next/index.cjs +0 -53
  392. package/dist/next/index.cjs.map +0 -1
  393. package/dist/next/index.d.ts +0 -30
  394. package/dist/next/index.js +0 -19
  395. package/dist/next/index.js.map +0 -1
  396. package/dist/next/proxy.cjs.map +0 -1
  397. package/dist/next/proxy.d.ts +0 -56
  398. package/dist/next/proxy.js.map +0 -1
  399. package/dist/next/remote/pages-router.cjs.map +0 -1
  400. package/dist/next/remote/pages-router.js.map +0 -1
  401. package/dist/next/remote/server.cjs.map +0 -1
  402. package/dist/next/remote/server.d.ts +0 -5
  403. package/dist/next/remote/server.js +0 -5
  404. package/dist/next/remote/server.js.map +0 -1
  405. package/dist/proxy-through-host-a676a522.d.ts +0 -52
  406. package/dist/react/index.cjs.map +0 -1
  407. package/dist/react/index.d.ts +0 -86
  408. package/dist/react/index.js.map +0 -1
  409. package/dist/shared/host/app.cjs.map +0 -1
  410. package/dist/shared/host/app.js +0 -12
  411. package/dist/shared/host/app.js.map +0 -1
  412. package/dist/shared/host/pages.cjs.map +0 -1
  413. package/dist/shared/host/pages.js +0 -12
  414. package/dist/shared/host/pages.js.map +0 -1
  415. package/dist/shared/host/proxy.cjs.map +0 -1
  416. package/dist/shared/host/proxy.js.map +0 -1
  417. package/dist/shared/remote/app.cjs.map +0 -1
  418. package/dist/shared/remote/app.js +0 -8
  419. package/dist/shared/remote/app.js.map +0 -1
  420. package/dist/shared/remote/pages.cjs.map +0 -1
  421. package/dist/shared/remote/pages.js +0 -8
  422. package/dist/shared/remote/pages.js.map +0 -1
  423. package/dist/shared/remote/proxy.cjs.map +0 -1
  424. package/dist/shared/remote/proxy.d.ts +0 -44
  425. package/dist/shared/remote/proxy.js.map +0 -1
  426. package/dist/shared/remote/wrapper.cjs.map +0 -1
  427. package/dist/shared/remote/wrapper.js +0 -25
  428. package/dist/shared/remote/wrapper.js.map +0 -1
  429. package/dist/webpack.cjs.map +0 -1
  430. package/dist/webpack.js.map +0 -1
  431. /package/dist/{webpack.d.ts → config/webpack.d.ts} +0 -0
  432. /package/dist/{shared/host → host/defaults}/app.d.ts +0 -0
  433. /package/dist/{shared/host → host/defaults}/pages.d.ts +0 -0
  434. /package/dist/{shared/host/proxy.d.ts → host/proxy/protected-fetch.d.ts} +0 -0
  435. /package/dist/internal/{webpack/shared-modules.d.ts → config/webpack/apply-shared-modules.d.ts} +0 -0
  436. /package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.d.ts +0 -0
  437. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.cjs +0 -0
  438. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.js +0 -0
  439. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.cjs +0 -0
  440. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.d.ts +0 -0
  441. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.js +0 -0
  442. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.cjs +0 -0
  443. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.d.ts +0 -0
  444. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.js +0 -0
  445. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.cjs +0 -0
  446. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.d.ts +0 -0
  447. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.js +0 -0
  448. /package/dist/internal/{shared/client → host/server}/get-client-src.d.ts +0 -0
  449. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.cjs +0 -0
  450. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.d.ts +0 -0
  451. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.js +0 -0
  452. /package/dist/internal/{shared/contract/host-state.d.ts → host/shared/state.d.ts} +0 -0
  453. /package/dist/internal/{shared/contract → host/utils}/resolve-name-from-src.cjs +0 -0
  454. /package/dist/internal/{shared/contract → host/utils}/resolve-name-from-src.d.ts +0 -0
  455. /package/dist/internal/{shared/contract → host/utils}/resolve-name-from-src.js +0 -0
  456. /package/dist/internal/{next/remote/render-client.d.ts → remote/nextjs/app-client.d.ts} +0 -0
  457. /package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs +0 -0
  458. /package/dist/internal/{shared/client → runtime/html}/apply-origin.js +0 -0
  459. /package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.d.ts +0 -0
  460. /package/dist/internal/{shared/utils → utils}/abort.cjs +0 -0
  461. /package/dist/internal/{shared/utils → utils}/abort.d.ts +0 -0
  462. /package/dist/internal/{shared/utils → utils}/abort.js +0 -0
  463. /package/dist/internal/{shared → utils}/error.d.ts +0 -0
  464. /package/dist/internal/{shared/utils.cjs → utils.cjs} +0 -0
  465. /package/dist/internal/{shared/utils.d.ts → utils.d.ts} +0 -0
  466. /package/dist/internal/{shared/utils.js → utils.js} +0 -0
  467. /package/dist/{shared/remote → remote/defaults}/app.d.ts +0 -0
  468. /package/dist/{shared/remote → remote/defaults}/pages.d.ts +0 -0
  469. /package/dist/{shared/remote → remote/defaults}/wrapper.d.ts +0 -0
  470. /package/dist/{html/remote.d.ts → remote/html.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/constants.ts","../../src/runtime/url/protected-rc-fallback.ts","../../src/utils/abort.ts","../../src/utils/error.ts","../../src/utils/logger.ts","../../src/runtime/loaders/static-loader.ts","../../src/remote/html/index.tsx"],"sourcesContent":["export const RC_PROTECTED_REMOTE_FETCH_PATHNAME = '/rc-fetch-protected-remote';\n\nexport const MISSING_SHARED_MODULES_MESSAGE =\n 'Remote Components shared modules not found. Did you forget to wrap your config with `withRemoteComponentsConfig` on both host and remote?';\n\nexport const CORS_DOCS_URL =\n 'https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components';\n","import { RC_PROTECTED_REMOTE_FETCH_PATHNAME } from '#internal/utils/constants';\n\n/**\n * Generates a fallback URL that proxies the request through the host's protected remote fetch endpoint\n */\nexport function generateProtectedRcFallbackSrc(url: string): string {\n return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;\n}\n\nexport function isProxiedUrl(url: string): boolean {\n try {\n return (\n new URL(url, location.href).pathname ===\n RC_PROTECTED_REMOTE_FETCH_PATHNAME\n );\n } catch {\n return false;\n }\n}\n","/**\n * Type guard to check if an error is an AbortError.\n * Handles cross-environment differences (Node.js, browsers, JSDOM).\n */\nexport function isAbortError(error: unknown): error is DOMException {\n if (error instanceof DOMException && error.name === 'AbortError') {\n return true;\n }\n\n // Handle Node.js native AbortError which may not be instanceof global DOMException\n if (\n error !== null &&\n typeof error === 'object' &&\n 'name' in error &&\n error.name === 'AbortError' &&\n 'message' in error &&\n typeof (error as { message: unknown }).message === 'string'\n ) {\n // Additional check: verify it has DOMException-like structure\n const e = error as { code?: unknown; constructor?: { name?: string } };\n return typeof e.code === 'number' || e.constructor?.name === 'DOMException';\n }\n\n return false;\n}\n","import { isProxiedUrl } from '#internal/runtime/url/protected-rc-fallback';\nimport { isAbortError } from '#internal/utils/abort';\nimport {\n CORS_DOCS_URL,\n RC_PROTECTED_REMOTE_FETCH_PATHNAME,\n} from '#internal/utils/constants';\n\nexport class RemoteComponentsError extends Error {\n code = 'REMOTE_COMPONENTS_ERROR';\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = 'RemoteComponentsError';\n }\n}\n\nexport function multipleRemoteComponentsError(url: string | undefined) {\n return new RemoteComponentsError(\n `Multiple Remote Components found at \"${url}\". When a page exposes multiple Remote Components you must specify the \"name\" prop to select which one to load.`,\n );\n}\n\nexport function failedToFetchRemoteComponentError(\n url: string,\n { status, statusText }: { status: number; statusText: string },\n help: string = 'Is the URL correct and accessible?',\n) {\n return new RemoteComponentsError(\n `Failed to fetch Remote Component from \"${url}\". ${help}`,\n { cause: new Error(`${status} ${statusText}`) },\n );\n}\n\nexport async function errorFromFailedFetch(\n originalUrl: string,\n resolvedUrl: URL,\n res: Response | null | undefined,\n): Promise<RemoteComponentsError> {\n const isProxied = isProxiedUrl(resolvedUrl.href);\n\n if (isProxied && res) {\n const body = await res.text().catch(() => '');\n return failedProxyFetchError(\n originalUrl,\n resolvedUrl.href,\n res.status,\n body,\n );\n }\n\n const fallback = failedToFetchRemoteComponentError(\n originalUrl,\n res ?? { status: 0, statusText: 'No Response' },\n );\n\n if (!res) return fallback;\n\n try {\n const body = await res.text();\n const parser = new DOMParser();\n const doc = parser.parseFromString(body, 'text/html');\n const errorTemplate = doc.querySelector(\n 'template[data-next-error-message]',\n );\n const errorMessage = errorTemplate?.getAttribute('data-next-error-message');\n if (errorMessage) {\n const error = new RemoteComponentsError(errorMessage);\n const errorStack = errorTemplate?.getAttribute('data-next-error-stack');\n if (errorStack) {\n error.stack = errorStack;\n }\n return error;\n }\n } catch (parseError) {\n // Re-throw abort errors, ignore parse errors\n if (isAbortError(parseError)) throw parseError;\n }\n\n return fallback;\n}\n\nexport function failedProxyFetchError(\n originalUrl: string,\n proxyUrl: string,\n status: number,\n responseBody?: string,\n): RemoteComponentsError {\n if (status === 404) {\n return new RemoteComponentsError(\n `Could not proxy the request to \"${originalUrl}\" — the proxy endpoint \"${RC_PROTECTED_REMOTE_FETCH_PATHNAME}\" returned 404.\\n\\n` +\n `The host server needs middleware or a route that handles \"${RC_PROTECTED_REMOTE_FETCH_PATHNAME}\".\\n\\n` +\n `Proxying requires two pieces:\\n` +\n ` 1. resolveClientUrl={routeThroughHostProxy} on <RemoteComponent>\\n` +\n ` 2. Middleware or a route for \"${RC_PROTECTED_REMOTE_FETCH_PATHNAME}\" on the host server\\n\\n` +\n `Docs: ${CORS_DOCS_URL}`,\n );\n }\n if (status === 403) {\n const detail = responseBody ? ` ${responseBody}` : '';\n return new RemoteComponentsError(\n `Proxied request to \"${proxyUrl}\" was forbidden.${detail} ` +\n `See: ${CORS_DOCS_URL}`,\n );\n }\n return new RemoteComponentsError(\n `Proxied request for \"${originalUrl}\" via \"${proxyUrl}\" failed with status ${status}. ` +\n `See: ${CORS_DOCS_URL}`,\n );\n}\n","import { CORS_DOCS_URL } from '#internal/utils/constants';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ntype LogLocation =\n | 'ChunkLoader'\n | 'ComponentLoader'\n | 'SharedModules'\n | 'WebpackRuntime'\n | 'TurbopackModule'\n | 'StaticLoader'\n | 'ScriptLoader'\n | 'Polyfill'\n | 'HtmlRemote'\n | 'HtmlHost'\n | 'Config'\n | 'NextAppRouter'\n | 'NextAppRouterCompat'\n | 'FetchRemoteComponent';\n\nconst PREFIX = 'remote-components';\nconst DEBUG =\n typeof window !== 'undefined' && localStorage.getItem('RC_DEBUG') === 'true';\n\nexport function logDebug(location: LogLocation, message: string) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.debug(`[${PREFIX}:${location}]: ${message}`);\n }\n}\n\nexport function logInfo(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.info(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logWarn(location: LogLocation, message: string) {\n // eslint-disable-next-line no-console\n console.warn(`[${PREFIX}:${location}]: ${message}`);\n}\n\nexport function logError(\n location: LogLocation,\n message: string,\n cause?: unknown,\n) {\n // eslint-disable-next-line no-console\n console.error(\n new RemoteComponentsError(`[${PREFIX}:${location}]: ${message}`, {\n cause,\n }),\n );\n}\n\n/**\n * Logs a warning when a cross-origin asset request fails, guiding users\n * to configure the withRemoteComponentsHostProxy middleware on their host.\n */\nexport function warnCrossOriginFetchError(\n logLocation: LogLocation,\n url: string | URL,\n): void {\n try {\n const parsed = typeof url === 'string' ? new URL(url) : url;\n if (typeof location === 'undefined' || parsed.origin === location.origin) {\n return;\n }\n logWarn(\n logLocation,\n `Failed to fetch cross-origin resource \"${parsed.href}\". ` +\n 'If this is a protected deployment, ensure withRemoteComponentsHostProxy middleware ' +\n 'is configured in your host and that the remote URL is included in allowedProxyUrls. ' +\n `See: ${CORS_DOCS_URL}`,\n );\n } catch {\n // URL parsing failed — skip the warning\n }\n}\n","import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type {\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\nimport { logError, warnCrossOriginFetchError } from '#internal/utils/logger';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = (\n globalThis as unknown as { __rc_module_registry__?: Record<string, T> }\n ).__rc_module_registry__;\n const mod = registry?.[absoluteSrc] ?? ({} as T);\n if (registry) delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const self = globalThis as typeof globalThis & MountUnmountFunctions;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n","import type { MountOrUnmountFunction } from '#internal/runtime/types';\nimport { logError } from '#internal/utils/logger';\n\nif (typeof HTMLElement !== 'undefined') {\n class RemoteComponent extends HTMLElement {\n name?: string;\n root?: ShadowRoot | null = null;\n unmount?: Set<MountOrUnmountFunction> | null = null;\n\n constructor() {\n super();\n\n const html = this.innerHTML;\n this.root = this.attachShadow({\n mode: this.getAttribute('mode') === 'closed' ? 'closed' : 'open',\n });\n this.root.innerHTML = html;\n // Clear light DOM — content was copied into the shadow root above.\n // Without this the original children render twice (once in light DOM,\n // once in shadow DOM).\n this.replaceChildren();\n\n // run the mount functions for any scripts inside the shadow root asynchronously\n (async () => {\n const { loadStaticRemoteComponent } = await import(\n '../../runtime/loaders/static-loader'\n );\n loadStaticRemoteComponent(\n Array.from(this.root?.querySelectorAll('script') ?? []),\n new URL(location.href),\n )\n .then(({ mount, unmount }) => {\n this.unmount = unmount;\n return Promise.all(\n Array.from(mount).map((mountFn) => mountFn(this.root)),\n );\n })\n .catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n })().catch((e) => {\n logError('HtmlRemote', 'Error mounting remote component.', e);\n });\n }\n\n disconnectedCallback() {\n // run the unmount functions for any scripts inside the shadow root asynchronously\n (async () => {\n if (this.unmount) {\n await Promise.all(\n Array.from(this.unmount).map(async (unmount) => {\n try {\n await unmount(this.root);\n } catch (e) {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n }\n }),\n );\n }\n })().catch((e) => {\n logError('HtmlRemote', 'Error unmounting remote component.', e);\n });\n }\n }\n\n // register the custom element\n customElements.define('remote-component', RemoteComponent);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAKa;AALb;AAAA;AAAA;AAKO,IAAM,gBACX;AAAA;AAAA;;;ACNF;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAOa;AAPb;AAAA;AAAA;AAAA;AACA;AACA;AAKO,IAAM,wBAAN,cAAoC,MAAM;AAAA,MAC/C,OAAO;AAAA,MAEP,YAAY,SAAiB,SAA+B;AAC1D,cAAM,SAAS,OAAO;AACtB,aAAK,OAAO;AAAA,MACd;AAAA,IACF;AAAA;AAAA;;;ACqBO,SAAS,QAAQA,WAAuB,SAAiB;AAE9D,UAAQ,KAAK,IAAI,UAAUA,eAAc,SAAS;AACpD;AAEO,SAAS,SACdA,WACA,SACA,OACA;AAEA,UAAQ;AAAA,IACN,IAAI,sBAAsB,IAAI,UAAUA,eAAc,WAAW;AAAA,MAC/D;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAMO,SAAS,0BACd,aACA,KACM;AACN,MAAI;AACF,UAAM,SAAS,OAAO,QAAQ,WAAW,IAAI,IAAI,GAAG,IAAI;AACxD,QAA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AAA,YACb,MAAM,KAAK,KAAK,EAAE,IAAI,CAAC,YAAY,QAAQ,KAAK,IAAI,CAAC;AAAA,UACvD;AAAA,QACF,CAAC,EACA,MAAM,CAAC,MAAM;AACZ,mBAAS,cAAc,oCAAoC,CAAC;AAAA,QAC9D,CAAC;AAAA,MACL,GAAG,EAAE,MAAM,CAAC,MAAM;AAChB,iBAAS,cAAc,oCAAoC,CAAC;AAAA,MAC9D,CAAC;AAAA,IACH;AAAA,IAEA,uBAAuB;AAErB,OAAC,YAAY;AACX,YAAI,KAAK,SAAS;AAChB,gBAAM,QAAQ;AAAA,YACZ,MAAM,KAAK,KAAK,OAAO,EAAE,IAAI,OAAO,YAAY;AAC9C,kBAAI;AACF,sBAAM,QAAQ,KAAK,IAAI;AAAA,cACzB,SAAS,GAAP;AACA,yBAAS,cAAc,sCAAsC,CAAC;AAAA,cAChE;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,GAAG,EAAE,MAAM,CAAC,MAAM;AAChB,iBAAS,cAAc,sCAAsC,CAAC;AAAA,MAChE,CAAC;AAAA,IACH;AAAA,EACF;AAGA,iBAAe,OAAO,oBAAoB,eAAe;AAC3D;","names":["location","loadStaticRemoteComponent"]}
@@ -16,14 +16,16 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var proxy_exports = {};
20
- __export(proxy_exports, {
21
- getCorsHeaders: () => getCorsHeaders,
22
- getHeader: () => getHeader,
23
- getSecurityHeaders: () => getSecurityHeaders,
24
- handleCorsPreflightRequest: () => handleCorsPreflightRequest
19
+
20
+ // src/remote/middleware/index.ts
21
+ var middleware_exports = {};
22
+ __export(middleware_exports, {
23
+ withExposeRemoteComponents: () => withExposeRemoteComponents
25
24
  });
26
- module.exports = __toCommonJS(proxy_exports);
25
+ module.exports = __toCommonJS(middleware_exports);
26
+ var import_server = require("next/server");
27
+
28
+ // src/remote/middleware/headers.ts
27
29
  function getHeader(headers, name) {
28
30
  if (headers instanceof Headers) {
29
31
  return headers.get(name) ?? void 0;
@@ -69,11 +71,34 @@ function handleCorsPreflightRequest(method, headers, options) {
69
71
  headers: { ...corsHeaders, ...getSecurityHeaders() }
70
72
  });
71
73
  }
74
+
75
+ // src/remote/middleware/index.ts
76
+ function withExposeRemoteComponents(proxy, options) {
77
+ return async (request) => {
78
+ const preflightResponse = handleCorsPreflightRequest(
79
+ request.method,
80
+ request.headers,
81
+ options?.cors
82
+ );
83
+ if (preflightResponse) {
84
+ return preflightResponse;
85
+ }
86
+ const response = typeof proxy === "function" ? await proxy(request) : import_server.NextResponse.next();
87
+ if (options?.cors !== false) {
88
+ const corsHeaders = getCorsHeaders(options?.cors, request.headers);
89
+ Object.entries(corsHeaders).forEach(
90
+ ([k, v]) => response.headers.set(k, v)
91
+ );
92
+ }
93
+ const securityHeaders = getSecurityHeaders();
94
+ Object.entries(securityHeaders).forEach(
95
+ ([k, v]) => response.headers.set(k, v)
96
+ );
97
+ return response;
98
+ };
99
+ }
72
100
  // Annotate the CommonJS export names for ESM import in node:
73
101
  0 && (module.exports = {
74
- getCorsHeaders,
75
- getHeader,
76
- getSecurityHeaders,
77
- handleCorsPreflightRequest
102
+ withExposeRemoteComponents
78
103
  });
79
- //# sourceMappingURL=proxy.cjs.map
104
+ //# sourceMappingURL=middleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/remote/middleware/index.ts","../../src/remote/middleware/headers.ts"],"sourcesContent":["import { type NextRequest, NextResponse } from 'next/server';\nimport {\n getCorsHeaders,\n getSecurityHeaders,\n handleCorsPreflightRequest,\n type RemoteComponentProxyOptions,\n} from './headers';\n\n/**\n * This proxy is used to handle CORS and other remote component related tasks.\n * It can be used to wrap a Next.js proxy handler function to add CORS headers and handle preflight requests.\n *\n * @param proxy - The Next.js proxy handler function to wrap.\n * @param options - Optional configuration for handling remote components.\n * @returns A Next.js proxy handler function that handles CORS and preflight requests\n */\nexport function withExposeRemoteComponents(\n proxy?: (request: NextRequest) => NextResponse | Promise<NextResponse>,\n options?: RemoteComponentProxyOptions,\n) {\n return async (request: NextRequest) => {\n // Check if this is a CORS preflight request\n const preflightResponse = handleCorsPreflightRequest(\n request.method,\n request.headers,\n options?.cors,\n );\n\n if (preflightResponse) {\n return preflightResponse;\n }\n\n // For all other requests, continue and attach CORS headers\n const response =\n typeof proxy === 'function' ? await proxy(request) : NextResponse.next();\n\n if (options?.cors !== false) {\n const corsHeaders = getCorsHeaders(options?.cors, request.headers);\n Object.entries(corsHeaders).forEach(([k, v]) =>\n response.headers.set(k, v),\n );\n }\n\n const securityHeaders = getSecurityHeaders();\n Object.entries(securityHeaders).forEach(([k, v]) =>\n response.headers.set(k, v),\n );\n\n return response;\n };\n}\n\nexport type { RemoteComponentProxyOptions } from './headers';\n","/**\n * Proxy utilities for remote applications that expose components to hosts.\n */\n\nimport type { IncomingHttpHeaders } from 'node:http';\n\nexport interface RemoteComponentProxyOptions {\n cors?:\n | {\n origin?: string | string[];\n method?: string | string[];\n headers?: string | string[];\n credentials?: boolean;\n maxAge?: string;\n }\n | false;\n}\n\n/**\n * Gets a header value from either a Headers object or a plain object.\n */\nexport function getHeader(\n headers: Record<string, string> | Headers | IncomingHttpHeaders,\n name: string,\n): string | undefined {\n if (headers instanceof Headers) {\n return headers.get(name) ?? undefined;\n }\n const value = headers[name];\n // IncomingHttpHeaders can have string | string[] | undefined\n return Array.isArray(value) ? value[0] : value;\n}\n\n/**\n * Computes CORS headers based on the provided options and request headers.\n *\n * @param options - CORS configuration options\n * @param requestHeaders - Headers from the incoming request (can be a Headers object or a plain object)\n * @returns Object containing CORS headers to be added to the response\n */\nexport function getCorsHeaders(\n options: RemoteComponentProxyOptions['cors'],\n requestHeaders: Record<string, string> | Headers | IncomingHttpHeaders,\n): Record<string, string> {\n if (options === false) {\n return {};\n }\n\n const originHeader = getHeader(requestHeaders, 'origin');\n const refererHeader = getHeader(requestHeaders, 'referer');\n const origin =\n originHeader ?? (refererHeader ? new URL(refererHeader).origin : '*');\n\n const ALLOWED_ORIGINS = (\n process.env.REMOTE_COMPONENTS_ALLOWED_ORIGINS ||\n (Array.isArray(options?.origin)\n ? options.origin.join(',')\n : options?.origin) ||\n '*'\n )\n .split(',')\n .map((allowedOrigin) => allowedOrigin.trim());\n\n const isAllowed =\n ALLOWED_ORIGINS.includes('*') || ALLOWED_ORIGINS.includes(origin);\n\n const allowedHeaders =\n process.env.REMOTE_COMPONENTS_ALLOW_HEADERS ||\n (Array.isArray(options?.headers)\n ? options.headers.map((h) => h.trim()).join(',')\n : options?.headers) ||\n getHeader(requestHeaders, 'access-control-request-headers');\n\n const CORS_HEADERS = (\n isAllowed\n ? {\n 'Access-Control-Allow-Origin': origin,\n 'Access-Control-Allow-Methods':\n process.env.REMOTE_COMPONENTS_ALLOW_METHODS ||\n (Array.isArray(options?.method)\n ? options.method.map((m) => m.trim()).join(',')\n : options?.method) ||\n 'GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS',\n ...(allowedHeaders\n ? { 'Access-Control-Allow-Headers': allowedHeaders }\n : {}),\n ...(process.env.REMOTE_COMPONENTS_ALLOW_CREDENTIALS ||\n options?.credentials\n ? {\n 'Access-Control-Allow-Credentials':\n process.env.REMOTE_COMPONENTS_ALLOW_CREDENTIALS || 'true',\n }\n : {}),\n 'Access-Control-Max-Age': options?.maxAge || '600',\n Vary: 'Origin',\n }\n : {}\n ) as Record<string, string>;\n\n return CORS_HEADERS;\n}\n\n/**\n * Returns security headers that prevent the remote component pages from being\n * embedded in frames. Remote components are fetched via HTTP and rendered\n * directly into the host's DOM — they should never be loaded in an iframe.\n */\nexport function getSecurityHeaders(): Record<string, string> {\n return {\n 'Content-Security-Policy': \"frame-ancestors 'none'\",\n 'X-Frame-Options': 'DENY',\n };\n}\n\n/**\n * Handles CORS preflight OPTIONS requests.\n *\n * @param method - The HTTP method of the incoming request\n * @param headers - Headers from the incoming request (can be a Headers object or a plain object)\n * @param options - CORS configuration options\n * @returns Response object for the preflight request, or null if not a preflight\n */\nexport function handleCorsPreflightRequest(\n method: string,\n headers: Record<string, string> | Headers | IncomingHttpHeaders,\n options?: RemoteComponentProxyOptions['cors'],\n): Response | null {\n if (method !== 'OPTIONS' || options === false) {\n return null;\n }\n\n const corsHeaders = getCorsHeaders(options, headers);\n\n return new Response(undefined, {\n status: 200,\n headers: { ...corsHeaders, ...getSecurityHeaders() },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;;;ACqBxC,SAAS,UACd,SACA,MACoB;AACpB,MAAI,mBAAmB,SAAS;AAC9B,WAAO,QAAQ,IAAI,IAAI,KAAK;AAAA,EAC9B;AACA,QAAM,QAAQ,QAAQ,IAAI;AAE1B,SAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,CAAC,IAAI;AAC3C;AASO,SAAS,eACd,SACA,gBACwB;AACxB,MAAI,YAAY,OAAO;AACrB,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,eAAe,UAAU,gBAAgB,QAAQ;AACvD,QAAM,gBAAgB,UAAU,gBAAgB,SAAS;AACzD,QAAM,SACJ,iBAAiB,gBAAgB,IAAI,IAAI,aAAa,EAAE,SAAS;AAEnE,QAAM,mBACJ,QAAQ,IAAI,sCACX,MAAM,QAAQ,SAAS,MAAM,IAC1B,QAAQ,OAAO,KAAK,GAAG,IACvB,SAAS,WACb,KAEC,MAAM,GAAG,EACT,IAAI,CAAC,kBAAkB,cAAc,KAAK,CAAC;AAE9C,QAAM,YACJ,gBAAgB,SAAS,GAAG,KAAK,gBAAgB,SAAS,MAAM;AAElE,QAAM,iBACJ,QAAQ,IAAI,oCACX,MAAM,QAAQ,SAAS,OAAO,IAC3B,QAAQ,QAAQ,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAC7C,SAAS,YACb,UAAU,gBAAgB,gCAAgC;AAE5D,Q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AG,CAAC;AAAA,MAC3B;AAAA,IACF;AAEA,UAAM,kBAAkB,mBAAmB;AAC3C,WAAO,QAAQ,eAAe,EAAE;AAAA,MAAQ,CAAC,CAAC,GAAG,CAAC,MAC5C,SAAS,QAAQ,IAAI,GAAG,CAAC;AAAA,IAC3B;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,27 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+
3
+ /**
4
+ * Proxy utilities for remote applications that expose components to hosts.
5
+ */
6
+
7
+ interface RemoteComponentProxyOptions {
8
+ cors?: {
9
+ origin?: string | string[];
10
+ method?: string | string[];
11
+ headers?: string | string[];
12
+ credentials?: boolean;
13
+ maxAge?: string;
14
+ } | false;
15
+ }
16
+
17
+ /**
18
+ * This proxy is used to handle CORS and other remote component related tasks.
19
+ * It can be used to wrap a Next.js proxy handler function to add CORS headers and handle preflight requests.
20
+ *
21
+ * @param proxy - The Next.js proxy handler function to wrap.
22
+ * @param options - Optional configuration for handling remote components.
23
+ * @returns A Next.js proxy handler function that handles CORS and preflight requests
24
+ */
25
+ declare function withExposeRemoteComponents(proxy?: (request: NextRequest) => NextResponse | Promise<NextResponse>, options?: RemoteComponentProxyOptions): (request: NextRequest) => Promise<Response>;
26
+
27
+ export { RemoteComponentProxyOptions, withExposeRemoteComponents };
@@ -1,3 +1,7 @@
1
+ // src/remote/middleware/index.ts
2
+ import { NextResponse } from "next/server";
3
+
4
+ // src/remote/middleware/headers.ts
1
5
  function getHeader(headers, name) {
2
6
  if (headers instanceof Headers) {
3
7
  return headers.get(name) ?? void 0;
@@ -43,10 +47,33 @@ function handleCorsPreflightRequest(method, headers, options) {
43
47
  headers: { ...corsHeaders, ...getSecurityHeaders() }
44
48
  });
45
49
  }
50
+
51
+ // src/remote/middleware/index.ts
52
+ function withExposeRemoteComponents(proxy, options) {
53
+ return async (request) => {
54
+ const preflightResponse = handleCorsPreflightRequest(
55
+ request.method,
56
+ request.headers,
57
+ options?.cors
58
+ );
59
+ if (preflightResponse) {
60
+ return preflightResponse;
61
+ }
62
+ const response = typeof proxy === "function" ? await proxy(request) : NextResponse.next();
63
+ if (options?.cors !== false) {
64
+ const corsHeaders = getCorsHeaders(options?.cors, request.headers);
65
+ Object.entries(corsHeaders).forEach(
66
+ ([k, v]) => response.headers.set(k, v)
67
+ );
68
+ }
69
+ const securityHeaders = getSecurityHeaders();
70
+ Object.entries(securityHeaders).forEach(
71
+ ([k, v]) => response.headers.set(k, v)
72
+ );
73
+ return response;
74
+ };
75
+ }
46
76
  export {
47
- getCorsHeaders,
48
- getHeader,
49
- getSecurityHeaders,
50
- handleCorsPreflightRequest
77
+ withExposeRemoteComponents
51
78
  };
52
- //# sourceMappingURL=proxy.js.map
79
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/remote/middleware/index.ts","../../src/remote/middleware/headers.ts"],"sourcesContent":["import { type NextRequest, NextResponse } from 'next/server';\nimport {\n getCorsHeaders,\n getSecurityHeaders,\n handleCorsPreflightRequest,\n type RemoteComponentProxyOptions,\n} from './headers';\n\n/**\n * This proxy is used to handle CORS and other remote component related tasks.\n * It can be used to wrap a Next.js proxy handler function to add CORS headers and handle preflight requests.\n *\n * @param proxy - The Next.js proxy handler function to wrap.\n * @param options - Optional configuration for handling remote components.\n * @returns A Next.js proxy handler function that handles CORS and preflight requests\n */\nexport function withExposeRemoteComponents(\n proxy?: (request: NextRequest) => NextResponse | Promise<NextResponse>,\n options?: RemoteComponentProxyOptions,\n) {\n return async (request: NextRequest) => {\n // Check if this is a CORS preflight request\n const preflightResponse = handleCorsPreflightRequest(\n request.method,\n request.headers,\n options?.cors,\n );\n\n if (preflightResponse) {\n return preflightResponse;\n }\n\n // For all other requests, continue and attach CORS headers\n const response =\n typeof proxy === 'function' ? await proxy(request) : NextResponse.next();\n\n if (options?.cors !== false) {\n const corsHeaders = getCorsHeaders(options?.cors, request.headers);\n Object.entries(corsHeaders).forEach(([k, v]) =>\n response.headers.set(k, v),\n );\n }\n\n const securityHeaders = getSecurityHeaders();\n Object.entries(securityHeaders).forEach(([k, v]) =>\n response.headers.set(k, v),\n );\n\n return response;\n };\n}\n\nexport type { RemoteComponentProxyOptions } from './headers';\n","/**\n * Proxy utilities for remote applications that expose components to hosts.\n */\n\nimport type { IncomingHttpHeaders } from 'node:http';\n\nexport interface RemoteComponentProxyOptions {\n cors?:\n | {\n origin?: string | string[];\n method?: string | string[];\n headers?: string | string[];\n credentials?: boolean;\n maxAge?: string;\n }\n | false;\n}\n\n/**\n * Gets a header value from either a Headers object or a plain object.\n */\nexport function getHeader(\n headers: Record<string, string> | Headers | IncomingHttpHeaders,\n name: string,\n): string | undefined {\n if (headers instanceof Headers) {\n return headers.get(name) ?? undefined;\n }\n const value = headers[name];\n // IncomingHttpHeaders can have string | string[] | undefined\n return Array.isArray(value) ? value[0] : value;\n}\n\n/**\n * Computes CORS headers based on the provided options and request headers.\n *\n * @param options - CORS configuration options\n * @param requestHeaders - Headers from the incoming request (can be a Headers object or a plain object)\n * @returns Object containing CORS headers to be added to the response\n */\nexport function getCorsHeaders(\n options: RemoteComponentProxyOptions['cors'],\n requestHeaders: Record<string, string> | Headers | IncomingHttpHeaders,\n): Record<string, string> {\n if (options === false) {\n return {};\n }\n\n const originHeader = getHeader(requestHeaders, 'origin');\n const refererHeader = getHeader(requestHeaders, 'referer');\n const origin =\n originHeader ?? (refererHeader ? new URL(refererHeader).origin : '*');\n\n const ALLOWED_ORIGINS = (\n process.env.REMOTE_COMPONENTS_ALLOWED_ORIGINS ||\n (Array.isArray(options?.origin)\n ? options.origin.join(',')\n : options?.origin) ||\n '*'\n )\n .split(',')\n .map((allowedOrigin) => allowedOrigin.trim());\n\n const isAllowed =\n ALLOWED_ORIGINS.includes('*') || ALLOWED_ORIGINS.includes(origin);\n\n const allowedHeaders =\n process.env.REMOTE_COMPONENTS_ALLOW_HEADERS ||\n (Array.isArray(options?.headers)\n ? options.headers.map((h) => h.trim()).join(',')\n : options?.headers) ||\n getHeader(requestHeaders, 'access-control-request-headers');\n\n const CORS_HEADERS = (\n isAllowed\n ? {\n 'Access-Control-Allow-Origin': origin,\n 'Access-Control-Allow-Methods':\n process.env.REMOTE_COMPONENTS_ALLOW_METHODS ||\n (Array.isArray(options?.method)\n ? options.method.map((m) => m.trim()).join(',')\n : options?.method) ||\n 'GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS',\n ...(allowedHeaders\n ? { 'Access-Control-Allow-Headers': allowedHeaders }\n : {}),\n ...(process.env.REMOTE_COMPONENTS_ALLOW_CREDENTIALS ||\n options?.credentials\n ? {\n 'Access-Control-Allow-Credentials':\n process.env.REMOTE_COMPONENTS_ALLOW_CREDENTIALS || 'true',\n }\n : {}),\n 'Access-Control-Max-Age': options?.maxAge || '600',\n Vary: 'Origin',\n }\n : {}\n ) as Record<string, string>;\n\n return CORS_HEADERS;\n}\n\n/**\n * Returns security headers that prevent the remote component pages from being\n * embedded in frames. Remote components are fetched via HTTP and rendered\n * directly into the host's DOM — they should never be loaded in an iframe.\n */\nexport function getSecurityHeaders(): Record<string, string> {\n return {\n 'Content-Security-Policy': \"frame-ancestors 'none'\",\n 'X-Frame-Options': 'DENY',\n };\n}\n\n/**\n * Handles CORS preflight OPTIONS requests.\n *\n * @param method - The HTTP method of the incoming request\n * @param headers - Headers from the incoming request (can be a Headers object or a plain object)\n * @param options - CORS configuration options\n * @returns Response object for the preflight request, or null if not a preflight\n */\nexport function handleCorsPreflightRequest(\n method: string,\n headers: Record<string, string> | Headers | IncomingHttpHeaders,\n options?: RemoteComponentProxyOptions['cors'],\n): Response | null {\n if (method !== 'OPTIONS' || options === false) {\n return null;\n }\n\n const corsHeaders = getCorsHeaders(options, headers);\n\n return new Response(undefined, {\n status: 200,\n headers: { ...corsHeaders, ...getSecurityHeaders() },\n });\n}\n"],"mappings":";AAAA,SAA2B,oBAAoB;;;ACqBxC,SAAS,UACd,SACA,MACoB;AACpB,MAAI,mBAAmB,SAAS;A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AGP,SAAO;AACT;AAOO,SAAS,qBAA6C;AAC3D,SAAO;AAAA,IACL,2BAA2B;AAAA,IAC3B,mBAAmB;AAAA,EACrB;AACF;AAUO,SAAS,2BACd,QACA,SACA,SACiB;AACjB,MAAI,WAAW,aAAa,YAAY,OAAO;AAC7C,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,eAAe,SAAS,OAAO;AAEnD,SAAO,IAAI,SAAS,QAAW;AAAA,IAC7B,QAAQ;AAAA,IACR,SAAS,EAAE,GAAG,aAAa,GAAG,mBAAmB,EAAE;AAAA,EACrD,CAAC;AACH;;;ADzHO,SAAS,2BACd,OACA,SACA;AACA,SAAO,OAAO,YAAyB;AAErC,UAAM,oBAAoB;AAAA,MACxB,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,SAAS;AAAA,IACX;AAEA,QAAI,mBAAmB;AACrB,aAAO;AAAA,IACT;AAGA,UAAM,WACJ,OAAO,UAAU,aAAa,MAAM,MAAM,OAAO,IAAI,aAAa,KAAK;AAEzE,QAAI,SAAS,SAAS,OAAO;AAC3B,YAAM,cAAc,eAAe,SAAS,MAAM,QAAQ,OAAO;AACjE,aAAO,QAAQ,WAAW,EAAE;AAAA,QAAQ,CAAC,CAAC,GAAG,CAAC,MACxC,SAAS,QAAQ,IAAI,GAAG,CAAC;AAAA,MAC3B;AAAA,IACF;AAEA,UAAM,kBAAkB,mBAAmB;AAC3C,WAAO,QAAQ,eAAe,EAAE;AAAA,MAAQ,CAAC,CAAC,GAAG,CAAC,MAC5C,SAAS,QAAQ,IAAI,GAAG,CAAC;AAAA,IAC3B;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -26,16 +26,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var render_server_exports = {};
30
- __export(render_server_exports, {
31
- RemoteComponent: () => RemoteComponent
29
+ var app_exports = {};
30
+ __export(app_exports, {
31
+ ExposeRemoteComponent: () => ExposeRemoteComponent
32
32
  });
33
- module.exports = __toCommonJS(render_server_exports);
33
+ module.exports = __toCommonJS(app_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_wrapper = require("remote-components/remote/defaults/wrapper");
35
36
  var import_work_async_storage = require("next/dist/server/app-render/work-async-storage.external");
36
37
  var import_react = require("react");
37
- var import_render_client = require("#internal/next/remote/render-client");
38
- var import_error = require("#internal/shared/error");
38
+ var import_app_client = require("#internal/remote/nextjs/app-client");
39
+ var import_error = require("#internal/utils/error");
39
40
  const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
40
41
  "next.server.action-manifests"
41
42
  );
@@ -52,13 +53,11 @@ function RemoteComponentData({ name, data }) {
52
53
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", { id: `${name}_rsc`, children: data.map(
53
54
  (chunk, i) => (
54
55
  // make the data handling somewhat safe
55
- `${i === 0 ? `self["${name}"]=self["${name}"]||[];` : ""}self["${name}"].push(${JSON.stringify(
56
- chunk
57
- )});`
56
+ `${i === 0 ? `self["${name}"]=self["${name}"]||[];` : ""}self["${name}"].push(${JSON.stringify(chunk)});`
58
57
  )
59
58
  ).join("\n") });
60
59
  }
61
- async function RemoteComponent({
60
+ async function ExposeRemoteComponent({
62
61
  name = "__vercel_remote_component",
63
62
  children
64
63
  }) {
@@ -73,10 +72,9 @@ async function RemoteComponent({
73
72
  self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;
74
73
  self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};
75
74
  self.__RSC_SERVER_MANIFEST[page] = self.__RSC_SERVER_MANIFEST[page] || manifest;
76
- let clientModules = manifest?.clientModules ?? {};
77
75
  const ssrModuleMapping = { ...manifest?.ssrModuleMapping };
78
- clientModules = Object.fromEntries(
79
- Object.entries(clientModules).map(([key, value]) => {
76
+ const clientModules = Object.fromEntries(
77
+ Object.entries(manifest?.clientModules ?? {}).map(([key, value]) => {
80
78
  const remoteId = `[${PROJECT_ID}] ${value.id}`;
81
79
  ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];
82
80
  return [
@@ -141,7 +139,7 @@ async function RemoteComponent({
141
139
  "data-type": "nextjs",
142
140
  id: `${remoteComponentName}_ssr`,
143
141
  children: [
144
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_render_client.RemoteComponentSharedRemote, { name: remoteComponentName }),
142
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_app_client.RemoteComponentSharedRemote, { name: remoteComponentName }),
145
143
  typeof error !== "undefined" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
146
144
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
147
145
  "template",
@@ -160,6 +158,6 @@ async function RemoteComponent({
160
158
  }
161
159
  // Annotate the CommonJS export names for ESM import in node:
162
160
  0 && (module.exports = {
163
- RemoteComponent
161
+ ExposeRemoteComponent
164
162
  });
165
- //# sourceMappingURL=render-server.cjs.map
163
+ //# sourceMappingURL=app.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/remote/nextjs/app.tsx"],"sourcesContent":["import 'remote-components/remote/defaults/wrapper';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { Suspense } from 'react';\nimport type { ConsumeLifecycleCallbacks } from '#internal/host/shared/config';\nimport { RemoteComponentSharedRemote } from '#internal/remote/nextjs/app-client';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ninterface Manifest {\n clientModules?: Record<\n string,\n { id: string; name: string; chunks: string[]; async: boolean }\n >;\n moduleLoading: { prefix?: string; crossOrigin?: boolean | null };\n ssrModuleMapping?: Record<string, unknown>;\n}\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\nconst MANIFESTS_SINGLETON = Symbol.for('next.server.manifests');\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${\n i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''\n }self[\"${name}\"].push(${JSON.stringify(chunk)});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\n/**\n * Props for exposing a Next.js component as a remote component.\n *\n * Extends {@link ConsumeLifecycleCallbacks} so the consuming host can wire up lifecycle\n * events. The `children` prop is the component content to expose (required,\n * unlike host props where children are an optional loading fallback).\n */\nexport interface ExposeRemoteComponentProps extends ConsumeLifecycleCallbacks {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * ExposeRemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<ExposeRemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { ExposeRemoteComponent } from 'remote-components/remote/nextjs/app';\n *\n * export default function MyPage() {\n * return (\n * <ExposeRemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </ExposeRemoteComponent>\n * );\n * }\n * ```\n */\nexport async function ExposeRemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: ExposeRemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n [MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerRoute?: Map<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n __RSC_SERVER_MANIFEST?: Record<string, unknown>;\n };\n const manifests =\n self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};\n const manifest =\n 'clientReferenceManifestsPerRoute' in manifests\n ? manifests.clientReferenceManifestsPerRoute?.get?.(route)\n : 'clientReferenceManifestsPerPage' in manifests\n ? manifests.clientReferenceManifestsPerPage?.[route]\n : undefined;\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};\n self.__RSC_SERVER_MANIFEST[page] =\n self.__RSC_SERVER_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n const clientModules = Object.fromEntries(\n Object.entries(manifest?.clientModules ?? {}).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\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;AACxE,SAAK,KAAK,QAAQ,OAAO,KAAK,CAAC;AAAA,EACjC;AAEA,QAAM,UAAU,QAAQ,IAAI,YAAY,cAAc;AACtD,QAAM,sBAAsB,GAAG,QAAQ,MAAM,QAAQ,YAAY,GAAG;AAEpE;AAAA;AAAA,IAEE;AAAA,MAAC;AAAA;AAAA,QACC,eAAa;AAAA,QACb,cAAY;AAAA,QACZ,gBAAc;AAAA,QACd,aAAU;AAAA,QACV,IAAI,GAAG;AAAA,QAEP;AAAA,sDAAC,iDAA4B,MAAM,qBAAqB;AAAA,UACvD,OAAO,UAAU,cAChB,4EACE;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,2BACE,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,gBAEvD,yBACE,iBAAiB,QAAS,MAAM,SAAS,KAAM;AAAA;AAAA,YAEnD;AAAA,YACA,4CAAC,yBAAS,UAAU,MAAO,UAAS;AAAA,aACtC,IAEA;AAAA,UAGF,4CAAC,uBAAoB,MAAY,MAAM,qBAAqB;AAAA;AAAA;AAAA,IAC9D;AAAA;AAEJ;","names":[]}
@@ -1,23 +1,22 @@
1
- import { a as HostLifecycleCallbacks } from '../../../host-config-58cdccea.js';
2
- import '../../shared/client/proxy-through-host.js';
3
- import '../../../types-2b26a246.js';
4
- import 'parse5/dist/tree-adapters/default';
1
+ import { ConsumeLifecycleCallbacks } from '../../internal/host/shared/config.js';
2
+ import '../../internal/runtime/url/resolve-client-url.js';
3
+ import '../../internal/host/shared/fetch-interceptors.js';
5
4
 
6
5
  /**
7
6
  * Props for exposing a Next.js component as a remote component.
8
7
  *
9
- * Extends {@link HostLifecycleCallbacks} so the host can wire up lifecycle
8
+ * Extends {@link ConsumeLifecycleCallbacks} so the consuming host can wire up lifecycle
10
9
  * events. The `children` prop is the component content to expose (required,
11
10
  * unlike host props where children are an optional loading fallback).
12
11
  */
13
- interface RemoteComponentProps extends HostLifecycleCallbacks {
12
+ interface ExposeRemoteComponentProps extends ConsumeLifecycleCallbacks {
14
13
  /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */
15
14
  name?: string;
16
15
  /** The content of the remote component. This is the content that will be rendered as the remote component. */
17
16
  children: React.ReactNode;
18
17
  }
19
18
  /**
20
- * RemoteComponent is a Next.js component that exposes a remote component
19
+ * ExposeRemoteComponent is a Next.js component that exposes a remote component
21
20
  * that can be used in a host application.
22
21
  *
23
22
  * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.
@@ -26,21 +25,21 @@ interface RemoteComponentProps extends HostLifecycleCallbacks {
26
25
  *
27
26
  * @example
28
27
  *
29
- * Use the `<RemoteComponent>` in your Next.js App Router application to expose the children as a remote component:
28
+ * Use the `<ExposeRemoteComponent>` in your Next.js App Router application to expose the children as a remote component:
30
29
  *
31
30
  * ```tsx
32
- * import { RemoteComponent } from 'remote-components/next';
31
+ * import { ExposeRemoteComponent } from 'remote-components/remote/nextjs/app';
33
32
  *
34
33
  * export default function MyPage() {
35
34
  * return (
36
- * <RemoteComponent>
35
+ * <ExposeRemoteComponent>
37
36
  * <h1>Hello from the remote component!</h1>
38
37
  * <p>This is a remote component that can be used in a host application.</p>
39
- * </RemoteComponent>
38
+ * </ExposeRemoteComponent>
40
39
  * );
41
40
  * }
42
41
  * ```
43
42
  */
44
- declare function RemoteComponent({ name, children, }: RemoteComponentProps): Promise<React.ReactElement>;
43
+ declare function ExposeRemoteComponent({ name, children, }: ExposeRemoteComponentProps): Promise<React.ReactElement>;
45
44
 
46
- export { RemoteComponent, RemoteComponentProps };
45
+ export { ExposeRemoteComponent, ExposeRemoteComponentProps };
@@ -1,8 +1,9 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import "remote-components/remote/defaults/wrapper";
2
3
  import { workAsyncStorage } from "next/dist/server/app-render/work-async-storage.external";
3
4
  import { Suspense } from "react";
4
- import { RemoteComponentSharedRemote } from "#internal/next/remote/render-client";
5
- import { RemoteComponentsError } from "#internal/shared/error";
5
+ import { RemoteComponentSharedRemote } from "#internal/remote/nextjs/app-client";
6
+ import { RemoteComponentsError } from "#internal/utils/error";
6
7
  const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
7
8
  "next.server.action-manifests"
8
9
  );
@@ -19,13 +20,11 @@ function RemoteComponentData({ name, data }) {
19
20
  return /* @__PURE__ */ jsx("script", { id: `${name}_rsc`, children: data.map(
20
21
  (chunk, i) => (
21
22
  // make the data handling somewhat safe
22
- `${i === 0 ? `self["${name}"]=self["${name}"]||[];` : ""}self["${name}"].push(${JSON.stringify(
23
- chunk
24
- )});`
23
+ `${i === 0 ? `self["${name}"]=self["${name}"]||[];` : ""}self["${name}"].push(${JSON.stringify(chunk)});`
25
24
  )
26
25
  ).join("\n") });
27
26
  }
28
- async function RemoteComponent({
27
+ async function ExposeRemoteComponent({
29
28
  name = "__vercel_remote_component",
30
29
  children
31
30
  }) {
@@ -40,10 +39,9 @@ async function RemoteComponent({
40
39
  self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;
41
40
  self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};
42
41
  self.__RSC_SERVER_MANIFEST[page] = self.__RSC_SERVER_MANIFEST[page] || manifest;
43
- let clientModules = manifest?.clientModules ?? {};
44
42
  const ssrModuleMapping = { ...manifest?.ssrModuleMapping };
45
- clientModules = Object.fromEntries(
46
- Object.entries(clientModules).map(([key, value]) => {
43
+ const clientModules = Object.fromEntries(
44
+ Object.entries(manifest?.clientModules ?? {}).map(([key, value]) => {
47
45
  const remoteId = `[${PROJECT_ID}] ${value.id}`;
48
46
  ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];
49
47
  return [
@@ -126,6 +124,6 @@ async function RemoteComponent({
126
124
  );
127
125
  }
128
126
  export {
129
- RemoteComponent
127
+ ExposeRemoteComponent
130
128
  };
131
- //# sourceMappingURL=render-server.js.map
129
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/remote/nextjs/app.tsx"],"sourcesContent":["import 'remote-components/remote/defaults/wrapper';\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\nimport { Suspense } from 'react';\nimport type { ConsumeLifecycleCallbacks } from '#internal/host/shared/config';\nimport { RemoteComponentSharedRemote } from '#internal/remote/nextjs/app-client';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ninterface Manifest {\n clientModules?: Record<\n string,\n { id: string; name: string; chunks: string[]; async: boolean }\n >;\n moduleLoading: { prefix?: string; crossOrigin?: boolean | null };\n ssrModuleMapping?: Record<string, unknown>;\n}\n\n// internal Next.js symbol to access the manifest which is stored in the global scope\nconst SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\nconst MANIFESTS_SINGLETON = Symbol.for('next.server.manifests');\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nasync function tryImport<T>(importer: () => Promise<T>) {\n try {\n return (await importer()) as T;\n } catch {\n return {} as T;\n }\n}\n\n// inject the RSC flight data into the HTML response using <script>\n// the RSC flight data is used to hydrate the remote component on the host\n// this approach is similar to an island architecture on the host\n// the remote component is static HTML until it is hydrated using this RSC flight data\nfunction RemoteComponentData({ name, data }: { name: string; data: string[] }) {\n return (\n <script id={`${name}_rsc`}>\n {data\n .map(\n (chunk, i) =>\n // make the data handling somewhat safe\n `${\n i === 0 ? `self[\"${name}\"]=self[\"${name}\"]||[];` : ''\n }self[\"${name}\"].push(${JSON.stringify(chunk)});`,\n )\n .join('\\n')}\n </script>\n );\n}\n\n/**\n * Props for exposing a Next.js component as a remote component.\n *\n * Extends {@link ConsumeLifecycleCallbacks} so the consuming host can wire up lifecycle\n * events. The `children` prop is the component content to expose (required,\n * unlike host props where children are an optional loading fallback).\n */\nexport interface ExposeRemoteComponentProps extends ConsumeLifecycleCallbacks {\n /** The name of the remote component. Use a unique name to expose multiple remote components from the same page. */\n name?: string;\n /** The content of the remote component. This is the content that will be rendered as the remote component. */\n children: React.ReactNode;\n}\n\n/**\n * ExposeRemoteComponent is a Next.js component that exposes a remote component\n * that can be used in a host application.\n *\n * @param name - The name of the remote component. Use a unique name to expose multiple remote components from the same page.\n * @param children - The content of the remote component. This is the content that will be rendered as the remote component.\n * @returns A React component that renders the remote component.\n *\n * @example\n *\n * Use the `<ExposeRemoteComponent>` in your Next.js App Router application to expose the children as a remote component:\n *\n * ```tsx\n * import { ExposeRemoteComponent } from 'remote-components/remote/nextjs/app';\n *\n * export default function MyPage() {\n * return (\n * <ExposeRemoteComponent>\n * <h1>Hello from the remote component!</h1>\n * <p>This is a remote component that can be used in a host application.</p>\n * </ExposeRemoteComponent>\n * );\n * }\n * ```\n */\nexport async function ExposeRemoteComponent({\n name = '__vercel_remote_component',\n children,\n}: ExposeRemoteComponentProps): Promise<React.ReactElement> {\n // access the internal Next.js work store to get the active page and route\n const { page, route } = workAsyncStorage.getStore() ?? {\n page: '/',\n route: '/',\n };\n\n // get reference to the manifests from the global scope\n const self = globalThis as typeof globalThis & {\n [SERVER_ACTION_MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n };\n [MANIFESTS_SINGLETON]?: {\n clientReferenceManifestsPerRoute?: Map<string, Manifest>;\n };\n __RSC_MANIFEST?: Record<string, unknown>;\n __RSC_SERVER_MANIFEST?: Record<string, unknown>;\n };\n const manifests =\n self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};\n const manifest =\n 'clientReferenceManifestsPerRoute' in manifests\n ? manifests.clientReferenceManifestsPerRoute?.get?.(route)\n : 'clientReferenceManifestsPerPage' in manifests\n ? manifests.clientReferenceManifestsPerPage?.[route]\n : undefined;\n\n // manually handle the internal Next.js manifest\n self.__RSC_MANIFEST = self.__RSC_MANIFEST || {};\n self.__RSC_MANIFEST[page] = self.__RSC_MANIFEST[page] || manifest;\n self.__RSC_SERVER_MANIFEST = self.__RSC_SERVER_MANIFEST || {};\n self.__RSC_SERVER_MANIFEST[page] =\n self.__RSC_SERVER_MANIFEST[page] || manifest;\n\n // get the client and SSR module mapping to be able to use client components in the remote component\n const ssrModuleMapping = { ...manifest?.ssrModuleMapping };\n\n // if the remote component is used in a hosting application, we need to mutate the module map to include the zone\n const clientModules = Object.fromEntries(\n Object.entries(manifest?.clientModules ?? {}).map(([key, value]) => {\n // append a prefix to each entry in the module map to include the zone of the remote component\n const remoteId = `[${PROJECT_ID}] ${value.id}`;\n ssrModuleMapping[remoteId] = ssrModuleMapping[value.id];\n // override the original id with the new remote id\n return [\n key,\n {\n ...value,\n id: remoteId,\n // prepend the current zone to the chunks to handle remote component chunk loading in Webpack\n // this is required to avoid loading the wrong chunk in the host application\n chunks: value.chunks.map((chunk) => `[${PROJECT_ID}] ${chunk}`),\n },\n ];\n }),\n );\n\n // dynamically import the runtime specific RSC rendering functions and client component\n const [\n { renderToReadableStream: nextRenderToReadableStream },\n { renderToReadableStream: legacyRenderToReadableStream },\n ] = await Promise.all(\n process.env.TURBOPACK\n ? [\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-turbopack/server.edge'),\n ),\n ]\n : [\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server'),\n ),\n tryImport<RSDWServer>(\n () => import('react-server-dom-webpack/server.edge'),\n ),\n ],\n );\n const renderToReadableStream =\n nextRenderToReadableStream ?? legacyRenderToReadableStream;\n\n if (typeof renderToReadableStream !== 'function') {\n throw new RemoteComponentsError(\n 'No valid `renderToReadableStream()` function found. Do you have Next.js installed?',\n );\n }\n\n let error: Error | undefined;\n // render the wrapped content of this component (children) into an RSC stream\n const stream = renderToReadableStream(children, clientModules, {\n onError(e) {\n error = e;\n },\n });\n\n const data = [];\n const decoder = new TextDecoder();\n\n // convert the stream to an array for safe passing to the client\n for await (const chunk of stream as unknown as AsyncIterable<Uint8Array>) {\n data.push(decoder.decode(chunk));\n }\n\n const runtime = process.env.TURBOPACK ? 'turbopack' : 'webpack';\n const remoteComponentName = `${name}_${route.replace(/[/[\\].]/g, '_')}`;\n\n return (\n // wrap the remote component content into a div to know which part of the HTML belongs to the remote component\n <div\n data-bundle={PROJECT_ID}\n data-route={route}\n data-runtime={runtime}\n data-type=\"nextjs\"\n id={`${remoteComponentName}_ssr`}\n >\n <RemoteComponentSharedRemote name={remoteComponentName} />\n {typeof error !== 'undefined' ? (\n <>\n <template\n data-next-error-message={\n error instanceof Error ? error.message : String(error)\n }\n data-next-error-stack={\n error instanceof Error ? (error.stack ?? '') : ''\n }\n />\n <Suspense fallback={null}>{children}</Suspense>\n </>\n ) : (\n children\n )}\n {/* inject RSC flight data as <script> */}\n <RemoteComponentData data={data} name={remoteComponentName} />\n </div>\n );\n}\n"],"mappings":"AAyCI,SA+KI,UA/KJ,KA+KI,YA/KJ;AAzCJ,OAAO;AACP,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AAEzB,SAAS,mCAAmC;AAC5C,SAAS,6BAA6B;AAYtC,MAAM,oCAAoC,OAAO;AAAA,EAC/C;AACF;AACA,MAAM,sBAAsB,OAAO,IAAI,uBAAuB;AAE9D,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AAEd,eAAe,UAAa,UAA4B;AACtD,MAAI;AACF,WAAQ,MAAM,SAAS;AAAA,EACzB,QAAE;AACA,WAAO,CAAC;AAAA,EACV;AACF;AAMA,SAAS,oBAAoB,EAAE,MAAM,KAAK,GAAqC;AAC7E,SACE,oBAAC,YAAO,IAAI,GAAG,YACZ,eACE;AAAA,IACC,CAAC,OAAO;AAAA;AAAA,MAEN,GACE,MAAM,IAAI,SAAS,gBAAgB,gBAAgB,WAC5C,eAAe,KAAK,UAAU,KAAK;AAAA;AAAA,EAChD,EACC,KAAK,IAAI,GACd;AAEJ;AAyCA,eAA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var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var pages_router_exports = {};
20
- __export(pages_router_exports, {
21
- getRemoteComponentMetadata: () => getRemoteComponentMetadata
19
+ var pages_exports = {};
20
+ __export(pages_exports, {
21
+ getExposeRemoteComponentProps: () => getExposeRemoteComponentProps
22
22
  });
23
- module.exports = __toCommonJS(pages_router_exports);
24
- var import_pages = require("remote-components/shared/remote/pages");
23
+ module.exports = __toCommonJS(pages_exports);
24
+ var import_pages = require("#remote-components/remote/defaults/pages");
25
25
  const PROJECT_ID = process.env.REMOTE_COMPONENTS_PROJECT_ID || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || process.env.VERCEL_PROJECT_ID;
26
- function getRemoteComponentMetadata() {
26
+ function getExposeRemoteComponentProps() {
27
27
  return {
28
28
  __REMOTE_COMPONENT__: {
29
29
  bundle: PROJECT_ID,
@@ -34,6 +34,6 @@ function getRemoteComponentMetadata() {
34
34
  }
35
35
  // Annotate the CommonJS export names for ESM import in node:
36
36
  0 && (module.exports = {
37
- getRemoteComponentMetadata
37
+ getExposeRemoteComponentProps
38
38
  });
39
- //# sourceMappingURL=pages-router.cjs.map
39
+ //# sourceMappingURL=pages.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/remote/nextjs/pages.ts"],"sourcesContent":["import { shared } from '#remote-components/remote/defaults/pages';\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nexport interface ExposeRemoteComponentProps {\n __REMOTE_COMPONENT__: {\n bundle: string | undefined;\n runtime: 'turbopack' | 'webpack';\n shared?: Record<string, string>;\n };\n}\n\n/**\n * Returns the metadata for the remote component.\n * This metadata is used to identify the remote component and its bundle.\n *\n * Extend your Next.js Pages Router page props with this metadata to ensure proper remote component loading.\n *\n * @returns The metadata for the remote component.\n *\n * @example\n *\n * Create a custom App component in your Next.js application to include the remote component metadata:\n *\n * ```\n * import {\n * getExposeRemoteComponentProps,\n * type ExposeRemoteComponentProps,\n * } from 'remote-components/remote/nextjs/pages';\n * import App from 'next/app';\n * import type { AppContext, AppInitialProps, AppProps } from 'next/app';\n *\n * export default function MyApp({ Component, pageProps }: AppProps) {\n * return <Component {...pageProps} />;\n * }\n *\n * MyApp.getInitialProps = async (\n * context: AppContext,\n * ): Promise<ExposeRemoteComponentProps & AppInitialProps> => {\n * const ctx = await App.getInitialProps(context);\n * return { ...ctx, ...getExposeRemoteComponentProps() };\n * };\n * ```\n */\nexport function getExposeRemoteComponentProps(): ExposeRemoteComponentProps {\n return {\n __REMOTE_COMPONENT__: {\n bundle: PROJECT_ID,\n runtime: process.env.TURBOPACK ? 'turbopack' : 'webpack',\n shared,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuB;AAEvB,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AA0CP,SAAS,gCAA4D;AAC1E,SAAO;AAAA,IACL,sBAAsB;AAAA,MACpB,QAAQ;AAAA,MACR,SAAS,QAAQ,IAAI,YAAY,cAAc;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,4 +1,4 @@
1
- interface RemoteComponentMetadata {
1
+ interface ExposeRemoteComponentProps {
2
2
  __REMOTE_COMPONENT__: {
3
3
  bundle: string | undefined;
4
4
  runtime: 'turbopack' | 'webpack';
@@ -19,9 +19,9 @@ interface RemoteComponentMetadata {
19
19
  *
20
20
  * ```
21
21
  * import {
22
- * getRemoteComponentMetadata,
23
- * type RemoteComponentMetadata,
24
- * } from 'remote-components/next/pages';
22
+ * getExposeRemoteComponentProps,
23
+ * type ExposeRemoteComponentProps,
24
+ * } from 'remote-components/remote/nextjs/pages';
25
25
  * import App from 'next/app';
26
26
  * import type { AppContext, AppInitialProps, AppProps } from 'next/app';
27
27
  *
@@ -31,12 +31,12 @@ interface RemoteComponentMetadata {
31
31
  *
32
32
  * MyApp.getInitialProps = async (
33
33
  * context: AppContext,
34
- * ): Promise<RemoteComponentMetadata & AppInitialProps> => {
34
+ * ): Promise<ExposeRemoteComponentProps & AppInitialProps> => {
35
35
  * const ctx = await App.getInitialProps(context);
36
- * return { ...ctx, ...getRemoteComponentMetadata() };
36
+ * return { ...ctx, ...getExposeRemoteComponentProps() };
37
37
  * };
38
38
  * ```
39
39
  */
40
- declare function getRemoteComponentMetadata(): RemoteComponentMetadata;
40
+ declare function getExposeRemoteComponentProps(): ExposeRemoteComponentProps;
41
41
 
42
- export { RemoteComponentMetadata, getRemoteComponentMetadata };
42
+ export { ExposeRemoteComponentProps, getExposeRemoteComponentProps };
@@ -1,6 +1,6 @@
1
- import { shared } from "remote-components/shared/remote/pages";
1
+ import { shared } from "#remote-components/remote/defaults/pages";
2
2
  const PROJECT_ID = process.env.REMOTE_COMPONENTS_PROJECT_ID || process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION || process.env.VERCEL_PROJECT_ID;
3
- function getRemoteComponentMetadata() {
3
+ function getExposeRemoteComponentProps() {
4
4
  return {
5
5
  __REMOTE_COMPONENT__: {
6
6
  bundle: PROJECT_ID,
@@ -10,6 +10,6 @@ function getRemoteComponentMetadata() {
10
10
  };
11
11
  }
12
12
  export {
13
- getRemoteComponentMetadata
13
+ getExposeRemoteComponentProps
14
14
  };
15
- //# sourceMappingURL=pages-router.js.map
15
+ //# sourceMappingURL=pages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/remote/nextjs/pages.ts"],"sourcesContent":["import { shared } from '#remote-components/remote/defaults/pages';\n\nconst PROJECT_ID =\n process.env.REMOTE_COMPONENTS_PROJECT_ID ||\n process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION ||\n process.env.VERCEL_PROJECT_ID;\n\nexport interface ExposeRemoteComponentProps {\n __REMOTE_COMPONENT__: {\n bundle: string | undefined;\n runtime: 'turbopack' | 'webpack';\n shared?: Record<string, string>;\n };\n}\n\n/**\n * Returns the metadata for the remote component.\n * This metadata is used to identify the remote component and its bundle.\n *\n * Extend your Next.js Pages Router page props with this metadata to ensure proper remote component loading.\n *\n * @returns The metadata for the remote component.\n *\n * @example\n *\n * Create a custom App component in your Next.js application to include the remote component metadata:\n *\n * ```\n * import {\n * getExposeRemoteComponentProps,\n * type ExposeRemoteComponentProps,\n * } from 'remote-components/remote/nextjs/pages';\n * import App from 'next/app';\n * import type { AppContext, AppInitialProps, AppProps } from 'next/app';\n *\n * export default function MyApp({ Component, pageProps }: AppProps) {\n * return <Component {...pageProps} />;\n * }\n *\n * MyApp.getInitialProps = async (\n * context: AppContext,\n * ): Promise<ExposeRemoteComponentProps & AppInitialProps> => {\n * const ctx = await App.getInitialProps(context);\n * return { ...ctx, ...getExposeRemoteComponentProps() };\n * };\n * ```\n */\nexport function getExposeRemoteComponentProps(): ExposeRemoteComponentProps {\n return {\n __REMOTE_COMPONENT__: {\n bundle: PROJECT_ID,\n runtime: process.env.TURBOPACK ? 'turbopack' : 'webpack',\n shared,\n },\n };\n}\n"],"mappings":"AAAA,SAAS,cAAc;AAEvB,MAAM,aACJ,QAAQ,IAAI,gCACZ,QAAQ,IAAI,uCACZ,QAAQ,IAAI;AA0CP,SAAS,gCAA4D;AAC1E,SAAO;AAAA,IACL,sBAAsB;AAAA,MACpB,QAAQ;AAAA,MACR,SAAS,QAAQ,IAAI,YAAY,cAAc;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}