vite-plugin-react-server 0.3.10 → 0.3.12

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 (318) hide show
  1. package/dist/client.d.ts +1 -1
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +1 -1
  4. package/dist/index.d.ts +3 -6
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/package.json +16 -14
  9. package/dist/plugin/assertServerCondition.d.ts +5 -1
  10. package/dist/plugin/assertServerCondition.d.ts.map +1 -1
  11. package/dist/plugin/assertServerCondition.js +1 -3
  12. package/dist/plugin/checkFilesExist.d.ts +2 -2
  13. package/dist/plugin/checkFilesExist.d.ts.map +1 -1
  14. package/dist/plugin/checkFilesExist.js +43 -58
  15. package/dist/plugin/checkFilesExist.js.map +1 -1
  16. package/dist/plugin/collect-css-manifest.d.ts.map +1 -1
  17. package/dist/plugin/collect-css-manifest.js +5 -0
  18. package/dist/plugin/collect-css-manifest.js.map +1 -1
  19. package/dist/plugin/components.js +10 -15
  20. package/dist/plugin/config/createModuleIdGenerator.d.ts +11 -0
  21. package/dist/plugin/config/createModuleIdGenerator.d.ts.map +1 -0
  22. package/dist/plugin/config/createModuleIdGenerator.js +44 -0
  23. package/dist/plugin/config/createModuleIdGenerator.js.map +1 -0
  24. package/dist/plugin/config/defaults.d.ts +27 -24
  25. package/dist/plugin/config/defaults.d.ts.map +1 -1
  26. package/dist/plugin/config/defaults.js +26 -31
  27. package/dist/plugin/config/defaults.js.map +1 -1
  28. package/dist/plugin/config/getPaths.js +1 -1
  29. package/dist/plugin/config/resolveOptions.d.ts +1 -1
  30. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  31. package/dist/plugin/config/resolveOptions.js +223 -16
  32. package/dist/plugin/config/resolveOptions.js.map +1 -1
  33. package/dist/plugin/config/resolvePages.d.ts +2 -0
  34. package/dist/plugin/config/resolvePages.d.ts.map +1 -1
  35. package/dist/plugin/config/resolvePages.js.map +1 -1
  36. package/dist/plugin/config/resolveUserConfig.d.ts +2 -2
  37. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  38. package/dist/plugin/config/resolveUserConfig.js +149 -50
  39. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  40. package/dist/plugin/helpers/getBundleManifest.d.ts +25 -0
  41. package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -0
  42. package/dist/plugin/helpers/getBundleManifest.js +72 -0
  43. package/dist/plugin/helpers/getBundleManifest.js.map +1 -0
  44. package/dist/plugin/helpers/inputNormalizer.d.ts +14 -1
  45. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  46. package/dist/plugin/helpers/inputNormalizer.js +128 -16
  47. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  48. package/dist/plugin/helpers/tryManifest.d.ts +3 -1
  49. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
  50. package/dist/plugin/helpers/tryManifest.js +1 -1
  51. package/dist/plugin/helpers/tryManifest.js.map +1 -1
  52. package/dist/plugin/loader/createBuildLoader.d.ts +6 -2
  53. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
  54. package/dist/plugin/loader/createBuildLoader.js +37 -9
  55. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  56. package/dist/plugin/loader/createPageLoader.d.ts.map +1 -1
  57. package/dist/plugin/loader/createPageLoader.js +0 -7
  58. package/dist/plugin/loader/css-loader.d.ts +16 -0
  59. package/dist/plugin/loader/css-loader.d.ts.map +1 -0
  60. package/dist/plugin/loader/css-loader.js +70 -0
  61. package/dist/plugin/loader/css-loader.js.map +1 -0
  62. package/dist/plugin/loader/react-loader.d.ts +17 -0
  63. package/dist/plugin/loader/react-loader.d.ts.map +1 -0
  64. package/dist/plugin/loader/react-loader.js +647 -0
  65. package/dist/plugin/loader/react-loader.js.map +1 -0
  66. package/dist/plugin/loader/rsc/messageHandler.d.ts +2 -0
  67. package/dist/plugin/loader/rsc/messageHandler.d.ts.map +1 -0
  68. package/dist/plugin/loader/rsc/messageHandler.js +1 -0
  69. package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +2 -0
  70. package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +1 -0
  71. package/dist/plugin/loader/rsc/rsc-worker.development.js +1 -0
  72. package/dist/plugin/plugin.d.ts +0 -1
  73. package/dist/plugin/plugin.d.ts.map +1 -1
  74. package/dist/plugin/plugin.js +2 -1
  75. package/dist/plugin/preserver/plugin.d.ts.map +1 -1
  76. package/dist/plugin/preserver/plugin.js +3 -2
  77. package/dist/plugin/preserver/plugin.js.map +1 -1
  78. package/dist/plugin/react-client/index.d.ts +2 -1
  79. package/dist/plugin/react-client/index.d.ts.map +1 -1
  80. package/dist/plugin/react-client/index.js +19 -1
  81. package/dist/plugin/react-client/index.js.map +1 -0
  82. package/dist/plugin/react-client/plugin.d.ts +2 -2
  83. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  84. package/dist/plugin/react-client/plugin.js +283 -10
  85. package/dist/plugin/react-client/plugin.js.map +1 -1
  86. package/dist/plugin/react-server/createHandler.d.ts +2 -2
  87. package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
  88. package/dist/plugin/react-server/createHandler.js +15 -9
  89. package/dist/plugin/react-server/createHandler.js.map +1 -1
  90. package/dist/plugin/react-server/createRscStream.d.ts +15 -3
  91. package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
  92. package/dist/plugin/react-server/createRscStream.js +53 -36
  93. package/dist/plugin/react-server/createRscStream.js.map +1 -1
  94. package/dist/plugin/react-server/createSsrHandler.d.ts +2 -2
  95. package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -1
  96. package/dist/plugin/react-server/createSsrHandler.js +5 -12
  97. package/dist/plugin/react-server/index.js +18 -9
  98. package/dist/plugin/react-server/index.js.map +1 -0
  99. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  100. package/dist/plugin/react-server/plugin.js +147 -137
  101. package/dist/plugin/react-server/plugin.js.map +1 -1
  102. package/dist/plugin/transformer/plugin.d.ts +2 -1
  103. package/dist/plugin/transformer/plugin.d.ts.map +1 -1
  104. package/dist/plugin/transformer/plugin.js +68 -75
  105. package/dist/plugin/transformer/plugin.js.map +1 -1
  106. package/dist/plugin/transformer/types.d.ts +4 -0
  107. package/dist/plugin/transformer/types.d.ts.map +1 -1
  108. package/dist/plugin/types.d.ts +56 -20
  109. package/dist/plugin/types.d.ts.map +1 -1
  110. package/dist/plugin/utils/logger.d.ts +9 -0
  111. package/dist/plugin/utils/logger.d.ts.map +1 -0
  112. package/dist/plugin/utils/logger.js +68 -0
  113. package/dist/plugin/utils/logger.js.map +1 -0
  114. package/dist/plugin/worker/createWorker.d.ts +1 -0
  115. package/dist/plugin/worker/createWorker.d.ts.map +1 -1
  116. package/dist/plugin/worker/createWorker.js +23 -36
  117. package/dist/plugin/worker/createWorker.js.map +1 -1
  118. package/dist/plugin/worker/html/html-worker.production.js +5 -1
  119. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  120. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
  121. package/dist/plugin/worker/html/messageHandler.js +33 -28
  122. package/dist/plugin/worker/html/messageHandler.js.map +1 -1
  123. package/dist/plugin/worker/html/plugin.d.ts.map +1 -1
  124. package/dist/plugin/worker/html/plugin.js +10 -5
  125. package/dist/plugin/worker/html/renderPages.d.ts +7 -6
  126. package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
  127. package/dist/plugin/worker/html/renderPages.js +147 -93
  128. package/dist/plugin/worker/html/renderPages.js.map +1 -1
  129. package/dist/plugin/worker/loader.d.ts +1 -11
  130. package/dist/plugin/worker/loader.d.ts.map +1 -1
  131. package/dist/plugin/worker/loader.js +2 -2
  132. package/dist/plugin/worker/loader.js.map +1 -1
  133. package/dist/plugin/worker/plugin.d.ts +10 -1
  134. package/dist/plugin/worker/plugin.d.ts.map +1 -1
  135. package/dist/plugin/worker/plugin.js +10 -1
  136. package/dist/plugin/worker/rsc/index.d.ts +1 -3
  137. package/dist/plugin/worker/rsc/index.d.ts.map +1 -1
  138. package/dist/plugin/worker/rsc/index.js +1 -9
  139. package/dist/plugin/worker/rsc/index.js.map +1 -1
  140. package/dist/plugin/worker/rsc/messageHandler.d.ts +3 -0
  141. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -0
  142. package/dist/plugin/worker/rsc/messageHandler.js +107 -0
  143. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -0
  144. package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
  145. package/dist/plugin/worker/rsc/plugin.js +74 -80
  146. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +32 -0
  147. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -0
  148. package/dist/plugin/worker/rsc/rsc-worker.development.js +43 -0
  149. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -0
  150. package/dist/plugin/worker/rsc/rsc-worker.js +4 -106
  151. package/dist/plugin/worker/rsc/rsc-worker.production.d.ts +2 -0
  152. package/dist/plugin/worker/rsc/rsc-worker.production.d.ts.map +1 -0
  153. package/dist/plugin/worker/rsc/rsc-worker.production.js +14 -0
  154. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -0
  155. package/dist/plugin/worker/rsc/state.d.ts +11 -0
  156. package/dist/plugin/worker/rsc/state.d.ts.map +1 -0
  157. package/dist/plugin/worker/rsc/state.js +12 -0
  158. package/dist/plugin/worker/rsc/state.js.map +1 -0
  159. package/dist/plugin/worker/types.d.ts +62 -35
  160. package/dist/plugin/worker/types.d.ts.map +1 -1
  161. package/dist/server.d.ts +1 -3
  162. package/dist/server.d.ts.map +1 -1
  163. package/dist/server.js +1 -3
  164. package/dist/server.js.map +1 -1
  165. package/dist/tsconfig.tsbuildinfo +1 -1
  166. package/package.json +16 -14
  167. package/plugin/assertServerCondition.ts +2 -3
  168. package/plugin/checkFilesExist.ts +46 -66
  169. package/plugin/collect-css-manifest.ts +5 -1
  170. package/plugin/config/createModuleIdGenerator.ts +52 -0
  171. package/plugin/config/defaults.ts +27 -20
  172. package/plugin/config/resolveOptions.ts +311 -25
  173. package/plugin/config/resolvePages.ts +1 -1
  174. package/plugin/config/resolveUserConfig.ts +195 -61
  175. package/plugin/helpers/getBundleManifest.ts +113 -0
  176. package/plugin/helpers/inputNormalizer.ts +186 -25
  177. package/plugin/helpers/tryManifest.ts +3 -1
  178. package/plugin/loader/createBuildLoader.ts +50 -9
  179. package/plugin/loader/createPageLoader.ts +1 -7
  180. package/plugin/loader/css-loader.ts +96 -0
  181. package/plugin/loader/react-loader.ts +945 -0
  182. package/plugin/loader/rsc/messageHandler.tsx +1 -0
  183. package/plugin/loader/rsc/rsc-worker.development.ts +1 -0
  184. package/plugin/plugin.ts +2 -1
  185. package/plugin/preserver/plugin.ts +2 -1
  186. package/plugin/react-client/index.ts +12 -1
  187. package/plugin/react-client/plugin.ts +351 -11
  188. package/plugin/react-server/createHandler.ts +16 -18
  189. package/plugin/react-server/createRscStream.ts +75 -42
  190. package/plugin/react-server/createSsrHandler.ts +7 -26
  191. package/plugin/react-server/plugin.ts +192 -155
  192. package/plugin/transformer/plugin.ts +70 -104
  193. package/plugin/transformer/types.ts +4 -0
  194. package/plugin/types/global.d.ts +8 -0
  195. package/plugin/types.ts +120 -64
  196. package/plugin/utils/logger.ts +52 -0
  197. package/plugin/worker/createWorker.ts +43 -44
  198. package/plugin/worker/html/html-worker.production.tsx +7 -2
  199. package/plugin/worker/html/messageHandler.ts +42 -35
  200. package/plugin/worker/html/plugin.ts +15 -11
  201. package/plugin/worker/html/renderPages.ts +177 -123
  202. package/plugin/worker/loader.ts +4 -13
  203. package/plugin/worker/plugin.ts +10 -1
  204. package/plugin/worker/rsc/index.ts +4 -13
  205. package/plugin/worker/rsc/messageHandler.tsx +143 -0
  206. package/plugin/worker/rsc/plugin.ts +38 -37
  207. package/plugin/worker/rsc/rsc-worker.development.ts +107 -0
  208. package/plugin/worker/rsc/rsc-worker.production.ts +13 -0
  209. package/plugin/worker/rsc/rsc-worker.tsx +5 -128
  210. package/plugin/worker/rsc/state.ts +37 -0
  211. package/plugin/worker/types.ts +83 -38
  212. package/scripts/check-react-version.mjs +17 -7
  213. package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +143 -4170
  214. package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +14271 -90079
  215. package/dist/node_modules/magic-string/dist/magic-string.es.js +0 -1283
  216. package/dist/node_modules/magic-string/dist/magic-string.es.js.map +0 -1
  217. package/dist/plugin/build/createClientBuildConfig.d.ts +0 -3
  218. package/dist/plugin/build/createClientBuildConfig.d.ts.map +0 -1
  219. package/dist/plugin/build/createClientBuildConfig.js +0 -14
  220. package/dist/plugin/build/createServerBuildConfig.d.ts +0 -12
  221. package/dist/plugin/build/createServerBuildConfig.d.ts.map +0 -1
  222. package/dist/plugin/build/createServerBuildConfig.js +0 -40
  223. package/dist/plugin/build/createSharedBuildConfig.d.ts +0 -5
  224. package/dist/plugin/build/createSharedBuildConfig.d.ts.map +0 -1
  225. package/dist/plugin/build/createSharedBuildConfig.js +0 -28
  226. package/dist/plugin/build/mergeInputs.d.ts +0 -9
  227. package/dist/plugin/build/mergeInputs.d.ts.map +0 -1
  228. package/dist/plugin/build/mergeInputs.js +0 -56
  229. package/dist/plugin/components.js.map +0 -1
  230. package/dist/plugin/config/moduleIdDefault.d.ts +0 -8
  231. package/dist/plugin/config/moduleIdDefault.d.ts.map +0 -1
  232. package/dist/plugin/config/moduleIdDefault.js +0 -23
  233. package/dist/plugin/config/moduleIdDefault.js.map +0 -1
  234. package/dist/plugin/helpers/createClientInputNormalizer.d.ts +0 -8
  235. package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +0 -1
  236. package/dist/plugin/helpers/createClientInputNormalizer.js +0 -35
  237. package/dist/plugin/helpers/createServerInputNormalizer.d.ts +0 -9
  238. package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +0 -1
  239. package/dist/plugin/helpers/createServerInputNormalizer.js +0 -37
  240. package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +0 -7
  241. package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +0 -1
  242. package/dist/plugin/helpers/createStaticInputNormalizer.js +0 -18
  243. package/dist/plugin/helpers/getModuleManifest.d.ts +0 -12
  244. package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
  245. package/dist/plugin/helpers/getModuleManifest.js +0 -24
  246. package/dist/plugin/helpers/getModuleManifest.js.map +0 -1
  247. package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -11
  248. package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
  249. package/dist/plugin/helpers/inputNormalizerWorker.js +0 -30
  250. package/dist/plugin/helpers/normalizedRelativePath.d.ts +0 -11
  251. package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +0 -1
  252. package/dist/plugin/helpers/normalizedRelativePath.js +0 -36
  253. package/dist/plugin/helpers/resolveFilePath.d.ts +0 -13
  254. package/dist/plugin/helpers/resolveFilePath.d.ts.map +0 -1
  255. package/dist/plugin/helpers/resolveFilePath.js +0 -74
  256. package/dist/plugin/helpers/resolveWorkerModule.d.ts +0 -6
  257. package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +0 -1
  258. package/dist/plugin/helpers/resolveWorkerModule.js +0 -24
  259. package/dist/plugin/helpers/validateModuleBase.d.ts +0 -3
  260. package/dist/plugin/helpers/validateModuleBase.d.ts.map +0 -1
  261. package/dist/plugin/helpers/validateModuleBase.js +0 -16
  262. package/dist/plugin/helpers/validateResolvedConfig.d.ts +0 -3
  263. package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +0 -1
  264. package/dist/plugin/helpers/validateResolvedConfig.js +0 -17
  265. package/dist/plugin/react-server/createDevMiddleware.d.ts +0 -8
  266. package/dist/plugin/react-server/createDevMiddleware.d.ts.map +0 -1
  267. package/dist/plugin/react-server/createDevMiddleware.js +0 -68
  268. package/dist/plugin/react-server/createDevServer.d.ts +0 -4
  269. package/dist/plugin/react-server/createDevServer.d.ts.map +0 -1
  270. package/dist/plugin/react-server/createDevServer.js +0 -4
  271. package/dist/plugin/react-server/createReactNodeStreamer.d.ts +0 -10
  272. package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +0 -1
  273. package/dist/plugin/react-server/createReactNodeStreamer.js +0 -7
  274. package/dist/plugin/transformer/transformer-client-components.d.ts +0 -21
  275. package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
  276. package/dist/plugin/transformer/transformer-client-components.js +0 -61
  277. package/dist/plugin/transformer/transformer-client-components.js.map +0 -1
  278. package/dist/plugin/transformer/transformer-server-actions.d.ts +0 -29
  279. package/dist/plugin/transformer/transformer-server-actions.d.ts.map +0 -1
  280. package/dist/plugin/transformer/transformer-server-actions.js +0 -76
  281. package/dist/plugin/transformer/transformer-server-actions.js.map +0 -1
  282. package/dist/plugin/worker/rsc/createRscStream.d.ts +0 -5
  283. package/dist/plugin/worker/rsc/createRscStream.d.ts.map +0 -1
  284. package/dist/plugin/worker/rsc/createRscStream.js +0 -39
  285. package/dist/plugin/worker/rsc/createRscStream.js.map +0 -1
  286. package/dist/plugin/worker/rsc/development.d.ts +0 -5
  287. package/dist/plugin/worker/rsc/development.d.ts.map +0 -1
  288. package/dist/plugin/worker/rsc/development.js +0 -13
  289. package/dist/plugin/worker/rsc/development.js.map +0 -1
  290. package/dist/plugin/worker/rsc/plugin.js.map +0 -1
  291. package/dist/plugin/worker/rsc/production.d.ts +0 -5
  292. package/dist/plugin/worker/rsc/production.d.ts.map +0 -1
  293. package/dist/plugin/worker/rsc/production.js +0 -13
  294. package/dist/plugin/worker/rsc/production.js.map +0 -1
  295. package/plugin/build/createClientBuildConfig.ts +0 -21
  296. package/plugin/build/createServerBuildConfig.ts +0 -66
  297. package/plugin/build/createSharedBuildConfig.ts +0 -35
  298. package/plugin/build/mergeInputs.ts +0 -58
  299. package/plugin/config/moduleIdDefault.ts +0 -23
  300. package/plugin/helpers/createClientInputNormalizer.ts +0 -48
  301. package/plugin/helpers/createServerInputNormalizer.ts +0 -52
  302. package/plugin/helpers/createStaticInputNormalizer.ts +0 -26
  303. package/plugin/helpers/getModuleManifest.ts +0 -31
  304. package/plugin/helpers/inputNormalizerWorker.ts +0 -47
  305. package/plugin/helpers/normalizedRelativePath.ts +0 -59
  306. package/plugin/helpers/resolveFilePath.ts +0 -108
  307. package/plugin/helpers/resolveWorkerModule.ts +0 -41
  308. package/plugin/helpers/validateModuleBase.ts +0 -30
  309. package/plugin/helpers/validateResolvedConfig.ts +0 -21
  310. package/plugin/react-server/createDevMiddleware.ts +0 -91
  311. package/plugin/react-server/createDevServer.ts +0 -9
  312. package/plugin/react-server/createReactNodeStreamer.ts +0 -26
  313. package/plugin/transformer/transformer-client-components.ts +0 -94
  314. package/plugin/transformer/transformer-server-actions.ts +0 -110
  315. package/plugin/worker/rsc/createRscStream.ts +0 -42
  316. package/plugin/worker/rsc/development.ts +0 -6
  317. package/plugin/worker/rsc/production.ts +0 -6
  318. package/scripts/react-server-dom-esm+0.0.1.patch +0 -24775
package/plugin/plugin.ts CHANGED
@@ -1,4 +1,4 @@
1
- import "./assertServerCondition.js";
1
+ import { assertServerCondition } from "./assertServerCondition.js";
2
2
  export { reactServerPlugin } from "./react-server/plugin.js";
3
3
  export { reactClientPlugin } from "./react-client/plugin.js";
4
4
  export { reactTransformPlugin } from "./transformer/plugin.js";
@@ -6,3 +6,4 @@ export { reactPreservePlugin } from "./preserver/plugin.js";
6
6
  export { vitePluginReactServer } from "./react-server/index.js";
7
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
8
  // this is because the workflow assumes main thread = react server condition
9
+ assertServerCondition(process);
@@ -1,6 +1,7 @@
1
1
  import type { Node } from "estree";
2
2
  import MagicString from "magic-string";
3
3
  import type { StreamPluginOptions } from "../types.js";
4
+ import { DEFAULT_CONFIG } from "../config/defaults.js";
4
5
 
5
6
  const REACT_DIRECTIVES = new Set(["use client", "use server"]);
6
7
 
@@ -15,7 +16,7 @@ export function reactPreservePlugin(_options: StreamPluginOptions): import("vite
15
16
  order: "post", // Ensure this runs last in transform phase
16
17
  handler(code: string, id: string) {
17
18
  // Skip node_modules and vite files
18
- if (id.includes("node_modules") || id.includes("vite/dist")) {
19
+ if (id.includes("node_modules") || id.includes("vite/dist") || !id.match(DEFAULT_CONFIG.FILE_REGEX)) {
19
20
  return null;
20
21
  }
21
22
 
@@ -1 +1,12 @@
1
- export { reactClientPlugin } from "./plugin.js";
1
+ import { reactPreservePlugin } from "../plugin.js";
2
+ import { reactTransformPlugin } from "../transformer/plugin.js";
3
+ import type { StreamPluginOptions } from "../types.js";
4
+ import { reactClientPlugin } from "./plugin.js";
5
+
6
+ export function vitePluginReactClient(options = {} as StreamPluginOptions): import("vite").Plugin[] {
7
+ return [
8
+ reactClientPlugin(options),
9
+ reactTransformPlugin(options),
10
+ reactPreservePlugin(options),
11
+ ];
12
+ }
@@ -1,33 +1,373 @@
1
- import type { Plugin as VitePlugin, UserConfig } from "vite";
2
-
3
- import type { ResolvedUserOptions, StreamPluginOptions } from "../types.js";
1
+ import { type Manifest, type Plugin, type ResolvedConfig } from "vite";
2
+ import type {
3
+ CheckFilesExistReturn,
4
+ ResolvedUserConfig,
5
+ ResolvedUserOptions,
6
+ StreamPluginOptions,
7
+ } from "../types.js";
4
8
  import { resolveOptions } from "../config/resolveOptions.js";
5
9
  import { resolveUserConfig } from "../config/resolveUserConfig.js";
10
+ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
11
+ import { dirname, join } from "node:path";
12
+ import { getBundleManifest } from "../helpers/getBundleManifest.js";
13
+ import { checkFilesExist } from "../checkFilesExist.js";
14
+ import { resolvePages } from "../config/resolvePages.js";
15
+ import { tryManifest } from "../helpers/tryManifest.js";
16
+ import { createInputNormalizer } from "../helpers/inputNormalizer.js";
17
+ import { createWorker } from "../worker/createWorker.js";
18
+ import type { Worker } from "node:worker_threads";
19
+ import { getPluginRoot } from "../config/getPaths.js";
20
+ import { DEFAULT_CONFIG } from "../config/defaults.js";
21
+ import type {
22
+ RscRenderMessage,
23
+ RscWorkerMessage,
24
+ RscWorkerResponse,
25
+ } from "../worker/types.js";
26
+ import { createLogger } from "../utils/logger.js";
6
27
 
28
+ const log = createLogger("react-client");
7
29
  let userOptions: ResolvedUserOptions;
30
+ let userConfig: ResolvedUserConfig;
31
+ let clientManifest: Manifest = {};
32
+ let resolvedConfig: ResolvedConfig;
33
+ let root: string;
34
+ let loader: (id: string) => Promise<Record<string, any>> = (id: string) =>
35
+ import(id);
36
+ let worker: Worker;
37
+ let files: CheckFilesExistReturn;
8
38
 
9
- export function reactClientPlugin(options: StreamPluginOptions): VitePlugin {
10
- const resolvedOptions = resolveOptions(options);
39
+ export function reactClientPlugin(options: StreamPluginOptions): Plugin {
40
+ const resolvedOptions = resolveOptions(options, true);
11
41
  if (resolvedOptions.type === "error") {
12
42
  throw resolvedOptions.error;
13
43
  }
14
44
  userOptions = resolvedOptions.userOptions;
45
+ root = userOptions.projectRoot;
46
+ const rscWorkerPath = join(getPluginRoot(), DEFAULT_CONFIG.RSC_WORKER_PATH);
47
+
48
+ log.info("RSC worker path:" + rscWorkerPath);
15
49
 
16
50
  return {
17
- name: "vite:react-stream-client",
18
- async config(config): Promise<UserConfig> {
51
+ name: "vite:react-client",
52
+
53
+ async config(config, configEnv) {
54
+ if (
55
+ typeof config.root === "string" &&
56
+ config.root !== root &&
57
+ config.root !== process.cwd() &&
58
+ config.root !== ""
59
+ ) {
60
+ root = config.root;
61
+ console.log("[vite:react-client] Root updated:", root);
62
+ }
63
+ if (configEnv.command === "serve" && !configEnv.isPreview && !worker) {
64
+ worker = await createWorker({
65
+ projectRoot: root,
66
+ workerPath: rscWorkerPath,
67
+ reverseCondition: true,
68
+ });
69
+ }
70
+ const pages = await resolvePages(userOptions.build.pages);
71
+ if (pages.type === "error") {
72
+ throw pages.error;
73
+ }
74
+
75
+ if (pages.pages.length > 0) {
76
+ files = await checkFilesExist(pages.pages, userOptions, root);
77
+ } else {
78
+ files = {
79
+ pageMap: new Map(),
80
+ propsMap: new Map(),
81
+ propsSet: new Set(),
82
+ pageSet: new Set(),
83
+ urlMap: new Map(),
84
+ errors: [],
85
+ };
86
+ }
87
+
19
88
  const resolvedConfig = resolveUserConfig({
20
- condition: "react-client",
89
+ isClient: true,
21
90
  config,
22
- configEnv: { command: "build", mode: "production" },
91
+ configEnv,
23
92
  userOptions,
93
+ files,
24
94
  });
25
95
 
26
96
  if (resolvedConfig.type === "error") {
27
97
  throw resolvedConfig.error;
28
98
  }
29
99
 
30
- return resolvedConfig.userConfig;
31
- }
100
+ userConfig = resolvedConfig.userConfig;
101
+ return userConfig;
102
+ },
103
+
104
+ configResolved(config) {
105
+ resolvedConfig = config;
106
+ },
107
+
108
+ async generateBundle(options, bundle) {
109
+ // Create manifest entries for each chunk
110
+ clientManifest = getBundleManifest({
111
+ pluginContext: this,
112
+ bundle,
113
+ moduleBase: userOptions.moduleBase,
114
+ preserveModulesRoot: userOptions.build.preserveModulesRoot,
115
+ });
116
+
117
+ // Write manifest immediately after generation
118
+ const manifestPath = join(
119
+ root,
120
+ resolvedConfig.environments["client"].build.outDir as string,
121
+ resolvedConfig.environments["client"].build.manifest as string
122
+ );
123
+ await mkdir(dirname(manifestPath), { recursive: true });
124
+
125
+ return await writeFile(
126
+ manifestPath,
127
+ JSON.stringify(clientManifest, null, 2)
128
+ );
129
+ },
130
+
131
+ async configurePreviewServer(server) {
132
+ if (root !== server.config.root) {
133
+ root = server.config.root;
134
+ }
135
+ if (typeof loader !== "function") {
136
+ loader = (id: string) => import(id);
137
+ }
138
+ const normalize = createInputNormalizer({
139
+ root,
140
+ removeExtension: false,
141
+ preserveModulesRoot: userOptions.build.preserveModulesRoot
142
+ ? userOptions.moduleBase
143
+ : undefined,
144
+ });
145
+ server.middlewares.use(async (req, res, next) => {
146
+ const [key, value] = normalize(req.url);
147
+ const fileRoot = key.startsWith("node_modules")
148
+ ? root
149
+ : join(root, userOptions.build.outDir, userOptions.build.client);
150
+ if (value.endsWith(".js")) {
151
+ try {
152
+ const stats = await stat(join(fileRoot, value));
153
+ if (stats.isFile()) {
154
+ const content = await readFile(join(fileRoot, value), "utf-8");
155
+ res.setHeader("Content-Type", "application/javascript");
156
+ res.end(content);
157
+ return;
158
+ } else {
159
+ next();
160
+ }
161
+ } catch (error) {
162
+ const { manifest: clientManifest } = tryManifest({
163
+ root,
164
+ outDir: join(userOptions.build.outDir, userOptions.build.client),
165
+ });
166
+ const { manifest: serverManifest } = tryManifest({
167
+ root,
168
+ outDir: join(userOptions.build.outDir, userOptions.build.server),
169
+ });
170
+ if (clientManifest && value in clientManifest) {
171
+ res.setHeader("Content-Type", "application/javascript");
172
+ res.end(clientManifest[value]);
173
+ return;
174
+ } else if (serverManifest && value in serverManifest) {
175
+ res.setHeader("Content-Type", "application/javascript");
176
+ res.end(serverManifest[value]);
177
+ return;
178
+ }
179
+ const foundClient =
180
+ clientManifest &&
181
+ Object.entries(clientManifest).find(
182
+ ([key, value]) =>
183
+ value === key ||
184
+ value === value.file ||
185
+ value === value.src ||
186
+ value === value.name
187
+ );
188
+ if (foundClient) {
189
+ res.setHeader("Content-Type", "application/javascript");
190
+ res.end(foundClient);
191
+ }
192
+ const foundServer =
193
+ serverManifest &&
194
+ Object.entries(serverManifest).find(
195
+ ([key, value]) =>
196
+ value === key ||
197
+ value === value.file ||
198
+ value === value.src ||
199
+ value === value.name
200
+ );
201
+
202
+ if (foundServer) {
203
+ res.setHeader("Content-Type", "application/javascript");
204
+ res.end(foundServer);
205
+ return;
206
+ }
207
+ next();
208
+ }
209
+ } else {
210
+ next();
211
+ }
212
+ });
213
+ },
214
+ // setup dev server
215
+ async configureServer(server) {
216
+ if (typeof loader !== "function") {
217
+ loader = server.ssrLoadModule;
218
+ }
219
+ if (!worker) {
220
+ log.info("Creating RSC worker...");
221
+ worker = await createWorker({
222
+ projectRoot: root,
223
+ workerPath: rscWorkerPath,
224
+ condition: "react-client",
225
+ });
226
+ log.info("RSC worker created");
227
+ }
228
+ const normalize = createInputNormalizer({
229
+ root,
230
+ removeExtension: false,
231
+ preserveModulesRoot: userOptions.build.preserveModulesRoot
232
+ ? userOptions.moduleBase
233
+ : undefined,
234
+ });
235
+ server.middlewares.use(async (req, res, next) => {
236
+ if (!req.url) {
237
+ next();
238
+ return;
239
+ }
240
+ if (
241
+ req.url.endsWith(".rsc") ||
242
+ req.headers.accept?.includes("text/x-component")
243
+ ) {
244
+ try {
245
+ const path = req.url?.includes("index.rsc")
246
+ ? req.url.replace("index.rsc", "")
247
+ : req.url?.replace(".rsc", "");
248
+ let [key, value] = normalize(path);
249
+
250
+ let pageImport = DEFAULT_CONFIG.PAGE as string;
251
+ let propsImport = DEFAULT_CONFIG.PROPS as string;
252
+ // PAGE
253
+ // no trailing slash
254
+ const pathNoTrailing = path?.replace(/\/$/, '');
255
+ if (files.urlMap.has(req.url)) {
256
+ pageImport = files.urlMap.get(req.url)!.page;
257
+ propsImport = files.urlMap.get(req.url)!.props;
258
+ } else if (files.urlMap.has(pathNoTrailing)) {
259
+ pageImport = files.urlMap.get(pathNoTrailing)!.page;
260
+ propsImport = files.urlMap.get(pathNoTrailing)!.props;
261
+ } else if (files.urlMap.has(path)) {
262
+ pageImport = files.urlMap.get(path)!.page;
263
+ propsImport = files.urlMap.get(path)!.props;
264
+ } else if (files.urlMap.has(value)) {
265
+ pageImport = files.urlMap.get(value)!.page;
266
+ propsImport = files.urlMap.get(value)!.props;
267
+ } else if (files.urlMap.has(key)) {
268
+ pageImport = files.urlMap.get(key)!.page;
269
+ propsImport = files.urlMap.get(key)!.props;
270
+ } else {
271
+ console.warn(`Page/props import not found for any of the following (in order of priority): ${[req.url, pathNoTrailing, path, value, key].filter(Boolean).join(', ')} available pages:${Array.from(files.urlMap.keys()).join(', ')}`);
272
+ }
273
+ // Set headers early
274
+ res.setHeader("Content-Type", "text/x-component");
275
+ res.setHeader("Transfer-Encoding", "chunked");
276
+ res.setHeader("Connection", "keep-alive");
277
+
278
+ let hasError = false;
279
+ const timeout = setTimeout(() => {
280
+ if (!hasError) {
281
+ hasError = true;
282
+ res.statusCode = 500;
283
+ res.end("RSC render timeout");
284
+ }
285
+ }, 5000);
286
+
287
+ const messageHandler = (
288
+ message: RscWorkerMessage | RscWorkerResponse
289
+ ) => {
290
+ try {
291
+ switch (message.type) {
292
+ case "RSC_CHUNK":
293
+ // Write chunk directly to response
294
+ if (!hasError) {
295
+ res.write(message.chunk);
296
+ }
297
+ break;
298
+
299
+ case "RSC_END":
300
+ clearTimeout(timeout);
301
+ if (!hasError) {
302
+ res.end();
303
+ }
304
+ worker.off("message", messageHandler);
305
+ break;
306
+
307
+ case "ERROR":
308
+ clearTimeout(timeout);
309
+ log.error("Render error", message);
310
+ if (!hasError) {
311
+ hasError = true;
312
+ res.statusCode = 500;
313
+ res.end(message.error);
314
+ }
315
+ worker.off("message", messageHandler);
316
+ break;
317
+ }
318
+ } catch (error) {
319
+ clearTimeout(timeout);
320
+ if (!hasError) {
321
+ hasError = true;
322
+ res.statusCode = 500;
323
+ res.end(
324
+ error instanceof Error ? error.message : String(error)
325
+ );
326
+ }
327
+ worker.off("message", messageHandler);
328
+ }
329
+ };
330
+
331
+ worker.on("message", messageHandler);
332
+ worker.once("error", (error) => {
333
+ clearTimeout(timeout);
334
+ if (!hasError) {
335
+ hasError = true;
336
+ res.statusCode = 500;
337
+ res.end(error instanceof Error ? error.message : String(error));
338
+ }
339
+ worker.off("message", messageHandler);
340
+ });
341
+ worker.postMessage({
342
+ type: "RSC_RENDER",
343
+ id: value,
344
+ pageImport,
345
+ propsImport,
346
+ url: req.url ?? "/",
347
+ pageExportName:
348
+ userOptions.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT_NAME,
349
+ propsExportName:
350
+ userOptions.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT_NAME,
351
+ outDir: userOptions.build.outDir,
352
+ projectRoot: root,
353
+ moduleRootPath:
354
+ userOptions.build.preserveModulesRoot === true
355
+ ? userOptions.moduleBase
356
+ : "",
357
+ moduleBaseURL: ``,
358
+ moduleBasePath: '/',
359
+ pipableStreamOptions: userOptions.pipableStreamOptions,
360
+ cssFiles: []
361
+ } satisfies RscRenderMessage);
362
+ } catch (error) {
363
+ log.error("Middleware error:", error);
364
+ res.statusCode = 500;
365
+ res.end(error instanceof Error ? error.message : String(error));
366
+ }
367
+ } else {
368
+ next();
369
+ }
370
+ });
371
+ },
32
372
  };
33
373
  }
@@ -7,7 +7,7 @@ import {
7
7
  import { DEFAULT_CONFIG } from "../config/defaults.js";
8
8
  import { resolvePage } from "../resolvePage.js";
9
9
  import { resolveProps } from "../resolveProps.js";
10
- import type { CreateHandlerOptions, StreamPluginOptions } from "../types.js";
10
+ import type { CreateHandlerOptions, ResolvedUserOptions } from "../types.js";
11
11
  import { createRscStream } from "./createRscStream.js";
12
12
 
13
13
  type CreateHandlerResult =
@@ -22,22 +22,16 @@ interface HandlerAssets {
22
22
 
23
23
  export async function createHandler<T>(
24
24
  url: string,
25
- pluginOptions: Pick<
26
- StreamPluginOptions,
27
- "Page" | "props" | "build" | "Html" | "pageExportName" | "propsExportName"
28
- > &
29
- Required<
30
- Pick<StreamPluginOptions, "moduleBase" | "moduleBasePath" | "projectRoot">
31
- >,
25
+ pluginOptions: ResolvedUserOptions,
32
26
  streamOptions: CreateHandlerOptions<T>
33
27
  ): Promise<CreateHandlerResult> {
34
28
  const root = pluginOptions.projectRoot ?? process.cwd();
35
29
 
36
30
  const Html = pluginOptions.Html ?? DEFAULT_CONFIG.HTML;
37
31
  const pageExportName =
38
- pluginOptions.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT;
32
+ pluginOptions.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT_NAME;
39
33
  const propsExportName =
40
- pluginOptions.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT;
34
+ pluginOptions.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT_NAME;
41
35
  const controller = new AbortController();
42
36
 
43
37
  const cssFiles = streamOptions.cssFiles;
@@ -52,13 +46,13 @@ export async function createHandler<T>(
52
46
 
53
47
  const cssModules = new Set<string>();
54
48
 
55
- if (!(streamOptions.manifest || streamOptions.moduleGraph))
56
- throw new Error("Missing manifest or moduleGraph, pass it to options.");
49
+ if (!(streamOptions.serverManifest || streamOptions.moduleGraph))
50
+ throw new Error("Missing server manifest or moduleGraph, pass it to options.");
57
51
 
58
- const getCss = streamOptions.manifest
52
+ const getCss = streamOptions.serverManifest
59
53
  ? (id: string) =>
60
54
  collectManifestCss(
61
- streamOptions.manifest!,
55
+ streamOptions.serverManifest!,
62
56
  root,
63
57
  id,
64
58
  streamOptions.onCssFile
@@ -69,7 +63,13 @@ export async function createHandler<T>(
69
63
  try {
70
64
  const mod = await streamOptions.loader(id);
71
65
  const pageCss = await Promise.resolve(getCss(id));
72
- Array.from(pageCss.keys()).forEach((css) => cssModules.add(css));
66
+ Array.from(pageCss.keys()).forEach((css) => {
67
+ cssModules.add(css);
68
+ // Notify about new CSS file if callback exists
69
+ if (streamOptions.onCssFile) {
70
+ streamOptions.onCssFile(css);
71
+ }
72
+ });
73
73
  return mod as Record<string, any>;
74
74
  } catch (e: any) {
75
75
  if (e.message?.includes("module runner has been closed")) {
@@ -126,12 +126,11 @@ export async function createHandler<T>(
126
126
  if (streamOptions.cssFiles) {
127
127
  streamOptions.cssFiles.forEach((css) => cssModules.add(css));
128
128
  }
129
-
130
129
  const stream = createRscStream({
131
130
  Html: Html,
132
131
  Page: Page,
133
132
  props: props,
134
- moduleBasePath: pluginOptions.moduleBasePath,
133
+ moduleBasePath: '',
135
134
  logger: streamOptions.logger ?? createLogger(),
136
135
  cssFiles: Array.from(cssModules),
137
136
  route: url,
@@ -145,7 +144,6 @@ export async function createHandler<T>(
145
144
  });
146
145
 
147
146
  if (!stream) {
148
- console.log("[createHandler] No stream created for route:", url);
149
147
  return { type: "skip" as const };
150
148
  }
151
149
 
@@ -1,49 +1,82 @@
1
1
  import * as React from "react";
2
- import type { PipeableStream } from "react-dom/server";
3
2
  // @ts-ignore
4
3
  import { renderToPipeableStream } from "react-server-dom-esm/server.node";
5
- import { CssCollector } from "../components.js";
6
- import type { RscStreamOptions } from "../types.js";
4
+ import type { PipeableStreamOptions } from "../worker/types.js";
5
+ import type { Logger } from "vite";
7
6
 
8
- export function createRscStream(
9
- streamOptions: RscStreamOptions
10
- ): PipeableStream {
11
- const {
12
- Html,
13
- Page,
14
- props,
15
- logger,
16
- cssFiles,
17
- moduleBasePath,
18
- pipableStreamOptions,
19
- htmlProps,
20
- } = streamOptions;
21
7
 
22
- const css = Array.isArray(cssFiles)
23
- ? cssFiles.map((css, index) =>
24
- React.createElement(CssCollector, {
25
- key: `css-${index}`,
26
- url: css.startsWith("/") ? css : `/${css}`,
27
- moduleBasePath,
28
- })
29
- )
30
- : [];
31
- return renderToPipeableStream(
32
- React.createElement(
33
- Html,
34
- {
35
- key: "html",
36
- ...htmlProps
37
- },
38
- React.createElement(Page, { key: "page", ...props }),
39
- ...css
40
- ),
41
- moduleBasePath,
42
- {
43
- onError: logger?.error ?? console.error,
44
- onPostpone: logger?.info ?? console.info,
45
- environmentName: "Server",
46
- ...pipableStreamOptions
47
- }
8
+ // CSS collector component
9
+ function CssCollector({
10
+ children,
11
+ cssFiles,
12
+ }: {
13
+ children?: React.ReactNode;
14
+ cssFiles: string[];
15
+ }) {
16
+ return React.createElement(
17
+ React.Fragment,
18
+ null,
19
+ ...cssFiles.map((css) => {
20
+ const url = css.startsWith('/') || css.startsWith('http') || css.startsWith('./') ? css : '/'+css
21
+ return React.createElement('link', {
22
+ key: css,
23
+ rel: 'stylesheet',
24
+ href: url
25
+ })
26
+ }),
27
+ children
48
28
  );
49
29
  }
30
+
31
+ export function createRscStream({
32
+ Html,
33
+ Page,
34
+ props,
35
+ moduleBasePath,
36
+ logger,
37
+ cssFiles = [],
38
+ route,
39
+ url,
40
+ pipableStreamOptions,
41
+ htmlProps,
42
+ }: {
43
+ Html: React.ComponentType<any>;
44
+ Page: React.ComponentType<any>;
45
+ props: any;
46
+ moduleBasePath: string;
47
+ logger: Logger;
48
+ cssFiles?: string[];
49
+ route: string;
50
+ url: string;
51
+ pipableStreamOptions?: PipeableStreamOptions;
52
+ htmlProps?: any;
53
+ }) {
54
+
55
+ const htmlIsFragment = Html == React.Fragment;
56
+ const withCss = React.createElement(
57
+ CssCollector,
58
+ { cssFiles },
59
+ React.createElement(Page, props)
60
+ )
61
+ // Otherwise wrap with Html component
62
+ const content = htmlIsFragment
63
+ ? withCss
64
+ : React.createElement(Html, htmlProps, withCss);
65
+ try {
66
+ return renderToPipeableStream(
67
+ content,
68
+ moduleBasePath,
69
+ {
70
+ onError: (error: Error) => {
71
+ logger.error(`Stream error at ${route}.`, {error});
72
+ },
73
+ onPostpone: logger.info ?? console.info,
74
+ environmentName: "Server",
75
+ ...pipableStreamOptions,
76
+ }
77
+ );
78
+ } catch (error) {
79
+ logger.error(`Failed to create stream for ${route}.`, {error: error as Error});
80
+ return null;
81
+ }
82
+ }