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
@@ -1,28 +1,16 @@
1
1
  import { join, resolve } from "node:path";
2
2
  import { Writable } from "node:stream";
3
3
  import { Worker } from "node:worker_threads";
4
- import { type ViteDevServer } from "vite";
4
+ import { type Manifest, type ViteDevServer } from "vite";
5
5
  import { DEFAULT_CONFIG } from "../config/defaults.js";
6
- import type { RequestHandler, StreamPluginOptions } from "../types.js";
6
+ import type { RequestHandler, ResolvedUserOptions } from "../types.js";
7
7
  import type { WorkerRscChunkMessage } from "../worker/types.js";
8
8
  import { createHandler } from "./createHandler.js";
9
9
 
10
10
 
11
11
  export function createSsrHandler(
12
- options: Required<
13
- Pick<
14
- StreamPluginOptions,
15
- "Page" | "props" | "build" | "Html" | "pageExportName" | "propsExportName"
16
- >
17
- > &
18
- Required<
19
- Pick<
20
- StreamPluginOptions,
21
- "moduleBase" | "moduleBasePath" | "moduleBaseURL" | "projectRoot" | "htmlWorkerPath"
22
- >
23
- >,
12
+ options: ResolvedUserOptions,
24
13
  server: ViteDevServer,
25
- _clientComponents: Map<string, string>
26
14
  ): RequestHandler {
27
15
  const worker = new Worker(
28
16
  options?.htmlWorkerPath
@@ -52,14 +40,7 @@ export function createSsrHandler(
52
40
  const result = await createHandler(
53
41
  req.url ?? "",
54
42
  {
55
- Page: options.Page,
56
- props: options.props,
57
- build: options.build,
58
- Html: options.Html,
59
- pageExportName: options.pageExportName,
60
- propsExportName: options.propsExportName,
61
- moduleBase: options.moduleBase,
62
- moduleBasePath: options.moduleBasePath,
43
+ ...options,
63
44
  projectRoot: server.config.root,
64
45
  },
65
46
  {
@@ -116,9 +97,9 @@ export function createSsrHandler(
116
97
  // Don't need file paths in dev mode
117
98
  outDir: "",
118
99
  htmlOutputPath: "",
119
- pipableStreamOptions: {
120
- bootstrapModules: ["/dist/client.js"],
121
- },
100
+ pipableStreamOptions: options.pipableStreamOptions ?? {},
101
+ clientManifest: {},
102
+ serverManifest: {},
122
103
  } satisfies WorkerRscChunkMessage);
123
104
 
124
105
  worker.once("message", (msg) => {
@@ -1,6 +1,4 @@
1
- import { readdirSync } from "fs";
2
- import type { ServerResponse } from "node:http";
3
- import { join, resolve } from "node:path";
1
+ import { join, resolve, dirname } from "node:path";
4
2
  import { performance } from "node:perf_hooks";
5
3
  import { Worker } from "node:worker_threads";
6
4
  import React from "react";
@@ -9,6 +7,8 @@ import {
9
7
  type ResolvedConfig,
10
8
  type UserConfig,
11
9
  type ViteDevServer,
10
+ type Manifest,
11
+ build,
12
12
  } from "vite";
13
13
  import { checkFilesExist } from "../checkFilesExist.js";
14
14
  import { DEFAULT_CONFIG } from "../config/defaults.js";
@@ -16,7 +16,6 @@ import { getPluginRoot } from "../config/getPaths.js";
16
16
  import { resolveOptions } from "../config/resolveOptions.js";
17
17
  import { resolvePages } from "../config/resolvePages.js";
18
18
  import { resolveUserConfig } from "../config/resolveUserConfig.js";
19
- import { getModuleManifest } from "../helpers/getModuleManifest.js";
20
19
  import { tryManifest } from "../helpers/tryManifest.js";
21
20
  import { createBuildLoader } from "../loader/createBuildLoader.js";
22
21
  import type {
@@ -30,7 +29,17 @@ import { type StreamPluginOptions } from "../types.js";
30
29
  import { createWorker } from "../worker/createWorker.js";
31
30
  import { renderPages } from "../worker/html/renderPages.js";
32
31
  import { createHandler } from "./createHandler.js";
32
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
33
+ import { getBundleManifest } from "../helpers/getBundleManifest.js";
34
+ import type { ServerResponse } from "node:http";
33
35
 
36
+ let resolvedConfig: ResolvedConfig | null = null;
37
+ let serverManifestPath: string | null = null;
38
+ let clientManifestPath: string | null = null;
39
+ let outpuptBundle: any;
40
+ let outputOptions: any;
41
+ let loader: ((id: string) => Promise<Record<string, any>>) | null = null;
42
+ let worker: Worker;
34
43
  export function reactServerPlugin(
35
44
  options: StreamPluginOptions
36
45
  ): import("vite").Plugin<{
@@ -43,8 +52,6 @@ export function reactServerPlugin(
43
52
 
44
53
  let files: CheckFilesExistReturn;
45
54
  // let env: Awaited<ReturnType<typeof getEnv>>;
46
- let worker: Worker;
47
- let finalConfig: ResolvedConfig;
48
55
  let cssModules = new Set<string>();
49
56
  let clientComponents = new Map<string, string>();
50
57
  // let define: Record<string, string>;
@@ -63,6 +70,7 @@ export function reactServerPlugin(
63
70
  dynamicImports: string[];
64
71
  }
65
72
  > = {};
73
+ let serverManifest: Manifest = {};
66
74
 
67
75
  interface BuildStats {
68
76
  htmlFiles: number;
@@ -82,7 +90,19 @@ export function reactServerPlugin(
82
90
  throw resolvedOptions.error;
83
91
  }
84
92
  userOptions = resolvedOptions.userOptions;
85
- root = userOptions.projectRoot;
93
+ if (
94
+ userOptions.projectRoot != root &&
95
+ typeof userOptions.projectRoot === "string" &&
96
+ userOptions.projectRoot !== process.cwd() &&
97
+ userOptions.projectRoot !== ""
98
+ ) {
99
+ root = userOptions.projectRoot;
100
+ console.log(
101
+ "[vite:plugin-react-server] Root dir changed in plugin",
102
+ userOptions.projectRoot,
103
+ root
104
+ );
105
+ }
86
106
  return {
87
107
  name: "vite:react-stream-server",
88
108
  enforce: "post",
@@ -92,20 +112,25 @@ export function reactServerPlugin(
92
112
  buildCssFiles.add(path);
93
113
  },
94
114
  },
95
- configResolved(resolvedConfig) {
96
- finalConfig = resolvedConfig;
115
+ configResolved(_resolvedConfig) {
116
+ resolvedConfig = _resolvedConfig;
117
+
118
+ serverManifestPath = join(
119
+ userOptions.build.outDir,
120
+ userOptions.build.server,
121
+ ".vite/manifest.json"
122
+ );
123
+ clientManifestPath = join(
124
+ resolvedConfig.build.outDir,
125
+ userOptions.build.client,
126
+ ".vite/manifest.json"
127
+ );
97
128
  timing.configResolved = performance.now();
98
- if (finalConfig.command === "build") {
99
- finalConfig = {
100
- ...finalConfig,
101
- mode: "production",
102
- };
103
- }
104
129
 
105
130
  // Verify transformer runs first, preserver runs last
106
- const plugins = finalConfig.plugins;
131
+ const plugins = resolvedConfig.plugins;
107
132
  const transformerIndex = plugins.findIndex(
108
- (p) => p.name === "vite:react-stream-transformer"
133
+ (p) => p.name === "vite:react-transform"
109
134
  );
110
135
  const preserverIndex = plugins.findIndex(
111
136
  (p) => p.name === "vite-plugin-react-server:preserve-directives"
@@ -119,17 +144,29 @@ export function reactServerPlugin(
119
144
  "Transformer plugin isn't installed or isn't running before preserver"
120
145
  );
121
146
  }
147
+ },
148
+ async configurePreviewServer(server) {
149
+
122
150
  },
123
151
  async configureServer(server: ViteDevServer) {
124
- if (server.config.root !== root) {
152
+ if (typeof loader !== "function") {
153
+ loader = server.ssrLoadModule;
154
+ }
155
+ if (
156
+ server.config.root !== root &&
157
+ typeof server.config.root === "string" &&
158
+ server.config.root !== process.cwd() &&
159
+ server.config.root !== ""
160
+ ) {
125
161
  console.log(
126
- "[vite-plugin-react-server] Root dir changed",
162
+ "[vite:plugin-react-server] Root dir changed in configureServer hook",
127
163
  server.config.root,
128
164
  root
129
165
  );
130
166
  root = server.config.root;
131
167
  }
132
168
 
169
+
133
170
  const activeStreams = new Set<ServerResponse>();
134
171
 
135
172
  // Handle Vite server restarts
@@ -150,35 +187,32 @@ export function reactServerPlugin(
150
187
  activeStreams.clear();
151
188
  });
152
189
 
153
- server.ws.on("connection", (_socket, _req) => {
154
- console.log("[vite-plugin-react-server] hooking up ws connection");
155
- });
190
+ // server.ws.on("connection", (_socket, _req) => {
191
+ // console.log("[vite-plugin-react-server] hooking up ws connection");
192
+ // });
156
193
 
157
- server.ws.on("listening", () => {
158
- console.log("[vite-plugin-react-server] hooking up ws listening");
159
- });
194
+ // server.ws.on("listening", () => {
195
+ // console.log("[vite-plugin-react-server] hooking up ws listening");
196
+ // });
160
197
 
161
198
  server.middlewares.use(async (req, res, next) => {
162
199
  if (req.headers.accept !== "text/x-component") return next();
163
- console.log("[vite-plugin-react-server] middleware called");
200
+ if (typeof loader !== "function") {
201
+ loader = server.ssrLoadModule;
202
+ }
164
203
  try {
165
204
  const handler = await createHandler(
166
205
  req.url ?? "",
167
206
  {
168
- Page: userOptions.Page,
169
- props: userOptions.props,
170
- build: userOptions.build,
207
+ ...userOptions,
208
+ // we'll leave the Html generation for later
171
209
  Html: React.Fragment,
172
- pageExportName: userOptions.pageExportName,
173
- propsExportName: userOptions.propsExportName,
174
- moduleBase: userOptions.moduleBase,
175
- moduleBasePath: userOptions.moduleBasePath,
176
210
  projectRoot: root,
177
211
  },
178
212
  {
179
- cssFiles: Array.from(cssModules),
213
+ cssFiles: [],
180
214
  logger: createLogger(),
181
- loader: server.ssrLoadModule,
215
+ loader,
182
216
  moduleGraph: server.moduleGraph,
183
217
  }
184
218
  );
@@ -188,17 +222,23 @@ export function reactServerPlugin(
188
222
  activeStreams.add(res);
189
223
  } finally {
190
224
  res.on("close", () => {
191
- console.log(
192
- "[vite-plugin-react-server] ➖ Stream closed for:",
193
- req.url
194
- );
195
225
  activeStreams.delete(res);
196
226
  });
197
227
  }
198
228
  });
199
229
  },
200
230
  async config(config, configEnv): Promise<UserConfig> {
201
- if (typeof config.root === "string" && config.root !== root && config.root !== process.cwd() && config.root !== "") {
231
+ if (
232
+ typeof config.root === "string" &&
233
+ config.root !== root &&
234
+ config.root !== process.cwd() &&
235
+ config.root !== ""
236
+ ) {
237
+ console.log(
238
+ "[vite:plugin-react-server] Root dir changed in config hook",
239
+ config.root,
240
+ root
241
+ );
202
242
  root = config.root;
203
243
  }
204
244
  const resolvedPages = await resolvePages(userOptions.build.pages);
@@ -209,7 +249,7 @@ export function reactServerPlugin(
209
249
  files = await checkFilesExist(resolvedPages.pages, userOptions, root);
210
250
 
211
251
  const resolvedConfig = resolveUserConfig({
212
- condition: "react-server",
252
+ isClient: false,
213
253
  config,
214
254
  configEnv,
215
255
  userOptions,
@@ -221,7 +261,6 @@ export function reactServerPlugin(
221
261
  }
222
262
 
223
263
  userConfig = resolvedConfig.userConfig;
224
-
225
264
  return resolvedConfig.userConfig;
226
265
  },
227
266
  async buildStart() {
@@ -232,82 +271,108 @@ export function reactServerPlugin(
232
271
  }
233
272
  },
234
273
  async closeBundle() {
235
- if (!userConfig || finalConfig.command !== "build") return;
274
+ if (!userConfig || resolvedConfig?.command !== "build") return;
236
275
  try {
237
276
  timing.renderStart = performance.now();
238
277
 
239
- const resolvedServerManifest = tryManifest({
240
- root,
241
- outDir: userOptions.build.server,
278
+ // Get the client manifest
279
+ const clientManifestResult = tryManifest({
280
+ root: root,
281
+ outDir: join(userOptions.build.outDir, userOptions.build.client),
242
282
  ssrManifest: false,
243
283
  });
244
284
 
245
- const serverManifest =
246
- resolvedServerManifest.type === "error"
247
- ? getModuleManifest.bind(this)()
248
- : resolvedServerManifest.manifest;
249
- // Get worker path from manifest
250
- // Look for the html-worker entry directly
251
- let htmlWorkerPath = serverManifest["html-worker"]?.file;
252
-
253
- if (options.htmlWorkerPath) {
254
- htmlWorkerPath = options.htmlWorkerPath;
255
- } else {
256
- htmlWorkerPath = join(
257
- getPluginRoot(),
258
- DEFAULT_CONFIG.HTML_WORKER_PATH
259
- );
285
+ if (clientManifestResult.type === "error") {
286
+ throw clientManifestResult.error;
260
287
  }
261
288
 
289
+ const clientManifest = clientManifestResult.manifest;
290
+
291
+ // Initialize worker
292
+ const htmlWorkerPath = join(
293
+ getPluginRoot(),
294
+ DEFAULT_CONFIG.HTML_WORKER_PATH
295
+ );
296
+
262
297
  worker = await createWorker({
263
298
  projectRoot: root,
264
299
  workerPath: htmlWorkerPath,
265
300
  condition: "react-server",
266
301
  reverseCondition: true,
267
- mode: finalConfig.mode as "production" | "development",
302
+ mode: (resolvedConfig?.mode ?? "production") as
303
+ | "production"
304
+ | "development",
268
305
  nodeOptions: "--conditions=react-client",
269
306
  });
270
307
 
271
- // Get routes directly from pages
308
+ // Create the loader
309
+ if (typeof loader !== "function") {
310
+ if (!Object.keys(serverManifest).length) {
311
+ console.warn("[vite-plugin-react-server] No server manifest found, the plugin will try to use the plugin context - it may differ from vite's manifest.");
312
+ serverManifest = getBundleManifest({
313
+ pluginContext: this,
314
+ bundle: outpuptBundle,
315
+ moduleBase: userOptions.moduleBase,
316
+ preserveModulesRoot: userOptions.build.preserveModulesRoot,
317
+ });
318
+ if (!Object.keys(serverManifest).length) {
319
+ console.warn("[vite-plugin-react-server] That didn't work, retrying to read manifest.");
320
+ const resolvedServerManifest = tryManifest({
321
+ root: root,
322
+ outDir: join(userOptions.build.outDir, userOptions.build.server),
323
+ ssrManifest: false,
324
+ });
325
+ if (resolvedServerManifest.type === "error") {
326
+ // dont build the static files without a server manifest
327
+ console.error("[vite-plugin-react-server] Failed to read manifest, aborting build.");
328
+ return;
329
+ }
330
+ serverManifest = resolvedServerManifest.manifest;
331
+ }
332
+ }
333
+ loader = createBuildLoader({
334
+ root: root,
335
+ userConfig,
336
+ userOptions,
337
+ pluginContext: this,
338
+ serverManifest,
339
+ clientManifest,
340
+ });
341
+ }
272
342
  const resolvedPages = await resolvePages(userOptions.build.pages);
273
343
  if (resolvedPages.type === "error") {
274
344
  throw resolvedPages.error;
275
345
  }
276
- const routes = resolvedPages.pages;
277
-
278
- const entries = Object.values(serverManifest).filter(
279
- (entry) => entry.isEntry
346
+ const { failedRoutes, completedRoutes } = await renderPages(
347
+ this,
348
+ resolvedPages.pages,
349
+ files,
350
+ {
351
+ pipableStreamOptions: {},
352
+ moduleBasePath: "",
353
+ moduleBaseURL: "",
354
+ clientCss:
355
+ Object.values(clientManifest)
356
+ .flatMap((entry) => entry.css)
357
+ .filter((css) => typeof css === "string")
358
+ .map((css) => "/" + css) ?? [],
359
+ userConfig,
360
+ pluginOptions: userOptions,
361
+ worker: worker,
362
+ clientManifest: clientManifest,
363
+ serverManifest: serverManifest,
364
+ loader,
365
+ onCssFile: async (path: string) => {
366
+ if (buildCssFiles && path.endsWith(".css")) {
367
+ buildCssFiles.add(path);
368
+ // copy the file to the client build dir
369
+ const clientPath = join(userOptions.build.outDir, userOptions.build.client, path);
370
+ await mkdir(dirname(clientPath), { recursive: true });
371
+ await writeFile(clientPath, await readFile(join(root, userOptions.build.outDir, userOptions.build.server, path)));
372
+ }
373
+ },
374
+ }
280
375
  );
281
- const css = entries.flatMap((entry) => entry.css);
282
- const loader = createBuildLoader({
283
- root,
284
- userConfig,
285
- pluginContext: this,
286
- });
287
-
288
- const { failedRoutes, completedRoutes } = await renderPages(routes, {
289
- pipableStreamOptions: {
290
- bootstrapModules: entries
291
- .filter((entry) =>
292
- userOptions.autoDiscover.clientComponents.test(entry.file)
293
- )
294
- .filter((t)=> typeof t === "object" && t != null && "file" in t)
295
- .map((entry) => "/" + entry.file),
296
- },
297
- moduleBasePath: userOptions.moduleBasePath,
298
- moduleBaseURL: userOptions.moduleBaseURL,
299
- clientCss: css?.filter((css) => typeof css === "string").map((css) => "/" + css) ?? [],
300
- userConfig,
301
- pluginOptions: userOptions,
302
- worker: worker,
303
- manifest: serverManifest,
304
- loader,
305
- onCssFile: (path: string) => {
306
- if (buildCssFiles && path.endsWith(".css")) {
307
- buildCssFiles.add(path);
308
- }
309
- },
310
- });
311
376
 
312
377
  if (failedRoutes.size) {
313
378
  console.error(
@@ -320,12 +385,16 @@ export function reactServerPlugin(
320
385
  timing.renderEnd = performance.now();
321
386
  timing.total = (timing.renderEnd - timing.start) / 1000;
322
387
 
323
- // Collect stats
388
+ // Update stats to include CSS and client components
324
389
  const stats: BuildStats = {
325
- htmlFiles: routes.length,
326
- clientComponents: clientComponents.size,
327
- cssFiles: cssModules.size,
328
- totalRoutes: routes.length,
390
+ htmlFiles: userOptions.build.pages.length,
391
+ clientComponents: Object.keys(clientManifest).filter(
392
+ userOptions.autoDiscover.clientComponents
393
+ ).length,
394
+ cssFiles: Object.keys(clientManifest)
395
+ .flatMap(userOptions.autoDiscover.cssPattern)
396
+ .filter(Boolean).length,
397
+ totalRoutes: userOptions.build.pages.length,
329
398
  timing: {
330
399
  config: ((timing.configResolved ?? 0) - timing.start) / 1000,
331
400
  build:
@@ -364,7 +433,6 @@ export function reactServerPlugin(
364
433
 
365
434
  // Ensure worker is terminated
366
435
  if (worker) {
367
- console.log("[vite-plugin-react-server] Terminating worker...");
368
436
  await worker.terminate();
369
437
  worker = null as any;
370
438
  }
@@ -372,72 +440,41 @@ export function reactServerPlugin(
372
440
  console.error("[vite-plugin-react-server] Build failed:", error);
373
441
  // Make sure to terminate worker even on error
374
442
  if (worker) await worker.terminate();
443
+ worker = null as any;
375
444
  throw error;
376
445
  }
377
446
  },
378
447
  async buildEnd(error) {
379
448
  if (error) {
380
449
  console.error("[vite-plugin-react-server] Build error:", error);
450
+ return;
381
451
  }
382
- if (worker) await worker.terminate();
383
452
  },
384
453
  handleHotUpdate({ file }) {
385
454
  if (file.endsWith(".css")) {
386
455
  cssModules.add(file);
387
456
  }
388
457
  },
389
- async renderChunk(_code: string, chunk: any, _options: any) {
390
- const moduleIds = this.getModuleIds();
391
- const fallbackManifestEntries = Object.fromEntries(
392
- Array.from(moduleIds)
393
- .map((module) => {
394
- const moduleInfo = this.getModuleInfo(module);
395
- if (!moduleInfo) return [module, null];
396
- const {
397
- code,
398
- id,
399
- isEntry,
400
- importedIds,
401
- dynamicallyImportedIds,
402
- ...rest
403
- } = moduleInfo;
404
- return [
405
- chunk.name ?? id,
406
- {
407
- file: chunk.fileName,
408
- src: module,
409
- name: chunk.name ?? id,
410
- isEntry: chunk.isEntry ?? isEntry,
411
- imports: chunk.imports ?? importedIds,
412
- dynamicImports: chunk.dynamicImports ?? dynamicallyImportedIds,
413
- directive: rest.meta["directive"],
414
- css: chunk.viteMetadata?.importedCss ?? [],
415
- assets: chunk.viteMetadata?.importedAssets ?? [],
416
- },
417
- ];
418
- })
419
- .filter(Boolean)
420
- );
421
-
422
- moduleGraph = {
423
- ...moduleGraph,
424
- ...fallbackManifestEntries,
425
- };
426
-
427
- if (chunk.fileName.includes("html-worker")) {
428
- const workerPath = resolve(root, chunk.fileName);
429
-
430
- // Don't initialize worker during build phase
431
- if (finalConfig.command === "build") {
432
- return null;
433
- }
434
-
435
- worker = await createWorker({
436
- projectRoot: userOptions.projectRoot,
437
- workerPath,
438
- });
458
+ async generateBundle(options, bundle) {
459
+ if (!resolvedConfig) {
460
+ throw new Error("Resolved config not found");
461
+ }
462
+ outpuptBundle = bundle;
463
+ outputOptions = options;
464
+ // Create manifest entries for each chunk
465
+ serverManifest = getBundleManifest({
466
+ pluginContext: this,
467
+ bundle,
468
+ moduleBase: userOptions.moduleBase,
469
+ preserveModulesRoot: userOptions.build.preserveModulesRoot,
470
+ });
471
+ if (serverManifestPath) {
472
+ await mkdir(dirname(serverManifestPath), { recursive: true });
473
+ await writeFile(
474
+ serverManifestPath,
475
+ JSON.stringify(serverManifest, null, 2)
476
+ );
439
477
  }
440
- return null;
441
478
  },
442
479
  };
443
480
  }