vite-plugin-react-server 1.1.11 → 1.1.13

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 (376) hide show
  1. package/dist/package.json +10 -8
  2. package/dist/plugin/components/css-collector-elements.d.ts +4 -2
  3. package/dist/plugin/components/css-collector-elements.d.ts.map +1 -1
  4. package/dist/plugin/components/css-collector-elements.js +21 -7
  5. package/dist/plugin/components/css-collector-elements.js.map +1 -1
  6. package/dist/plugin/components/css-collector.d.ts +4 -5
  7. package/dist/plugin/components/css-collector.d.ts.map +1 -1
  8. package/dist/plugin/components/css-collector.js +5 -9
  9. package/dist/plugin/components/css-collector.js.map +1 -1
  10. package/dist/plugin/components/html.d.ts +1 -1
  11. package/dist/plugin/components/html.d.ts.map +1 -1
  12. package/dist/plugin/components/html.js +14 -3
  13. package/dist/plugin/components/html.js.map +1 -1
  14. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts +4 -4
  15. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -1
  16. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js +14 -9
  17. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -1
  18. package/dist/plugin/config/defaults.d.ts +66 -12
  19. package/dist/plugin/config/defaults.d.ts.map +1 -1
  20. package/dist/plugin/config/defaults.js +69 -15
  21. package/dist/plugin/config/defaults.js.map +1 -1
  22. package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts +5 -0
  23. package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts.map +1 -0
  24. package/dist/plugin/config/resolveAutoDiscoverMatcher.js +25 -0
  25. package/dist/plugin/config/resolveAutoDiscoverMatcher.js.map +1 -0
  26. package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
  27. package/dist/plugin/config/resolveEnv.js +16 -5
  28. package/dist/plugin/config/resolveEnv.js.map +1 -1
  29. package/dist/plugin/config/resolveOptions.d.ts +3 -3
  30. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  31. package/dist/plugin/config/resolveOptions.js +59 -87
  32. package/dist/plugin/config/resolveOptions.js.map +1 -1
  33. package/dist/plugin/config/resolveUserConfig.d.ts +4 -4
  34. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  35. package/dist/plugin/config/resolveUserConfig.js +8 -1
  36. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  37. package/dist/plugin/error/toError.d.ts +3 -0
  38. package/dist/plugin/error/toError.d.ts.map +1 -1
  39. package/dist/plugin/error/toError.js +33 -4
  40. package/dist/plugin/error/toError.js.map +1 -1
  41. package/dist/plugin/helpers/cleanObject.d.ts.map +1 -1
  42. package/dist/plugin/helpers/cleanObject.js +19 -5
  43. package/dist/plugin/helpers/cleanObject.js.map +1 -1
  44. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +3 -3
  45. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
  46. package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
  47. package/dist/plugin/helpers/createCssProps.d.ts +4 -3
  48. package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
  49. package/dist/plugin/helpers/createCssProps.js +7 -2
  50. package/dist/plugin/helpers/createCssProps.js.map +1 -1
  51. package/dist/plugin/helpers/createHandler.d.ts +4 -3
  52. package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
  53. package/dist/plugin/helpers/createHandler.js +1 -1
  54. package/dist/plugin/helpers/createHandler.js.map +1 -1
  55. package/dist/plugin/helpers/createRscStream.d.ts +2 -2
  56. package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
  57. package/dist/plugin/helpers/createRscStream.js +15 -5
  58. package/dist/plugin/helpers/createRscStream.js.map +1 -1
  59. package/dist/plugin/helpers/index.d.ts +2 -2
  60. package/dist/plugin/helpers/index.d.ts.map +1 -1
  61. package/dist/plugin/helpers/index.js +2 -2
  62. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  63. package/dist/plugin/helpers/inputNormalizer.js +4 -1
  64. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  65. package/dist/plugin/helpers/moduleResolver.d.ts +3 -0
  66. package/dist/plugin/helpers/moduleResolver.d.ts.map +1 -0
  67. package/dist/plugin/helpers/moduleResolver.js +25 -0
  68. package/dist/plugin/helpers/requestInfo.d.ts +18 -3
  69. package/dist/plugin/helpers/requestInfo.d.ts.map +1 -1
  70. package/dist/plugin/helpers/requestInfo.js +75 -11
  71. package/dist/plugin/helpers/requestInfo.js.map +1 -1
  72. package/dist/plugin/helpers/resolvePage.d.ts.map +1 -1
  73. package/dist/plugin/helpers/resolvePage.js +2 -3
  74. package/dist/plugin/helpers/resolvePage.js.map +1 -1
  75. package/dist/plugin/helpers/resolvePageAndProps.d.ts +4 -3
  76. package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
  77. package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
  78. package/dist/plugin/helpers/serializeUserOptions.d.ts +3 -2
  79. package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -1
  80. package/dist/plugin/helpers/serializeUserOptions.js +13 -1
  81. package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
  82. package/dist/plugin/helpers/sourceMap.d.ts +8 -0
  83. package/dist/plugin/helpers/sourceMap.d.ts.map +1 -0
  84. package/dist/plugin/helpers/sourceMap.js +136 -0
  85. package/dist/plugin/helpers.js +1 -1
  86. package/dist/plugin/loader/createBuildLoader.d.ts +7 -22
  87. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
  88. package/dist/plugin/loader/createBuildLoader.js +79 -65
  89. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  90. package/dist/plugin/loader/createDefaultLoader.d.ts +13 -0
  91. package/dist/plugin/loader/createDefaultLoader.d.ts.map +1 -0
  92. package/dist/plugin/loader/createDefaultLoader.js +47 -0
  93. package/dist/plugin/loader/css-loader.development.d.ts +1 -0
  94. package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
  95. package/dist/plugin/loader/css-loader.development.js +1 -1
  96. package/dist/plugin/loader/css-loader.development.js.map +1 -1
  97. package/dist/plugin/loader/handleExports.d.ts +33 -0
  98. package/dist/plugin/loader/handleExports.d.ts.map +1 -0
  99. package/dist/plugin/loader/handleExports.js +174 -0
  100. package/dist/plugin/loader/handleExports.js.map +1 -0
  101. package/dist/plugin/loader/index.d.ts +1 -1
  102. package/dist/plugin/loader/index.d.ts.map +1 -1
  103. package/dist/plugin/loader/index.js +4 -1
  104. package/dist/plugin/loader/parse.d.ts +6 -0
  105. package/dist/plugin/loader/parse.d.ts.map +1 -0
  106. package/dist/plugin/loader/parse.js +23 -0
  107. package/dist/plugin/loader/parse.js.map +1 -0
  108. package/dist/plugin/loader/react-loader.client.d.ts +2 -0
  109. package/dist/plugin/loader/react-loader.client.d.ts.map +1 -0
  110. package/dist/plugin/loader/react-loader.client.js +2 -0
  111. package/dist/plugin/loader/react-loader.d.ts +1 -12
  112. package/dist/plugin/loader/react-loader.d.ts.map +1 -1
  113. package/dist/plugin/loader/react-loader.js +5 -687
  114. package/dist/plugin/loader/react-loader.js.map +1 -1
  115. package/dist/plugin/loader/react-loader.server.d.ts +21 -0
  116. package/dist/plugin/loader/react-loader.server.d.ts.map +1 -0
  117. package/dist/plugin/loader/react-loader.server.js +69 -0
  118. package/dist/plugin/loader/sourceMap.d.ts +35 -0
  119. package/dist/plugin/loader/sourceMap.d.ts.map +1 -0
  120. package/dist/plugin/loader/sourceMap.js +105 -0
  121. package/dist/plugin/loader/temporaryReferences.d.ts +1 -1
  122. package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -1
  123. package/dist/plugin/loader/transformModuleIfNeeded.d.ts +2 -0
  124. package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -0
  125. package/dist/plugin/loader/transformModuleIfNeeded.js +27 -0
  126. package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -0
  127. package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts +27 -0
  128. package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +1 -0
  129. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +52 -0
  130. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +1 -0
  131. package/dist/plugin/loader/types.d.ts +8 -0
  132. package/dist/plugin/loader/types.d.ts.map +1 -0
  133. package/dist/plugin/loader/types.js +1 -0
  134. package/dist/plugin/plugin.client.d.ts +2 -2
  135. package/dist/plugin/plugin.client.d.ts.map +1 -1
  136. package/dist/plugin/plugin.client.js +2 -3
  137. package/dist/plugin/plugin.client.js.map +1 -1
  138. package/dist/plugin/plugin.server.d.ts +2 -2
  139. package/dist/plugin/plugin.server.d.ts.map +1 -1
  140. package/dist/plugin/plugin.server.js +2 -2
  141. package/dist/plugin/plugin.server.js.map +1 -1
  142. package/dist/plugin/preserver/plugin.d.ts +2 -2
  143. package/dist/plugin/preserver/plugin.d.ts.map +1 -1
  144. package/dist/plugin/preserver/plugin.js +6 -2
  145. package/dist/plugin/preserver/plugin.js.map +1 -1
  146. package/dist/plugin/react-client/{server.d.ts → configureWorkerRequestHandler.d.ts} +4 -4
  147. package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -0
  148. package/dist/plugin/react-client/{server.js → configureWorkerRequestHandler.js} +11 -8
  149. package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -0
  150. package/dist/plugin/react-client/createMessageHandlers.d.ts +1 -1
  151. package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
  152. package/dist/plugin/react-client/createMessageHandlers.js +18 -11
  153. package/dist/plugin/react-client/createMessageHandlers.js.map +1 -1
  154. package/dist/plugin/react-client/createWorkerStream.d.ts +5 -3
  155. package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
  156. package/dist/plugin/react-client/createWorkerStream.js +61 -27
  157. package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
  158. package/dist/plugin/react-client/handleWorkerRscStream.d.ts +1 -1
  159. package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -1
  160. package/dist/plugin/react-client/handleWorkerRscStream.js +14 -4
  161. package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -1
  162. package/dist/plugin/react-client/plugin.d.ts +2 -2
  163. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  164. package/dist/plugin/react-client/plugin.js +7 -8
  165. package/dist/plugin/react-client/plugin.js.map +1 -1
  166. package/dist/plugin/react-client/restartWorker.d.ts +1 -1
  167. package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
  168. package/dist/plugin/react-client/restartWorker.js +9 -3
  169. package/dist/plugin/react-client/restartWorker.js.map +1 -1
  170. package/dist/plugin/react-server/configureReactServer.d.ts +9 -0
  171. package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -0
  172. package/dist/plugin/react-server/{server.js → configureReactServer.js} +26 -8
  173. package/dist/plugin/react-server/configureReactServer.js.map +1 -0
  174. package/dist/plugin/react-server/handleServerAction.d.ts +5 -0
  175. package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -0
  176. package/dist/plugin/react-server/handleServerAction.js +145 -0
  177. package/dist/plugin/react-server/handleServerAction.js.map +1 -0
  178. package/dist/plugin/react-server/plugin.d.ts +2 -2
  179. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  180. package/dist/plugin/react-server/plugin.js +1 -1
  181. package/dist/plugin/react-server/plugin.js.map +1 -1
  182. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +2 -2
  183. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
  184. package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
  185. package/dist/plugin/react-static/collectRscContent.d.ts +2 -2
  186. package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -1
  187. package/dist/plugin/react-static/collectRscContent.js.map +1 -1
  188. package/dist/plugin/react-static/configurePreviewServer.d.ts +3 -3
  189. package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
  190. package/dist/plugin/react-static/configurePreviewServer.js +18 -7
  191. package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
  192. package/dist/plugin/react-static/plugin.d.ts +2 -2
  193. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  194. package/dist/plugin/react-static/plugin.js +28 -12
  195. package/dist/plugin/react-static/plugin.js.map +1 -1
  196. package/dist/plugin/react-static/renderPage.d.ts +2 -2
  197. package/dist/plugin/react-static/renderPage.d.ts.map +1 -1
  198. package/dist/plugin/react-static/renderPage.js.map +1 -1
  199. package/dist/plugin/react-static/renderPages.d.ts +2 -2
  200. package/dist/plugin/react-static/renderPages.d.ts.map +1 -1
  201. package/dist/plugin/react-static/renderPages.js.map +1 -1
  202. package/dist/plugin/react-static/renderStreams.d.ts +2 -2
  203. package/dist/plugin/react-static/renderStreams.d.ts.map +1 -1
  204. package/dist/plugin/react-static/renderStreams.js +4 -4
  205. package/dist/plugin/react-static/renderStreams.js.map +1 -1
  206. package/dist/plugin/source-map/createMappingsSerializer.d.ts +2 -0
  207. package/dist/plugin/source-map/createMappingsSerializer.d.ts.map +1 -0
  208. package/dist/plugin/source-map/createMappingsSerializer.js +159 -0
  209. package/dist/plugin/source-map/readMappings.d.ts +2 -0
  210. package/dist/plugin/source-map/readMappings.d.ts.map +1 -0
  211. package/dist/plugin/source-map/readMappings.js +201 -0
  212. package/dist/plugin/transformer/index.d.ts +0 -1
  213. package/dist/plugin/transformer/index.d.ts.map +1 -1
  214. package/dist/plugin/transformer/index.js +0 -1
  215. package/dist/plugin/transformer/plugin.client.d.ts +1 -3
  216. package/dist/plugin/transformer/plugin.client.d.ts.map +1 -1
  217. package/dist/plugin/transformer/plugin.client.js +1 -84
  218. package/dist/plugin/transformer/plugin.server.d.ts +2 -2
  219. package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
  220. package/dist/plugin/transformer/plugin.server.js +52 -20
  221. package/dist/plugin/transformer/plugin.server.js.map +1 -1
  222. package/dist/plugin/types.d.ts +89 -119
  223. package/dist/plugin/types.d.ts.map +1 -1
  224. package/dist/plugin/utils/callServer.d.ts +1 -1
  225. package/dist/plugin/utils/callServer.d.ts.map +1 -1
  226. package/dist/plugin/utils/callServer.js +1 -1
  227. package/dist/plugin/utils/callServer.js.map +1 -1
  228. package/dist/plugin/utils/createCallServer.d.ts +1 -1
  229. package/dist/plugin/utils/createCallServer.d.ts.map +1 -1
  230. package/dist/plugin/utils/createCallServer.js +13 -4
  231. package/dist/plugin/utils/createCallServer.js.map +1 -1
  232. package/dist/plugin/utils/index.d.ts +1 -0
  233. package/dist/plugin/utils/index.d.ts.map +1 -1
  234. package/dist/plugin/utils/index.js +1 -0
  235. package/dist/plugin/utils.js +1 -0
  236. package/dist/plugin/utils.js.map +1 -1
  237. package/dist/plugin/vendor/vendor.client.d.ts +2 -1
  238. package/dist/plugin/vendor/vendor.client.d.ts.map +1 -1
  239. package/dist/plugin/vendor/vendor.client.js +2 -1
  240. package/dist/plugin/vendor/vendor.client.js.map +1 -1
  241. package/dist/plugin/vendor/vendor.server.d.ts.map +1 -1
  242. package/dist/plugin/vendor/vendor.server.js +1 -1
  243. package/dist/plugin/vendor/vendor.server.js.map +1 -1
  244. package/dist/plugin/worker/createWorker.d.ts.map +1 -1
  245. package/dist/plugin/worker/createWorker.js +17 -22
  246. package/dist/plugin/worker/createWorker.js.map +1 -1
  247. package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -1
  248. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +25 -4
  249. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
  250. package/dist/plugin/worker/html/html-worker.development.js +15 -13
  251. package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
  252. package/dist/plugin/worker/html/html-worker.production.js +2 -12
  253. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  254. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
  255. package/dist/plugin/worker/html/messageHandler.js +2 -2
  256. package/dist/plugin/worker/html/messageHandler.js.map +1 -1
  257. package/dist/plugin/worker/rsc/handleRender.d.ts +2 -1
  258. package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
  259. package/dist/plugin/worker/rsc/handleRender.js +8 -8
  260. package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
  261. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  262. package/dist/plugin/worker/rsc/messageHandler.js +166 -107
  263. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  264. package/dist/plugin/worker/rsc/rsc-worker.development.js +112 -52
  265. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  266. package/dist/plugin/worker/rsc/rsc-worker.production.js +1 -1
  267. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
  268. package/dist/plugin/worker/rsc/state.d.ts +5 -64
  269. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  270. package/dist/plugin/worker/rsc/state.js +5 -1
  271. package/dist/plugin/worker/rsc/state.js.map +1 -1
  272. package/dist/plugin/worker/sendMessage.d.ts +2 -0
  273. package/dist/plugin/worker/sendMessage.d.ts.map +1 -1
  274. package/dist/plugin/worker/sendMessage.js +2 -1
  275. package/dist/plugin/worker/sendMessage.js.map +1 -1
  276. package/dist/plugin/worker/types.d.ts +52 -53
  277. package/dist/plugin/worker/types.d.ts.map +1 -1
  278. package/dist/tsconfig.tsbuildinfo +1 -1
  279. package/package.json +10 -8
  280. package/plugin/components/css-collector-elements.tsx +30 -9
  281. package/plugin/components/css-collector.tsx +13 -22
  282. package/plugin/components/html.tsx +12 -5
  283. package/plugin/config/autoDiscover/resolveAutoDiscover.ts +31 -13
  284. package/plugin/config/defaults.tsx +72 -16
  285. package/plugin/config/resolveAutoDiscoverMatcher.ts +23 -0
  286. package/plugin/config/resolveEnv.ts +20 -12
  287. package/plugin/config/resolveOptions.ts +152 -155
  288. package/plugin/config/resolveUserConfig.ts +20 -5
  289. package/plugin/error/toError.ts +35 -1
  290. package/plugin/helpers/cleanObject.ts +79 -15
  291. package/plugin/helpers/collectViteModuleGraphCss.ts +4 -3
  292. package/plugin/helpers/createCssProps.tsx +26 -9
  293. package/plugin/helpers/createHandler.ts +7 -4
  294. package/plugin/helpers/createRscStream.tsx +20 -14
  295. package/plugin/helpers/index.ts +2 -2
  296. package/plugin/helpers/inputNormalizer.ts +4 -2
  297. package/plugin/helpers/moduleResolver.ts +36 -0
  298. package/plugin/helpers/requestInfo.ts +117 -23
  299. package/plugin/helpers/resolvePage.ts +2 -3
  300. package/plugin/helpers/resolvePageAndProps.ts +7 -6
  301. package/plugin/helpers/serializeUserOptions.ts +20 -2
  302. package/plugin/helpers/sourceMap.ts +182 -0
  303. package/plugin/loader/createBuildLoader.ts +124 -104
  304. package/plugin/loader/createDefaultLoader.ts +62 -0
  305. package/plugin/loader/css-loader.development.ts +3 -2
  306. package/plugin/loader/handleExports.ts +276 -0
  307. package/plugin/loader/index.ts +6 -1
  308. package/plugin/loader/parse.ts +22 -0
  309. package/plugin/loader/react-loader.client.ts +1 -0
  310. package/plugin/loader/react-loader.server.ts +107 -0
  311. package/plugin/loader/react-loader.ts +4 -1002
  312. package/plugin/loader/sourceMap.ts +118 -0
  313. package/plugin/loader/transformModuleIfNeeded.ts +33 -0
  314. package/plugin/loader/transformModuleWithPreservedFunctions.ts +119 -0
  315. package/plugin/loader/types.ts +10 -0
  316. package/plugin/plugin.client.ts +18 -11
  317. package/plugin/plugin.server.ts +6 -3
  318. package/plugin/preserver/plugin.ts +37 -17
  319. package/plugin/react-client/{server.ts → configureWorkerRequestHandler.ts} +22 -12
  320. package/plugin/react-client/createMessageHandlers.ts +21 -13
  321. package/plugin/react-client/createWorkerStream.ts +71 -33
  322. package/plugin/react-client/handleWorkerRscStream.ts +15 -5
  323. package/plugin/react-client/plugin.ts +18 -13
  324. package/plugin/react-client/restartWorker.ts +17 -5
  325. package/plugin/react-server/{server.ts → configureReactServer.ts} +40 -9
  326. package/plugin/react-server/handleServerAction.ts +177 -0
  327. package/plugin/react-server/plugin.ts +8 -3
  328. package/plugin/react-static/collectHtmlWorkerContent.ts +11 -3
  329. package/plugin/react-static/collectRscContent.ts +17 -9
  330. package/plugin/react-static/configurePreviewServer.ts +37 -17
  331. package/plugin/react-static/plugin.ts +45 -22
  332. package/plugin/react-static/renderPage.ts +12 -6
  333. package/plugin/react-static/renderPages.ts +15 -4
  334. package/plugin/react-static/renderStreams.ts +13 -12
  335. package/plugin/source-map/createMappingsSerializer.ts +182 -0
  336. package/plugin/source-map/readMappings.ts +195 -0
  337. package/plugin/transformer/README.md +295 -29
  338. package/plugin/transformer/index.ts +0 -1
  339. package/plugin/transformer/plugin.client.ts +0 -111
  340. package/plugin/transformer/plugin.server.ts +94 -25
  341. package/plugin/types/react-server-dom-esm.d.ts +183 -24
  342. package/plugin/types/sourceMap.d.ts +2 -0
  343. package/plugin/types/webpack-sources.d.ts +24 -0
  344. package/plugin/types.ts +169 -132
  345. package/plugin/utils/callServer.ts +1 -1
  346. package/plugin/utils/createCallServer.ts +21 -6
  347. package/plugin/utils/index.ts +2 -1
  348. package/plugin/vendor/vendor.client.ts +2 -1
  349. package/plugin/vendor/vendor.server.ts +1 -1
  350. package/plugin/worker/createWorker.ts +21 -24
  351. package/plugin/worker/html/createHtmlWorkerRenderState.tsx +31 -7
  352. package/plugin/worker/html/html-worker.development.tsx +16 -16
  353. package/plugin/worker/html/html-worker.production.tsx +3 -19
  354. package/plugin/worker/html/messageHandler.tsx +2 -4
  355. package/plugin/worker/rsc/handleRender.ts +15 -12
  356. package/plugin/worker/rsc/messageHandler.tsx +191 -120
  357. package/plugin/worker/rsc/rsc-worker.development.ts +148 -77
  358. package/plugin/worker/rsc/rsc-worker.production.ts +1 -1
  359. package/plugin/worker/rsc/state.ts +10 -0
  360. package/plugin/worker/sendMessage.ts +32 -14
  361. package/plugin/worker/types.ts +99 -64
  362. package/dist/plugin/react-client/server.d.ts.map +0 -1
  363. package/dist/plugin/react-client/server.js.map +0 -1
  364. package/dist/plugin/react-server/server.d.ts +0 -9
  365. package/dist/plugin/react-server/server.d.ts.map +0 -1
  366. package/dist/plugin/react-server/server.js.map +0 -1
  367. package/dist/plugin/transformer/plugin.client.js.map +0 -1
  368. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +0 -2
  369. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +0 -1
  370. package/dist/plugin/transformer/upgradeCssModuleCode.js +0 -40
  371. package/dist/plugin/worker/loader.d.ts +0 -5
  372. package/dist/plugin/worker/loader.d.ts.map +0 -1
  373. package/dist/plugin/worker/loader.js +0 -11
  374. package/dist/plugin/worker/loader.js.map +0 -1
  375. package/plugin/transformer/upgradeCssModuleCode.ts +0 -42
  376. package/plugin/worker/loader.ts +0 -7
@@ -0,0 +1,159 @@
1
+ // alternative to webpack-sources/lib/helpers/createMappingsSerializer.js
2
+ // unused for now, but it's a dependency of react-server-dom-esm and you may or may not want to download webpack-sources
3
+ export function createMappingsSerializer() {
4
+ let generatedLine = 1;
5
+ let generatedColumn = 0;
6
+ let sourceIndex = 0;
7
+ let originalLine = 1;
8
+ let originalColumn = 0;
9
+ let nameIndex = 0;
10
+ let mappings = "";
11
+ return function serializeMapping(newGeneratedLine, newGeneratedColumn, newSourceIndex, newOriginalLine, newOriginalColumn, newNameIndex) {
12
+ if (newGeneratedLine !== generatedLine) {
13
+ generatedLine = newGeneratedLine;
14
+ generatedColumn = newGeneratedColumn;
15
+ if (mappings) {
16
+ mappings += ";";
17
+ }
18
+ }
19
+ else if (mappings) {
20
+ mappings += ",";
21
+ }
22
+ // Encode the generated column.
23
+ let value = newGeneratedColumn - generatedColumn;
24
+ generatedColumn = newGeneratedColumn;
25
+ let isNegative = value < 0;
26
+ if (isNegative) {
27
+ value = -value;
28
+ }
29
+ value = value << 1;
30
+ if (isNegative) {
31
+ value = value | 1;
32
+ }
33
+ while (value > 0) {
34
+ let digit = value & 63;
35
+ value = value >>> 6;
36
+ if (value > 0) {
37
+ digit = digit | 64;
38
+ }
39
+ mappings += String.fromCharCode(digit < 26
40
+ ? digit + 65
41
+ : digit < 52
42
+ ? digit + 97 - 26
43
+ : digit < 62
44
+ ? digit + 48 - 52
45
+ : digit === 62
46
+ ? 43
47
+ : 47);
48
+ }
49
+ // Encode the source index.
50
+ value = newSourceIndex - sourceIndex;
51
+ sourceIndex = newSourceIndex;
52
+ isNegative = value < 0;
53
+ if (isNegative) {
54
+ value = -value;
55
+ }
56
+ value = value << 1;
57
+ if (isNegative) {
58
+ value = value | 1;
59
+ }
60
+ while (value > 0) {
61
+ let digit = value & 63;
62
+ value = value >>> 6;
63
+ if (value > 0) {
64
+ digit = digit | 64;
65
+ }
66
+ mappings += String.fromCharCode(digit < 26
67
+ ? digit + 65
68
+ : digit < 52
69
+ ? digit + 97 - 26
70
+ : digit < 62
71
+ ? digit + 48 - 52
72
+ : digit === 62
73
+ ? 43
74
+ : 47);
75
+ }
76
+ // Encode the original line.
77
+ value = newOriginalLine - originalLine;
78
+ originalLine = newOriginalLine;
79
+ isNegative = value < 0;
80
+ if (isNegative) {
81
+ value = -value;
82
+ }
83
+ value = value << 1;
84
+ if (isNegative) {
85
+ value = value | 1;
86
+ }
87
+ while (value > 0) {
88
+ let digit = value & 63;
89
+ value = value >>> 6;
90
+ if (value > 0) {
91
+ digit = digit | 64;
92
+ }
93
+ mappings += String.fromCharCode(digit < 26
94
+ ? digit + 65
95
+ : digit < 52
96
+ ? digit + 97 - 26
97
+ : digit < 62
98
+ ? digit + 48 - 52
99
+ : digit === 62
100
+ ? 43
101
+ : 47);
102
+ }
103
+ // Encode the original column.
104
+ value = newOriginalColumn - originalColumn;
105
+ originalColumn = newOriginalColumn;
106
+ isNegative = value < 0;
107
+ if (isNegative) {
108
+ value = -value;
109
+ }
110
+ value = value << 1;
111
+ if (isNegative) {
112
+ value = value | 1;
113
+ }
114
+ while (value > 0) {
115
+ let digit = value & 63;
116
+ value = value >>> 6;
117
+ if (value > 0) {
118
+ digit = digit | 64;
119
+ }
120
+ mappings += String.fromCharCode(digit < 26
121
+ ? digit + 65
122
+ : digit < 52
123
+ ? digit + 97 - 26
124
+ : digit < 62
125
+ ? digit + 48 - 52
126
+ : digit === 62
127
+ ? 43
128
+ : 47);
129
+ }
130
+ // Encode the name index.
131
+ value = newNameIndex - nameIndex;
132
+ nameIndex = newNameIndex;
133
+ isNegative = value < 0;
134
+ if (isNegative) {
135
+ value = -value;
136
+ }
137
+ value = value << 1;
138
+ if (isNegative) {
139
+ value = value | 1;
140
+ }
141
+ while (value > 0) {
142
+ let digit = value & 63;
143
+ value = value >>> 6;
144
+ if (value > 0) {
145
+ digit = digit | 64;
146
+ }
147
+ mappings += String.fromCharCode(digit < 26
148
+ ? digit + 65
149
+ : digit < 52
150
+ ? digit + 97 - 26
151
+ : digit < 62
152
+ ? digit + 48 - 52
153
+ : digit === 62
154
+ ? 43
155
+ : 47);
156
+ }
157
+ return mappings;
158
+ };
159
+ }
@@ -0,0 +1,2 @@
1
+ export declare function readMappings(mappings: string, onMapping: (generatedLine: number, generatedColumn: number, sourceIndex: number, originalLine: number, originalColumn: number, nameIndex: number) => void): void;
2
+ //# sourceMappingURL=readMappings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readMappings.d.ts","sourceRoot":"","sources":["../../../plugin/source-map/readMappings.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,CACT,aAAa,EAAE,MAAM,EACrB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,KACd,IAAI,QAuLV"}
@@ -0,0 +1,201 @@
1
+ // alternative to webpack-sources/lib/helpers/readMappings.js
2
+ // unused for now, but it's a dependency of react-server-dom-esm and you may or may not want to download webpack-sources
3
+ export function readMappings(mappings, onMapping) {
4
+ let generatedLine = 1;
5
+ let generatedColumn = 0;
6
+ let sourceIndex = 0;
7
+ let originalLine = 1;
8
+ let originalColumn = 0;
9
+ let nameIndex = 0;
10
+ let i = 0;
11
+ while (i < mappings.length) {
12
+ if (mappings[i] === ";") {
13
+ generatedLine++;
14
+ generatedColumn = 0;
15
+ i++;
16
+ }
17
+ else if (mappings[i] === ",") {
18
+ i++;
19
+ }
20
+ else {
21
+ let value = 0;
22
+ let shift = 0;
23
+ let hasMore = true;
24
+ while (hasMore) {
25
+ const c = mappings.charCodeAt(i++);
26
+ if (c >= 65 && c <= 90) {
27
+ value += (c - 65) << shift;
28
+ }
29
+ else if (c >= 97 && c <= 122) {
30
+ value += (c - 97) << shift;
31
+ }
32
+ else if (c >= 48 && c <= 57) {
33
+ value += (c - 48 + 26) << shift;
34
+ }
35
+ else if (c === 43) {
36
+ value += 62 << shift;
37
+ }
38
+ else if (c === 47) {
39
+ value += 63 << shift;
40
+ }
41
+ else {
42
+ hasMore = false;
43
+ }
44
+ if (hasMore) {
45
+ shift += 6;
46
+ }
47
+ }
48
+ let isNegative = value & 1;
49
+ value = value >> 1;
50
+ if (isNegative) {
51
+ value = -value;
52
+ }
53
+ generatedColumn += value;
54
+ if (i < mappings.length && mappings[i] !== ";" && mappings[i] !== ",") {
55
+ value = 0;
56
+ shift = 0;
57
+ hasMore = true;
58
+ while (hasMore) {
59
+ const c = mappings.charCodeAt(i++);
60
+ if (c >= 65 && c <= 90) {
61
+ value += (c - 65) << shift;
62
+ }
63
+ else if (c >= 97 && c <= 122) {
64
+ value += (c - 97) << shift;
65
+ }
66
+ else if (c >= 48 && c <= 57) {
67
+ value += (c - 48 + 26) << shift;
68
+ }
69
+ else if (c === 43) {
70
+ value += 62 << shift;
71
+ }
72
+ else if (c === 47) {
73
+ value += 63 << shift;
74
+ }
75
+ else {
76
+ hasMore = false;
77
+ }
78
+ if (hasMore) {
79
+ shift += 6;
80
+ }
81
+ }
82
+ isNegative = value & 1;
83
+ value = value >> 1;
84
+ if (isNegative) {
85
+ value = -value;
86
+ }
87
+ sourceIndex += value;
88
+ if (i < mappings.length && mappings[i] !== ";" && mappings[i] !== ",") {
89
+ value = 0;
90
+ shift = 0;
91
+ hasMore = true;
92
+ while (hasMore) {
93
+ const c = mappings.charCodeAt(i++);
94
+ if (c >= 65 && c <= 90) {
95
+ value += (c - 65) << shift;
96
+ }
97
+ else if (c >= 97 && c <= 122) {
98
+ value += (c - 97) << shift;
99
+ }
100
+ else if (c >= 48 && c <= 57) {
101
+ value += (c - 48 + 26) << shift;
102
+ }
103
+ else if (c === 43) {
104
+ value += 62 << shift;
105
+ }
106
+ else if (c === 47) {
107
+ value += 63 << shift;
108
+ }
109
+ else {
110
+ hasMore = false;
111
+ }
112
+ if (hasMore) {
113
+ shift += 6;
114
+ }
115
+ }
116
+ isNegative = value & 1;
117
+ value = value >> 1;
118
+ if (isNegative) {
119
+ value = -value;
120
+ }
121
+ originalLine += value;
122
+ if (i < mappings.length &&
123
+ mappings[i] !== ";" &&
124
+ mappings[i] !== ",") {
125
+ value = 0;
126
+ shift = 0;
127
+ hasMore = true;
128
+ while (hasMore) {
129
+ const c = mappings.charCodeAt(i++);
130
+ if (c >= 65 && c <= 90) {
131
+ value += (c - 65) << shift;
132
+ }
133
+ else if (c >= 97 && c <= 122) {
134
+ value += (c - 97) << shift;
135
+ }
136
+ else if (c >= 48 && c <= 57) {
137
+ value += (c - 48 + 26) << shift;
138
+ }
139
+ else if (c === 43) {
140
+ value += 62 << shift;
141
+ }
142
+ else if (c === 47) {
143
+ value += 63 << shift;
144
+ }
145
+ else {
146
+ hasMore = false;
147
+ }
148
+ if (hasMore) {
149
+ shift += 6;
150
+ }
151
+ }
152
+ isNegative = value & 1;
153
+ value = value >> 1;
154
+ if (isNegative) {
155
+ value = -value;
156
+ }
157
+ originalColumn += value;
158
+ if (i < mappings.length &&
159
+ mappings[i] !== ";" &&
160
+ mappings[i] !== ",") {
161
+ value = 0;
162
+ shift = 0;
163
+ hasMore = true;
164
+ while (hasMore) {
165
+ const c = mappings.charCodeAt(i++);
166
+ if (c >= 65 && c <= 90) {
167
+ value += (c - 65) << shift;
168
+ }
169
+ else if (c >= 97 && c <= 122) {
170
+ value += (c - 97) << shift;
171
+ }
172
+ else if (c >= 48 && c <= 57) {
173
+ value += (c - 48 + 26) << shift;
174
+ }
175
+ else if (c === 43) {
176
+ value += 62 << shift;
177
+ }
178
+ else if (c === 47) {
179
+ value += 63 << shift;
180
+ }
181
+ else {
182
+ hasMore = false;
183
+ }
184
+ if (hasMore) {
185
+ shift += 6;
186
+ }
187
+ }
188
+ isNegative = value & 1;
189
+ value = value >> 1;
190
+ if (isNegative) {
191
+ value = -value;
192
+ }
193
+ nameIndex += value;
194
+ }
195
+ }
196
+ }
197
+ }
198
+ onMapping(generatedLine, generatedColumn, sourceIndex, originalLine, originalColumn, nameIndex);
199
+ }
200
+ }
201
+ }
@@ -1,3 +1,2 @@
1
1
  export { reactTransformPlugin as reactTransformPluginServer } from "./plugin.server.js";
2
- export { reactTransformPlugin as reactTransformPluginClient } from "./plugin.client.js";
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,oBAAoB,IAAI,0BAA0B,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,0BAA0B,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,2 +1 @@
1
1
  export { reactTransformPlugin as reactTransformPluginServer } from "./plugin.server.js";
2
- export { reactTransformPlugin as reactTransformPluginClient } from "./plugin.client.js";
@@ -1,4 +1,2 @@
1
- import type { StreamPluginOptions } from "../types.js";
2
- import { type Plugin } from "vite";
3
- export declare function reactTransformPlugin(options: StreamPluginOptions): Plugin;
1
+ export {};
4
2
  //# sourceMappingURL=plugin.client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.client.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/plugin.client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AA+BlD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CA6EzE"}
1
+ {"version":3,"file":"plugin.client.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/plugin.client.ts"],"names":[],"mappings":""}
@@ -1,84 +1 @@
1
- /**
2
- * vite-plugin-react-server
3
- * Copyright (c) Nico Brinkkemper
4
- * MIT License
5
- */
6
- import { resolveOptions } from '../config/resolveOptions.js';
7
- import 'vite';
8
- import { transformModuleIfNeeded } from '../loader/react-loader.js';
9
- import { join } from 'node:path';
10
- import { tryManifest } from '../helpers/tryManifest.js';
11
-
12
- let isBuild = true;
13
- function reactTransformPlugin(options) {
14
- let userOptions;
15
- const resolvedOptionsResult = resolveOptions(options);
16
- if (resolvedOptionsResult.type === "error") throw resolvedOptionsResult.error;
17
- userOptions = resolvedOptionsResult.userOptions;
18
- let staticManifest;
19
- return {
20
- name: "vite:react-server-action-transform",
21
- enforce: "pre",
22
- async config(_, configEnv) {
23
- isBuild = configEnv.command !== "serve";
24
- if (!configEnv.isSsrBuild) {
25
- staticManifest = {};
26
- } else {
27
- const staticManifestResult = await tryManifest({
28
- root: userOptions.projectRoot,
29
- ssrManifest: false,
30
- outDir: join(userOptions.build.outDir, userOptions.build.static)
31
- });
32
- if (staticManifestResult.type === "error") {
33
- staticManifest = {};
34
- } else {
35
- staticManifest = staticManifestResult.manifest;
36
- }
37
- }
38
- },
39
- async transform(code, id, options2) {
40
- const ssr = options2?.ssr;
41
- const isServer = code.match('"use server"') !== null;
42
- const isClient = code.match('"use client"') !== null;
43
- if (!ssr) return null;
44
- if (!isServer && !isClient) return null;
45
- if (isServer && isClient) {
46
- throw new Error(
47
- "Server and client components cannot be used in the same file"
48
- );
49
- }
50
- if (isClient) {
51
- return null;
52
- }
53
- const [key, value] = userOptions.normalizer(id);
54
- if (isServer && isBuild) {
55
- id = key + ".js";
56
- }
57
- const finalID = userOptions.moduleID(value);
58
- const transformed = await transformModuleIfNeeded(code, finalID, null);
59
- if (!transformed) return null;
60
- return {
61
- code: transformed,
62
- id: finalID,
63
- map: null
64
- };
65
- },
66
- renderChunk(code, chunk, _options) {
67
- if (!chunk.fileName.includes(".client")) return null;
68
- const originalName = chunk.fileName.replace(userOptions.autoDiscover.moduleExtension, "");
69
- const manifestEntry = Object.entries(staticManifest).find(
70
- ([_, info]) => info.file.startsWith(originalName)
71
- );
72
- if (manifestEntry) {
73
- return {
74
- code,
75
- fileName: manifestEntry[1].file
76
- };
77
- }
78
- return null;
79
- }
80
- };
81
- }
82
-
83
- export { reactTransformPlugin };
84
- //# sourceMappingURL=plugin.client.js.map
1
+ export {};
@@ -1,4 +1,4 @@
1
- import type { StreamPluginOptions } from "../types.js";
1
+ import type { InlineCssOpt, PagePropOpt, StreamPluginOptions } from "../types.js";
2
2
  import type { Plugin } from "vite";
3
- export declare function reactTransformPlugin(options: StreamPluginOptions): Plugin;
3
+ export declare function reactTransformPlugin<T extends PagePropOpt = PagePropOpt, InlineCSS extends InlineCssOpt = InlineCssOpt>(options: StreamPluginOptions<T, InlineCSS>): Plugin;
4
4
  //# sourceMappingURL=plugin.server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.server.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/plugin.server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAY,MAAM,EAAE,MAAM,MAAM,CAAC;AA8B7C,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAoEzE"}
1
+ {"version":3,"file":"plugin.server.d.ts","sourceRoot":"","sources":["../../../plugin/transformer/plugin.server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EAEX,mBAAmB,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAY,MAAM,EAAE,MAAM,MAAM,CAAC;AAkC7C,wBAAgB,oBAAoB,CAClC,CAAC,SAAS,WAAW,GAAG,WAAW,EACnC,SAAS,SAAS,YAAY,GAAG,YAAY,EAC7C,OAAO,EAAE,mBAAmB,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,MAAM,CA6HpD"}
@@ -4,11 +4,12 @@
4
4
  * MIT License
5
5
  */
6
6
  import { resolveOptions } from '../config/resolveOptions.js';
7
- import { transformModuleIfNeeded } from '../loader/react-loader.js';
8
7
  import { tryManifest } from '../helpers/tryManifest.js';
9
8
  import { join } from 'node:path';
9
+ import { transformModuleIfNeeded } from '../loader/transformModuleIfNeeded.js';
10
10
 
11
11
  let isBuild = true;
12
+ let isSSR = false;
12
13
  function reactTransformPlugin(options) {
13
14
  let userOptions;
14
15
  const resolvedOptionsResult = resolveOptions(options);
@@ -17,11 +18,12 @@ function reactTransformPlugin(options) {
17
18
  let staticManifest;
18
19
  return {
19
20
  name: "vite:react-server-transform",
20
- enforce: "pre",
21
- // Run before Vite's transforms
22
- async config(_config, configEnv) {
23
- isBuild = configEnv.command !== "serve";
24
- if (isBuild) {
21
+ enforce: "post",
22
+ // Run after Vite's transforms
23
+ async configResolved(config) {
24
+ isBuild = config.command === "build";
25
+ isSSR = config.build?.ssr === true;
26
+ if (isBuild && isSSR) {
25
27
  const staticManifestResult = await tryManifest({
26
28
  root: userOptions.projectRoot,
27
29
  ssrManifest: false,
@@ -33,16 +35,22 @@ function reactTransformPlugin(options) {
33
35
  staticManifest = staticManifestResult.manifest;
34
36
  }
35
37
  },
38
+ async resolveId(_id, importer, options2) {
39
+ if (!options2?.ssr) {
40
+ return null;
41
+ }
42
+ return null;
43
+ },
36
44
  async transform(code, id, options2) {
37
- const ssr = options2?.ssr;
38
- if (!ssr) return null;
39
- if (!userOptions.autoDiscover.modulePattern(id)) return null;
40
- if (!code.match('"use client"')) return null;
45
+ if (!options2?.ssr || !userOptions.autoDiscover.modulePattern(id)) {
46
+ return null;
47
+ }
41
48
  const [key, value] = userOptions.normalizer(id);
49
+ let moduleID = value;
42
50
  if (isBuild) {
43
51
  if (staticManifest) {
44
52
  if (value in staticManifest) {
45
- id = userOptions.moduleID(staticManifest[value].file);
53
+ moduleID = staticManifest[value].file;
46
54
  } else {
47
55
  const hash = this.emitFile({
48
56
  id,
@@ -51,24 +59,48 @@ function reactTransformPlugin(options) {
51
59
  name: value
52
60
  });
53
61
  const fileName = this.getFileName(hash);
54
- id = userOptions.moduleID(fileName);
62
+ moduleID = fileName;
55
63
  }
56
64
  } else {
57
- throw new Error(`Client manifest not found.`);
65
+ throw new Error(`Static manifest not found during dev build.`);
58
66
  }
59
67
  } else {
60
- id = join(userOptions.moduleBasePath, value);
68
+ moduleID = join(userOptions.moduleBasePath, value);
61
69
  }
62
- const transformed = await transformModuleIfNeeded(
70
+ let finalID = userOptions.moduleID(moduleID);
71
+ const transformed = transformModuleIfNeeded(
63
72
  code,
64
- id,
65
- // Pass null for nextLoad since we don't need module loading in the plugin
66
- null
73
+ finalID,
74
+ userOptions.autoDiscover.isServerFunction(code),
75
+ userOptions.autoDiscover.isClientComponent(code),
76
+ true
67
77
  );
68
- if (!transformed) return null;
78
+ if (userOptions.verbose) {
79
+ if (transformed !== code) {
80
+ if (id !== finalID) {
81
+ this.environment.logger.info(
82
+ "[react-server-transform] " + id.split("/").pop() + " -> " + finalID
83
+ );
84
+ } else {
85
+ this.environment.logger.info(
86
+ "[react-server-transform] " + id.split("/").pop() + (code.startsWith('"use client"') ? " (client)" : "")
87
+ );
88
+ }
89
+ this.environment.logger.info(
90
+ "[react-server-transform] " + transformed
91
+ );
92
+ }
93
+ }
94
+ if (!transformed) {
95
+ return {
96
+ id: finalID,
97
+ code: "",
98
+ map: null
99
+ };
100
+ }
69
101
  return {
102
+ id: finalID,
70
103
  code: transformed,
71
- id,
72
104
  map: null
73
105
  };
74
106
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.server.js","sources":["../../../plugin/transformer/plugin.server.ts"],"sourcesContent":["import { resolveOptions } from \"../config/resolveOptions.js\";\nimport type { ResolvedUserOptions, StreamPluginOptions } from \"../types.js\";\nimport type { Manifest, Plugin } from \"vite\";\nimport { transformModuleIfNeeded } from \"../loader/react-loader.js\";\nimport { tryManifest } from \"../helpers/tryManifest.js\";\nimport { join } from \"node:path\";\n/**\n * Plugin for transforming React Client Components.\n *\n * Core responsibilities:\n * 1. Detects \"use client\" directives\n * 2. Transforms client components for RSC boundaries\n * 3. Adds client reference metadata for RSC\n *\n * When a component is marked with \"use client\", it:\n * - Gets transformed into a client reference\n * - Maintains module ID for RSC boundaries\n * - Preserves class/function behavior\n *\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [\n * viteReactClientTransformPlugin({\n * projectRoot: process.cwd(),\n * })\n * ]\n * });\n * ```\n */\nlet isBuild = true;\n\nexport function reactTransformPlugin(options: StreamPluginOptions): Plugin {\n let userOptions: ResolvedUserOptions;\n const resolvedOptionsResult = resolveOptions(options);\n if (resolvedOptionsResult.type === \"error\") throw resolvedOptionsResult.error;\n userOptions = resolvedOptionsResult.userOptions;\n\n let staticManifest: Manifest;\n\n return {\n name: \"vite:react-server-transform\",\n enforce: \"pre\", // Run before Vite's transforms\n async config(_config, configEnv) {\n isBuild = configEnv.command !== \"serve\";\n if (isBuild) {\n const staticManifestResult = await tryManifest({\n root: userOptions.projectRoot,\n ssrManifest: false,\n outDir: join(userOptions.build.outDir, userOptions.build.static),\n });\n if (staticManifestResult.type === \"error\") {\n throw staticManifestResult.error;\n }\n staticManifest = staticManifestResult.manifest;\n }\n },\n async transform(code, id, options) {\n const ssr = options?.ssr;\n if (!ssr) return null;\n if (!userOptions.autoDiscover.modulePattern(id)) return null;\n if (!code.match('\"use client\"')) return null;\n\n const [key, value] = userOptions.normalizer(id);\n if (isBuild) {\n if (staticManifest) {\n if (value in staticManifest) {\n id = userOptions.moduleID(staticManifest[value].file);\n } else {\n const hash = this.emitFile({\n id,\n type: \"chunk\",\n fileName: key + \".js\",\n name: value,\n });\n // get fileName from hash\n\n const fileName = this.getFileName(hash);\n id = userOptions.moduleID(fileName);\n }\n } else {\n throw new Error(`Client manifest not found.`);\n }\n } else {\n id = join(userOptions.moduleBasePath, value);\n }\n const transformed = await transformModuleIfNeeded(\n code,\n id,\n // Pass null for nextLoad since we don't need module loading in the plugin\n null\n );\n if (!transformed) return null;\n return {\n code: transformed,\n id: id,\n map: null,\n };\n },\n };\n}\n"],"names":["options"],"mappings":";;;;;;;;;;AA8BA,IAAI,OAAU,GAAA,IAAA;AAEP,SAAS,qBAAqB,OAAsC,EAAA;AACzE,EAAI,IAAA,WAAA;AACJ,EAAM,MAAA,qBAAA,GAAwB,eAAe,OAAO,CAAA;AACpD,EAAA,IAAI,qBAAsB,CAAA,IAAA,KAAS,OAAS,EAAA,MAAM,qBAAsB,CAAA,KAAA;AACxE,EAAA,WAAA,GAAc,qBAAsB,CAAA,WAAA;AAEpC,EAAI,IAAA,cAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,6BAAA;AAAA,IACN,OAAS,EAAA,KAAA;AAAA;AAAA,IACT,MAAM,MAAO,CAAA,OAAA,EAAS,SAAW,EAAA;AAC/B,MAAA,OAAA,GAAU,UAAU,OAAY,KAAA,OAAA;AAChC,MAAA,IAAI,OAAS,EAAA;AACX,QAAM,MAAA,oBAAA,GAAuB,MAAM,WAAY,CAAA;AAAA,UAC7C,MAAM,WAAY,CAAA,WAAA;AAAA,UAClB,WAAa,EAAA,KAAA;AAAA,UACb,QAAQ,IAAK,CAAA,WAAA,CAAY,MAAM,MAAQ,EAAA,WAAA,CAAY,MAAM,MAAM;AAAA,SAChE,CAAA;AACD,QAAI,IAAA,oBAAA,CAAqB,SAAS,OAAS,EAAA;AACzC,UAAA,MAAM,oBAAqB,CAAA,KAAA;AAAA;AAE7B,QAAA,cAAA,GAAiB,oBAAqB,CAAA,QAAA;AAAA;AACxC,KACF;AAAA,IACA,MAAM,SAAA,CAAU,IAAM,EAAA,EAAA,EAAIA,QAAS,EAAA;AACjC,MAAA,MAAM,MAAMA,QAAS,EAAA,GAAA;AACrB,MAAI,IAAA,CAAC,KAAY,OAAA,IAAA;AACjB,MAAA,IAAI,CAAC,WAAY,CAAA,YAAA,CAAa,aAAc,CAAA,EAAE,GAAU,OAAA,IAAA;AACxD,MAAA,IAAI,CAAC,IAAA,CAAK,KAAM,CAAA,cAAc,GAAU,OAAA,IAAA;AAExC,MAAA,MAAM,CAAC,GAAK,EAAA,KAAK,CAAI,GAAA,WAAA,CAAY,WAAW,EAAE,CAAA;AAC9C,MAAA,IAAI,OAAS,EAAA;AACX,QAAA,IAAI,cAAgB,EAAA;AAClB,UAAA,IAAI,SAAS,cAAgB,EAAA;AAC3B,YAAA,EAAA,GAAK,WAAY,CAAA,QAAA,CAAS,cAAe,CAAA,KAAK,EAAE,IAAI,CAAA;AAAA,WAC/C,MAAA;AACL,YAAM,MAAA,IAAA,GAAO,KAAK,QAAS,CAAA;AAAA,cACzB,EAAA;AAAA,cACA,IAAM,EAAA,OAAA;AAAA,cACN,UAAU,GAAM,GAAA,KAAA;AAAA,cAChB,IAAM,EAAA;AAAA,aACP,CAAA;AAGD,YAAM,MAAA,QAAA,GAAW,IAAK,CAAA,WAAA,CAAY,IAAI,CAAA;AACtC,YAAK,EAAA,GAAA,WAAA,CAAY,SAAS,QAAQ,CAAA;AAAA;AACpC,SACK,MAAA;AACL,UAAM,MAAA,IAAI,MAAM,CAA4B,0BAAA,CAAA,CAAA;AAAA;AAC9C,OACK,MAAA;AACL,QAAK,EAAA,GAAA,IAAA,CAAK,WAAY,CAAA,cAAA,EAAgB,KAAK,CAAA;AAAA;AAE7C,MAAA,MAAM,cAAc,MAAM,uBAAA;AAAA,QACxB,IAAA;AAAA,QACA,EAAA;AAAA;AAAA,QAEA;AAAA,OACF;AACA,MAAI,IAAA,CAAC,aAAoB,OAAA,IAAA;AACzB,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,WAAA;AAAA,QACN,EAAA;AAAA,QACA,GAAK,EAAA;AAAA,OACP;AAAA;AACF,GACF;AACF;;;;"}
1
+ {"version":3,"file":"plugin.server.js","sources":["../../../plugin/transformer/plugin.server.ts"],"sourcesContent":["import { resolveOptions } from \"../config/resolveOptions.js\";\nimport type {\n InlineCssOpt,\n PagePropOpt,\n ResolvedUserOptions,\n StreamPluginOptions,\n} from \"../types.js\";\nimport type { Manifest, Plugin } from \"vite\";\nimport { tryManifest } from \"../helpers/tryManifest.js\";\nimport { join } from \"node:path\";\nimport { setStashedResolve } from \"../helpers/moduleResolver.js\";\nimport { transformModuleIfNeeded } from \"../loader/transformModuleIfNeeded.js\";\nimport { logError } from \"../error/toError.js\";\n\n/**\n * Plugin for transforming React Client Components.\n *\n * Core responsibilities:\n * 1. Detects \"use client\" directives\n * 2. Transforms client components for RSC boundaries\n * 3. Adds client reference metadata for RSC\n *\n * When a component is marked with \"use client\", it:\n * - Gets transformed into a client reference\n * - Maintains module ID for RSC boundaries\n * - Preserves class/function behavior\n *\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [\n * viteReactClientTransformPlugin({\n * projectRoot: process.cwd(),\n * })\n * ]\n * });\n * ```\n */\nlet isBuild = true;\nlet isSSR = false;\n\nexport function reactTransformPlugin<\n T extends PagePropOpt = PagePropOpt,\n InlineCSS extends InlineCssOpt = InlineCssOpt\n>(options: StreamPluginOptions<T, InlineCSS>): Plugin {\n let userOptions: ResolvedUserOptions<T, InlineCSS>;\n const resolvedOptionsResult = resolveOptions(options);\n if (resolvedOptionsResult.type === \"error\") throw resolvedOptionsResult.error;\n userOptions = resolvedOptionsResult.userOptions;\n\n let staticManifest: Manifest;\n\n return {\n name: \"vite:react-server-transform\",\n enforce: \"post\", // Run after Vite's transforms\n async configResolved(config) {\n isBuild = config.command === \"build\";\n isSSR = config.build?.ssr === true;\n if (isBuild && isSSR) {\n const staticManifestResult = await tryManifest({\n root: userOptions.projectRoot,\n ssrManifest: false,\n outDir: join(userOptions.build.outDir, userOptions.build.static),\n });\n if (staticManifestResult.type === \"error\") {\n throw staticManifestResult.error;\n }\n staticManifest = staticManifestResult.manifest;\n }\n },\n async resolveId(\n _id: string,\n importer: string | undefined,\n options: {\n attributes: Record<string, string>;\n custom?: any;\n ssr?: boolean;\n isEntry: boolean;\n }\n ) {\n if (!options?.ssr) {\n return null;\n }\n // Set stashedResolve before any transform operations\n setStashedResolve(async (specifier: string) => {\n try {\n const resolved = await this.resolve(specifier, importer, {\n custom: { conditions: [\"react-server\"] },\n });\n if (!resolved) return null;\n return { id: resolved.id };\n } catch (error) {\n logError(error, this.environment.logger);\n return null;\n }\n });\n return null; // Let Vite handle the resolution\n },\n async transform(code, id, options) {\n if (!options?.ssr || !userOptions.autoDiscover.modulePattern(id)) {\n return null;\n }\n const [key, value] = userOptions.normalizer(id);\n let moduleID = value;\n if (isBuild) {\n if (staticManifest) {\n if (value in staticManifest) {\n moduleID = staticManifest[value].file;\n } else {\n const hash = this.emitFile({\n id,\n type: \"chunk\",\n fileName: key + \".js\",\n name: value,\n });\n const fileName = this.getFileName(hash);\n moduleID = fileName;\n }\n } else {\n throw new Error(`Static manifest not found during dev build.`);\n }\n } else {\n // For non-SSR builds, just use the normalized path\n moduleID = join(userOptions.moduleBasePath, value);\n }\n let finalID = userOptions.moduleID(moduleID);\n // Always transform in server context\n const transformed = transformModuleIfNeeded(\n code,\n finalID,\n userOptions.autoDiscover.isServerFunction(code),\n userOptions.autoDiscover.isClientComponent(code),\n true\n );\n if (userOptions.verbose)\n if (transformed !== code) {\n if (id !== finalID) {\n this.environment.logger.info(\n \"[react-server-transform] \" +\n id.split(\"/\").pop() +\n \" -> \" +\n finalID\n );\n } else {\n this.environment.logger.info(\n \"[react-server-transform] \" +\n id.split(\"/\").pop() +\n (code.startsWith('\"use client\"') ? \" (client)\" : \"\")\n );\n }\n this.environment.logger.info(\n \"[react-server-transform] \" + transformed\n );\n }\n if (!transformed) {\n return {\n id: finalID,\n code: \"\",\n map: null,\n };\n }\n\n return {\n id: finalID,\n code: transformed,\n map: null,\n };\n },\n };\n}\n"],"names":["options"],"mappings":";;;;;;;;;;AAsCA,IAAI,OAAU,GAAA,IAAA;AACd,IAAI,KAAQ,GAAA,KAAA;AAEL,SAAS,qBAGd,OAAoD,EAAA;AACpD,EAAI,IAAA,WAAA;AACJ,EAAM,MAAA,qBAAA,GAAwB,eAAe,OAAO,CAAA;AACpD,EAAA,IAAI,qBAAsB,CAAA,IAAA,KAAS,OAAS,EAAA,MAAM,qBAAsB,CAAA,KAAA;AACxE,EAAA,WAAA,GAAc,qBAAsB,CAAA,WAAA;AAEpC,EAAI,IAAA,cAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,6BAAA;AAAA,IACN,OAAS,EAAA,MAAA;AAAA;AAAA,IACT,MAAM,eAAe,MAAQ,EAAA;AAC3B,MAAA,OAAA,GAAU,OAAO,OAAY,KAAA,OAAA;AAC7B,MAAQ,KAAA,GAAA,MAAA,CAAO,OAAO,GAAQ,KAAA,IAAA;AAC9B,MAAA,IAAI,WAAW,KAAO,EAAA;AACpB,QAAM,MAAA,oBAAA,GAAuB,MAAM,WAAY,CAAA;AAAA,UAC7C,MAAM,WAAY,CAAA,WAAA;AAAA,UAClB,WAAa,EAAA,KAAA;AAAA,UACb,QAAQ,IAAK,CAAA,WAAA,CAAY,MAAM,MAAQ,EAAA,WAAA,CAAY,MAAM,MAAM;AAAA,SAChE,CAAA;AACD,QAAI,IAAA,oBAAA,CAAqB,SAAS,OAAS,EAAA;AACzC,UAAA,MAAM,oBAAqB,CAAA,KAAA;AAAA;AAE7B,QAAA,cAAA,GAAiB,oBAAqB,CAAA,QAAA;AAAA;AACxC,KACF;AAAA,IACA,MAAM,SAAA,CACJ,GACA,EAAA,QAAA,EACAA,QAMA,EAAA;AACA,MAAI,IAAA,CAACA,UAAS,GAAK,EAAA;AACjB,QAAO,OAAA,IAAA;AAAA;AAeT,MAAO,OAAA,IAAA;AAAA,KACT;AAAA,IACA,MAAM,SAAA,CAAU,IAAM,EAAA,EAAA,EAAIA,QAAS,EAAA;AACjC,MAAI,IAAA,CAACA,UAAS,GAAO,IAAA,CAAC,YAAY,YAAa,CAAA,aAAA,CAAc,EAAE,CAAG,EAAA;AAChE,QAAO,OAAA,IAAA;AAAA;AAET,MAAA,MAAM,CAAC,GAAK,EAAA,KAAK,CAAI,GAAA,WAAA,CAAY,WAAW,EAAE,CAAA;AAC9C,MAAA,IAAI,QAAW,GAAA,KAAA;AACf,MAAA,IAAI,OAAS,EAAA;AACX,QAAA,IAAI,cAAgB,EAAA;AAClB,UAAA,IAAI,SAAS,cAAgB,EAAA;AAC3B,YAAW,QAAA,GAAA,cAAA,CAAe,KAAK,CAAE,CAAA,IAAA;AAAA,WAC5B,MAAA;AACL,YAAM,MAAA,IAAA,GAAO,KAAK,QAAS,CAAA;AAAA,cACzB,EAAA;AAAA,cACA,IAAM,EAAA,OAAA;AAAA,cACN,UAAU,GAAM,GAAA,KAAA;AAAA,cAChB,IAAM,EAAA;AAAA,aACP,CAAA;AACD,YAAM,MAAA,QAAA,GAAW,IAAK,CAAA,WAAA,CAAY,IAAI,CAAA;AACtC,YAAW,QAAA,GAAA,QAAA;AAAA;AACb,SACK,MAAA;AACL,UAAM,MAAA,IAAI,MAAM,CAA6C,2CAAA,CAAA,CAAA;AAAA;AAC/D,OACK,MAAA;AAEL,QAAW,QAAA,GAAA,IAAA,CAAK,WAAY,CAAA,cAAA,EAAgB,KAAK,CAAA;AAAA;AAEnD,MAAI,IAAA,OAAA,GAAU,WAAY,CAAA,QAAA,CAAS,QAAQ,CAAA;AAE3C,MAAA,MAAM,WAAc,GAAA,uBAAA;AAAA,QAClB,IAAA;AAAA,QACA,OAAA;AAAA,QACA,WAAA,CAAY,YAAa,CAAA,gBAAA,CAAiB,IAAI,CAAA;AAAA,QAC9C,WAAA,CAAY,YAAa,CAAA,iBAAA,CAAkB,IAAI,CAAA;AAAA,QAC/C;AAAA,OACF;AACA,MAAA,IAAI,WAAY,CAAA,OAAA,EAAA;AACd,QAAA,IAAI,gBAAgB,IAAM,EAAA;AACxB,UAAA,IAAI,OAAO,OAAS,EAAA;AAClB,YAAA,IAAA,CAAK,YAAY,MAAO,CAAA,IAAA;AAAA,cACtB,8BACE,EAAG,CAAA,KAAA,CAAM,GAAG,CAAE,CAAA,GAAA,KACd,MACA,GAAA;AAAA,aACJ;AAAA,WACK,MAAA;AACL,YAAA,IAAA,CAAK,YAAY,MAAO,CAAA,IAAA;AAAA,cACtB,2BAAA,GACE,EAAG,CAAA,KAAA,CAAM,GAAG,CAAA,CAAE,GAAI,EAAA,IACjB,IAAK,CAAA,UAAA,CAAW,cAAc,CAAA,GAAI,WAAc,GAAA,EAAA;AAAA,aACrD;AAAA;AAEF,UAAA,IAAA,CAAK,YAAY,MAAO,CAAA,IAAA;AAAA,YACtB,2BAA8B,GAAA;AAAA,WAChC;AAAA;AACF;AACF,MAAA,IAAI,CAAC,WAAa,EAAA;AAChB,QAAO,OAAA;AAAA,UACL,EAAI,EAAA,OAAA;AAAA,UACJ,IAAM,EAAA,EAAA;AAAA,UACN,GAAK,EAAA;AAAA,SACP;AAAA;AAGF,MAAO,OAAA;AAAA,QACL,EAAI,EAAA,OAAA;AAAA,QACJ,IAAM,EAAA,WAAA;AAAA,QACN,GAAK,EAAA;AAAA,OACP;AAAA;AACF,GACF;AACF;;;;"}