remote-components 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (470) hide show
  1. package/dist/{next/config.cjs → config/nextjs.cjs} +77 -102
  2. package/dist/config/nextjs.cjs.map +1 -0
  3. package/dist/{next/config.d.ts → config/nextjs.d.ts} +4 -4
  4. package/dist/{next/config.js → config/nextjs.js} +73 -98
  5. package/dist/config/nextjs.js.map +1 -0
  6. package/dist/{webpack.cjs → config/webpack.cjs} +13 -29
  7. package/dist/config/webpack.cjs.map +1 -0
  8. package/dist/{webpack.js → config/webpack.js} +12 -28
  9. package/dist/config/webpack.js.map +1 -0
  10. package/dist/{shared/remote → host/defaults}/app.cjs +2 -2
  11. package/dist/host/defaults/app.cjs.map +1 -0
  12. package/dist/host/defaults/app.js +8 -0
  13. package/dist/host/defaults/app.js.map +1 -0
  14. package/dist/{shared/remote → host/defaults}/pages.cjs +2 -2
  15. package/dist/host/defaults/pages.cjs.map +1 -0
  16. package/dist/host/defaults/pages.js +8 -0
  17. package/dist/host/defaults/pages.js.map +1 -0
  18. package/dist/{html/host.cjs → host/html.cjs} +1019 -1080
  19. package/dist/host/html.cjs.map +1 -0
  20. package/dist/{html/host.d.ts → host/html.d.ts} +0 -2
  21. package/dist/{html/host.js → host/html.js} +1016 -1076
  22. package/dist/host/html.js.map +1 -0
  23. package/dist/{next/host/client/index.cjs → host/nextjs/app/client-only.cjs} +685 -623
  24. package/dist/host/nextjs/app/client-only.cjs.map +1 -0
  25. package/dist/host/nextjs/app/client-only.d.ts +16 -0
  26. package/dist/{next/host/client/index.js → host/nextjs/app/client-only.js} +687 -618
  27. package/dist/host/nextjs/app/client-only.js.map +1 -0
  28. package/dist/{next/host/app-router-server.cjs → host/nextjs/app.cjs} +11 -10
  29. package/dist/host/nextjs/app.cjs.map +1 -0
  30. package/dist/host/nextjs/app.d.ts +29 -0
  31. package/dist/{next/host/app-router-server.js → host/nextjs/app.js} +7 -6
  32. package/dist/host/nextjs/app.js.map +1 -0
  33. package/dist/{next/host/pages-router-client.cjs → host/nextjs/pages/client-only.cjs} +8 -8
  34. package/dist/host/nextjs/pages/client-only.cjs.map +1 -0
  35. package/dist/host/nextjs/pages/client-only.d.ts +31 -0
  36. package/dist/{next/host/pages-router-client.js → host/nextjs/pages/client-only.js} +4 -4
  37. package/dist/host/nextjs/pages/client-only.js.map +1 -0
  38. package/dist/{next/host/pages-router-server.cjs → host/nextjs/pages.cjs} +44 -55
  39. package/dist/host/nextjs/pages.cjs.map +1 -0
  40. package/dist/{next/host/pages-router-server.d.ts → host/nextjs/pages.d.ts} +11 -13
  41. package/dist/{next/host/pages-router-server.js → host/nextjs/pages.js} +38 -49
  42. package/dist/host/nextjs/pages.js.map +1 -0
  43. package/dist/host/proxy/client.cjs +57 -0
  44. package/dist/host/proxy/client.cjs.map +1 -0
  45. package/dist/host/proxy/client.d.ts +31 -0
  46. package/dist/host/proxy/client.js +30 -0
  47. package/dist/host/proxy/client.js.map +1 -0
  48. package/dist/{shared/host/proxy.cjs → host/proxy/protected-fetch.cjs} +6 -6
  49. package/dist/host/proxy/protected-fetch.cjs.map +1 -0
  50. package/dist/{shared/host/proxy.js → host/proxy/protected-fetch.js} +3 -3
  51. package/dist/host/proxy/protected-fetch.js.map +1 -0
  52. package/dist/{next → host}/proxy.cjs +12 -92
  53. package/dist/host/proxy.cjs.map +1 -0
  54. package/dist/host/proxy.d.ts +30 -0
  55. package/dist/{next → host}/proxy.js +11 -88
  56. package/dist/host/proxy.js.map +1 -0
  57. package/dist/{react/index.cjs → host/react.cjs} +524 -555
  58. package/dist/host/react.cjs.map +1 -0
  59. package/dist/{component-loader-21865da3.d.ts → host/react.d.ts} +141 -99
  60. package/dist/{react/index.js → host/react.js} +523 -552
  61. package/dist/host/react.js.map +1 -0
  62. package/dist/internal/{webpack/shared-modules.cjs → config/webpack/apply-shared-modules.cjs} +18 -17
  63. package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -0
  64. package/dist/internal/{webpack/shared-modules.js → config/webpack/apply-shared-modules.js} +15 -14
  65. package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -0
  66. package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.cjs +1 -1
  67. package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -0
  68. package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.js +1 -1
  69. package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -0
  70. package/dist/internal/{next/host/app-router-client.cjs → host/nextjs/app-client.cjs} +29 -24
  71. package/dist/internal/host/nextjs/app-client.cjs.map +1 -0
  72. package/dist/internal/host/nextjs/app-client.d.ts +25 -0
  73. package/dist/internal/{next/host/app-router-client.js → host/nextjs/app-client.js} +19 -19
  74. package/dist/internal/host/nextjs/app-client.js.map +1 -0
  75. package/dist/internal/{next/host/app-router-compat.cjs → host/nextjs/app-compat.cjs} +5 -22
  76. package/dist/internal/host/nextjs/app-compat.cjs.map +1 -0
  77. package/dist/internal/{next/host/app-router-compat.d.ts → host/nextjs/app-compat.d.ts} +1 -7
  78. package/dist/internal/{next/host/app-router-compat.js → host/nextjs/app-compat.js} +2 -18
  79. package/dist/internal/host/nextjs/app-compat.js.map +1 -0
  80. package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -0
  81. package/dist/internal/host/nextjs/dom-flight.d.ts +39 -0
  82. package/dist/internal/host/nextjs/dom-flight.js.map +1 -0
  83. package/dist/internal/host/nextjs/image-impl.cjs +60 -0
  84. package/dist/internal/host/nextjs/image-impl.cjs.map +1 -0
  85. package/dist/internal/host/nextjs/image-impl.d.ts +10 -0
  86. package/dist/internal/host/nextjs/image-impl.js +36 -0
  87. package/dist/internal/host/nextjs/image-impl.js.map +1 -0
  88. package/dist/internal/host/nextjs/image-shared.cjs +43 -0
  89. package/dist/internal/host/nextjs/image-shared.cjs.map +1 -0
  90. package/dist/internal/host/nextjs/image-shared.d.ts +9 -0
  91. package/dist/internal/host/nextjs/image-shared.js +19 -0
  92. package/dist/internal/host/nextjs/image-shared.js.map +1 -0
  93. package/dist/internal/{next/host → host/nextjs}/remote-component-links.cjs +2 -2
  94. package/dist/internal/host/nextjs/remote-component-links.cjs.map +1 -0
  95. package/dist/internal/{next/host → host/nextjs}/remote-component-links.d.ts +1 -1
  96. package/dist/internal/{next/host → host/nextjs}/remote-component-links.js +2 -2
  97. package/dist/internal/host/nextjs/remote-component-links.js.map +1 -0
  98. package/dist/internal/host/nextjs/skeleton.cjs.map +1 -0
  99. package/dist/internal/host/nextjs/skeleton.js.map +1 -0
  100. package/dist/internal/{react → host/react}/context.cjs +3 -3
  101. package/dist/internal/host/react/context.cjs.map +1 -0
  102. package/dist/internal/{react → host/react}/context.d.ts +4 -4
  103. package/dist/internal/{react → host/react}/context.js +2 -2
  104. package/dist/internal/host/react/context.js.map +1 -0
  105. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.cjs +2 -2
  106. package/dist/internal/host/react/hooks/use-resolve-client-url.cjs.map +1 -0
  107. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.d.ts +1 -1
  108. package/dist/internal/{react → host/react}/hooks/use-resolve-client-url.js +2 -2
  109. package/dist/internal/host/react/hooks/use-resolve-client-url.js.map +1 -0
  110. package/dist/internal/host/server/fetch-headers.cjs.map +1 -0
  111. package/dist/internal/host/server/fetch-headers.js.map +1 -0
  112. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.cjs +6 -6
  113. package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -0
  114. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.d.ts +6 -1
  115. package/dist/internal/{shared/ssr → host/server}/fetch-remote-component.js +9 -9
  116. package/dist/internal/host/server/fetch-remote-component.js.map +1 -0
  117. package/dist/internal/{shared/ssr → host/server}/fetch-with-hooks.cjs +11 -15
  118. package/dist/internal/host/server/fetch-with-hooks.cjs.map +1 -0
  119. package/dist/internal/host/server/fetch-with-hooks.d.ts +21 -0
  120. package/dist/internal/{shared/ssr → host/server}/fetch-with-hooks.js +11 -15
  121. package/dist/internal/host/server/fetch-with-hooks.js.map +1 -0
  122. package/dist/internal/host/server/get-client-or-server-url.cjs.map +1 -0
  123. package/dist/internal/host/server/get-client-or-server-url.js.map +1 -0
  124. package/dist/internal/{shared/client → host/server}/get-client-src.cjs +1 -1
  125. package/dist/internal/host/server/get-client-src.cjs.map +1 -0
  126. package/dist/internal/{shared/client → host/server}/get-client-src.js +1 -1
  127. package/dist/internal/host/server/get-client-src.js.map +1 -0
  128. package/dist/internal/host/server/get-ssr-relative-path-base-url.cjs.map +1 -0
  129. package/dist/internal/host/server/get-ssr-relative-path-base-url.js.map +1 -0
  130. package/dist/{next/remote/server.cjs → internal/host/server/types.cjs} +3 -15
  131. package/dist/internal/host/server/types.cjs.map +1 -0
  132. package/dist/internal/host/server/types.d.ts +33 -0
  133. package/dist/internal/host/server/types.js +1 -0
  134. package/dist/internal/host/server/types.js.map +1 -0
  135. package/dist/internal/host/shared/asset-descriptors.cjs +17 -0
  136. package/dist/internal/host/shared/asset-descriptors.cjs.map +1 -0
  137. package/dist/internal/host/shared/asset-descriptors.d.ts +21 -0
  138. package/dist/internal/host/shared/asset-descriptors.js +1 -0
  139. package/dist/internal/host/shared/asset-descriptors.js.map +1 -0
  140. package/dist/internal/host/shared/config.cjs +17 -0
  141. package/dist/internal/host/shared/config.cjs.map +1 -0
  142. package/dist/{host-config-58cdccea.d.ts → internal/host/shared/config.d.ts} +32 -19
  143. package/dist/internal/host/shared/config.js +1 -0
  144. package/dist/internal/host/shared/config.js.map +1 -0
  145. package/dist/internal/host/shared/fetch-interceptors.cjs +17 -0
  146. package/dist/internal/host/shared/fetch-interceptors.cjs.map +1 -0
  147. package/dist/{types-2b26a246.d.ts → internal/host/shared/fetch-interceptors.d.ts} +4 -87
  148. package/dist/internal/host/shared/fetch-interceptors.js +1 -0
  149. package/dist/internal/host/shared/fetch-interceptors.js.map +1 -0
  150. package/dist/internal/{shared/client → host/shared}/polyfill.cjs +7 -6
  151. package/dist/internal/host/shared/polyfill.cjs.map +1 -0
  152. package/dist/internal/{shared/client → host/shared}/polyfill.d.ts +2 -1
  153. package/dist/internal/{shared/client → host/shared}/polyfill.js +7 -6
  154. package/dist/internal/host/shared/polyfill.js.map +1 -0
  155. package/dist/internal/host/shared/resolved-data.cjs +17 -0
  156. package/dist/internal/host/shared/resolved-data.cjs.map +1 -0
  157. package/dist/internal/host/shared/resolved-data.d.ts +48 -0
  158. package/dist/internal/host/shared/resolved-data.js +1 -0
  159. package/dist/internal/host/shared/resolved-data.js.map +1 -0
  160. package/dist/internal/{shared/contract/host-state.cjs → host/shared/state.cjs} +4 -4
  161. package/dist/internal/host/shared/state.cjs.map +1 -0
  162. package/dist/internal/{shared/contract/host-state.js → host/shared/state.js} +1 -1
  163. package/dist/internal/host/shared/state.js.map +1 -0
  164. package/dist/internal/host/utils/resolve-name-from-src.cjs.map +1 -0
  165. package/dist/internal/host/utils/resolve-name-from-src.js.map +1 -0
  166. package/dist/internal/{next/remote/render-client.cjs → remote/nextjs/app-client.cjs} +8 -8
  167. package/dist/internal/remote/nextjs/app-client.cjs.map +1 -0
  168. package/dist/internal/{next/remote/render-client.js → remote/nextjs/app-client.js} +4 -4
  169. package/dist/internal/remote/nextjs/app-client.js.map +1 -0
  170. package/dist/internal/runtime/constants.cjs +50 -0
  171. package/dist/internal/runtime/constants.cjs.map +1 -0
  172. package/dist/internal/runtime/constants.d.ts +10 -0
  173. package/dist/internal/runtime/constants.js +20 -0
  174. package/dist/internal/runtime/constants.js.map +1 -0
  175. package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs.map +1 -1
  176. package/dist/internal/{shared/client → runtime/html}/apply-origin.d.ts +1 -1
  177. package/dist/internal/{shared/client → runtime/html}/apply-origin.js.map +1 -1
  178. package/dist/internal/runtime/html/parse-remote-html.cjs +140 -0
  179. package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -0
  180. package/dist/internal/runtime/html/parse-remote-html.d.ts +88 -0
  181. package/dist/internal/runtime/html/parse-remote-html.js +110 -0
  182. package/dist/internal/runtime/html/parse-remote-html.js.map +1 -0
  183. package/dist/internal/runtime/html/set-attributes-from-props.cjs +68 -0
  184. package/dist/internal/runtime/html/set-attributes-from-props.cjs.map +1 -0
  185. package/dist/internal/runtime/html/set-attributes-from-props.d.ts +3 -0
  186. package/dist/internal/runtime/html/set-attributes-from-props.js +44 -0
  187. package/dist/internal/runtime/html/set-attributes-from-props.js.map +1 -0
  188. package/dist/internal/runtime/loaders/component-loader.cjs +184 -0
  189. package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -0
  190. package/dist/internal/runtime/loaders/component-loader.d.ts +31 -0
  191. package/dist/internal/runtime/loaders/component-loader.js +150 -0
  192. package/dist/internal/runtime/loaders/component-loader.js.map +1 -0
  193. package/dist/internal/runtime/loaders/script-loader.cjs +64 -0
  194. package/dist/internal/runtime/loaders/script-loader.cjs.map +1 -0
  195. package/dist/internal/runtime/loaders/script-loader.d.ts +10 -0
  196. package/dist/internal/runtime/loaders/script-loader.js +43 -0
  197. package/dist/internal/runtime/loaders/script-loader.js.map +1 -0
  198. package/dist/internal/runtime/loaders/static-loader.cjs +177 -0
  199. package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -0
  200. package/dist/internal/runtime/loaders/static-loader.d.ts +10 -0
  201. package/dist/internal/runtime/loaders/static-loader.js +153 -0
  202. package/dist/internal/runtime/loaders/static-loader.js.map +1 -0
  203. package/dist/internal/runtime/metadata.cjs +17 -0
  204. package/dist/internal/runtime/metadata.cjs.map +1 -0
  205. package/dist/internal/runtime/metadata.d.ts +16 -0
  206. package/dist/internal/runtime/metadata.js +1 -0
  207. package/dist/internal/runtime/metadata.js.map +1 -0
  208. package/dist/internal/runtime/rsc.cjs +92 -0
  209. package/dist/internal/runtime/rsc.cjs.map +1 -0
  210. package/dist/internal/runtime/rsc.d.ts +8 -0
  211. package/dist/internal/runtime/rsc.js +68 -0
  212. package/dist/internal/runtime/rsc.js.map +1 -0
  213. package/dist/internal/runtime/turbopack/chunk-loader.cjs +239 -0
  214. package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -0
  215. package/dist/internal/runtime/turbopack/chunk-loader.d.ts +11 -0
  216. package/dist/internal/runtime/turbopack/chunk-loader.js +222 -0
  217. package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -0
  218. package/dist/internal/runtime/turbopack/module.cjs +257 -0
  219. package/dist/internal/runtime/turbopack/module.cjs.map +1 -0
  220. package/dist/internal/runtime/turbopack/module.d.ts +61 -0
  221. package/dist/internal/runtime/turbopack/module.js +233 -0
  222. package/dist/internal/runtime/turbopack/module.js.map +1 -0
  223. package/dist/internal/runtime/turbopack/patterns.cjs +44 -0
  224. package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -0
  225. package/dist/internal/runtime/turbopack/patterns.d.ts +109 -0
  226. package/dist/internal/runtime/turbopack/patterns.js +15 -0
  227. package/dist/internal/runtime/turbopack/patterns.js.map +1 -0
  228. package/dist/internal/runtime/turbopack/shared-modules.cjs +153 -0
  229. package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -0
  230. package/dist/internal/runtime/turbopack/shared-modules.d.ts +17 -0
  231. package/dist/internal/runtime/turbopack/shared-modules.js +134 -0
  232. package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -0
  233. package/dist/internal/runtime/turbopack/webpack-runtime.cjs +137 -0
  234. package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +1 -0
  235. package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +20 -0
  236. package/dist/internal/runtime/turbopack/webpack-runtime.js +107 -0
  237. package/dist/internal/runtime/turbopack/webpack-runtime.js.map +1 -0
  238. package/dist/internal/runtime/types.cjs +17 -0
  239. package/dist/internal/runtime/types.cjs.map +1 -0
  240. package/dist/internal/runtime/types.d.ts +40 -0
  241. package/dist/internal/runtime/types.js +1 -0
  242. package/dist/internal/runtime/types.js.map +1 -0
  243. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.cjs +2 -2
  244. package/dist/internal/runtime/url/default-resolve-client-url.cjs.map +1 -0
  245. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.d.ts +1 -1
  246. package/dist/internal/{shared/client → runtime/url}/default-resolve-client-url.js +1 -1
  247. package/dist/internal/runtime/url/default-resolve-client-url.js.map +1 -0
  248. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.cjs +1 -1
  249. package/dist/internal/runtime/url/protected-rc-fallback.cjs.map +1 -0
  250. package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.js +1 -1
  251. package/dist/internal/runtime/url/protected-rc-fallback.js.map +1 -0
  252. package/dist/internal/{shared/client/proxy-through-host.cjs → runtime/url/resolve-client-url.cjs} +4 -24
  253. package/dist/internal/runtime/url/resolve-client-url.cjs.map +1 -0
  254. package/dist/internal/{shared/client/proxy-through-host.d.ts → runtime/url/resolve-client-url.d.ts} +1 -25
  255. package/dist/internal/runtime/url/resolve-client-url.js +21 -0
  256. package/dist/internal/runtime/url/resolve-client-url.js.map +1 -0
  257. package/dist/internal/utils/abort.cjs.map +1 -0
  258. package/dist/internal/utils/abort.js.map +1 -0
  259. package/dist/internal/{shared → utils}/constants.cjs +3 -0
  260. package/dist/internal/utils/constants.cjs.map +1 -0
  261. package/dist/internal/utils/constants.d.ts +5 -0
  262. package/dist/internal/{shared → utils}/constants.js +2 -0
  263. package/dist/internal/utils/constants.js.map +1 -0
  264. package/dist/internal/{shared → utils}/error.cjs +11 -4
  265. package/dist/internal/utils/error.cjs.map +1 -0
  266. package/dist/internal/{shared → utils}/error.d.ts +2 -1
  267. package/dist/internal/{shared → utils}/error.js +10 -4
  268. package/dist/internal/utils/error.js.map +1 -0
  269. package/dist/internal/{shared/utils → utils}/logger.cjs +3 -3
  270. package/dist/internal/utils/logger.cjs.map +1 -0
  271. package/dist/internal/{shared/utils → utils}/logger.d.ts +2 -2
  272. package/dist/internal/{shared/utils → utils}/logger.js +3 -3
  273. package/dist/internal/utils/logger.js.map +1 -0
  274. package/dist/internal/utils.cjs.map +1 -0
  275. package/dist/internal/utils.js.map +1 -0
  276. package/dist/{shared/host → remote/defaults}/app.cjs +2 -6
  277. package/dist/remote/defaults/app.cjs.map +1 -0
  278. package/dist/remote/defaults/app.js +8 -0
  279. package/dist/remote/defaults/app.js.map +1 -0
  280. package/dist/{shared/host → remote/defaults}/pages.cjs +2 -6
  281. package/dist/remote/defaults/pages.cjs.map +1 -0
  282. package/dist/remote/defaults/pages.js +8 -0
  283. package/dist/remote/defaults/pages.js.map +1 -0
  284. package/dist/{shared/remote → remote/defaults}/wrapper.cjs +12 -10
  285. package/dist/remote/defaults/wrapper.cjs.map +1 -0
  286. package/dist/remote/defaults/wrapper.js +27 -0
  287. package/dist/remote/defaults/wrapper.js.map +1 -0
  288. package/dist/{html/remote.cjs → remote/html.cjs} +16 -16
  289. package/dist/remote/html.cjs.map +1 -0
  290. package/dist/{html/remote.js → remote/html.js} +16 -16
  291. package/dist/remote/html.js.map +1 -0
  292. package/dist/{shared/remote/proxy.cjs → remote/middleware.cjs} +37 -12
  293. package/dist/remote/middleware.cjs.map +1 -0
  294. package/dist/remote/middleware.d.ts +27 -0
  295. package/dist/{shared/remote/proxy.js → remote/middleware.js} +32 -5
  296. package/dist/remote/middleware.js.map +1 -0
  297. package/dist/{internal/next/remote/render-server.cjs → remote/nextjs/app.cjs} +14 -16
  298. package/dist/remote/nextjs/app.cjs.map +1 -0
  299. package/dist/{internal/next/remote/render-server.d.ts → remote/nextjs/app.d.ts} +12 -13
  300. package/dist/{internal/next/remote/render-server.js → remote/nextjs/app.js} +9 -11
  301. package/dist/remote/nextjs/app.js.map +1 -0
  302. package/dist/{next/remote/pages-router.cjs → remote/nextjs/pages.cjs} +8 -8
  303. package/dist/remote/nextjs/pages.cjs.map +1 -0
  304. package/dist/{next/remote/pages-router.d.ts → remote/nextjs/pages.d.ts} +8 -8
  305. package/dist/{next/remote/pages-router.js → remote/nextjs/pages.js} +4 -4
  306. package/dist/remote/nextjs/pages.js.map +1 -0
  307. package/dist/server-handoff-8c89b856.d.ts +46 -0
  308. package/package.json +126 -157
  309. package/dist/html/host.cjs.map +0 -1
  310. package/dist/html/host.js.map +0 -1
  311. package/dist/html/remote.cjs.map +0 -1
  312. package/dist/html/remote.js.map +0 -1
  313. package/dist/internal/next/host/app-router-client.cjs.map +0 -1
  314. package/dist/internal/next/host/app-router-client.d.ts +0 -79
  315. package/dist/internal/next/host/app-router-client.js.map +0 -1
  316. package/dist/internal/next/host/app-router-compat.cjs.map +0 -1
  317. package/dist/internal/next/host/app-router-compat.js.map +0 -1
  318. package/dist/internal/next/host/remote-component-links.cjs.map +0 -1
  319. package/dist/internal/next/host/remote-component-links.js.map +0 -1
  320. package/dist/internal/next/remote/render-client.cjs.map +0 -1
  321. package/dist/internal/next/remote/render-client.js.map +0 -1
  322. package/dist/internal/next/remote/render-server.cjs.map +0 -1
  323. package/dist/internal/next/remote/render-server.js.map +0 -1
  324. package/dist/internal/react/context.cjs.map +0 -1
  325. package/dist/internal/react/context.js.map +0 -1
  326. package/dist/internal/react/hooks/use-resolve-client-url.cjs.map +0 -1
  327. package/dist/internal/react/hooks/use-resolve-client-url.js.map +0 -1
  328. package/dist/internal/shared/client/default-resolve-client-url.cjs.map +0 -1
  329. package/dist/internal/shared/client/default-resolve-client-url.js.map +0 -1
  330. package/dist/internal/shared/client/get-client-src.cjs.map +0 -1
  331. package/dist/internal/shared/client/get-client-src.js.map +0 -1
  332. package/dist/internal/shared/client/polyfill.cjs.map +0 -1
  333. package/dist/internal/shared/client/polyfill.js.map +0 -1
  334. package/dist/internal/shared/client/protected-rc-fallback.cjs.map +0 -1
  335. package/dist/internal/shared/client/protected-rc-fallback.js.map +0 -1
  336. package/dist/internal/shared/client/proxy-through-host.cjs.map +0 -1
  337. package/dist/internal/shared/client/proxy-through-host.js +0 -40
  338. package/dist/internal/shared/client/proxy-through-host.js.map +0 -1
  339. package/dist/internal/shared/client/remote-component.cjs +0 -1436
  340. package/dist/internal/shared/client/remote-component.cjs.map +0 -1
  341. package/dist/internal/shared/client/remote-component.d.ts +0 -62
  342. package/dist/internal/shared/client/remote-component.js +0 -1385
  343. package/dist/internal/shared/client/remote-component.js.map +0 -1
  344. package/dist/internal/shared/constants.cjs.map +0 -1
  345. package/dist/internal/shared/constants.d.ts +0 -4
  346. package/dist/internal/shared/constants.js.map +0 -1
  347. package/dist/internal/shared/contract/host-state.cjs.map +0 -1
  348. package/dist/internal/shared/contract/host-state.js.map +0 -1
  349. package/dist/internal/shared/contract/resolve-name-from-src.cjs.map +0 -1
  350. package/dist/internal/shared/contract/resolve-name-from-src.js.map +0 -1
  351. package/dist/internal/shared/error.cjs.map +0 -1
  352. package/dist/internal/shared/error.js.map +0 -1
  353. package/dist/internal/shared/ssr/dom-flight.cjs.map +0 -1
  354. package/dist/internal/shared/ssr/dom-flight.d.ts +0 -2
  355. package/dist/internal/shared/ssr/dom-flight.js.map +0 -1
  356. package/dist/internal/shared/ssr/fetch-headers.cjs.map +0 -1
  357. package/dist/internal/shared/ssr/fetch-headers.js.map +0 -1
  358. package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +0 -1
  359. package/dist/internal/shared/ssr/fetch-remote-component.js.map +0 -1
  360. package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +0 -1
  361. package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +0 -56
  362. package/dist/internal/shared/ssr/fetch-with-hooks.js.map +0 -1
  363. package/dist/internal/shared/ssr/get-client-or-server-url.cjs.map +0 -1
  364. package/dist/internal/shared/ssr/get-client-or-server-url.js.map +0 -1
  365. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.cjs.map +0 -1
  366. package/dist/internal/shared/ssr/get-ssr-relative-path-base-url.js.map +0 -1
  367. package/dist/internal/shared/ssr/skeleton.cjs.map +0 -1
  368. package/dist/internal/shared/ssr/skeleton.js.map +0 -1
  369. package/dist/internal/shared/utils/abort.cjs.map +0 -1
  370. package/dist/internal/shared/utils/abort.js.map +0 -1
  371. package/dist/internal/shared/utils/logger.cjs.map +0 -1
  372. package/dist/internal/shared/utils/logger.js.map +0 -1
  373. package/dist/internal/shared/utils.cjs.map +0 -1
  374. package/dist/internal/shared/utils.js.map +0 -1
  375. package/dist/internal/webpack/next-client-pages-loader.cjs.map +0 -1
  376. package/dist/internal/webpack/next-client-pages-loader.js.map +0 -1
  377. package/dist/internal/webpack/shared-modules.cjs.map +0 -1
  378. package/dist/internal/webpack/shared-modules.js.map +0 -1
  379. package/dist/next/config.cjs.map +0 -1
  380. package/dist/next/config.js.map +0 -1
  381. package/dist/next/host/app-router-server.cjs.map +0 -1
  382. package/dist/next/host/app-router-server.d.ts +0 -30
  383. package/dist/next/host/app-router-server.js.map +0 -1
  384. package/dist/next/host/client/index.cjs.map +0 -1
  385. package/dist/next/host/client/index.d.ts +0 -19
  386. package/dist/next/host/client/index.js.map +0 -1
  387. package/dist/next/host/pages-router-client.cjs.map +0 -1
  388. package/dist/next/host/pages-router-client.d.ts +0 -33
  389. package/dist/next/host/pages-router-client.js.map +0 -1
  390. package/dist/next/host/pages-router-server.cjs.map +0 -1
  391. package/dist/next/host/pages-router-server.js.map +0 -1
  392. package/dist/next/index.cjs +0 -53
  393. package/dist/next/index.cjs.map +0 -1
  394. package/dist/next/index.d.ts +0 -30
  395. package/dist/next/index.js +0 -19
  396. package/dist/next/index.js.map +0 -1
  397. package/dist/next/proxy.cjs.map +0 -1
  398. package/dist/next/proxy.d.ts +0 -56
  399. package/dist/next/proxy.js.map +0 -1
  400. package/dist/next/remote/pages-router.cjs.map +0 -1
  401. package/dist/next/remote/pages-router.js.map +0 -1
  402. package/dist/next/remote/server.cjs.map +0 -1
  403. package/dist/next/remote/server.d.ts +0 -5
  404. package/dist/next/remote/server.js +0 -5
  405. package/dist/next/remote/server.js.map +0 -1
  406. package/dist/proxy-through-host-a676a522.d.ts +0 -52
  407. package/dist/react/index.cjs.map +0 -1
  408. package/dist/react/index.d.ts +0 -86
  409. package/dist/react/index.js.map +0 -1
  410. package/dist/shared/host/app.cjs.map +0 -1
  411. package/dist/shared/host/app.js +0 -12
  412. package/dist/shared/host/app.js.map +0 -1
  413. package/dist/shared/host/pages.cjs.map +0 -1
  414. package/dist/shared/host/pages.js +0 -12
  415. package/dist/shared/host/pages.js.map +0 -1
  416. package/dist/shared/host/proxy.cjs.map +0 -1
  417. package/dist/shared/host/proxy.js.map +0 -1
  418. package/dist/shared/remote/app.cjs.map +0 -1
  419. package/dist/shared/remote/app.js +0 -8
  420. package/dist/shared/remote/app.js.map +0 -1
  421. package/dist/shared/remote/pages.cjs.map +0 -1
  422. package/dist/shared/remote/pages.js +0 -8
  423. package/dist/shared/remote/pages.js.map +0 -1
  424. package/dist/shared/remote/proxy.cjs.map +0 -1
  425. package/dist/shared/remote/proxy.d.ts +0 -44
  426. package/dist/shared/remote/proxy.js.map +0 -1
  427. package/dist/shared/remote/wrapper.cjs.map +0 -1
  428. package/dist/shared/remote/wrapper.js +0 -25
  429. package/dist/shared/remote/wrapper.js.map +0 -1
  430. package/dist/webpack.cjs.map +0 -1
  431. package/dist/webpack.js.map +0 -1
  432. /package/dist/{webpack.d.ts → config/webpack.d.ts} +0 -0
  433. /package/dist/{shared/host → host/defaults}/app.d.ts +0 -0
  434. /package/dist/{shared/host → host/defaults}/pages.d.ts +0 -0
  435. /package/dist/{shared/host/proxy.d.ts → host/proxy/protected-fetch.d.ts} +0 -0
  436. /package/dist/internal/{webpack/shared-modules.d.ts → config/webpack/apply-shared-modules.d.ts} +0 -0
  437. /package/dist/internal/{webpack → config/webpack}/next-client-pages-loader.d.ts +0 -0
  438. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.cjs +0 -0
  439. /package/dist/internal/{shared/ssr → host/nextjs}/dom-flight.js +0 -0
  440. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.cjs +0 -0
  441. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.d.ts +0 -0
  442. /package/dist/internal/{shared/ssr → host/nextjs}/skeleton.js +0 -0
  443. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.cjs +0 -0
  444. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.d.ts +0 -0
  445. /package/dist/internal/{shared/ssr → host/server}/fetch-headers.js +0 -0
  446. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.cjs +0 -0
  447. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.d.ts +0 -0
  448. /package/dist/internal/{shared/ssr → host/server}/get-client-or-server-url.js +0 -0
  449. /package/dist/internal/{shared/client → host/server}/get-client-src.d.ts +0 -0
  450. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.cjs +0 -0
  451. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.d.ts +0 -0
  452. /package/dist/internal/{shared/ssr → host/server}/get-ssr-relative-path-base-url.js +0 -0
  453. /package/dist/internal/{shared/contract/host-state.d.ts → host/shared/state.d.ts} +0 -0
  454. /package/dist/internal/{shared/contract → host/utils}/resolve-name-from-src.cjs +0 -0
  455. /package/dist/internal/{shared/contract → host/utils}/resolve-name-from-src.d.ts +0 -0
  456. /package/dist/internal/{shared/contract → host/utils}/resolve-name-from-src.js +0 -0
  457. /package/dist/internal/{next/remote/render-client.d.ts → remote/nextjs/app-client.d.ts} +0 -0
  458. /package/dist/internal/{shared/client → runtime/html}/apply-origin.cjs +0 -0
  459. /package/dist/internal/{shared/client → runtime/html}/apply-origin.js +0 -0
  460. /package/dist/internal/{shared/client → runtime/url}/protected-rc-fallback.d.ts +0 -0
  461. /package/dist/internal/{shared/utils → utils}/abort.cjs +0 -0
  462. /package/dist/internal/{shared/utils → utils}/abort.d.ts +0 -0
  463. /package/dist/internal/{shared/utils → utils}/abort.js +0 -0
  464. /package/dist/internal/{shared/utils.cjs → utils.cjs} +0 -0
  465. /package/dist/internal/{shared/utils.d.ts → utils.d.ts} +0 -0
  466. /package/dist/internal/{shared/utils.js → utils.js} +0 -0
  467. /package/dist/{shared/remote → remote/defaults}/app.d.ts +0 -0
  468. /package/dist/{shared/remote → remote/defaults}/pages.d.ts +0 -0
  469. /package/dist/{shared/remote → remote/defaults}/wrapper.d.ts +0 -0
  470. /package/dist/{html/remote.d.ts → remote/html.d.ts} +0 -0
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var static_loader_exports = {};
20
+ __export(static_loader_exports, {
21
+ loadStaticRemoteComponent: () => loadStaticRemoteComponent
22
+ });
23
+ module.exports = __toCommonJS(static_loader_exports);
24
+ var import_logger = require("#internal/utils/logger");
25
+ async function importViaCallback(absoluteSrc, resolveClientUrl) {
26
+ const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
27
+ const fetchUrl = new URL(resolvedUrl, location.href).href;
28
+ const response = await fetch(fetchUrl);
29
+ if (!response.ok)
30
+ throw new Error(`Proxied fetch failed: ${response.status}`);
31
+ const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
32
+ /\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
33
+ (_, keyword, quote, relativePath) => {
34
+ const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
35
+ const resolvedImportUrl = new URL(
36
+ resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
37
+ location.href
38
+ ).href;
39
+ return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
40
+ }
41
+ );
42
+ const moduleBlobUrl = URL.createObjectURL(
43
+ new Blob([content], { type: "text/javascript" })
44
+ );
45
+ const wrapperContent = [
46
+ `import*as m from${JSON.stringify(moduleBlobUrl)};`,
47
+ `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
48
+ `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
49
+ ].join("");
50
+ const wrapperBlobUrl = URL.createObjectURL(
51
+ new Blob([wrapperContent], { type: "text/javascript" })
52
+ );
53
+ const scriptEl = document.createElement("script");
54
+ scriptEl.type = "module";
55
+ scriptEl.src = wrapperBlobUrl;
56
+ try {
57
+ await new Promise((resolve, reject) => {
58
+ scriptEl.onload = () => resolve();
59
+ scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
60
+ document.head.appendChild(scriptEl);
61
+ });
62
+ } finally {
63
+ scriptEl.remove();
64
+ URL.revokeObjectURL(moduleBlobUrl);
65
+ URL.revokeObjectURL(wrapperBlobUrl);
66
+ }
67
+ const registry = globalThis.__rc_module_registry__;
68
+ const mod = registry?.[absoluteSrc] ?? {};
69
+ if (registry)
70
+ delete registry[absoluteSrc];
71
+ return mod;
72
+ }
73
+ async function importDirectly(absoluteSrc) {
74
+ try {
75
+ return await import(
76
+ /* @vite-ignore */
77
+ /* webpackIgnore: true */
78
+ absoluteSrc
79
+ );
80
+ } catch (importError) {
81
+ if (!absoluteSrc.startsWith("blob:")) {
82
+ (0, import_logger.warnCrossOriginFetchError)("StaticLoader", absoluteSrc);
83
+ }
84
+ throw importError;
85
+ }
86
+ }
87
+ function resolveScriptSrc(script, url) {
88
+ const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
89
+ if (!rawSrc && script.textContent) {
90
+ return URL.createObjectURL(
91
+ new Blob(
92
+ [script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
93
+ { type: "text/javascript" }
94
+ )
95
+ );
96
+ }
97
+ return rawSrc;
98
+ }
99
+ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
100
+ const self = globalThis;
101
+ if (self.__remote_script_entrypoint_mount__?.[url.href]) {
102
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
103
+ }
104
+ if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
105
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
106
+ }
107
+ const mountUnmountSets = await Promise.all(
108
+ scripts.map(async (script) => {
109
+ try {
110
+ const src = resolveScriptSrc(script, url);
111
+ const absoluteSrc = new URL(src, url).href;
112
+ const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
113
+ if (src.startsWith("blob:")) {
114
+ URL.revokeObjectURL(src);
115
+ }
116
+ if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
117
+ if (!self.__remote_script_entrypoint_mount__) {
118
+ self.__remote_script_entrypoint_mount__ = {};
119
+ }
120
+ if (!self.__remote_script_entrypoint_mount__[url.href]) {
121
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
122
+ }
123
+ self.__remote_script_entrypoint_mount__[url.href]?.add(
124
+ mod.mount || mod.default?.mount || (() => {
125
+ })
126
+ );
127
+ }
128
+ if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
129
+ if (!self.__remote_script_entrypoint_unmount__) {
130
+ self.__remote_script_entrypoint_unmount__ = {};
131
+ }
132
+ if (!self.__remote_script_entrypoint_unmount__[url.href]) {
133
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
134
+ }
135
+ self.__remote_script_entrypoint_unmount__[url.href]?.add(
136
+ mod.unmount || mod.default?.unmount || (() => {
137
+ })
138
+ );
139
+ }
140
+ return {
141
+ mount: mod.mount || mod.default?.mount,
142
+ unmount: mod.unmount || mod.default?.unmount
143
+ };
144
+ } catch (e) {
145
+ (0, import_logger.logError)(
146
+ "StaticLoader",
147
+ `Error loading remote component script from "${script.src || url.href}".`,
148
+ e
149
+ );
150
+ return {
151
+ mount: void 0,
152
+ unmount: void 0
153
+ };
154
+ }
155
+ })
156
+ );
157
+ return mountUnmountSets.reduce(
158
+ (acc, { mount, unmount }) => {
159
+ if (typeof mount === "function") {
160
+ acc.mount.add(mount);
161
+ }
162
+ if (typeof unmount === "function") {
163
+ acc.unmount.add(unmount);
164
+ }
165
+ return acc;
166
+ },
167
+ {
168
+ mount: /* @__PURE__ */ new Set(),
169
+ unmount: /* @__PURE__ */ new Set()
170
+ }
171
+ );
172
+ }
173
+ // Annotate the CommonJS export names for ESM import in node:
174
+ 0 && (module.exports = {
175
+ loadStaticRemoteComponent
176
+ });
177
+ //# sourceMappingURL=static-loader.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/runtime/loaders/static-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type {\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\nimport { logError, warnCrossOriginFetchError } from '#internal/utils/logger';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = (\n globalThis as unknown as { __rc_module_registry__?: Record<string, T> }\n ).__rc_module_registry__;\n const mod = registry?.[absoluteSrc] ?? ({} as T);\n if (registry) delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const self = globalThis as typeof globalThis & MountUnmountFunctions;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmountFunction>(),\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,oBAAoD;AAsBpD,eAAe,kBACb,aACA,kBACY;AACZ,QAAM,cAAc,iBAAiB,WAAW,KAAK;AACrD,QAAM,WAAW,IAAI,IAAI,aAAa,SAAS,IAAI,EAAE;AACrD,QAAM,WAAW,MAAM,MAAM,QAAQ;AACrC,MAAI,CAAC,SAAS;AAAI,UAAM,IAAI,MAAM,yBAAyB,SAAS,QAAQ;AAM5E,QAAM,WAAW,MAAM,SAAS,KAAK,GAClC,QAAQ,sBAAsB,KAAK,UAAU,WAAW,CAAC,EACzD;AAAA,IACC;AAAA,IACA,CAAC,GAAG,SAAS,OAAO,iBAAiB;AACnC,YAAM,oBAAoB,IAAI,IAAI,cAAc,WAAW,EAAE;AAC7D,YA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IAAI,SAAS,UACZ,MAAM;AAAA,YAEP;AAAA,UACJ;AAAA,QACF;AACA,YACE,OAAO,IAAI,YAAY,cACvB,OAAO,IAAI,SAAS,YAAY,YAChC;AACA,cAAI,CAAC,KAAK,sCAAsC;AAE9C,iBAAK,uCAAuC,CAAC;AAAA,UAC/C;AACA,cAAI,CAAC,KAAK,qCAAqC,IAAI,IAAI,GAAG;AACxD,iBAAK,qCAAqC,IAAI,IAAI,IAAI,oBAAI,IAAI;AAAA,UAChE;AACA,eAAK,qCAAqC,IAAI,IAAI,GAAG;AAAA,YACnD,IAAI,WACF,IAAI,SAAS,YACZ,MAAM;AAAA,YAEP;AAAA,UACJ;AAAA,QACF;AACA,eAAO;AAAA,UACL,OAAO,IAAI,SAAS,IAAI,SAAS;AAAA,UACjC,SAAS,IAAI,WAAW,IAAI,SAAS;AAAA,QACvC;AAAA,MACF,SAAS,GAAP;AACA;AAAA,UACE;AAAA,UACA,+CAA+C,OAAO,OAAO,IAAI;AAAA,UACjE;AAAA,QACF;AACA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,iBAAiB;AAAA,IACtB,CAAC,KAAK,EAAE,OAAO,QAAQ,MAAM;AAC3B,UAAI,OAAO,UAAU,YAAY;AAC/B,YAAI,MAAM,IAAI,KAAK;AAAA,MACrB;AACA,UAAI,OAAO,YAAY,YAAY;AACjC,YAAI,QAAQ,IAAI,OAAO;AAAA,MACzB;AACA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,MACE,OAAO,oBAAI,IAA4B;AAAA,MACvC,SAAS,oBAAI,IAA4B;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,10 @@
1
+ import { InternalResolveClientUrl } from '../url/resolve-client-url.js';
2
+ import { MountOrUnmountFunction } from '../types.js';
3
+ import '../metadata.js';
4
+
5
+ declare function loadStaticRemoteComponent(scripts: HTMLScriptElement[], url: URL, resolveClientUrl?: InternalResolveClientUrl): Promise<{
6
+ mount: Set<MountOrUnmountFunction>;
7
+ unmount: Set<MountOrUnmountFunction>;
8
+ }>;
9
+
10
+ export { loadStaticRemoteComponent };
@@ -0,0 +1,153 @@
1
+ import { logError, warnCrossOriginFetchError } from "#internal/utils/logger";
2
+ async function importViaCallback(absoluteSrc, resolveClientUrl) {
3
+ const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
4
+ const fetchUrl = new URL(resolvedUrl, location.href).href;
5
+ const response = await fetch(fetchUrl);
6
+ if (!response.ok)
7
+ throw new Error(`Proxied fetch failed: ${response.status}`);
8
+ const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
9
+ /\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
10
+ (_, keyword, quote, relativePath) => {
11
+ const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
12
+ const resolvedImportUrl = new URL(
13
+ resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
14
+ location.href
15
+ ).href;
16
+ return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
17
+ }
18
+ );
19
+ const moduleBlobUrl = URL.createObjectURL(
20
+ new Blob([content], { type: "text/javascript" })
21
+ );
22
+ const wrapperContent = [
23
+ `import*as m from${JSON.stringify(moduleBlobUrl)};`,
24
+ `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,
25
+ `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`
26
+ ].join("");
27
+ const wrapperBlobUrl = URL.createObjectURL(
28
+ new Blob([wrapperContent], { type: "text/javascript" })
29
+ );
30
+ const scriptEl = document.createElement("script");
31
+ scriptEl.type = "module";
32
+ scriptEl.src = wrapperBlobUrl;
33
+ try {
34
+ await new Promise((resolve, reject) => {
35
+ scriptEl.onload = () => resolve();
36
+ scriptEl.onerror = () => reject(new Error(`Failed to load module for ${absoluteSrc}`));
37
+ document.head.appendChild(scriptEl);
38
+ });
39
+ } finally {
40
+ scriptEl.remove();
41
+ URL.revokeObjectURL(moduleBlobUrl);
42
+ URL.revokeObjectURL(wrapperBlobUrl);
43
+ }
44
+ const registry = globalThis.__rc_module_registry__;
45
+ const mod = registry?.[absoluteSrc] ?? {};
46
+ if (registry)
47
+ delete registry[absoluteSrc];
48
+ return mod;
49
+ }
50
+ async function importDirectly(absoluteSrc) {
51
+ try {
52
+ return await import(
53
+ /* @vite-ignore */
54
+ /* webpackIgnore: true */
55
+ absoluteSrc
56
+ );
57
+ } catch (importError) {
58
+ if (!absoluteSrc.startsWith("blob:")) {
59
+ warnCrossOriginFetchError("StaticLoader", absoluteSrc);
60
+ }
61
+ throw importError;
62
+ }
63
+ }
64
+ function resolveScriptSrc(script, url) {
65
+ const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
66
+ if (!rawSrc && script.textContent) {
67
+ return URL.createObjectURL(
68
+ new Blob(
69
+ [script.textContent.replace(/import\.meta\.url/g, JSON.stringify(url))],
70
+ { type: "text/javascript" }
71
+ )
72
+ );
73
+ }
74
+ return rawSrc;
75
+ }
76
+ async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
77
+ const self = globalThis;
78
+ if (self.__remote_script_entrypoint_mount__?.[url.href]) {
79
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
80
+ }
81
+ if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
82
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
83
+ }
84
+ const mountUnmountSets = await Promise.all(
85
+ scripts.map(async (script) => {
86
+ try {
87
+ const src = resolveScriptSrc(script, url);
88
+ const absoluteSrc = new URL(src, url).href;
89
+ const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
90
+ if (src.startsWith("blob:")) {
91
+ URL.revokeObjectURL(src);
92
+ }
93
+ if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
94
+ if (!self.__remote_script_entrypoint_mount__) {
95
+ self.__remote_script_entrypoint_mount__ = {};
96
+ }
97
+ if (!self.__remote_script_entrypoint_mount__[url.href]) {
98
+ self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
99
+ }
100
+ self.__remote_script_entrypoint_mount__[url.href]?.add(
101
+ mod.mount || mod.default?.mount || (() => {
102
+ })
103
+ );
104
+ }
105
+ if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
106
+ if (!self.__remote_script_entrypoint_unmount__) {
107
+ self.__remote_script_entrypoint_unmount__ = {};
108
+ }
109
+ if (!self.__remote_script_entrypoint_unmount__[url.href]) {
110
+ self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
111
+ }
112
+ self.__remote_script_entrypoint_unmount__[url.href]?.add(
113
+ mod.unmount || mod.default?.unmount || (() => {
114
+ })
115
+ );
116
+ }
117
+ return {
118
+ mount: mod.mount || mod.default?.mount,
119
+ unmount: mod.unmount || mod.default?.unmount
120
+ };
121
+ } catch (e) {
122
+ logError(
123
+ "StaticLoader",
124
+ `Error loading remote component script from "${script.src || url.href}".`,
125
+ e
126
+ );
127
+ return {
128
+ mount: void 0,
129
+ unmount: void 0
130
+ };
131
+ }
132
+ })
133
+ );
134
+ return mountUnmountSets.reduce(
135
+ (acc, { mount, unmount }) => {
136
+ if (typeof mount === "function") {
137
+ acc.mount.add(mount);
138
+ }
139
+ if (typeof unmount === "function") {
140
+ acc.unmount.add(unmount);
141
+ }
142
+ return acc;
143
+ },
144
+ {
145
+ mount: /* @__PURE__ */ new Set(),
146
+ unmount: /* @__PURE__ */ new Set()
147
+ }
148
+ );
149
+ }
150
+ export {
151
+ loadStaticRemoteComponent
152
+ };
153
+ //# sourceMappingURL=static-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/runtime/loaders/static-loader.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type {\n MountOrUnmountFunction,\n MountUnmountFunctions,\n} from '#internal/runtime/types';\nimport { logError, warnCrossOriginFetchError } from '#internal/utils/logger';\n\ntype ScriptMod = {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n default?: {\n mount?: MountOrUnmountFunction;\n unmount?: MountOrUnmountFunction;\n };\n};\n\n/**\n * Fetches an ES module via the resolveClientUrl callback, rewrites its\n * relative imports to also go through the callback, then loads it by injecting a\n * wrapper <script type=\"module\"> tag. The module's namespace is captured via\n * a temporary global and returned.\n *\n * This is needed when a direct import() of a cross-origin module fails due to\n * CORS restrictions or Vercel preview-deployment auth. A simple URL rewrite\n * doesn't work for import() because relative imports inside the module would\n * resolve against the rewritten URL instead of the original remote origin.\n */\nasync function importViaCallback<T>(\n absoluteSrc: string,\n resolveClientUrl: InternalResolveClientUrl,\n): Promise<T> {\n const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;\n const fetchUrl = new URL(resolvedUrl, location.href).href;\n const response = await fetch(fetchUrl);\n if (!response.ok) throw new Error(`Proxied fetch failed: ${response.status}`);\n\n // Restore import.meta.url to the original module URL so any code that\n // relies on it (e.g. for asset resolution) gets the right value.\n // Rewrite relative imports to absolute URLs resolved through the callback so\n // that transitive dependencies also bypass CORS/auth.\n const content = (await response.text())\n .replace(/import\\.meta\\.url/g, JSON.stringify(absoluteSrc))\n .replace(\n /\\b(from|import)\\s*([\"'])(\\.\\.?\\/[^\"']+)\\2/g,\n (_, keyword, quote, relativePath) => {\n const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;\n const resolvedImportUrl = new URL(\n resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,\n location.href,\n ).href;\n return `${keyword} ${quote}${resolvedImportUrl}${quote}`;\n },\n );\n const moduleBlobUrl = URL.createObjectURL(\n new Blob([content], { type: 'text/javascript' }),\n );\n const wrapperContent = [\n `import*as m from${JSON.stringify(moduleBlobUrl)};`,\n `globalThis.__rc_module_registry__=globalThis.__rc_module_registry__||{};`,\n `globalThis.__rc_module_registry__[${JSON.stringify(absoluteSrc)}]=m;`,\n ].join('');\n const wrapperBlobUrl = URL.createObjectURL(\n new Blob([wrapperContent], { type: 'text/javascript' }),\n );\n const scriptEl = document.createElement('script');\n scriptEl.type = 'module';\n scriptEl.src = wrapperBlobUrl;\n try {\n await new Promise<void>((resolve, reject) => {\n scriptEl.onload = () => resolve();\n scriptEl.onerror = () =>\n reject(new Error(`Failed to load module for ${absoluteSrc}`));\n document.head.appendChild(scriptEl);\n });\n } finally {\n scriptEl.remove();\n URL.revokeObjectURL(moduleBlobUrl);\n URL.revokeObjectURL(wrapperBlobUrl);\n }\n const registry = (\n globalThis as unknown as { __rc_module_registry__?: Record<string, T> }\n ).__rc_module_registry__;\n const mod = registry?.[absoluteSrc] ?? ({} as T);\n if (registry) delete registry[absoluteSrc];\n return mod;\n}\n\nasync function importDirectly<T>(absoluteSrc: string): Promise<T> {\n try {\n return (await import(\n /* @vite-ignore */\n /* webpackIgnore: true */ absoluteSrc\n )) as T;\n } catch (importError) {\n if (!absoluteSrc.startsWith('blob:')) {\n warnCrossOriginFetchError('StaticLoader', absoluteSrc);\n }\n throw importError;\n }\n}\n\nfunction resolveScriptSrc(script: HTMLScriptElement, url: URL): string {\n const rawSrc =\n typeof script.getAttribute === 'function'\n ? (script.getAttribute('src') ?? script.src)\n : script.src;\n if (!rawSrc && script.textContent) {\n return URL.createObjectURL(\n new Blob(\n [script.textContent.replace(/import\\.meta\\.url/g, JSON.stringify(url))],\n { type: 'text/javascript' },\n ),\n );\n }\n return rawSrc;\n}\n\nexport async function loadStaticRemoteComponent(\n scripts: HTMLScriptElement[],\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n const self = globalThis as typeof globalThis & MountUnmountFunctions;\n if (self.__remote_script_entrypoint_mount__?.[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n if (self.__remote_script_entrypoint_unmount__?.[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n const mountUnmountSets = await Promise.all(\n scripts.map(async (script) => {\n try {\n const src = resolveScriptSrc(script, url);\n const absoluteSrc = new URL(src, url).href;\n const mod: ScriptMod = resolveClientUrl\n ? await importViaCallback<ScriptMod>(absoluteSrc, resolveClientUrl)\n : await importDirectly<ScriptMod>(absoluteSrc);\n // revoke the object URL if we created one for inline script content\n if (src.startsWith('blob:')) {\n URL.revokeObjectURL(src);\n }\n if (\n typeof mod.mount === 'function' ||\n typeof mod.default?.mount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_mount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_mount__ = {};\n }\n if (!self.__remote_script_entrypoint_mount__[url.href]) {\n self.__remote_script_entrypoint_mount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_mount__[url.href]?.add(\n mod.mount ||\n mod.default?.mount ||\n (() => {\n // noop\n }),\n );\n }\n if (\n typeof mod.unmount === 'function' ||\n typeof mod.default?.unmount === 'function'\n ) {\n if (!self.__remote_script_entrypoint_unmount__) {\n // eslint-disable-next-line camelcase\n self.__remote_script_entrypoint_unmount__ = {};\n }\n if (!self.__remote_script_entrypoint_unmount__[url.href]) {\n self.__remote_script_entrypoint_unmount__[url.href] = new Set();\n }\n self.__remote_script_entrypoint_unmount__[url.href]?.add(\n mod.unmount ||\n mod.default?.unmount ||\n (() => {\n // noop\n }),\n );\n }\n return {\n mount: mod.mount || mod.default?.mount,\n unmount: mod.unmount || mod.default?.unmount,\n };\n } catch (e) {\n logError(\n 'StaticLoader',\n `Error loading remote component script from \"${script.src || url.href}\".`,\n e,\n );\n return {\n mount: undefined,\n unmount: undefined,\n };\n }\n }),\n );\n return mountUnmountSets.reduce(\n (acc, { mount, unmount }) => {\n if (typeof mount === 'function') {\n acc.mount.add(mount);\n }\n if (typeof unmount === 'function') {\n acc.unmount.add(unmount);\n }\n return acc;\n },\n {\n mount: new Set<MountOrUnmountFunction>(),\n unmount: new Set<MountOrUnmount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AAiB;AAAA,IACtB,CAAC,KAAK,EAAE,OAAO,QAAQ,MAAM;AAC3B,UAAI,OAAO,UAAU,YAAY;AAC/B,YAAI,MAAM,IAAI,KAAK;AAAA,MACrB;AACA,UAAI,OAAO,YAAY,YAAY;AACjC,YAAI,QAAQ,IAAI,OAAO;AAAA,MACzB;AACA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,MACE,OAAO,oBAAI,IAA4B;AAAA,MACvC,SAAS,oBAAI,IAA4B;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var metadata_exports = {};
16
+ module.exports = __toCommonJS(metadata_exports);
17
+ //# sourceMappingURL=metadata.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/metadata.ts"],"sourcesContent":["/**\n * Metadata embedded in the HTML response by a remote application.\n *\n * Extracted from a `<script type=\"application/json\" data-remote-component>`\n * element during both SSR parsing ({@link fetchRemoteComponent}) and\n * client-side parsing ({@link parseRemoteComponentDocument}).\n */\nexport interface RemoteComponentMetadata {\n bundle: string;\n route: string;\n runtime: 'webpack' | 'turbopack' | 'script';\n id: string;\n type: 'nextjs' | 'remote-component' | 'unknown';\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Metadata embedded in the HTML response by a remote application.
3
+ *
4
+ * Extracted from a `<script type="application/json" data-remote-component>`
5
+ * element during both SSR parsing ({@link fetchRemoteComponent}) and
6
+ * client-side parsing ({@link parseRemoteComponentDocument}).
7
+ */
8
+ interface RemoteComponentMetadata {
9
+ bundle: string;
10
+ route: string;
11
+ runtime: 'webpack' | 'turbopack' | 'script';
12
+ id: string;
13
+ type: 'nextjs' | 'remote-component' | 'unknown';
14
+ }
15
+
16
+ export { RemoteComponentMetadata };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var rsc_exports = {};
20
+ __export(rsc_exports, {
21
+ createRSCStream: () => createRSCStream
22
+ });
23
+ module.exports = __toCommonJS(rsc_exports);
24
+ var import_web_streams_polyfill = require("web-streams-polyfill");
25
+ function fixPayload(payload) {
26
+ if (Array.isArray(payload)) {
27
+ if (payload[0] === "$") {
28
+ fixPayload(payload[3]);
29
+ if (payload.length === 4) {
30
+ payload.push(null, null, 1);
31
+ }
32
+ } else {
33
+ for (const item of payload) {
34
+ fixPayload(item);
35
+ }
36
+ }
37
+ } else if (typeof payload === "object" && payload !== null) {
38
+ for (const key in payload) {
39
+ fixPayload(payload[key]);
40
+ }
41
+ }
42
+ }
43
+ function createRSCStream(rscName, data) {
44
+ return new import_web_streams_polyfill.ReadableStream({
45
+ type: "bytes",
46
+ start(controller) {
47
+ const encoder = new TextEncoder();
48
+ const self = globalThis;
49
+ if (data.length > 0) {
50
+ data.forEach((chunk) => {
51
+ const lines = chunk.split("\n");
52
+ for (const line of lines) {
53
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
54
+ if (match?.groups?.rsc) {
55
+ self[rscName] = self[rscName] ?? [];
56
+ self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
57
+ }
58
+ }
59
+ });
60
+ }
61
+ const allChunks = (self[rscName] ?? [`0:[null]
62
+ `]).join("");
63
+ self[rscName] = null;
64
+ allChunks.split("\n").forEach((chunk) => {
65
+ if (chunk.length > 0) {
66
+ const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
67
+ chunk
68
+ )?.groups ?? {};
69
+ if (payload) {
70
+ const jsonPayload = JSON.parse(payload);
71
+ fixPayload(jsonPayload);
72
+ const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
73
+ controller.enqueue(encoder.encode(`${reconstruct}
74
+ `));
75
+ } else {
76
+ controller.enqueue(encoder.encode(`${chunk}
77
+ `));
78
+ }
79
+ } else {
80
+ controller.enqueue(encoder.encode(`${chunk}
81
+ `));
82
+ }
83
+ });
84
+ controller.close();
85
+ }
86
+ });
87
+ }
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ createRSCStream
91
+ });
92
+ //# sourceMappingURL=rsc.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload to make it compatible with React JSX development runtime\n */\nfunction fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n // if the current node is a React element, we need to fix the payload\n if (payload[0] === '$') {\n // fix the props (children or other React elements)\n fixPayload(payload[3]);\n if (payload.length === 4) {\n // add placeholder for the missing debug info\n payload.push(null, null, 1);\n }\n } else {\n // we are in an array, continue with visiting each item\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n // we are in an object, continue with visiting each property\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // when the remote component RSC scripts are not found or loaded\n // we need to load the RSC flight data parsing the chunks\n if (data.length > 0) {\n data.forEach((chunk) => {\n const lines = chunk.split('\\n');\n for (const line of lines) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n });\n }\n\n // get the RSC flight data from the global scope\n // the RSC flight data is stored in an array\n // fallback to an empty RSC payload if the data is not found\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n\n // clear the RSC flight data from the global scope\n self[rscName] = null;\n\n // process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n // parse the chunk to get the id, prefix and payload\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n // parse the payload to a JSON object\n const jsonPayload = JSON.parse(payload) as unknown[];\n // fix the payload to make it compatible with React JSX development runtime\n fixPayload(jsonPayload);\n // reconstruct the chunk to a string\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n // encode the chunk to a byte buffer\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n // close the stream when all chunks are enqueued\n controller.close();\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAA+B;AAK/B,SAAS,WAAW,SAAwB;AAC1C,MAAI,MAAM,QAAQ,OAAO,GAAG;AAE1B,QAAI,QAAQ,CAAC,MAAM,KAAK;AAEtB,iBAAW,QAAQ,CAAC,CAAC;AACrB,UAAI,QAAQ,WAAW,GAAG;AAExB,gBAAQ,KAAK,MAAM,MAAM,CAAC;AAAA,MAC5B;AAAA,IACF,OAAO;AAEL,iBAAW,QAAQ,SAAS;AAC1B,mBAAW,IAAI;AAAA,MACjB;AAAA,IACF;AAAA,EACF,WAAW,OAAO,YAAY,YAAY,YAAY,MAAM;AAE1D,eAAW,OAAO,SAAS;AACzB,iBAAY,QAAoC,GAAG,CAAC;AAAA,IACtD;AAAA,EACF;AACF;AAKO,SAAS,gBACd,SACA,MAC4B;AAC5B,SAAO,IAAI,2CAAe;AAAA,IACxB,MAAM;AAAA,IACN,MAAM,YAAY;AAChB,YAAM,UAAU,IAAI,YAAY;AAChC,YAAM,OAAO;AAKb,UAAI,KAAK,SAAS,GAAG;AACnB,aAAK,QAAQ,CAAC,UAAU;AACtB,gBAAM,QAAQ,MAAM,MAAM,IAAI;AAC9B,qBAAW,QAAQ,OAAO;AACxB,kBAAM,QAAQ,2BAA2B,KAAK,IAAI;AAClD,gBAAI,OAAO,QAAQ,KAAK;AACtB,mBAAK,OAAO,IAAI,KAAK,OAAO,KAAK,CAAC;AAClC,mBAAK,OAAO,EAAE,KAAK,KAAK,MAAM,IAAI,MAAM,OAAO,MAAM,CAAW;AAAA,YAClE;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAKA,YAAM,aAAa,KAAK,OAAO,KAAK,CAAC;AAAA,CAAY,GAAG,KAAK,EAAE;AAG3D,WAAK,OAAO,IAAI;AAGhB,gBAAU,MAAM,IAAI,EAAE,QAAQ,CAAC,UAAU;AACvC,YAAI,MAAM,SAAS,GAAG;AAEpB,gBAAM,EAAE,QAAQ,IAAI,QAAQ,QAAQ,IAClC,6EAA6E;AAAA,YAC3E;AAAA,UACF,GAAG,UAAU,CAAC;AAEhB,cAAI,SAAS;AAEX,kBAAM,cAAc,KAAK,MAAM,OAAO;AAEtC,uBAAW,WAAW;AAEtB,kBAAM,cAAc,GAAG,UAAU,KAAK,MAAM,UAAU,KAAK,KAAK,UAAU,WAAW;AAErF,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAe,CAAC;AAAA,UACvD,OAAO;AAEL,uBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,UACjD;AAAA,QACF,OAAO;AAEL,qBAAW,QAAQ,QAAQ,OAAO,GAAG;AAAA,CAAS,CAAC;AAAA,QACjD;AAAA,MACF,CAAC;AAED,iBAAW,MAAM;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,8 @@
1
+ import { ReadableStream } from 'web-streams-polyfill';
2
+
3
+ /**
4
+ * Processes RSC flight data and creates a ReadableStream
5
+ */
6
+ declare function createRSCStream(rscName: string, data: string[]): ReadableStream<Uint8Array>;
7
+
8
+ export { createRSCStream };
@@ -0,0 +1,68 @@
1
+ import { ReadableStream } from "web-streams-polyfill";
2
+ function fixPayload(payload) {
3
+ if (Array.isArray(payload)) {
4
+ if (payload[0] === "$") {
5
+ fixPayload(payload[3]);
6
+ if (payload.length === 4) {
7
+ payload.push(null, null, 1);
8
+ }
9
+ } else {
10
+ for (const item of payload) {
11
+ fixPayload(item);
12
+ }
13
+ }
14
+ } else if (typeof payload === "object" && payload !== null) {
15
+ for (const key in payload) {
16
+ fixPayload(payload[key]);
17
+ }
18
+ }
19
+ }
20
+ function createRSCStream(rscName, data) {
21
+ return new ReadableStream({
22
+ type: "bytes",
23
+ start(controller) {
24
+ const encoder = new TextEncoder();
25
+ const self = globalThis;
26
+ if (data.length > 0) {
27
+ data.forEach((chunk) => {
28
+ const lines = chunk.split("\n");
29
+ for (const line of lines) {
30
+ const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
31
+ if (match?.groups?.rsc) {
32
+ self[rscName] = self[rscName] ?? [];
33
+ self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
34
+ }
35
+ }
36
+ });
37
+ }
38
+ const allChunks = (self[rscName] ?? [`0:[null]
39
+ `]).join("");
40
+ self[rscName] = null;
41
+ allChunks.split("\n").forEach((chunk) => {
42
+ if (chunk.length > 0) {
43
+ const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
44
+ chunk
45
+ )?.groups ?? {};
46
+ if (payload) {
47
+ const jsonPayload = JSON.parse(payload);
48
+ fixPayload(jsonPayload);
49
+ const reconstruct = `${before ?? ""}${id}:${prefix ?? ""}${JSON.stringify(jsonPayload)}`;
50
+ controller.enqueue(encoder.encode(`${reconstruct}
51
+ `));
52
+ } else {
53
+ controller.enqueue(encoder.encode(`${chunk}
54
+ `));
55
+ }
56
+ } else {
57
+ controller.enqueue(encoder.encode(`${chunk}
58
+ `));
59
+ }
60
+ });
61
+ controller.close();
62
+ }
63
+ });
64
+ }
65
+ export {
66
+ createRSCStream
67
+ };
68
+ //# sourceMappingURL=rsc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/rsc.ts"],"sourcesContent":["import { ReadableStream } from 'web-streams-polyfill';\n\n/**\n * Fixes RSC payload to make it compatible with React JSX development runtime\n */\nfunction fixPayload(payload: unknown): void {\n if (Array.isArray(payload)) {\n // if the current node is a React element, we need to fix the payload\n if (payload[0] === '$') {\n // fix the props (children or other React elements)\n fixPayload(payload[3]);\n if (payload.length === 4) {\n // add placeholder for the missing debug info\n payload.push(null, null, 1);\n }\n } else {\n // we are in an array, continue with visiting each item\n for (const item of payload) {\n fixPayload(item);\n }\n }\n } else if (typeof payload === 'object' && payload !== null) {\n // we are in an object, continue with visiting each property\n for (const key in payload) {\n fixPayload((payload as Record<string, unknown>)[key]);\n }\n }\n}\n\n/**\n * Processes RSC flight data and creates a ReadableStream\n */\nexport function createRSCStream(\n rscName: string,\n data: string[],\n): ReadableStream<Uint8Array> {\n return new ReadableStream({\n type: 'bytes',\n start(controller) {\n const encoder = new TextEncoder();\n const self = globalThis as typeof globalThis &\n Record<string, string[] | null>;\n\n // when the remote component RSC scripts are not found or loaded\n // we need to load the RSC flight data parsing the chunks\n if (data.length > 0) {\n data.forEach((chunk) => {\n const lines = chunk.split('\\n');\n for (const line of lines) {\n const match = /\\.push\\(\"(?<rsc>.*)\"\\);$/.exec(line);\n if (match?.groups?.rsc) {\n self[rscName] = self[rscName] ?? [];\n self[rscName].push(JSON.parse(`\"${match.groups.rsc}\"`) as string);\n }\n }\n });\n }\n\n // get the RSC flight data from the global scope\n // the RSC flight data is stored in an array\n // fallback to an empty RSC payload if the data is not found\n const allChunks = (self[rscName] ?? [`0:[null]\\n`]).join('');\n\n // clear the RSC flight data from the global scope\n self[rscName] = null;\n\n // process each line in the RSC flight data\n allChunks.split('\\n').forEach((chunk) => {\n if (chunk.length > 0) {\n // parse the chunk to get the id, prefix and payload\n const { before, id, prefix, payload } =\n /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\\[.*\\])/.exec(\n chunk,\n )?.groups ?? {};\n\n if (payload) {\n // parse the payload to a JSON object\n const jsonPayload = JSON.parse(payload) as unknown[];\n // fix the payload to make it compatible with React JSX development runtime\n fixPayload(jsonPayload);\n // reconstruct the chunk to a string\n const reconstruct = `${before ?? ''}${id}:${prefix ?? ''}${JSON.stringify(jsonPayload)}`;\n // encode the chunk to a byte buffer\n controller.enqueue(encoder.encode(`${reconstruct}\\n`));\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n } else {\n // add empty line before closing the stream\n controller.enqueue(encoder.encode(`${chunk}\\n`));\n }\n });\n // close the stream when all chunks are enqueued\n controller.close();\n },\n });\n}\n"],"mappings":"AAAA,SAAS,sBAAsB;AAK/B,SAAS,WAAW,SAAwB;AAC1C,MAAI,MAAM,QAAQ,OAAO,GAAG;AAE1B,QAAI,QAAQ,CAAC,MAAM,KAAK;AAEtB,iBAAW,QAAQ,CAAC,CAAC;AACrB,UAAI,QAAQ,WAAW,GAAG;AAExB,gBAAQ,KAAK,MAAM,MAAM,CAAC;AAAA,MAC5B;AAAA,IACF,OAAO;AAEL,iBAAW,QAAQ,SAAS;AAC1B,mBAAW,IAAI;AAAA,MACjB;AAAA,IACF;AAAA,EACF,WAAW,OAAO,YAAY,YAAY,YAAY,MAAM;AAE1D,eAAW,OAAO,SAAS;AACzB,iBAAY,QAAoC,GAAG,CAAC;AAAA,IACtD;AAAA,EACF;AACF;AAKO,SAAS,gBACd,SACA,MAC4B;AAC5B,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM;AAAA,IACN,MAAM,YAAY;AAChB,YAAM,UAAU,IAAI,YAAY;AAChC,YAAM,OAAO;AAKb,UAAI,KAAK,SAAS,GAAG;AACnB,aAAK,QAAQ,CAAC,UAAU;AACtB,gBAAM,QAAQ,MAAM,MAAM,IAAI;AAC9B,qBAAW,QAAQ,OAAO;AACxB,kBAAM,QAAQ,2BAA2B,KAAK,IAAI;AAClD,gBAAI,OAAO,QAAQ,KAAK;AACtB,mBAAK,OAAO,IAAI,KAAK,OAAO,K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