vite-plugin-react-server 1.0.2 → 1.1.0

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 (490) hide show
  1. package/README.md +49 -76
  2. package/bin/patch.mjs +27 -20
  3. package/dist/_virtual/dynamic-import-helper.js +24 -0
  4. package/dist/_virtual/dynamic-import-helper.js.map +1 -0
  5. package/dist/client.d.ts +1 -1
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +1 -1
  8. package/dist/index.d.ts +2 -4
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +9 -26
  11. package/dist/index.js.map +1 -1
  12. package/dist/package.json +24 -14
  13. package/dist/plugin/components.d.ts +1 -1
  14. package/dist/plugin/components.d.ts.map +1 -1
  15. package/dist/plugin/components.js +1 -1
  16. package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts +6 -0
  17. package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -0
  18. package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js +30 -0
  19. package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js.map +1 -0
  20. package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts +13 -0
  21. package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -0
  22. package/dist/plugin/config/autoDiscover/customWorkerFiles.js +24 -0
  23. package/dist/plugin/config/autoDiscover/customWorkerFiles.js.map +1 -0
  24. package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts +11 -0
  25. package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -0
  26. package/dist/plugin/config/autoDiscover/pageAndPropFiles.js +29 -0
  27. package/dist/plugin/config/autoDiscover/pageAndPropFiles.js.map +1 -0
  28. package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts +6 -0
  29. package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -0
  30. package/dist/plugin/config/autoDiscover/resolveBuildPages.js +83 -0
  31. package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -0
  32. package/dist/plugin/config/defaults.d.ts +18 -14
  33. package/dist/plugin/config/defaults.d.ts.map +1 -1
  34. package/dist/plugin/config/defaults.js +42 -21
  35. package/dist/plugin/config/defaults.js.map +1 -1
  36. package/dist/plugin/config/getCondition.d.ts +1 -1
  37. package/dist/plugin/config/getCondition.d.ts.map +1 -1
  38. package/dist/plugin/config/getCondition.js +2 -2
  39. package/dist/plugin/config/getCondition.js.map +1 -1
  40. package/dist/plugin/config/getPaths.d.ts +0 -1
  41. package/dist/plugin/config/getPaths.d.ts.map +1 -1
  42. package/dist/plugin/config/getPaths.js.map +1 -1
  43. package/dist/plugin/config/index.d.ts +0 -1
  44. package/dist/plugin/config/index.d.ts.map +1 -1
  45. package/dist/plugin/config/index.js +0 -1
  46. package/dist/plugin/config/resolveAutoDiscover.d.ts +20 -0
  47. package/dist/plugin/config/resolveAutoDiscover.d.ts.map +1 -0
  48. package/dist/plugin/config/resolveAutoDiscover.js +128 -0
  49. package/dist/plugin/config/resolveAutoDiscover.js.map +1 -0
  50. package/dist/plugin/config/resolveOptions.d.ts +1 -1
  51. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  52. package/dist/plugin/config/resolveOptions.js +109 -77
  53. package/dist/plugin/config/resolveOptions.js.map +1 -1
  54. package/dist/plugin/config/resolvePages.d.ts +0 -1
  55. package/dist/plugin/config/resolvePages.d.ts.map +1 -1
  56. package/dist/plugin/config/resolvePages.js +6 -8
  57. package/dist/plugin/config/resolvePages.js.map +1 -1
  58. package/dist/plugin/config/resolveUrlOption.d.ts +16 -0
  59. package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -0
  60. package/dist/plugin/config/resolveUrlOption.js +37 -0
  61. package/dist/plugin/config/resolveUrlOption.js.map +1 -0
  62. package/dist/plugin/config/resolveUserConfig.d.ts +4 -5
  63. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  64. package/dist/plugin/config/resolveUserConfig.js +80 -132
  65. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  66. package/dist/plugin/copy.d.ts +7 -0
  67. package/dist/plugin/copy.d.ts.map +1 -0
  68. package/dist/plugin/copy.js +30 -0
  69. package/dist/plugin/css-collector-elements.d.ts +4 -0
  70. package/dist/plugin/css-collector-elements.d.ts.map +1 -0
  71. package/dist/plugin/css-collector-elements.js +19 -0
  72. package/dist/plugin/css-collector-elements.js.map +1 -0
  73. package/dist/plugin/css-collector.d.ts +2 -8
  74. package/dist/plugin/css-collector.d.ts.map +1 -1
  75. package/dist/plugin/css-collector.js +9 -36
  76. package/dist/plugin/css-collector.js.map +1 -1
  77. package/dist/plugin/helpers/cleanObject.d.ts +3 -0
  78. package/dist/plugin/helpers/cleanObject.d.ts.map +1 -0
  79. package/dist/plugin/helpers/cleanObject.js +47 -0
  80. package/dist/plugin/helpers/cleanObject.js.map +1 -0
  81. package/dist/plugin/helpers/collectBundleManifestCss.d.ts +8 -0
  82. package/dist/plugin/helpers/collectBundleManifestCss.d.ts.map +1 -0
  83. package/dist/plugin/helpers/collectBundleManifestCss.js +110 -0
  84. package/dist/plugin/helpers/collectManifestCss.d.ts +7 -0
  85. package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -0
  86. package/dist/plugin/helpers/collectManifestCss.js +44 -0
  87. package/dist/plugin/helpers/collectManifestCss.js.map +1 -0
  88. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +31 -0
  89. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -0
  90. package/dist/plugin/helpers/collectViteModuleGraphCss.js +104 -0
  91. package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -0
  92. package/dist/plugin/helpers/createCssProps.d.ts +25 -0
  93. package/dist/plugin/helpers/createCssProps.d.ts.map +1 -0
  94. package/dist/plugin/helpers/createCssProps.js +57 -0
  95. package/dist/plugin/helpers/createCssProps.js.map +1 -0
  96. package/dist/plugin/helpers/createEventHandler.d.ts +22 -0
  97. package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -0
  98. package/dist/plugin/helpers/createEventHandler.js +36 -0
  99. package/dist/plugin/helpers/createEventHandler.js.map +1 -0
  100. package/dist/plugin/helpers/createHandler.d.ts +7 -13
  101. package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
  102. package/dist/plugin/helpers/createHandler.js +54 -96
  103. package/dist/plugin/helpers/createHandler.js.map +1 -1
  104. package/dist/plugin/helpers/createRscStream.d.ts +12 -26
  105. package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
  106. package/dist/plugin/helpers/createRscStream.js +105 -51
  107. package/dist/plugin/helpers/createRscStream.js.map +1 -1
  108. package/dist/plugin/helpers/defaultFileWriter.d.ts +2 -0
  109. package/dist/plugin/helpers/defaultFileWriter.d.ts.map +1 -0
  110. package/dist/plugin/helpers/defaultFileWriter.js +1 -0
  111. package/dist/plugin/helpers/getBundleManifest.d.ts +10 -16
  112. package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
  113. package/dist/plugin/helpers/getBundleManifest.js +30 -22
  114. package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
  115. package/dist/plugin/helpers/getRouteFiles.d.ts +14 -0
  116. package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -0
  117. package/dist/plugin/helpers/getRouteFiles.js +36 -0
  118. package/dist/plugin/helpers/getRouteFiles.js.map +1 -0
  119. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  120. package/dist/plugin/helpers/inputNormalizer.js +38 -32
  121. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  122. package/dist/plugin/helpers/metrics.d.ts +11 -0
  123. package/dist/plugin/helpers/metrics.d.ts.map +1 -0
  124. package/dist/plugin/helpers/metrics.js +35 -0
  125. package/dist/plugin/helpers/metrics.js.map +1 -0
  126. package/dist/plugin/helpers/resolvePageAndProps.d.ts +27 -0
  127. package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -0
  128. package/dist/plugin/helpers/resolvePageAndProps.js +51 -0
  129. package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -0
  130. package/dist/plugin/helpers/serializeUserOptions.d.ts +8 -0
  131. package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -0
  132. package/dist/plugin/helpers/serializeUserOptions.js +182 -0
  133. package/dist/plugin/helpers/serializeUserOptions.js.map +1 -0
  134. package/dist/plugin/helpers/stashReturnValue.d.ts +2 -0
  135. package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -0
  136. package/dist/plugin/helpers/stashReturnValue.js +14 -0
  137. package/dist/plugin/helpers/tryManifest.d.ts +5 -3
  138. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
  139. package/dist/plugin/helpers/tryManifest.js +16 -7
  140. package/dist/plugin/helpers/tryManifest.js.map +1 -1
  141. package/dist/plugin/html.d.ts +2 -3
  142. package/dist/plugin/html.d.ts.map +1 -1
  143. package/dist/plugin/html.js +7 -1
  144. package/dist/plugin/html.js.map +1 -1
  145. package/dist/plugin/index.d.ts +1 -2
  146. package/dist/plugin/index.d.ts.map +1 -1
  147. package/dist/plugin/index.js +3 -1
  148. package/dist/plugin/loader/createBuildLoader.d.ts +26 -4
  149. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
  150. package/dist/plugin/loader/createBuildLoader.js +98 -33
  151. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  152. package/dist/plugin/loader/css-loader.development.d.ts +57 -0
  153. package/dist/plugin/loader/css-loader.development.d.ts.map +1 -0
  154. package/dist/plugin/loader/css-loader.development.js +81 -0
  155. package/dist/plugin/loader/css-loader.development.js.map +1 -0
  156. package/dist/plugin/loader/css-loader.production.d.ts +31 -0
  157. package/dist/plugin/loader/css-loader.production.d.ts.map +1 -0
  158. package/dist/plugin/loader/css-loader.production.js +45 -0
  159. package/dist/plugin/loader/css-loader.production.js.map +1 -0
  160. package/dist/plugin/loader/index.d.ts +2 -0
  161. package/dist/plugin/loader/index.d.ts.map +1 -0
  162. package/dist/plugin/loader/index.js +1 -0
  163. package/dist/plugin/loader/plugin.d.ts +22 -0
  164. package/dist/plugin/loader/plugin.d.ts.map +1 -0
  165. package/dist/plugin/loader/plugin.js +27 -0
  166. package/dist/plugin/loader/react-loader.d.ts +3 -7
  167. package/dist/plugin/loader/react-loader.d.ts.map +1 -1
  168. package/dist/plugin/loader/react-loader.js +85 -30
  169. package/dist/plugin/loader/react-loader.js.map +1 -1
  170. package/dist/plugin/loader/temporaryReferences.d.ts +2 -0
  171. package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -0
  172. package/dist/plugin/loader/temporaryReferences.js +11 -0
  173. package/dist/plugin/loader/temporaryReferences.js.map +1 -0
  174. package/dist/plugin/moduleRefs.d.ts +7 -0
  175. package/dist/plugin/moduleRefs.d.ts.map +1 -0
  176. package/dist/plugin/moduleRefs.js +17 -0
  177. package/dist/plugin/moduleRefs.js.map +1 -0
  178. package/dist/plugin/plugin.client.d.ts +3 -0
  179. package/dist/plugin/plugin.client.d.ts.map +1 -0
  180. package/dist/plugin/plugin.client.js +19 -0
  181. package/dist/plugin/plugin.client.js.map +1 -0
  182. package/dist/plugin/plugin.d.ts +1 -5
  183. package/dist/plugin/plugin.d.ts.map +1 -1
  184. package/dist/plugin/plugin.js +3 -9
  185. package/dist/plugin/plugin.server.d.ts +3 -0
  186. package/dist/plugin/plugin.server.d.ts.map +1 -0
  187. package/dist/plugin/plugin.server.js +28 -0
  188. package/dist/plugin/plugin.server.js.map +1 -0
  189. package/dist/plugin/preserver/plugin.js +1 -1
  190. package/dist/plugin/preserver/plugin.js.map +1 -1
  191. package/dist/plugin/react-client/index.d.ts +1 -2
  192. package/dist/plugin/react-client/index.d.ts.map +1 -1
  193. package/dist/plugin/react-client/index.js +1 -19
  194. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  195. package/dist/plugin/react-client/plugin.js +60 -219
  196. package/dist/plugin/react-client/plugin.js.map +1 -1
  197. package/dist/plugin/react-client/server.d.ts +27 -0
  198. package/dist/plugin/react-client/server.d.ts.map +1 -0
  199. package/dist/plugin/react-client/server.js +197 -0
  200. package/dist/plugin/react-client/server.js.map +1 -0
  201. package/dist/plugin/react-server/index.d.ts +1 -2
  202. package/dist/plugin/react-server/index.d.ts.map +1 -1
  203. package/dist/plugin/react-server/index.js +1 -21
  204. package/dist/plugin/react-server/plugin.d.ts +0 -1
  205. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  206. package/dist/plugin/react-server/plugin.js +60 -186
  207. package/dist/plugin/react-server/plugin.js.map +1 -1
  208. package/dist/plugin/react-server/server.d.ts +9 -0
  209. package/dist/plugin/react-server/server.d.ts.map +1 -0
  210. package/dist/plugin/react-server/server.js +120 -0
  211. package/dist/plugin/react-server/server.js.map +1 -0
  212. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +23 -0
  213. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -0
  214. package/dist/plugin/react-static/collectHtmlWorkerContent.js +85 -0
  215. package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -0
  216. package/dist/plugin/react-static/collectRscContent.d.ts +24 -0
  217. package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -0
  218. package/dist/plugin/react-static/collectRscContent.js +49 -0
  219. package/dist/plugin/react-static/collectRscContent.js.map +1 -0
  220. package/dist/plugin/react-static/configurePreviewServer.d.ts +7 -0
  221. package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -0
  222. package/dist/plugin/react-static/configurePreviewServer.js +67 -0
  223. package/dist/plugin/react-static/configurePreviewServer.js.map +1 -0
  224. package/dist/plugin/react-static/fileWriter.d.ts +23 -0
  225. package/dist/plugin/react-static/fileWriter.d.ts.map +1 -0
  226. package/dist/plugin/react-static/fileWriter.js +65 -0
  227. package/dist/plugin/react-static/fileWriter.js.map +1 -0
  228. package/dist/plugin/react-static/plugin.d.ts +15 -0
  229. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  230. package/dist/plugin/react-static/plugin.js +248 -149
  231. package/dist/plugin/react-static/plugin.js.map +1 -1
  232. package/dist/plugin/react-static/renderPage.d.ts +3 -0
  233. package/dist/plugin/react-static/renderPage.d.ts.map +1 -0
  234. package/dist/plugin/react-static/renderPage.js +116 -0
  235. package/dist/plugin/react-static/renderPage.js.map +1 -0
  236. package/dist/plugin/react-static/renderPages.d.ts +3 -0
  237. package/dist/plugin/react-static/renderPages.d.ts.map +1 -0
  238. package/dist/plugin/react-static/renderPages.js +125 -0
  239. package/dist/plugin/react-static/renderPages.js.map +1 -0
  240. package/dist/plugin/react-static/renderStreams.d.ts +26 -0
  241. package/dist/plugin/react-static/renderStreams.d.ts.map +1 -0
  242. package/dist/plugin/react-static/renderStreams.js +27 -0
  243. package/dist/plugin/react-static/renderStreams.js.map +1 -0
  244. package/dist/plugin/react-static/rscToHtmlStream.d.ts +22 -0
  245. package/dist/plugin/react-static/rscToHtmlStream.d.ts.map +1 -0
  246. package/dist/plugin/react-static/rscToHtmlStream.js +54 -0
  247. package/dist/plugin/react-static/rscToHtmlStream.js.map +1 -0
  248. package/dist/plugin/react-static/streamHandler.d.ts +2 -0
  249. package/dist/plugin/react-static/streamHandler.d.ts.map +1 -0
  250. package/dist/plugin/react-static/streamHandler.js +1 -0
  251. package/dist/plugin/react-static/types.d.ts +11 -0
  252. package/dist/plugin/react-static/types.d.ts.map +1 -1
  253. package/dist/plugin/resolvePage.d.ts +26 -9
  254. package/dist/plugin/resolvePage.d.ts.map +1 -1
  255. package/dist/plugin/resolvePage.js +41 -39
  256. package/dist/plugin/resolvePage.js.map +1 -1
  257. package/dist/plugin/resolveProps.d.ts +40 -7
  258. package/dist/plugin/resolveProps.d.ts.map +1 -1
  259. package/dist/plugin/resolveProps.js +100 -75
  260. package/dist/plugin/resolveProps.js.map +1 -1
  261. package/dist/plugin/root.d.ts +1 -0
  262. package/dist/plugin/root.d.ts.map +1 -1
  263. package/dist/plugin/root.js +1 -0
  264. package/dist/plugin/root.js.map +1 -1
  265. package/dist/plugin/transformer/index.d.ts +2 -1
  266. package/dist/plugin/transformer/index.d.ts.map +1 -1
  267. package/dist/plugin/transformer/index.js +2 -1
  268. package/dist/plugin/transformer/plugin.client.d.ts +4 -0
  269. package/dist/plugin/transformer/plugin.client.d.ts.map +1 -0
  270. package/dist/plugin/transformer/plugin.client.js +83 -0
  271. package/dist/plugin/transformer/plugin.client.js.map +1 -0
  272. package/dist/plugin/transformer/plugin.d.ts +1 -27
  273. package/dist/plugin/transformer/plugin.d.ts.map +1 -1
  274. package/dist/plugin/transformer/plugin.js +3 -87
  275. package/dist/plugin/transformer/plugin.js.map +1 -1
  276. package/dist/plugin/transformer/plugin.server.d.ts +4 -0
  277. package/dist/plugin/transformer/plugin.server.d.ts.map +1 -0
  278. package/dist/plugin/transformer/plugin.server.js +76 -0
  279. package/dist/plugin/transformer/plugin.server.js.map +1 -0
  280. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +11 -0
  281. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -0
  282. package/dist/plugin/transformer/upgradeCssModuleCode.js +38 -0
  283. package/dist/plugin/types/css-tracking.d.ts +6 -0
  284. package/dist/plugin/types/css-tracking.d.ts.map +1 -0
  285. package/dist/plugin/types/css-tracking.js +1 -0
  286. package/dist/plugin/types.d.ts +372 -86
  287. package/dist/plugin/types.d.ts.map +1 -1
  288. package/dist/plugin/types.js +1 -1
  289. package/dist/plugin/vendor.client.d.ts +4 -0
  290. package/dist/plugin/vendor.client.d.ts.map +1 -0
  291. package/dist/plugin/vendor.client.js +16 -0
  292. package/dist/plugin/vendor.client.js.map +1 -0
  293. package/dist/plugin/vendor.server.d.ts +4 -0
  294. package/dist/plugin/vendor.server.d.ts.map +1 -0
  295. package/dist/plugin/vendor.server.js +16 -0
  296. package/dist/plugin/vendor.server.js.map +1 -0
  297. package/dist/plugin/worker/createWorker.d.ts +25 -7
  298. package/dist/plugin/worker/createWorker.d.ts.map +1 -1
  299. package/dist/plugin/worker/createWorker.js +108 -33
  300. package/dist/plugin/worker/createWorker.js.map +1 -1
  301. package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts +12 -0
  302. package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -0
  303. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +103 -0
  304. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -0
  305. package/dist/plugin/worker/html/html-worker.development.d.ts +0 -30
  306. package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
  307. package/dist/plugin/worker/html/html-worker.development.js +3 -17
  308. package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
  309. package/dist/plugin/worker/html/html-worker.production.js +12 -5
  310. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  311. package/dist/plugin/worker/html/messageHandler.d.ts +2 -2
  312. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
  313. package/dist/plugin/worker/html/messageHandler.js +87 -84
  314. package/dist/plugin/worker/html/messageHandler.js.map +1 -1
  315. package/dist/plugin/worker/html/types.d.ts +18 -0
  316. package/dist/plugin/worker/html/types.d.ts.map +1 -0
  317. package/dist/plugin/worker/html/types.js +1 -0
  318. package/dist/plugin/worker/registerLoaders.d.ts +9 -0
  319. package/dist/plugin/worker/registerLoaders.d.ts.map +1 -0
  320. package/dist/plugin/worker/registerLoaders.js +45 -0
  321. package/dist/plugin/worker/rsc/handleRender.d.ts +4 -0
  322. package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -0
  323. package/dist/plugin/worker/rsc/handleRender.js +147 -0
  324. package/dist/plugin/worker/rsc/handleRender.js.map +1 -0
  325. package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -2
  326. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  327. package/dist/plugin/worker/rsc/messageHandler.js +47 -112
  328. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  329. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +0 -30
  330. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -1
  331. package/dist/plugin/worker/rsc/rsc-worker.development.js +29 -4
  332. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  333. package/dist/plugin/worker/rsc/rsc-worker.production.js +3 -3
  334. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
  335. package/dist/plugin/worker/rsc/state.d.ts +73 -2
  336. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  337. package/dist/plugin/worker/rsc/state.js +40 -3
  338. package/dist/plugin/worker/rsc/state.js.map +1 -1
  339. package/dist/plugin/worker/sendMessage.d.ts +3 -0
  340. package/dist/plugin/worker/sendMessage.d.ts.map +1 -0
  341. package/dist/plugin/worker/sendMessage.js +48 -0
  342. package/dist/plugin/worker/types.d.ts +218 -76
  343. package/dist/plugin/worker/types.d.ts.map +1 -1
  344. package/dist/server.d.ts +1 -1
  345. package/dist/server.d.ts.map +1 -1
  346. package/dist/server.js +6 -1
  347. package/dist/server.js.map +1 -1
  348. package/dist/tsconfig.tsbuildinfo +1 -1
  349. package/package.json +24 -14
  350. package/plugin/components.ts +1 -1
  351. package/plugin/config/autoDiscover/createGlobAutoDiscover.ts +29 -0
  352. package/plugin/config/autoDiscover/customWorkerFiles.ts +27 -0
  353. package/plugin/config/autoDiscover/pageAndPropFiles.ts +36 -0
  354. package/plugin/config/autoDiscover/resolveBuildPages.ts +98 -0
  355. package/plugin/config/defaults.tsx +38 -29
  356. package/plugin/config/getCondition.ts +7 -3
  357. package/plugin/config/getPaths.ts +1 -7
  358. package/plugin/config/index.ts +0 -1
  359. package/plugin/config/resolveAutoDiscover.ts +177 -0
  360. package/plugin/config/resolveOptions.ts +220 -118
  361. package/plugin/config/resolvePages.ts +5 -7
  362. package/plugin/config/resolveUrlOption.ts +43 -0
  363. package/plugin/config/resolveUserConfig.ts +116 -166
  364. package/plugin/copy.ts +39 -0
  365. package/plugin/css-collector-elements.tsx +21 -0
  366. package/plugin/css-collector.tsx +20 -53
  367. package/plugin/helpers/cleanObject.ts +50 -0
  368. package/plugin/helpers/collectBundleManifestCss.ts +160 -0
  369. package/plugin/helpers/collectManifestCss.ts +61 -0
  370. package/plugin/helpers/collectViteModuleGraphCss.ts +158 -0
  371. package/plugin/helpers/createCssProps.tsx +85 -0
  372. package/plugin/helpers/createEventHandler.ts +44 -0
  373. package/plugin/helpers/createHandler.ts +57 -126
  374. package/plugin/helpers/createRscStream.tsx +156 -0
  375. package/plugin/helpers/defaultFileWriter.ts +0 -0
  376. package/plugin/helpers/getBundleManifest.ts +42 -37
  377. package/plugin/helpers/getRouteFiles.ts +47 -0
  378. package/plugin/helpers/inputNormalizer.ts +16 -10
  379. package/plugin/helpers/metrics.ts +64 -0
  380. package/plugin/helpers/resolvePageAndProps.ts +81 -0
  381. package/plugin/helpers/serializeUserOptions.ts +209 -0
  382. package/plugin/helpers/stashReturnValue.ts +16 -0
  383. package/plugin/helpers/tryManifest.ts +35 -18
  384. package/plugin/html.tsx +14 -3
  385. package/plugin/index.ts +5 -2
  386. package/plugin/loader/createBuildLoader.ts +152 -47
  387. package/plugin/loader/css-loader.development.ts +157 -0
  388. package/plugin/loader/css-loader.production.ts +86 -0
  389. package/plugin/loader/index.ts +1 -0
  390. package/plugin/loader/plugin.ts +33 -0
  391. package/plugin/loader/react-loader.ts +109 -41
  392. package/plugin/loader/temporaryReferences.ts +3 -0
  393. package/plugin/moduleRefs.ts +11 -0
  394. package/plugin/plugin.client.ts +12 -0
  395. package/plugin/plugin.server.ts +25 -0
  396. package/plugin/plugin.ts +5 -9
  397. package/plugin/preserver/plugin.ts +1 -1
  398. package/plugin/react-client/index.ts +1 -12
  399. package/plugin/react-client/plugin.ts +70 -259
  400. package/plugin/react-client/server.ts +276 -0
  401. package/plugin/react-server/index.ts +1 -14
  402. package/plugin/react-server/plugin.ts +69 -220
  403. package/plugin/react-server/server.ts +128 -0
  404. package/plugin/react-static/collectHtmlWorkerContent.ts +120 -0
  405. package/plugin/react-static/collectRscContent.ts +77 -0
  406. package/plugin/react-static/configurePreviewServer.ts +68 -0
  407. package/plugin/react-static/fileWriter.ts +103 -0
  408. package/plugin/react-static/plugin.ts +308 -181
  409. package/plugin/react-static/renderPage.ts +151 -0
  410. package/plugin/react-static/renderPages.ts +154 -0
  411. package/plugin/react-static/renderStreams.ts +48 -0
  412. package/plugin/react-static/rscToHtmlStream.ts +85 -0
  413. package/plugin/react-static/streamHandler.ts +0 -0
  414. package/plugin/react-static/types.ts +10 -0
  415. package/plugin/resolvePage.ts +67 -57
  416. package/plugin/resolveProps.ts +148 -104
  417. package/plugin/root.ts +1 -1
  418. package/plugin/transformer/index.ts +2 -1
  419. package/plugin/transformer/plugin.client.ts +109 -0
  420. package/plugin/transformer/plugin.server.ts +98 -0
  421. package/plugin/transformer/plugin.ts +2 -115
  422. package/plugin/transformer/upgradeCssModuleCode.ts +42 -0
  423. package/plugin/types/css-tracking.ts +5 -0
  424. package/plugin/types/react-server-dom-esm.d.ts +54 -0
  425. package/plugin/types.ts +508 -97
  426. package/plugin/vendor.client.ts +12 -0
  427. package/plugin/vendor.server.ts +12 -0
  428. package/plugin/worker/createWorker.ts +158 -53
  429. package/plugin/worker/html/createHtmlWorkerRenderState.tsx +112 -0
  430. package/plugin/worker/html/html-worker.development.tsx +5 -75
  431. package/plugin/worker/html/html-worker.production.tsx +18 -7
  432. package/plugin/worker/html/messageHandler.tsx +126 -0
  433. package/plugin/worker/html/types.ts +19 -0
  434. package/plugin/worker/registerLoaders.ts +54 -0
  435. package/plugin/worker/rsc/handleRender.ts +180 -0
  436. package/plugin/worker/rsc/messageHandler.tsx +58 -132
  437. package/plugin/worker/rsc/rsc-worker.development.ts +49 -63
  438. package/plugin/worker/rsc/rsc-worker.production.ts +5 -5
  439. package/plugin/worker/rsc/state.ts +79 -2
  440. package/plugin/worker/sendMessage.ts +49 -0
  441. package/plugin/worker/types.ts +299 -100
  442. package/scripts/check-react-version.mjs +60 -48
  443. package/scripts/react+0.0.0-experimental-0ca8420f-20250504.patch +57 -0
  444. package/scripts/react-dom+0.0.0-experimental-0ca8420f-20250504.patch +819 -0
  445. package/scripts/{react-server-dom-esm+0.0.0-experimental-eda36a1c-20250228.patch → react-server-dom-esm+0.0.0-experimental-0ca8420f-20250504.patch} +1702 -2820
  446. package/tsconfig.json +7 -2
  447. package/dist/plugin/assertServerCondition.d.ts +0 -6
  448. package/dist/plugin/assertServerCondition.d.ts.map +0 -1
  449. package/dist/plugin/assertServerCondition.js +0 -13
  450. package/dist/plugin/checkFilesExist.d.ts +0 -3
  451. package/dist/plugin/checkFilesExist.d.ts.map +0 -1
  452. package/dist/plugin/checkFilesExist.js +0 -67
  453. package/dist/plugin/checkFilesExist.js.map +0 -1
  454. package/dist/plugin/collect-manifest-client-files.d.ts +0 -23
  455. package/dist/plugin/collect-manifest-client-files.d.ts.map +0 -1
  456. package/dist/plugin/collect-manifest-client-files.js +0 -131
  457. package/dist/plugin/collect-manifest-client-files.js.map +0 -1
  458. package/dist/plugin/config/getWorkerPath.d.ts +0 -2
  459. package/dist/plugin/config/getWorkerPath.d.ts.map +0 -1
  460. package/dist/plugin/config/getWorkerPath.js +0 -4
  461. package/dist/plugin/copy-dir.d.ts +0 -4
  462. package/dist/plugin/copy-dir.d.ts.map +0 -1
  463. package/dist/plugin/copy-dir.js +0 -25
  464. package/dist/plugin/copy-dir.js.map +0 -1
  465. package/dist/plugin/css-collector-inline.d.ts +0 -10
  466. package/dist/plugin/css-collector-inline.d.ts.map +0 -1
  467. package/dist/plugin/css-collector-inline.js +0 -55
  468. package/dist/plugin/css-collector-inline.js.map +0 -1
  469. package/dist/plugin/loader/css-loader.d.ts +0 -16
  470. package/dist/plugin/loader/css-loader.d.ts.map +0 -1
  471. package/dist/plugin/loader/css-loader.js +0 -70
  472. package/dist/plugin/loader/css-loader.js.map +0 -1
  473. package/dist/plugin/react-client/index.js.map +0 -1
  474. package/dist/plugin/react-server/index.js.map +0 -1
  475. package/dist/plugin/worker/html/renderPages.d.ts +0 -26
  476. package/dist/plugin/worker/html/renderPages.d.ts.map +0 -1
  477. package/dist/plugin/worker/html/renderPages.js +0 -241
  478. package/dist/plugin/worker/html/renderPages.js.map +0 -1
  479. package/plugin/assertServerCondition.ts +0 -12
  480. package/plugin/checkFilesExist.ts +0 -66
  481. package/plugin/collect-manifest-client-files.ts +0 -167
  482. package/plugin/config/getWorkerPath.ts +0 -5
  483. package/plugin/copy-dir.ts +0 -27
  484. package/plugin/css-collector-inline.tsx +0 -60
  485. package/plugin/helpers/createRscStream.ts +0 -109
  486. package/plugin/loader/css-loader.ts +0 -94
  487. package/plugin/worker/html/messageHandler.ts +0 -130
  488. package/plugin/worker/html/renderPages.ts +0 -293
  489. package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +0 -159
  490. package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +0 -12508
@@ -0,0 +1,157 @@
1
+ import { type MessagePort } from "node:worker_threads";
2
+ import type { LoadHookContext } from "node:module";
3
+ import type { LoaderContext, SerializedUserConfig } from "../types.js";
4
+ import { fileURLToPath } from "node:url";
5
+ import { preprocessCSS } from "vite";
6
+ import type { ResolvedConfig } from "vite";
7
+ import { readFile } from "node:fs/promises";
8
+ import { join } from "node:path";
9
+
10
+ /**
11
+ * Global port for communication between the main thread and the CSS loader.
12
+ * This port is used to send CSS file requests and receive responses.
13
+ */
14
+ export let loaderPort: MessagePort | undefined;
15
+
16
+ /**
17
+ * Tracks CSS files used by each page.
18
+ * Maps page URLs to sets of CSS file paths that are used by that page.
19
+ */
20
+ const cssFilesByPage = new Map<string, Set<string>>();
21
+
22
+ let currentPage: string | null = null;
23
+ let resolvedConfig: ResolvedConfig | undefined;
24
+ // Get environment variables
25
+ const env = import.meta?.env || {
26
+ BASE_URL: '/',
27
+ DEV: true,
28
+ MODE: 'development',
29
+ PROD: false,
30
+ SSR: true
31
+ };
32
+
33
+ /**
34
+ * Initializes the CSS loader with the necessary communication channels.
35
+ * Sets up message handlers for CSS file requests and responses.
36
+ *
37
+ * @param data - Configuration data for the CSS loader
38
+ * @param data.port - The message port for communication
39
+ */
40
+ export async function initialize(data: { port: MessagePort, resolvedConfig: SerializedUserConfig }) {
41
+ loaderPort = data.port;
42
+ resolvedConfig = data.resolvedConfig;
43
+ data.port.postMessage({ type: "INITIALIZED_CSS_LOADER" });
44
+ }
45
+
46
+ /**
47
+ * Sets the current page being processed.
48
+ * Used to track which CSS files are associated with which pages.
49
+ *
50
+ * @param page - The URL of the current page, or null if no page is active
51
+ */
52
+ export function setCurrentPage(page: string | null) {
53
+ currentPage = page;
54
+ }
55
+
56
+ /**
57
+ * Retrieves all CSS files associated with a specific page.
58
+ *
59
+ * @param page - The URL of the page
60
+ * @returns An array of CSS file paths used by the page
61
+ */
62
+ export function getCssFilesForPage(page: string): string[] {
63
+ return Array.from(cssFilesByPage.get(page) || []);
64
+ }
65
+
66
+ /**
67
+ * Processes a CSS file request.
68
+ * Sends a request to the main thread and waits for the processed CSS.
69
+ *
70
+ * @param filePath - The file system path of the CSS file
71
+ * @param config - The Vite config
72
+ * @returns A promise that resolves to the processed CSS content
73
+ */
74
+ async function processCssFile(
75
+ filePath: string,
76
+ config: ResolvedConfig,
77
+ inline: boolean
78
+ ): Promise<{ format: string; source: string; shortCircuit: boolean }> {
79
+ try {
80
+ // Convert file URL to path if needed
81
+ const path = filePath.startsWith("file://")
82
+ ? fileURLToPath(filePath)
83
+ : filePath;
84
+
85
+ // Process CSS using Vite's preprocessCSS
86
+ const source = await readFile(path, "utf-8");
87
+ const processed = await preprocessCSS(source, path, {
88
+ ...config,
89
+ env: env
90
+ });
91
+
92
+ // If we're processing CSS for a specific page, notify the message handler
93
+ if (loaderPort) {
94
+ loaderPort.postMessage({
95
+ type: "CSS_FILE",
96
+ id: currentPage ? join(path, "?page=" + currentPage) : path,
97
+ path: path,
98
+ content: processed.code,
99
+ modules: processed.modules || {},
100
+ inline,
101
+ });
102
+ }
103
+
104
+ // Return a module that can be used by React components
105
+ if (inline) {
106
+ return {
107
+ format: "module",
108
+ source: processed.code,
109
+ shortCircuit: true,
110
+ };
111
+ }
112
+ return {
113
+ format: "module",
114
+ source: `export default ${JSON.stringify(processed.modules || {})};`,
115
+ shortCircuit: true,
116
+ };
117
+ } catch (error) {
118
+ console.error(`[css-loader] Error processing CSS file: ${error}`);
119
+ throw error;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Vite's load hook implementation for CSS files.
125
+ * Handles CSS file loading requests and returns a placeholder module.
126
+ * The actual CSS content is processed in the main thread.
127
+ *
128
+ * @param url - The URL of the module to load
129
+ * @param context - The load hook context
130
+ * @param defaultLoad - The default load function
131
+ * @returns A promise that resolves to the module content
132
+ */
133
+ export async function load(
134
+ url: string,
135
+ context: LoadHookContext & LoaderContext & { resolvedConfig: SerializedUserConfig },
136
+ defaultLoad: any
137
+ ) {
138
+ const [name, query] = url.split("?");
139
+ if (name.endsWith(".css")) {
140
+ return processCssFile(url, resolvedConfig as ResolvedConfig, query === "inline");
141
+ }
142
+
143
+ return defaultLoad(url, context, defaultLoad);
144
+ }
145
+
146
+ /**
147
+ * Vite's resolve hook implementation.
148
+ * Handles module resolution during development.
149
+ *
150
+ * @param specifier - The module specifier to resolve
151
+ * @param context - The resolve hook context
152
+ * @param defaultResolve - The default resolve function
153
+ * @returns A promise that resolves to the resolved module
154
+ */
155
+ export function resolve(specifier: string, context: any, defaultResolve: any) {
156
+ return defaultResolve(specifier, context, defaultResolve);
157
+ }
@@ -0,0 +1,86 @@
1
+ import type { MessagePort } from "node:worker_threads";
2
+ import type { LoadHookContext } from "node:module";
3
+ import type { LoaderContext } from "../types.js";
4
+ import { fileURLToPath } from "node:url";
5
+ import { readFile } from "node:fs/promises";
6
+
7
+ /**
8
+ * Global port for communication between the main thread and the CSS loader.
9
+ * This port is used to send CSS file requests and receive responses.
10
+ */
11
+ export let loaderPort: MessagePort | undefined;
12
+
13
+ let stashedCssFiles = new Map();
14
+
15
+ /**
16
+ * Initializes the CSS loader with the necessary communication channels.
17
+ * Sets up message handlers for CSS file requests and responses.
18
+ *
19
+ * @param data - Configuration data for the CSS loader
20
+ * @param data.port - The message port for communication
21
+ * @param data.server - The Vite dev server instance
22
+ */
23
+ export async function initialize(data: { port: MessagePort }) {
24
+ loaderPort = data.port;
25
+ data.port.postMessage({ type: "INITIALIZED_CSS_LOADER" });
26
+ }
27
+
28
+ /**
29
+ * Processes a CSS file request.
30
+ * Sends a request to the main thread and waits for the processed CSS.
31
+ *
32
+ * @param filePath - The file system path of the CSS file
33
+ * @param config - The Vite config
34
+ * @returns A promise that resolves to the processed CSS content
35
+ */
36
+ async function processCssFile(
37
+ filePath: string
38
+ ): Promise<{ format: string; source: string; shortCircuit: boolean }> {
39
+ try {
40
+ // Convert file URL to path if needed
41
+ const path = filePath.startsWith("file://")
42
+ ? fileURLToPath(filePath)
43
+ : filePath;
44
+ if (stashedCssFiles.has(filePath)) {
45
+ return {
46
+ format: "module",
47
+ source: stashedCssFiles.get(filePath),
48
+ shortCircuit: true,
49
+ };
50
+ }
51
+ // Process CSS using Vite's preprocessCSS
52
+ const source = await readFile(path, "utf-8");
53
+ stashedCssFiles.set(path, source);
54
+ return {
55
+ format: "module",
56
+ source: source,
57
+ shortCircuit: true,
58
+ };
59
+ } catch (error) {
60
+ throw error;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Vite's load hook implementation for CSS files.
66
+ * Handles CSS file loading requests and returns a placeholder module.
67
+ * The actual CSS content is processed in the main thread.
68
+ *
69
+ * @param url - The URL of the module to load
70
+ * @param context - The load hook context
71
+ * @param defaultLoad - The default load function
72
+ * @returns A promise that resolves to the module content
73
+ */
74
+ export async function load(
75
+ url: string,
76
+ context: LoadHookContext & LoaderContext,
77
+ defaultLoad: any
78
+ ) {
79
+ // Handle CSS files
80
+ const [name] = url.split("?");
81
+ if (name.endsWith(".css")) {
82
+ return processCssFile(url);
83
+ }
84
+
85
+ return defaultLoad(url, context, defaultLoad);
86
+ }
@@ -0,0 +1 @@
1
+ export { reactLoaderPlugin } from "./plugin.js";
@@ -0,0 +1,33 @@
1
+ import { resolveOptions } from "../config/resolveOptions.js";
2
+ import type {
3
+ StreamPluginOptions,
4
+ } from "../types.js";
5
+ import type { Plugin } from "vite";
6
+
7
+ /**
8
+ * Plugin for loading various front-end react files like css-loader, react-loader, etc.
9
+ *
10
+ * Core responsibilities:
11
+ * 1. Use the load hook to use the appropriate loader for the file type
12
+ * 2. When used, we can assume that such files work the same as when used as node loader
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * export default defineConfig({
17
+ * plugins: [
18
+ * reactLoaderPlugin({
19
+ * projectRoot: process.cwd(),
20
+ * })
21
+ * ]
22
+ * });
23
+ * ```
24
+ */
25
+
26
+ export function reactLoaderPlugin(options: StreamPluginOptions): Plugin {
27
+ const resolvedOptionsResult = resolveOptions(options);
28
+ if (resolvedOptionsResult.type === "error") throw resolvedOptionsResult.error;
29
+
30
+ return {
31
+ name: "vite:react-loader",
32
+ };
33
+ }
@@ -8,7 +8,9 @@ import {
8
8
  type LoadHookContext,
9
9
  type ResolveHookContext,
10
10
  } from "node:module";
11
+ import { workerData } from "node:worker_threads";
11
12
  import type { MessagePort } from "node:worker_threads";
13
+ import type { LoaderContext } from "../types.js";
12
14
 
13
15
  let stashedGetSource: any = null;
14
16
  let stashedResolve: any = null;
@@ -19,13 +21,20 @@ setSourceMapsSupport(true, {
19
21
  generatedCode: true, // Enable for generated code
20
22
  });
21
23
 
22
- // Add type for our context with port
23
- interface LoaderContext {
24
- data?: { port: MessagePort };
25
- }
24
+ // Get environment variables from workerData or import.meta
25
+ const env = workerData?.importMeta?.env ||
26
+ import.meta?.env || {
27
+ BASE_URL: "/",
28
+ DEV: false,
29
+ MODE: "production",
30
+ PROD: true,
31
+ SSR: true,
32
+ };
26
33
 
27
34
  // Store port globally for use in load hook
28
- let loaderPort: MessagePort | undefined;
35
+ export let loaderPort: MessagePort | undefined;
36
+ // during development, we actually just want to be explicit about the .node extension
37
+ let isDev = process.env["NODE_ENV"] === "development";
29
38
 
30
39
  export async function getSource(
31
40
  url: string,
@@ -353,9 +362,13 @@ function transformServerModule(
353
362
  }
354
363
  }
355
364
 
356
- newSrc += "\n\n;";
357
- newSrc +=
358
- 'import {registerServerReference} from "react-server-dom-esm/server";\n';
365
+ newSrc = "";
366
+ newSrc += `import ReactDOMServerESM from "react-server-dom-esm/server${
367
+ isDev ? ".node" : ""
368
+ }";\n`;
369
+ // include stack trace where module is imported from
370
+ newSrc += `if(ReactDOMServerESM instanceof Error){ throw ReactDOMServerESM; }`;
371
+ newSrc += `export const registerServerReference = ReactDOMServerESM.registerServerReference;\n`;
359
372
 
360
373
  if (mappings) {
361
374
  mappings += ";;";
@@ -564,14 +577,16 @@ async function transformClientModule(
564
577
  const names: any[] = [];
565
578
  await parseExportNamesInto(body, names, url, loader);
566
579
 
567
-
568
580
  if (names.length === 0) {
569
- console.log("[react-loader] No exports found in:", url);
570
- return "";
581
+ return null;
571
582
  }
572
583
 
573
- let newSrc =
574
- 'import {registerClientReference} from "react-server-dom-esm/server";\n';
584
+ let newSrc = `import ReactDOMServerESM from "react-server-dom-esm/server${
585
+ isDev ? ".node" : ""
586
+ }";\n`;
587
+ // check if the module is poisoned
588
+ newSrc += `if(ReactDOMServerESM instanceof Error){ throw new Error(ReactDOMServerESM); }`;
589
+ newSrc += `export const registerClientReference = ReactDOMServerESM.registerClientReference;\n`;
575
590
 
576
591
  for (let i = 0; i < names.length; i++) {
577
592
  const name = names[i];
@@ -685,13 +700,7 @@ export async function transformModuleIfNeeded(
685
700
 
686
701
  if (node.directive === "use client") {
687
702
  useClient = true;
688
- if (port) {
689
- port.postMessage({
690
- type: "CLIENT_COMPONENT",
691
- url,
692
- source,
693
- });
694
- }
703
+
695
704
  break;
696
705
  }
697
706
  if (node.directive === "use server") {
@@ -699,14 +708,19 @@ export async function transformModuleIfNeeded(
699
708
  break;
700
709
  }
701
710
  }
711
+ if (useClient && useServer) {
712
+ throw new Error(
713
+ "Cannot use both use client and use server directives in the same module"
714
+ );
715
+ }
716
+ if (!useClient && !useServer) {
717
+ return source;
718
+ }
702
719
 
703
720
  if (useClient) {
704
721
  return transformClientModule(program, url, undefined, loader);
705
- } else if (useServer) {
706
- return transformServerModule(source, program, url, undefined, loader, port);
707
722
  }
708
-
709
- return source;
723
+ return transformServerModule(source, program, url, undefined, loader, port);
710
724
  }
711
725
 
712
726
  function readMappings(
@@ -881,7 +895,7 @@ function decodeVLQ(str: string): number[] {
881
895
  // Initialize hook
882
896
  export async function initialize(data: { port: MessagePort }) {
883
897
  loaderPort = data.port; // Store port
884
- data.port.postMessage({ type: "INITIALIZED" });
898
+ data.port.postMessage({ type: "INITIALIZED_REACT_LOADER" });
885
899
  data.port.unref();
886
900
  }
887
901
 
@@ -900,17 +914,62 @@ export async function load(
900
914
  context: LoadHookContext & LoaderContext,
901
915
  nextLoad: any
902
916
  ) {
903
- const result = await nextLoad(url, context);
904
- if (result.format === "module") {
905
- const newSrc = await transformModuleIfNeeded(
906
- result.source,
907
- url,
908
- nextLoad,
909
- loaderPort ?? undefined
917
+ const result = await nextLoad(url, {
918
+ ...context,
919
+ env: env,
920
+ });
921
+
922
+ // If not a module, return as is
923
+ if (result.format !== "module") {
924
+ return result;
925
+ }
926
+
927
+ // Convert source to string if it's a Buffer or Uint8Array
928
+ let sourceStr: string;
929
+ if (typeof result.source === "string") {
930
+ sourceStr = result.source;
931
+ } else if (
932
+ result.source instanceof Uint8Array ||
933
+ Buffer.isBuffer(result.source)
934
+ ) {
935
+ sourceStr = result.source.toString("utf-8");
936
+ } else {
937
+ console.warn(
938
+ `[react-loader] Unexpected source type: ${typeof result.source}`
939
+ );
940
+ return result;
941
+ }
942
+
943
+ // Transform the module if needed
944
+ const transformResult = await transformModuleIfNeeded(
945
+ sourceStr,
946
+ url,
947
+ nextLoad,
948
+ loaderPort ?? undefined
949
+ );
950
+
951
+ // Handle different return types from transformModuleIfNeeded
952
+ if (transformResult === null) {
953
+ return result;
954
+ } else if (typeof transformResult === "string") {
955
+ return { ...result, source: transformResult };
956
+ } else if (typeof transformResult === "object") {
957
+ // Type assertion for object with code and map properties
958
+ const typedResult = transformResult as { code: string; map?: any };
959
+ if (!("code" in typedResult)) {
960
+ throw new Error("Failed to transform module");
961
+ }
962
+ return {
963
+ ...result,
964
+ source: typedResult.code,
965
+ map: typedResult.map || result.map,
966
+ };
967
+ } else {
968
+ console.warn(
969
+ `[react-loader] Unexpected transform result type: ${typeof transformResult}`
910
970
  );
911
- return { ...result, source: newSrc };
971
+ return result;
912
972
  }
913
- return result;
914
973
  }
915
974
 
916
975
  // Transform hook
@@ -924,18 +983,27 @@ export async function transformSource(
924
983
  context,
925
984
  defaultTransformSource
926
985
  );
927
-
928
986
  if (context.format === "module") {
929
- const transformedSource = transformed.source;
930
- if (typeof transformedSource !== "string") {
931
- throw new Error("Expected source to have been transformed to a string.");
987
+ // Convert transformedSource to string if it's a Buffer or Uint8Array
988
+ let transformedSourceStr: string;
989
+ if (typeof transformed.source === "string") {
990
+ transformedSourceStr = transformed.source;
991
+ } else if (
992
+ transformed.source instanceof Uint8Array ||
993
+ Buffer.isBuffer(transformed.source)
994
+ ) {
995
+ transformedSourceStr = transformed.source.toString("utf-8");
996
+ } else {
997
+ console.warn(
998
+ `[react-loader] Unexpected transformed source type: ${typeof transformed.source}`
999
+ );
1000
+ return transformed;
932
1001
  }
933
1002
 
934
1003
  const newSrc = await transformModuleIfNeeded(
935
- transformedSource,
1004
+ transformedSourceStr,
936
1005
  context.url,
937
- (url: string) =>
938
- loadClientImport(url, defaultTransformSource),
1006
+ (url: string) => loadClientImport(url, defaultTransformSource),
939
1007
  context.data?.port!
940
1008
  );
941
1009
  return { source: newSrc };
@@ -0,0 +1,3 @@
1
+ import { createTemporaryReferenceSet } from "react-server-dom-esm/server.node";
2
+
3
+ export const temporaryReferences = createTemporaryReferenceSet();
@@ -0,0 +1,11 @@
1
+ // Create a shared map to store module references
2
+ export const moduleRefs = new Map<string, { id: string }>();
3
+
4
+ export function getModuleRef(id: string): { id: string } {
5
+ let moduleRef = moduleRefs.get(id);
6
+ if (!moduleRef) {
7
+ moduleRef = { id };
8
+ moduleRefs.set(id, moduleRef);
9
+ }
10
+ return moduleRef;
11
+ }
@@ -0,0 +1,12 @@
1
+ import { reactPreservePlugin } from "./preserver/plugin.js";
2
+ import { reactTransformPlugin } from "./transformer/plugin.client.js";
3
+ import type { StreamPluginOptions } from "../types.js";
4
+ import { reactClientPlugin } from "./react-client/plugin.js";
5
+
6
+ export function vitePluginReactServer(options = {} as StreamPluginOptions): import("vite").Plugin[] {
7
+ return [
8
+ reactClientPlugin(options),
9
+ reactTransformPlugin(options),
10
+ reactPreservePlugin(options),
11
+ ];
12
+ }
@@ -0,0 +1,25 @@
1
+ import { reactPreservePlugin } from "./preserver/plugin.js";
2
+ import { reactStaticPlugin } from "./react-static/plugin.js";
3
+ import { reactTransformPlugin } from "./transformer/plugin.server.js";
4
+ import type { StreamPluginOptions } from "./types.js";
5
+ import { reactServerPlugin } from "./react-server/plugin.js";
6
+
7
+
8
+ export function vitePluginReactServer(
9
+ options = {} as StreamPluginOptions
10
+ ): import("vite").Plugin[] {
11
+ if(!options.build?.pages || (Array.isArray(options.build.pages) && options.build.pages.length === 0)) {
12
+ // in this case we do not need the static plugin at all
13
+ return [
14
+ reactTransformPlugin(options),
15
+ reactServerPlugin(options),
16
+ reactPreservePlugin(options),
17
+ ];
18
+ }
19
+ return [
20
+ reactTransformPlugin(options),
21
+ reactServerPlugin(options),
22
+ reactStaticPlugin(options),
23
+ reactPreservePlugin(options),
24
+ ];
25
+ }
package/plugin/plugin.ts CHANGED
@@ -1,9 +1,5 @@
1
- import { assertServerCondition } from "./assertServerCondition.js";
2
- export { reactServerPlugin } from "./react-server/plugin.js";
3
- export { reactClientPlugin } from "./react-client/plugin.js";
4
- export { reactTransformPlugin } from "./transformer/plugin.js";
5
- export { reactPreservePlugin } from "./preserver/plugin.js";
6
- export { vitePluginReactServer } from "./react-server/index.js";
7
- // the main plugin is version is the server version, if you want the client version, use the `vite-plugin-react-server/client` import
8
- // this is because the workflow assumes main thread = react server condition
9
- assertServerCondition(process);
1
+ import { getCondition } from './config/getCondition.js';
2
+
3
+ const condition = getCondition().slice(6); // remove react-
4
+
5
+ export const { vitePluginReactServer } = await import(`./plugin.${condition}.js`);
@@ -47,7 +47,7 @@ export function reactPreservePlugin(_options: StreamPluginOptions): import("vite
47
47
  order: "post", // Ensure this runs last in transform phase
48
48
  handler(code: string, id: string) {
49
49
  // Skip node_modules and vite files
50
- if (id.includes("node_modules") || id.includes("vite/dist") || !id.match(DEFAULT_CONFIG.FILE_REGEX)) {
50
+ if (id.includes("node_modules") || id.includes("vite/dist") || !id.match(DEFAULT_CONFIG.MODULE_EXTENSION)) {
51
51
  return null;
52
52
  }
53
53
 
@@ -1,12 +1 @@
1
- import { reactPreservePlugin } from "../plugin.js";
2
- import { reactTransformPlugin } from "../transformer/plugin.js";
3
- import type { StreamPluginOptions } from "../types.js";
4
- import { reactClientPlugin } from "./plugin.js";
5
-
6
- export function vitePluginReactClient(options = {} as StreamPluginOptions): import("vite").Plugin[] {
7
- return [
8
- reactClientPlugin(options),
9
- reactTransformPlugin(options),
10
- reactPreservePlugin(options),
11
- ];
12
- }
1
+ export { reactClientPlugin } from "./plugin.js";