vite-plugin-react-server 0.3.4 → 0.3.6

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 (484) hide show
  1. package/README.md +113 -222
  2. package/bin/patch.mjs +84 -0
  3. package/dist/client.d.ts +3 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +7 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/index.d.ts +7 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +32 -3
  10. package/dist/index.js.map +1 -1
  11. package/dist/node_modules/magic-string/dist/magic-string.es.js +1283 -0
  12. package/dist/node_modules/magic-string/dist/magic-string.es.js.map +1 -0
  13. package/dist/package.json +130 -0
  14. package/dist/plugin/assertServerCondition.d.ts.map +1 -0
  15. package/dist/plugin/assertServerCondition.js +15 -0
  16. package/dist/plugin/build/createClientBuildConfig.d.ts +3 -0
  17. package/dist/plugin/build/createClientBuildConfig.d.ts.map +1 -0
  18. package/dist/plugin/build/createClientBuildConfig.js +14 -0
  19. package/dist/plugin/build/createServerBuildConfig.d.ts +12 -0
  20. package/dist/plugin/build/createServerBuildConfig.d.ts.map +1 -0
  21. package/dist/plugin/build/createServerBuildConfig.js +40 -0
  22. package/dist/plugin/build/createSharedBuildConfig.d.ts +5 -0
  23. package/dist/plugin/build/createSharedBuildConfig.d.ts.map +1 -0
  24. package/dist/plugin/build/createSharedBuildConfig.js +28 -0
  25. package/dist/plugin/build/mergeInputs.d.ts +9 -0
  26. package/dist/plugin/build/mergeInputs.d.ts.map +1 -0
  27. package/dist/plugin/build/mergeInputs.js +56 -0
  28. package/dist/plugin/checkFilesExist.d.ts +3 -0
  29. package/dist/plugin/checkFilesExist.d.ts.map +1 -0
  30. package/dist/plugin/checkFilesExist.js +78 -0
  31. package/dist/plugin/checkFilesExist.js.map +1 -0
  32. package/dist/{collect-css-manifest.d.ts → plugin/collect-css-manifest.d.ts} +2 -2
  33. package/dist/plugin/collect-css-manifest.d.ts.map +1 -0
  34. package/dist/{src → plugin}/collect-css-manifest.js +8 -5
  35. package/dist/plugin/collect-css-manifest.js.map +1 -0
  36. package/dist/plugin/components.d.ts.map +1 -0
  37. package/dist/{src → plugin}/components.js +9 -4
  38. package/dist/plugin/components.js.map +1 -0
  39. package/dist/plugin/config/defaults.d.ts +51 -0
  40. package/dist/plugin/config/defaults.d.ts.map +1 -0
  41. package/dist/plugin/config/defaults.js +52 -0
  42. package/dist/plugin/config/defaults.js.map +1 -0
  43. package/dist/plugin/config/getCondition.d.ts +2 -0
  44. package/dist/plugin/config/getCondition.d.ts.map +1 -0
  45. package/dist/plugin/config/getCondition.js +11 -0
  46. package/dist/plugin/config/getCondition.js.map +1 -0
  47. package/dist/plugin/config/getPaths.d.ts +5 -0
  48. package/dist/plugin/config/getPaths.d.ts.map +1 -0
  49. package/dist/plugin/config/getPaths.js +21 -0
  50. package/dist/plugin/config/getPaths.js.map +1 -0
  51. package/dist/plugin/config/getWorkerPath.d.ts +2 -0
  52. package/dist/plugin/config/getWorkerPath.d.ts.map +1 -0
  53. package/dist/plugin/config/getWorkerPath.js +4 -0
  54. package/dist/plugin/config/index.d.ts +8 -0
  55. package/dist/plugin/config/index.d.ts.map +1 -0
  56. package/dist/plugin/config/index.js +7 -0
  57. package/dist/plugin/config/moduleIdDefault.d.ts +8 -0
  58. package/dist/plugin/config/moduleIdDefault.d.ts.map +1 -0
  59. package/dist/plugin/config/moduleIdDefault.js +23 -0
  60. package/dist/plugin/config/moduleIdDefault.js.map +1 -0
  61. package/dist/plugin/config/resolveOptions.d.ts +9 -0
  62. package/dist/plugin/config/resolveOptions.d.ts.map +1 -0
  63. package/dist/plugin/config/resolveOptions.js +56 -0
  64. package/dist/plugin/config/resolveOptions.js.map +1 -0
  65. package/dist/plugin/config/resolvePages.d.ts +9 -0
  66. package/dist/plugin/config/resolvePages.d.ts.map +1 -0
  67. package/dist/plugin/config/resolvePages.js +38 -0
  68. package/dist/plugin/config/resolvePages.js.map +1 -0
  69. package/dist/plugin/config/resolveUserConfig.d.ts +18 -0
  70. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -0
  71. package/dist/plugin/config/resolveUserConfig.js +84 -0
  72. package/dist/plugin/config/resolveUserConfig.js.map +1 -0
  73. package/dist/plugin/copy-dir.d.ts.map +1 -0
  74. package/dist/plugin/copy-dir.js +20 -0
  75. package/dist/plugin/getCondition.d.ts +2 -0
  76. package/dist/plugin/getCondition.d.ts.map +1 -0
  77. package/dist/plugin/getCondition.js +1 -0
  78. package/dist/plugin/getEnv.d.ts.map +1 -0
  79. package/dist/plugin/getEnv.js +107 -0
  80. package/dist/plugin/helpers/createClientInputNormalizer.d.ts +8 -0
  81. package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +1 -0
  82. package/dist/plugin/helpers/createClientInputNormalizer.js +35 -0
  83. package/dist/plugin/helpers/createServerInputNormalizer.d.ts +9 -0
  84. package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +1 -0
  85. package/dist/plugin/helpers/createServerInputNormalizer.js +37 -0
  86. package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +7 -0
  87. package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +1 -0
  88. package/dist/plugin/helpers/createStaticInputNormalizer.js +18 -0
  89. package/dist/plugin/helpers/getModuleManifest.d.ts +12 -0
  90. package/dist/plugin/helpers/getModuleManifest.d.ts.map +1 -0
  91. package/dist/plugin/helpers/getModuleManifest.js +24 -0
  92. package/dist/plugin/helpers/getModuleManifest.js.map +1 -0
  93. package/dist/plugin/helpers/inputNormalizer.d.ts +3 -0
  94. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -0
  95. package/dist/plugin/helpers/inputNormalizer.js +35 -0
  96. package/dist/plugin/helpers/inputNormalizer.js.map +1 -0
  97. package/dist/plugin/helpers/inputNormalizerWorker.d.ts +11 -0
  98. package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +1 -0
  99. package/dist/plugin/helpers/inputNormalizerWorker.js +30 -0
  100. package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +1 -0
  101. package/dist/plugin/helpers/normalizedRelativePath.js +36 -0
  102. package/dist/plugin/helpers/resolveFilePath.d.ts +13 -0
  103. package/dist/plugin/helpers/resolveFilePath.d.ts.map +1 -0
  104. package/dist/plugin/helpers/resolveFilePath.js +74 -0
  105. package/dist/plugin/helpers/resolveWorkerModule.d.ts +6 -0
  106. package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +1 -0
  107. package/dist/plugin/helpers/resolveWorkerModule.js +24 -0
  108. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -0
  109. package/dist/{src → plugin}/helpers/tryManifest.js +11 -6
  110. package/dist/plugin/helpers/tryManifest.js.map +1 -0
  111. package/dist/plugin/helpers/validateModuleBase.d.ts +3 -0
  112. package/dist/plugin/helpers/validateModuleBase.d.ts.map +1 -0
  113. package/dist/plugin/helpers/validateModuleBase.js +16 -0
  114. package/dist/plugin/helpers/validateResolvedConfig.d.ts +3 -0
  115. package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +1 -0
  116. package/dist/plugin/helpers/validateResolvedConfig.js +17 -0
  117. package/dist/plugin/index.d.ts +3 -0
  118. package/dist/plugin/index.d.ts.map +1 -0
  119. package/dist/plugin/index.js +1 -0
  120. package/dist/plugin/loader/createBuildLoader.d.ts +9 -0
  121. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -0
  122. package/dist/plugin/loader/createBuildLoader.js +38 -0
  123. package/dist/plugin/loader/createBuildLoader.js.map +1 -0
  124. package/dist/plugin/loader/createCssLoader.d.ts +30 -0
  125. package/dist/plugin/loader/createCssLoader.d.ts.map +1 -0
  126. package/dist/plugin/loader/createCssLoader.js +35 -0
  127. package/dist/{html → plugin/loader}/createPageLoader.d.ts +2 -4
  128. package/dist/plugin/loader/createPageLoader.d.ts.map +1 -0
  129. package/dist/plugin/loader/createPageLoader.js +57 -0
  130. package/dist/plugin/manifest.d.ts.map +1 -0
  131. package/dist/plugin/manifest.js +13 -0
  132. package/dist/plugin/module-graph.d.ts.map +1 -0
  133. package/dist/plugin/module-graph.js +35 -0
  134. package/dist/plugin/plugin.d.ts +7 -0
  135. package/dist/plugin/plugin.d.ts.map +1 -0
  136. package/dist/plugin/plugin.js +8 -0
  137. package/dist/plugin/preserver/index.d.ts +2 -0
  138. package/dist/plugin/preserver/index.d.ts.map +1 -0
  139. package/dist/plugin/preserver/index.js +1 -0
  140. package/dist/plugin/preserver/plugin.d.ts +3 -0
  141. package/dist/plugin/preserver/plugin.d.ts.map +1 -0
  142. package/dist/plugin/preserver/plugin.js +90 -0
  143. package/dist/plugin/preserver/plugin.js.map +1 -0
  144. package/dist/plugin/react-client/index.d.ts +2 -0
  145. package/dist/plugin/react-client/index.d.ts.map +1 -0
  146. package/dist/plugin/react-client/index.js +1 -0
  147. package/dist/plugin/react-client/plugin.d.ts +4 -0
  148. package/dist/plugin/react-client/plugin.d.ts.map +1 -0
  149. package/dist/plugin/react-client/plugin.js +34 -0
  150. package/dist/plugin/react-client/plugin.js.map +1 -0
  151. package/dist/plugin/react-server/createDevMiddleware.d.ts.map +1 -0
  152. package/dist/plugin/react-server/createDevMiddleware.js +68 -0
  153. package/dist/plugin/react-server/createDevServer.d.ts.map +1 -0
  154. package/dist/plugin/react-server/createDevServer.js +4 -0
  155. package/dist/plugin/react-server/createHandler.d.ts +17 -0
  156. package/dist/plugin/react-server/createHandler.d.ts.map +1 -0
  157. package/dist/{src → plugin}/react-server/createHandler.js +28 -17
  158. package/dist/plugin/react-server/createHandler.js.map +1 -0
  159. package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +1 -0
  160. package/dist/plugin/react-server/createReactNodeStreamer.js +7 -0
  161. package/dist/{react-server → plugin/react-server}/createRscStream.d.ts +1 -1
  162. package/dist/plugin/react-server/createRscStream.d.ts.map +1 -0
  163. package/dist/{src → plugin}/react-server/createRscStream.js +14 -13
  164. package/dist/plugin/react-server/createRscStream.js.map +1 -0
  165. package/dist/{react-server → plugin/react-server}/createSsrHandler.d.ts +1 -1
  166. package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -0
  167. package/dist/plugin/react-server/createSsrHandler.js +102 -0
  168. package/dist/plugin/react-server/index.d.ts +3 -0
  169. package/dist/plugin/react-server/index.d.ts.map +1 -0
  170. package/dist/plugin/react-server/index.js +10 -0
  171. package/dist/plugin/react-server/plugin.d.ts +7 -0
  172. package/dist/plugin/react-server/plugin.d.ts.map +1 -0
  173. package/dist/plugin/react-server/plugin.js +377 -0
  174. package/dist/plugin/react-server/plugin.js.map +1 -0
  175. package/dist/plugin/resolvePage.d.ts.map +1 -0
  176. package/dist/{src → plugin}/resolvePage.js +8 -4
  177. package/dist/plugin/resolvePage.js.map +1 -0
  178. package/dist/plugin/resolveProps.d.ts.map +1 -0
  179. package/dist/{src → plugin}/resolveProps.js +21 -8
  180. package/dist/plugin/resolveProps.js.map +1 -0
  181. package/dist/plugin/server.d.ts +2 -0
  182. package/dist/plugin/server.d.ts.map +1 -0
  183. package/dist/plugin/server.js +1 -0
  184. package/dist/plugin/transformer/index.d.ts +2 -0
  185. package/dist/plugin/transformer/index.d.ts.map +1 -0
  186. package/dist/plugin/transformer/index.js +1 -0
  187. package/dist/{transformer/index.d.ts → plugin/transformer/plugin.d.ts} +3 -4
  188. package/dist/plugin/transformer/plugin.d.ts.map +1 -0
  189. package/dist/plugin/transformer/plugin.js +94 -0
  190. package/dist/plugin/transformer/plugin.js.map +1 -0
  191. package/dist/plugin/transformer/transformer-client-components.d.ts +21 -0
  192. package/dist/plugin/transformer/transformer-client-components.d.ts.map +1 -0
  193. package/dist/plugin/transformer/transformer-client-components.js +61 -0
  194. package/dist/plugin/transformer/transformer-client-components.js.map +1 -0
  195. package/dist/{transformer/transformer.d.ts → plugin/transformer/transformer-server-actions.d.ts} +3 -4
  196. package/dist/plugin/transformer/transformer-server-actions.d.ts.map +1 -0
  197. package/dist/plugin/transformer/transformer-server-actions.js +76 -0
  198. package/dist/plugin/transformer/transformer-server-actions.js.map +1 -0
  199. package/dist/plugin/transformer/types.d.ts.map +1 -0
  200. package/dist/plugin/transformer/types.js +1 -0
  201. package/dist/plugin/types.d.ts +225 -0
  202. package/dist/plugin/types.d.ts.map +1 -0
  203. package/dist/plugin/types.js +1 -0
  204. package/dist/plugin/worker/createWorker.d.ts +15 -0
  205. package/dist/plugin/worker/createWorker.d.ts.map +1 -0
  206. package/dist/plugin/worker/createWorker.js +71 -0
  207. package/dist/plugin/worker/createWorker.js.map +1 -0
  208. package/dist/plugin/worker/html/html-worker.d.ts +2 -0
  209. package/dist/plugin/worker/html/html-worker.d.ts.map +1 -0
  210. package/dist/plugin/worker/html/html-worker.development.d.ts +2 -0
  211. package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -0
  212. package/dist/plugin/worker/html/html-worker.development.js +12 -0
  213. package/dist/plugin/worker/html/html-worker.development.js.map +1 -0
  214. package/dist/plugin/worker/html/html-worker.js +4 -0
  215. package/dist/plugin/worker/html/html-worker.production.d.ts +2 -0
  216. package/dist/plugin/worker/html/html-worker.production.d.ts.map +1 -0
  217. package/dist/plugin/worker/html/html-worker.production.js +12 -0
  218. package/dist/plugin/worker/html/html-worker.production.js.map +1 -0
  219. package/dist/plugin/worker/html/index.d.ts +2 -0
  220. package/dist/plugin/worker/html/index.d.ts.map +1 -0
  221. package/dist/plugin/worker/html/index.js +7 -0
  222. package/dist/plugin/worker/html/index.js.map +1 -0
  223. package/dist/plugin/worker/html/messageHandler.d.ts +3 -0
  224. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -0
  225. package/dist/plugin/worker/html/messageHandler.js +98 -0
  226. package/dist/plugin/worker/html/messageHandler.js.map +1 -0
  227. package/dist/plugin/worker/html/plugin.d.ts +4 -0
  228. package/dist/plugin/worker/html/plugin.d.ts.map +1 -0
  229. package/dist/plugin/worker/html/plugin.js +89 -0
  230. package/dist/plugin/worker/html/renderPages.d.ts +38 -0
  231. package/dist/plugin/worker/html/renderPages.d.ts.map +1 -0
  232. package/dist/plugin/worker/html/renderPages.js +123 -0
  233. package/dist/plugin/worker/html/renderPages.js.map +1 -0
  234. package/dist/plugin/worker/loader.d.ts.map +1 -0
  235. package/dist/plugin/worker/loader.js +11 -0
  236. package/dist/plugin/worker/loader.js.map +1 -0
  237. package/dist/plugin/worker/plugin.d.ts +10 -0
  238. package/dist/plugin/worker/plugin.d.ts.map +1 -0
  239. package/dist/plugin/worker/plugin.js +14 -0
  240. package/dist/plugin/worker/rsc/createRscStream.d.ts +5 -0
  241. package/dist/plugin/worker/rsc/createRscStream.d.ts.map +1 -0
  242. package/dist/plugin/worker/rsc/createRscStream.js +39 -0
  243. package/dist/plugin/worker/rsc/createRscStream.js.map +1 -0
  244. package/dist/plugin/worker/rsc/development.d.ts +5 -0
  245. package/dist/plugin/worker/rsc/development.d.ts.map +1 -0
  246. package/dist/plugin/worker/rsc/development.js +13 -0
  247. package/dist/plugin/worker/rsc/development.js.map +1 -0
  248. package/dist/plugin/worker/rsc/index.d.ts +4 -0
  249. package/dist/plugin/worker/rsc/index.d.ts.map +1 -0
  250. package/dist/plugin/worker/rsc/index.js +15 -0
  251. package/dist/plugin/worker/rsc/index.js.map +1 -0
  252. package/dist/plugin/worker/rsc/plugin.d.ts +4 -0
  253. package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -0
  254. package/dist/plugin/worker/rsc/plugin.js +82 -0
  255. package/dist/plugin/worker/rsc/plugin.js.map +1 -0
  256. package/dist/plugin/worker/rsc/production.d.ts +5 -0
  257. package/dist/plugin/worker/rsc/production.d.ts.map +1 -0
  258. package/dist/plugin/worker/rsc/production.js +13 -0
  259. package/dist/plugin/worker/rsc/production.js.map +1 -0
  260. package/dist/plugin/worker/rsc/rsc-worker.d.ts +2 -0
  261. package/dist/plugin/worker/rsc/rsc-worker.d.ts.map +1 -0
  262. package/dist/plugin/worker/rsc/rsc-worker.js +106 -0
  263. package/dist/plugin/worker/types.d.ts +99 -0
  264. package/dist/plugin/worker/types.d.ts.map +1 -0
  265. package/dist/plugin/worker/types.js +1 -0
  266. package/dist/server.d.ts +4 -1
  267. package/dist/server.d.ts.map +1 -1
  268. package/dist/server.js +9 -0
  269. package/dist/server.js.map +1 -0
  270. package/dist/tsconfig.tsbuildinfo +1 -0
  271. package/dist/types.d.ts +1 -201
  272. package/dist/types.d.ts.map +1 -1
  273. package/dist/types.js +1 -0
  274. package/package.json +42 -25
  275. package/plugin/build/createClientBuildConfig.ts +21 -0
  276. package/plugin/build/createServerBuildConfig.ts +66 -0
  277. package/plugin/build/createSharedBuildConfig.ts +35 -0
  278. package/plugin/build/mergeInputs.ts +58 -0
  279. package/plugin/checkFilesExist.ts +82 -0
  280. package/{src → plugin}/collect-css-manifest.ts +4 -2
  281. package/plugin/config/defaults.ts +44 -0
  282. package/plugin/config/getCondition.ts +3 -0
  283. package/plugin/config/getPaths.ts +25 -0
  284. package/plugin/config/getWorkerPath.ts +5 -0
  285. package/plugin/config/index.ts +8 -0
  286. package/plugin/config/moduleIdDefault.ts +23 -0
  287. package/plugin/config/resolveOptions.ts +53 -0
  288. package/plugin/config/resolvePages.ts +43 -0
  289. package/plugin/config/resolveUserConfig.ts +97 -0
  290. package/{src → plugin}/getEnv.ts +1 -1
  291. package/plugin/helpers/createClientInputNormalizer.ts +48 -0
  292. package/plugin/helpers/createServerInputNormalizer.ts +52 -0
  293. package/plugin/helpers/createStaticInputNormalizer.ts +26 -0
  294. package/plugin/helpers/getModuleManifest.ts +31 -0
  295. package/plugin/helpers/inputNormalizer.ts +39 -0
  296. package/plugin/helpers/inputNormalizerWorker.ts +47 -0
  297. package/plugin/helpers/resolveFilePath.ts +108 -0
  298. package/plugin/helpers/resolveWorkerModule.ts +41 -0
  299. package/plugin/helpers/validateModuleBase.ts +30 -0
  300. package/plugin/helpers/validateResolvedConfig.ts +21 -0
  301. package/plugin/index.ts +2 -0
  302. package/plugin/loader/createBuildLoader.ts +44 -0
  303. package/plugin/loader/createCssLoader.ts +73 -0
  304. package/{src/html → plugin/loader}/createPageLoader.ts +35 -27
  305. package/plugin/plugin.ts +8 -0
  306. package/plugin/preserver/index.ts +1 -0
  307. package/plugin/preserver/plugin.ts +109 -0
  308. package/plugin/react-client/index.ts +1 -0
  309. package/plugin/react-client/plugin.ts +33 -0
  310. package/{src → plugin}/react-server/createDevMiddleware.ts +17 -1
  311. package/{src → plugin}/react-server/createDevServer.ts +0 -1
  312. package/{src → plugin}/react-server/createHandler.ts +31 -10
  313. package/{src → plugin}/react-server/createReactNodeStreamer.ts +1 -0
  314. package/{src → plugin}/react-server/createRscStream.ts +8 -12
  315. package/{src → plugin}/react-server/createSsrHandler.ts +16 -19
  316. package/plugin/react-server/index.ts +12 -0
  317. package/plugin/react-server/plugin.ts +464 -0
  318. package/{src → plugin}/resolvePage.ts +1 -1
  319. package/{src → plugin}/resolveProps.ts +15 -6
  320. package/plugin/server.tsx +0 -0
  321. package/plugin/transformer/index.ts +1 -0
  322. package/plugin/transformer/plugin.ts +141 -0
  323. package/plugin/transformer/transformer-client-components.ts +94 -0
  324. package/{src/transformer/transformer.ts → plugin/transformer/transformer-server-actions.ts} +14 -27
  325. package/{src → plugin}/types.ts +97 -55
  326. package/plugin/worker/createWorker.ts +84 -0
  327. package/plugin/worker/html/html-worker.development.tsx +8 -0
  328. package/plugin/worker/html/html-worker.production.tsx +8 -0
  329. package/plugin/worker/html/html-worker.ts +5 -0
  330. package/plugin/worker/html/index.ts +5 -0
  331. package/plugin/worker/html/messageHandler.ts +116 -0
  332. package/plugin/worker/html/plugin.ts +97 -0
  333. package/plugin/worker/html/renderPages.ts +188 -0
  334. package/plugin/worker/plugin.ts +17 -0
  335. package/plugin/worker/rsc/createRscStream.ts +42 -0
  336. package/plugin/worker/rsc/development.ts +6 -0
  337. package/plugin/worker/rsc/index.ts +14 -0
  338. package/plugin/worker/rsc/plugin.ts +83 -0
  339. package/plugin/worker/rsc/production.ts +6 -0
  340. package/plugin/worker/rsc/rsc-worker.tsx +128 -0
  341. package/plugin/worker/types.ts +124 -0
  342. package/scripts/check-react-version.mjs +48 -30
  343. package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +4291 -0
  344. package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +108798 -0
  345. package/scripts/react-server-dom-esm+0.0.0-experimental-b3a95caf-20250113.patch +24775 -0
  346. package/{patches → scripts}/react-server-dom-esm+0.0.1.patch +11354 -3
  347. package/tsconfig.json +15 -13
  348. package/dist/assertServerCondition.d.ts.map +0 -1
  349. package/dist/bin/patch.js +0 -51
  350. package/dist/bin/patch.js.map +0 -1
  351. package/dist/build/createBuildConfig.d.ts +0 -13
  352. package/dist/build/createBuildConfig.d.ts.map +0 -1
  353. package/dist/build/mergeInputs.d.ts +0 -5
  354. package/dist/build/mergeInputs.d.ts.map +0 -1
  355. package/dist/checkFilesExist.d.ts +0 -8
  356. package/dist/checkFilesExist.d.ts.map +0 -1
  357. package/dist/collect-css-manifest.d.ts.map +0 -1
  358. package/dist/components.d.ts.map +0 -1
  359. package/dist/copy-dir.d.ts.map +0 -1
  360. package/dist/getEnv.d.ts.map +0 -1
  361. package/dist/helpers/inputNormalizer.d.ts +0 -6
  362. package/dist/helpers/inputNormalizer.d.ts.map +0 -1
  363. package/dist/helpers/normalizedRelativePath.d.ts.map +0 -1
  364. package/dist/helpers/tryManifest.d.ts.map +0 -1
  365. package/dist/html/createPageLoader.d.ts.map +0 -1
  366. package/dist/manifest.d.ts.map +0 -1
  367. package/dist/module-graph.d.ts.map +0 -1
  368. package/dist/options.d.ts +0 -91
  369. package/dist/options.d.ts.map +0 -1
  370. package/dist/plugin.d.ts +0 -3
  371. package/dist/plugin.d.ts.map +0 -1
  372. package/dist/react-client/plugin.d.ts +0 -4
  373. package/dist/react-client/plugin.d.ts.map +0 -1
  374. package/dist/react-client/plugin.js +0 -28
  375. package/dist/react-client/plugin.js.map +0 -1
  376. package/dist/react-server/createDevMiddleware.d.ts.map +0 -1
  377. package/dist/react-server/createDevServer.d.ts.map +0 -1
  378. package/dist/react-server/createHandler.d.ts +0 -23
  379. package/dist/react-server/createHandler.d.ts.map +0 -1
  380. package/dist/react-server/createReactNodeStreamer.d.ts.map +0 -1
  381. package/dist/react-server/createRscStream.d.ts.map +0 -1
  382. package/dist/react-server/createSsrHandler.d.ts.map +0 -1
  383. package/dist/react-server/plugin.d.ts +0 -8
  384. package/dist/react-server/plugin.d.ts.map +0 -1
  385. package/dist/react-server/plugin.js +0 -345
  386. package/dist/react-server/plugin.js.map +0 -1
  387. package/dist/resolvePage.d.ts.map +0 -1
  388. package/dist/resolveProps.d.ts.map +0 -1
  389. package/dist/scripts/check-react-version.js +0 -34
  390. package/dist/scripts/check-react-version.js.map +0 -1
  391. package/dist/src/build/createBuildConfig.js +0 -44
  392. package/dist/src/build/createBuildConfig.js.map +0 -1
  393. package/dist/src/build/mergeInputs.js +0 -16
  394. package/dist/src/build/mergeInputs.js.map +0 -1
  395. package/dist/src/checkFilesExist.js +0 -61
  396. package/dist/src/checkFilesExist.js.map +0 -1
  397. package/dist/src/collect-css-manifest.js.map +0 -1
  398. package/dist/src/components.js.map +0 -1
  399. package/dist/src/getEnv.js +0 -76
  400. package/dist/src/getEnv.js.map +0 -1
  401. package/dist/src/helpers/inputNormalizer.js +0 -11
  402. package/dist/src/helpers/inputNormalizer.js.map +0 -1
  403. package/dist/src/helpers/normalizedRelativePath.js +0 -34
  404. package/dist/src/helpers/normalizedRelativePath.js.map +0 -1
  405. package/dist/src/helpers/tryManifest.js.map +0 -1
  406. package/dist/src/html/createPageLoader.js +0 -72
  407. package/dist/src/html/createPageLoader.js.map +0 -1
  408. package/dist/src/options.js +0 -307
  409. package/dist/src/options.js.map +0 -1
  410. package/dist/src/react-server/createHandler.js.map +0 -1
  411. package/dist/src/react-server/createRscStream.js.map +0 -1
  412. package/dist/src/resolvePage.js.map +0 -1
  413. package/dist/src/resolveProps.js.map +0 -1
  414. package/dist/src/worker/createHtmlStream.js +0 -62
  415. package/dist/src/worker/createHtmlStream.js.map +0 -1
  416. package/dist/src/worker/createWorker.js +0 -34
  417. package/dist/src/worker/createWorker.js.map +0 -1
  418. package/dist/src/worker/renderPages.js +0 -99
  419. package/dist/src/worker/renderPages.js.map +0 -1
  420. package/dist/transformer/index.d.ts.map +0 -1
  421. package/dist/transformer/preserveDirectives.d.ts +0 -4
  422. package/dist/transformer/preserveDirectives.d.ts.map +0 -1
  423. package/dist/transformer/preserver.d.ts +0 -2
  424. package/dist/transformer/preserver.d.ts.map +0 -1
  425. package/dist/transformer/transformer.d.ts.map +0 -1
  426. package/dist/transformer/types.d.ts.map +0 -1
  427. package/dist/worker/createHtmlStream.d.ts +0 -7
  428. package/dist/worker/createHtmlStream.d.ts.map +0 -1
  429. package/dist/worker/createWorker.d.ts +0 -10
  430. package/dist/worker/createWorker.d.ts.map +0 -1
  431. package/dist/worker/loader.d.ts.map +0 -1
  432. package/dist/worker/loader.js +0 -7
  433. package/dist/worker/loader.js.map +0 -1
  434. package/dist/worker/renderPages.d.ts +0 -18
  435. package/dist/worker/renderPages.d.ts.map +0 -1
  436. package/dist/worker/types.d.ts +0 -31
  437. package/dist/worker/types.d.ts.map +0 -1
  438. package/dist/worker/worker.d.ts +0 -7
  439. package/dist/worker/worker.d.ts.map +0 -1
  440. package/dist/worker/worker.js +0 -112
  441. package/dist/worker/worker.js.map +0 -1
  442. package/src/build/createBuildConfig.ts +0 -57
  443. package/src/build/mergeInputs.ts +0 -42
  444. package/src/checkFilesExist.ts +0 -67
  445. package/src/helpers/inputNormalizer.ts +0 -22
  446. package/src/index.ts +0 -4
  447. package/src/options.ts +0 -423
  448. package/src/plugin.ts +0 -5
  449. package/src/react-client/plugin.ts +0 -34
  450. package/src/react-server/plugin.ts +0 -409
  451. package/src/transformer/index.ts +0 -112
  452. package/src/transformer/preserveDirectives.ts +0 -100
  453. package/src/transformer/preserver.ts +0 -47
  454. package/src/worker/createHtmlStream.ts +0 -76
  455. package/src/worker/createWorker.ts +0 -44
  456. package/src/worker/renderPages.ts +0 -144
  457. package/src/worker/types.ts +0 -38
  458. package/src/worker/worker.tsx +0 -136
  459. /package/dist/{assertServerCondition.d.ts → plugin/assertServerCondition.d.ts} +0 -0
  460. /package/dist/{components.d.ts → plugin/components.d.ts} +0 -0
  461. /package/dist/{copy-dir.d.ts → plugin/copy-dir.d.ts} +0 -0
  462. /package/dist/{getEnv.d.ts → plugin/getEnv.d.ts} +0 -0
  463. /package/dist/{helpers → plugin/helpers}/normalizedRelativePath.d.ts +0 -0
  464. /package/dist/{helpers → plugin/helpers}/tryManifest.d.ts +0 -0
  465. /package/dist/{manifest.d.ts → plugin/manifest.d.ts} +0 -0
  466. /package/dist/{module-graph.d.ts → plugin/module-graph.d.ts} +0 -0
  467. /package/dist/{react-server → plugin/react-server}/createDevMiddleware.d.ts +0 -0
  468. /package/dist/{react-server → plugin/react-server}/createDevServer.d.ts +0 -0
  469. /package/dist/{react-server → plugin/react-server}/createReactNodeStreamer.d.ts +0 -0
  470. /package/dist/{resolvePage.d.ts → plugin/resolvePage.d.ts} +0 -0
  471. /package/dist/{resolveProps.d.ts → plugin/resolveProps.d.ts} +0 -0
  472. /package/dist/{transformer → plugin/transformer}/types.d.ts +0 -0
  473. /package/dist/{worker → plugin/worker}/loader.d.ts +0 -0
  474. /package/{src → plugin}/assertServerCondition.ts +0 -0
  475. /package/{src → plugin}/components.tsx +0 -0
  476. /package/{src → plugin}/copy-dir.ts +0 -0
  477. /package/{src/server.tsx → plugin/getCondition.ts} +0 -0
  478. /package/{src → plugin}/helpers/normalizedRelativePath.ts +0 -0
  479. /package/{src → plugin}/helpers/tryManifest.ts +0 -0
  480. /package/{src → plugin}/manifest.ts +0 -0
  481. /package/{src → plugin}/module-graph.ts +0 -0
  482. /package/{src → plugin}/transformer/README.md +0 -0
  483. /package/{src → plugin}/transformer/types.ts +0 -0
  484. /package/{src → plugin}/worker/loader.ts +0 -0
@@ -0,0 +1,47 @@
1
+ import type { Worker } from "node:worker_threads";
2
+ import type { InputNormalizerWorker, NormalizerInput } from "../types.js";
3
+ import { createInputNormalizer } from "./inputNormalizer.js";
4
+
5
+ interface WorkerNormalizerOptions {
6
+ root: string;
7
+ moduleBase: string;
8
+ worker: Worker;
9
+ moduleBaseExceptions?: string[];
10
+ }
11
+
12
+ export function createInputNormalizerWorker({
13
+ root,
14
+ worker,
15
+ }: WorkerNormalizerOptions): InputNormalizerWorker {
16
+
17
+ const baseNormalizer = createInputNormalizer(root);
18
+
19
+ return async (input: NormalizerInput): Promise<[string, string]> => {
20
+ // Handle React components specially with worker
21
+ if (typeof input === "function") {
22
+ return new Promise((resolve, reject) => {
23
+ const handler = (message: any) => {
24
+ if (message.type === "CLIENT_REFERENCE") {
25
+ worker.off('message', handler);
26
+ resolve([message.ref.$$id, message.ref.$$location]);
27
+ }
28
+ if (message.type === "ERROR") {
29
+ worker.off('message', handler);
30
+ reject(new Error(message.error));
31
+ }
32
+ };
33
+
34
+ worker.on('message', handler);
35
+ worker.postMessage({
36
+ type: "CLIENT_REFERENCE",
37
+ id: input.name || 'AnonymousComponent',
38
+ location: input.toString(),
39
+ key: input.name
40
+ });
41
+ });
42
+ }
43
+
44
+ // For all other types, use the base normalizer
45
+ return baseNormalizer(input);
46
+ };
47
+ }
@@ -0,0 +1,108 @@
1
+ import { join, basename } from "node:path";
2
+ import { access, realpath } from "node:fs/promises";
3
+ import { normalizePath } from "vite";
4
+ import { getDistDir, getMode, getNodePath, getPluginRoot } from "../config/getPaths.js";
5
+ import pkg from "../../package.json" with { type: 'json' };
6
+
7
+ type ResolveOptions = {
8
+ projectRoot?: string;
9
+ nodePath?: string;
10
+ pluginRoot?: string;
11
+ filePath: string;
12
+ subDir?: string;
13
+ normalize?: boolean;
14
+ distDir?: string;
15
+ mode?: "production" | "development" | "test";
16
+ };
17
+
18
+ export async function resolveFilePath({
19
+ projectRoot = process.cwd(),
20
+ nodePath = getNodePath(projectRoot),
21
+ mode = getMode(),
22
+ pluginRoot = getPluginRoot(),
23
+ distDir = getDistDir(mode),
24
+ filePath,
25
+ subDir,
26
+ normalize = false,
27
+ }: ResolveOptions) {
28
+ try {
29
+ let resolvedPath: string | undefined;
30
+
31
+ // Helper to check if file exists
32
+ const exists = async (path: string) => {
33
+ try {
34
+ await access(path);
35
+ return true;
36
+ } catch {
37
+ return false;
38
+ }
39
+ };
40
+
41
+ // If it's a plugin export (like '/rsc-worker'), use exports map
42
+ if (filePath.startsWith('/') && filePath.slice(1) in pkg.exports) {
43
+ const exportPath = filePath.slice(1);
44
+ const pluginPath = pkg.exports[exportPath as keyof typeof pkg.exports];
45
+ return join(process.cwd(), pluginRoot, pluginPath); // Make absolute
46
+ }
47
+
48
+ // In test mode, preserve relative paths
49
+ if (mode === 'test' && !filePath.startsWith('/')) {
50
+ return filePath;
51
+ }
52
+
53
+ // For all other paths, try relative to project root first
54
+ const projectPath = join(projectRoot, filePath);
55
+ if (await exists(projectPath)) {
56
+ return normalize ? normalizePath(projectPath) : projectPath;
57
+ }
58
+
59
+ // 1. Try dist folder
60
+ const distPath = join(distDir, subDir ?? '', basename(filePath));
61
+ if (await exists(distPath)) {
62
+ resolvedPath = await realpath(distPath);
63
+ }
64
+
65
+ // 2. Try node_modules path
66
+ if (!resolvedPath && filePath.startsWith('/node_modules/')) {
67
+ const npmPath = join(nodePath, filePath.slice('/node_modules/'.length));
68
+ if (await exists(npmPath)) {
69
+ resolvedPath = await realpath(npmPath);
70
+ }
71
+ }
72
+
73
+ // 3. Try direct path
74
+ if (!resolvedPath && await exists(filePath)) {
75
+ resolvedPath = await realpath(filePath);
76
+ }
77
+
78
+ // 4. Try relative to project root
79
+ if (!resolvedPath) {
80
+ const projectPath = join(projectRoot, filePath);
81
+ if (await exists(projectPath)) {
82
+ resolvedPath = await realpath(projectPath);
83
+ }
84
+ }
85
+
86
+ if (!resolvedPath) {
87
+ throw new Error(
88
+ `Could not resolve path. Tried:\n` +
89
+ `- ${distPath}\n` +
90
+ `- ${join(nodePath, filePath.slice('/node_modules/'.length))}\n` +
91
+ `- ${filePath}\n` +
92
+ `- ${join(projectRoot, filePath)}`
93
+ );
94
+ }
95
+
96
+ return normalize ? normalizePath(
97
+ resolvedPath
98
+ .replace(pluginRoot, "/node_modules/vite-plugin-react-server")
99
+ .replace(projectRoot, "/")
100
+ .replace(nodePath, "/node_modules")
101
+ .replace(/^(?!\/)/, '/')
102
+ ) : resolvedPath;
103
+
104
+ } catch (error) {
105
+ // If realpath fails, return normalized input path
106
+ return normalize ? normalizePath(filePath) : filePath;
107
+ }
108
+ }
@@ -0,0 +1,41 @@
1
+ import { tryManifest } from "./tryManifest.js";
2
+
3
+ export async function resolveWorkerModule(
4
+ moduleGraph: Set<string> | string[],
5
+ options: {
6
+ root: string,
7
+ outDir: string,
8
+ workerPath: string
9
+ }
10
+ ) {
11
+ console.log('Resolving worker module:', {
12
+ moduleGraph: Array.from(moduleGraph),
13
+ options
14
+ });
15
+
16
+ // Try module graph first
17
+ const workerModule = Array.from(moduleGraph).find(id =>
18
+ id.includes(options.workerPath)
19
+ );
20
+
21
+ console.log('Found in module graph:', workerModule);
22
+
23
+ if (workerModule) {
24
+ return workerModule;
25
+ }
26
+
27
+ // Fallback to manifest
28
+ const resolvedManifest = tryManifest({
29
+ root: options.root,
30
+ outDir: options.outDir,
31
+ ssrManifest: false
32
+ });
33
+
34
+ console.log('Manifest result:', resolvedManifest);
35
+
36
+ if (resolvedManifest.type === "error") {
37
+ throw new Error(`Could not find worker path in module graph or manifest: ${options.workerPath}`);
38
+ }
39
+
40
+ return resolvedManifest.manifest[options.workerPath]?.file;
41
+ }
@@ -0,0 +1,30 @@
1
+ import type { InputOption } from "rollup";
2
+
3
+ export function validateModuleBase(
4
+ input: InputOption,
5
+ moduleBase: string,
6
+ moduleBaseExceptions: string[]
7
+ ) {
8
+ for (const [key, value] of Object.entries(input)) {
9
+ const isException =
10
+ moduleBaseExceptions.includes(key) || ["/index", "index"].includes(key);
11
+ if (!key.includes("/")) return;
12
+ if (value.startsWith("//")) {
13
+ throw new Error(`Path shouldn't start with //`);
14
+ }
15
+ if (!key.startsWith(moduleBase) && !isException) {
16
+ throw new Error(
17
+ `Invalid input: ${key} does not start with ${moduleBase}. If this is a valid key, add it to moduleBaseExceptions otherwise put the file in the ${moduleBase} directory. Exception: ${moduleBaseExceptions.join(
18
+ ", "
19
+ )}`
20
+ );
21
+ }
22
+ if (!value.startsWith("/" + moduleBase) && !isException) {
23
+ throw new Error(
24
+ `Invalid value: ${value} does not start with ${moduleBase}. If this is a valid path, add it to moduleBaseExceptions otherwise put the file in the ${moduleBase} directory. Exception: ${moduleBaseExceptions.join(
25
+ ", "
26
+ )}`
27
+ );
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,21 @@
1
+ import type { ResolvedConfig } from "vite";
2
+
3
+ export function validateResolvedConfig(config: ResolvedConfig): asserts config is ResolvedConfig {
4
+ if (
5
+ typeof config === "object" &&
6
+ config != null &&
7
+ "build" in config &&
8
+ typeof config.build === "object" &&
9
+ config.build != null &&
10
+ "rollupOptions" in config.build &&
11
+ typeof config.build.rollupOptions === "object" &&
12
+ config.build.rollupOptions != null &&
13
+ "input" in config.build.rollupOptions &&
14
+ typeof config.build.rollupOptions.input === "object" &&
15
+ config.build.rollupOptions.input != null
16
+ ) {
17
+ return undefined;
18
+ }
19
+ throw new Error("Invalid config");
20
+ };
21
+
@@ -0,0 +1,2 @@
1
+ export * from './plugin.js';
2
+ export type * from './types.js';
@@ -0,0 +1,44 @@
1
+ import { join, relative } from "path";
2
+ import type { PluginContext } from "rollup";
3
+ import type { ResolvedUserConfig } from "../../server.js";
4
+ import { createInputNormalizer } from "../helpers/inputNormalizer.js";
5
+ import { DEFAULT_CONFIG } from "../config/defaults.js";
6
+ import { mkdir, stat, writeFile } from "node:fs/promises";
7
+ import { dirname } from "node:path";
8
+
9
+ export interface BuildLoaderOptions {
10
+ root: string;
11
+ pluginContext: PluginContext;
12
+ userConfig: ResolvedUserConfig;
13
+ }
14
+
15
+ export function createBuildLoader({
16
+ root,
17
+ pluginContext,
18
+ userConfig,
19
+ }: BuildLoaderOptions) {
20
+ const normalizer = createInputNormalizer(root);
21
+ return async (id: string) => {
22
+ console.log("[createBuildLoader] Loading module:", id);
23
+ const moduleId = join(root, id);
24
+ const info = pluginContext.getModuleInfo(id)!;
25
+ if(info){
26
+ return await import(id);
27
+ }
28
+ // Load the module source
29
+ const result = await pluginContext.load({ id: moduleId });
30
+ if (!result) {
31
+ throw new Error(`Failed to load module: ${id}`);
32
+ }
33
+ let destination = id.replace(DEFAULT_CONFIG.FILE_REGEX, "") + ".js";
34
+ let fullDestination = join(root, userConfig.build.outDir, destination);
35
+
36
+
37
+ // Import and evaluate the module
38
+ try {
39
+ return import(fullDestination);
40
+ } catch (error) {
41
+ import(id);
42
+ }
43
+ };
44
+ }
@@ -0,0 +1,73 @@
1
+ import { ModuleGraph, type Manifest } from "vite";
2
+ import {
3
+ collectManifestCss,
4
+ collectModuleGraphCss,
5
+ } from "../collect-css-manifest.js";
6
+
7
+ type BaseCssLoaderOptions = {
8
+ /** callback to add css files to the stream */
9
+ onCssFile: (css: string) => void;
10
+ /** loader to load the module */
11
+ loader: (id: string) => Promise<Record<string, any>>;
12
+ /** url of the page */
13
+ url: string;
14
+ /** manually provided css files to add */
15
+ cssFiles: string[];
16
+ };
17
+
18
+ type CreateCssLoaderOptions =
19
+ | (BaseCssLoaderOptions & {
20
+ /** manifest to collect css from */
21
+ manifest: Manifest;
22
+ /** when manifest is given, moduleGraph is not needed */
23
+ moduleGraph?: never;
24
+ })
25
+ | (BaseCssLoaderOptions & {
26
+ /** when moduleGraph is given, manifest is not needed, manual cssFiles can still be provided */
27
+ manifest?: never;
28
+ /** when moduleGraph is given, manifest is not needed, manual cssFiles can still be provided */
29
+ moduleGraph: ModuleGraph;
30
+ });
31
+
32
+ /**
33
+ * create a loader that can be used to load css files from a manifest or a moduleGraph
34
+ * @param options
35
+ * @returns
36
+ */
37
+ export async function createCssLoader(options: CreateCssLoaderOptions) {
38
+ const root = process.cwd();
39
+
40
+ const cssModules = new Set<string>();
41
+
42
+ if (!(options.manifest || options.moduleGraph))
43
+ throw new Error("Missing manifest or moduleGraph, pass it to options.");
44
+
45
+ const getCss = options.manifest
46
+ ? (id: string) =>
47
+ collectManifestCss(
48
+ options.manifest,
49
+ root,
50
+ id,
51
+ options.onCssFile
52
+ )
53
+ : (id: string) => collectModuleGraphCss(options.moduleGraph!, id, options.onCssFile);
54
+
55
+ const loadWithCss = async (id: string) => {
56
+ if (!id) return {};
57
+
58
+ try {
59
+ const mod = await options.loader(id);
60
+ const pageCss = await Promise.resolve(getCss(id));
61
+ Array.from(pageCss.keys()).forEach((css) => cssModules.add(css));
62
+ return mod as Record<string, any>;
63
+ } catch (e: any) {
64
+ if (e.message?.includes("module runner has been closed")) {
65
+ return { type: "skip" } as Record<string, any>;
66
+ } else {
67
+ return { type: "error", error: e } as Record<string, any>;
68
+ }
69
+ }
70
+ };
71
+
72
+ return loadWithCss;
73
+ }
@@ -1,13 +1,18 @@
1
1
  import { resolve as resolvePath } from "node:path";
2
- import { load } from "react-server-dom-esm/node-loader";
2
+
3
+ import {
4
+ load
5
+ // @ts-ignore
6
+ } from "react-server-dom-esm/node-loader";
7
+
3
8
  import {
4
9
  registerClientReference,
5
10
  registerServerReference,
11
+ // @ts-ignore
6
12
  } from "react-server-dom-esm/server.node";
7
- import { createNormalizedRelativePath } from "../helpers/normalizedRelativePath.js";
8
13
 
9
14
  type CreatePageLoaderOptions = {
10
- manifest: Record<string, { file: string }>;
15
+ manifest: Record<string, { file: string; src?: string }>;
11
16
  root: string;
12
17
  outDir: string;
13
18
  moduleBase: string;
@@ -52,41 +57,44 @@ export const createDefaultLoader = ({
52
57
  return [key, value];
53
58
  }
54
59
  };
55
- return async (url: string) =>
56
- Object.fromEntries(Object.entries(await import(url)).map(mapper));
60
+ return async (url: string) => {
61
+ console.log("[createDefaultLoader] Loading:", url);
62
+ const result = await import(url);
63
+ console.log("[createDefaultLoader] Result:", result);
64
+ return Object.fromEntries(Object.entries(result).map(mapper));
65
+ };
57
66
  };
58
67
 
59
- export const createPageLoader = ({
68
+ export function createPageLoader({
60
69
  manifest,
61
70
  root,
62
71
  outDir,
63
72
  moduleBase,
64
- registerServer,
65
- registerClient,
66
73
  alwaysRegisterServer,
67
74
  alwaysRegisterClient,
68
- }: CreatePageLoaderOptions) => {
69
- const pathNormalizer = createNormalizedRelativePath({
70
- root,
71
- outDir,
72
- moduleBase,
73
- noLeadingSlash: true,
74
- noTrailingSlash: true,
75
- moduleBaseExceptions: [],
76
- });
77
- return async (id: string) => {
78
- const normalizedId = pathNormalizer(id);
79
- const entry =
80
- normalizedId in manifest
81
- ? manifest[normalizedId]
82
- : Object.values(manifest).find((entry) => entry.file === normalizedId);
83
- if (!entry) {
75
+ registerServer,
76
+ registerClient,
77
+ }: CreatePageLoaderOptions) {
78
+ return async function loader(id: string) {
79
+ console.log("[pageLoader] Loading:", {
80
+ id,
81
+ manifest: Object.keys(manifest),
82
+ outDir,
83
+ moduleBase
84
+ });
85
+ console.log("[pageLoader] Manifest:", manifest);
86
+ // Try to find the entry directly or by source file
87
+ const manifestEntry = manifest[id] ||
88
+ Object.values(manifest).find(entry => entry.src === id);
89
+
90
+ if (!manifestEntry) {
84
91
  throw new Error(
85
- `Could not find manifest entry for ${id}, ${normalizedId} from ${root}`
92
+ `Could not find manifest entry for ${id} from ${root}. Available entries: ${Object.keys(manifest).join(', ')}`
86
93
  );
87
94
  }
95
+
88
96
  const loaderResult = await load(
89
- resolvePath(root, outDir, entry.file),
97
+ resolvePath(root, outDir, manifestEntry.file),
90
98
  { format: "module" },
91
99
  createDefaultLoader({
92
100
  id,
@@ -98,4 +106,4 @@ export const createPageLoader = ({
98
106
  );
99
107
  return loaderResult;
100
108
  };
101
- };
109
+ }
@@ -0,0 +1,8 @@
1
+ import "./assertServerCondition.js";
2
+ export { reactServerPlugin } from "./react-server/plugin.js";
3
+ export { reactClientPlugin } from "./react-client/plugin.js";
4
+ export { reactTransformPlugin } from "./transformer/plugin.js";
5
+ export { reactPreservePlugin } from "./preserver/plugin.js";
6
+ export { vitePluginReactServer } from "./react-server/index.js";
7
+ // the main plugin is version is the server version, if you want the client version, use the `vite-plugin-react-server/client` import
8
+ // this is because the workflow assumes main thread = react server condition
@@ -0,0 +1 @@
1
+ export { reactPreservePlugin } from "./plugin.js";
@@ -0,0 +1,109 @@
1
+ import type { Node } from "estree";
2
+ import MagicString from "magic-string";
3
+ import type { StreamPluginOptions } from "../types.js";
4
+
5
+ const REACT_DIRECTIVES = new Set(["use client", "use server"]);
6
+
7
+ export function reactPreservePlugin(_options: StreamPluginOptions): import("vite").Plugin {
8
+ const meta: Record<string, Set<string>> = {};
9
+
10
+ return {
11
+ name: "vite-plugin-react-server:preserve-directives",
12
+ enforce: "post",
13
+
14
+ transform: {
15
+ order: "post", // Ensure this runs last in transform phase
16
+ handler(code: string, id: string) {
17
+ // Skip node_modules and vite files
18
+ if (id.includes("node_modules") || id.includes("vite/dist")) {
19
+ return null;
20
+ }
21
+
22
+ let ast: Node;
23
+ try {
24
+ ast = this.parse(code, {
25
+ allowReturnOutsideFunction: true,
26
+ jsx: true,
27
+ }) as Node;
28
+ } catch (e) {
29
+ console.warn(`[PreservePlugin] Failed to parse ${id}`, e);
30
+ return null;
31
+ }
32
+
33
+ if (ast.type !== "Program") {
34
+ return null;
35
+ }
36
+
37
+ const magicString = new MagicString(code);
38
+ let hasChanged = false;
39
+
40
+ // Only look at top-level directives
41
+ for (const node of ast.body) {
42
+ if (node.type !== "ExpressionStatement") {
43
+ break;
44
+ }
45
+
46
+ let directive: string | null = null;
47
+ if ("directive" in node) {
48
+ directive = node.directive;
49
+ } else if (
50
+ node.expression.type === "Literal" &&
51
+ typeof node.expression.value === "string" &&
52
+ REACT_DIRECTIVES.has(node.expression.value)
53
+ ) {
54
+ directive = node.expression.value;
55
+ }
56
+
57
+ if (directive) {
58
+ meta[id] ||= new Set<string>();
59
+ meta[id].add(directive);
60
+
61
+ if ("start" in node && "end" in node) {
62
+ magicString.remove(node.start as number, node.end as number);
63
+ hasChanged = true;
64
+ }
65
+ }
66
+ }
67
+
68
+ if (!hasChanged) {
69
+ return null;
70
+ }
71
+
72
+ return {
73
+ code: magicString.toString(),
74
+ map: magicString.generateMap({ hires: true }),
75
+ meta: {
76
+ directives: Array.from(meta[id] || []),
77
+ },
78
+ };
79
+ },
80
+ },
81
+
82
+ renderChunk(code, chunk) {
83
+ const chunkDirectives = new Set<string>();
84
+
85
+ // Collect directives from all modules in chunk
86
+ for (const id of chunk.moduleIds) {
87
+ if (meta[id]) {
88
+ meta[id].forEach((d) => chunkDirectives.add(d));
89
+ }
90
+ }
91
+
92
+ if (chunkDirectives.size) {
93
+ const magicString = new MagicString(code);
94
+ magicString.prepend(
95
+ Array.from(chunkDirectives)
96
+ .map((d) => `"${d}";`)
97
+ .join("\n") + "\n"
98
+ );
99
+
100
+ return {
101
+ code: magicString.toString(),
102
+ map: magicString.generateMap({ hires: true }),
103
+ };
104
+ }
105
+
106
+ return null;
107
+ },
108
+ };
109
+ }
@@ -0,0 +1 @@
1
+ export { reactClientPlugin } from "./plugin.js";
@@ -0,0 +1,33 @@
1
+ import type { Plugin as VitePlugin, UserConfig } from "vite";
2
+
3
+ import type { ResolvedUserOptions, StreamPluginOptions } from "../types.js";
4
+ import { resolveOptions } from "../config/resolveOptions.js";
5
+ import { resolveUserConfig } from "../config/resolveUserConfig.js";
6
+
7
+ let userOptions: ResolvedUserOptions;
8
+
9
+ export function reactClientPlugin(options: StreamPluginOptions): VitePlugin {
10
+ const resolvedOptions = resolveOptions(options);
11
+ if (resolvedOptions.type === "error") {
12
+ throw resolvedOptions.error;
13
+ }
14
+ userOptions = resolvedOptions.userOptions;
15
+
16
+ return {
17
+ name: "vite:react-stream-client",
18
+ async config(config): Promise<UserConfig> {
19
+ const resolvedConfig = resolveUserConfig({
20
+ condition: "react-client",
21
+ config,
22
+ configEnv: { command: "build", mode: "production" },
23
+ userOptions,
24
+ });
25
+
26
+ if (resolvedConfig.type === "error") {
27
+ throw resolvedConfig.error;
28
+ }
29
+
30
+ return resolvedConfig.userConfig;
31
+ }
32
+ };
33
+ }
@@ -18,6 +18,14 @@ export function createDevMiddleware(
18
18
  server: ViteDevServer,
19
19
  options: DevMiddlewareOptions
20
20
  ): RequestHandler {
21
+ // Add HMR support
22
+ const hmr = server.hot;
23
+
24
+ hmr?.on('vite:beforeUpdate', () => {
25
+ // Clear module cache before updates
26
+ server.moduleGraph.invalidateAll();
27
+ });
28
+
21
29
  return async (req: IncomingMessage, res: ServerResponse, next: any) => {
22
30
  // Skip non-page requests
23
31
  if (
@@ -34,7 +42,15 @@ export function createDevMiddleware(
34
42
  console.log("[stream] Handling RSC stream");
35
43
 
36
44
  const result = await createHandler(url, options, {
37
- loader: server.ssrLoadModule,
45
+ loader: (id)=>{
46
+ const mod = server.ssrLoadModule(id);
47
+ if(!mod) {
48
+ throw new Error(`[RSC] Module not found: ${id}`);
49
+ } else {
50
+ console.log('[RSC] Loaded module:', id);
51
+ }
52
+ return mod;
53
+ },
38
54
  moduleGraph: server.moduleGraph,
39
55
  });
40
56
 
@@ -1,5 +1,4 @@
1
1
  import type { ViteDevServer } from "vite";
2
- import type { StreamPluginOptions } from "../types.js";
3
2
  import { createDevMiddleware, type DevMiddlewareOptions } from "./createDevMiddleware.js";
4
3
 
5
4
  export function createDevServer(