vite-plugin-react-server 1.1.10 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/README.md +208 -27
  2. package/dist/package.json +34 -14
  3. package/dist/plugin/{css-collector-elements.d.ts → components/css-collector-elements.d.ts} +1 -1
  4. package/dist/plugin/components/css-collector-elements.d.ts.map +1 -0
  5. package/dist/plugin/components/css-collector-elements.js.map +1 -0
  6. package/dist/plugin/{css-collector.d.ts → components/css-collector.d.ts} +1 -1
  7. package/dist/plugin/components/css-collector.d.ts.map +1 -0
  8. package/dist/plugin/components/css-collector.js.map +1 -0
  9. package/dist/plugin/components/html.d.ts +4 -0
  10. package/dist/plugin/components/html.d.ts.map +1 -0
  11. package/dist/plugin/components/html.js +17 -0
  12. package/dist/plugin/components/html.js.map +1 -0
  13. package/dist/plugin/components/index.d.ts +5 -0
  14. package/dist/plugin/components/index.d.ts.map +1 -0
  15. package/dist/plugin/components.js +9 -3
  16. package/dist/plugin/components.js.map +1 -0
  17. package/dist/plugin/config/autoDiscover/index.d.ts +6 -0
  18. package/dist/plugin/config/autoDiscover/index.d.ts.map +1 -0
  19. package/dist/plugin/config/autoDiscover/index.js +8 -0
  20. package/dist/plugin/config/{resolveAutoDiscover.d.ts → autoDiscover/resolveAutoDiscover.d.ts} +1 -1
  21. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -0
  22. package/dist/plugin/config/{resolveAutoDiscover.js → autoDiscover/resolveAutoDiscover.js} +10 -9
  23. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -0
  24. package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -1
  25. package/dist/plugin/config/autoDiscover/resolveBuildPages.js +10 -10
  26. package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -1
  27. package/dist/plugin/config/defaults.d.ts +4 -3
  28. package/dist/plugin/config/defaults.d.ts.map +1 -1
  29. package/dist/plugin/config/defaults.js +5 -3
  30. package/dist/plugin/config/defaults.js.map +1 -1
  31. package/dist/plugin/config/index.d.ts +1 -0
  32. package/dist/plugin/config/index.d.ts.map +1 -1
  33. package/dist/plugin/config/index.js +1 -0
  34. package/dist/plugin/config/resolveEnv.d.ts +11 -1
  35. package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
  36. package/dist/plugin/config/resolveEnv.js +104 -5
  37. package/dist/plugin/config/resolveEnv.js.map +1 -1
  38. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  39. package/dist/plugin/config/resolveOptions.js +11 -4
  40. package/dist/plugin/config/resolveOptions.js.map +1 -1
  41. package/dist/plugin/config/resolveUrlOption.d.ts +1 -1
  42. package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -1
  43. package/dist/plugin/config/resolveUrlOption.js +1 -2
  44. package/dist/plugin/config/resolveUrlOption.js.map +1 -1
  45. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  46. package/dist/plugin/config/resolveUserConfig.js +43 -18
  47. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  48. package/dist/plugin/config.js +17 -0
  49. package/dist/plugin/config.js.map +1 -0
  50. package/dist/plugin/env/index.d.ts +2 -0
  51. package/dist/plugin/env/index.d.ts.map +1 -0
  52. package/dist/plugin/env/index.js +1 -0
  53. package/dist/plugin/env/plugin.d.ts +30 -0
  54. package/dist/plugin/env/plugin.d.ts.map +1 -0
  55. package/dist/plugin/env/plugin.js +64 -0
  56. package/dist/plugin/env.js +45 -0
  57. package/dist/plugin/env.js.map +1 -0
  58. package/dist/plugin/error/toError.d.ts +6 -0
  59. package/dist/plugin/error/toError.d.ts.map +1 -0
  60. package/dist/plugin/error/toError.js +19 -0
  61. package/dist/plugin/error/toError.js.map +1 -0
  62. package/dist/plugin/file-preserver/plugin.d.ts +19 -0
  63. package/dist/plugin/file-preserver/plugin.d.ts.map +1 -0
  64. package/dist/plugin/file-preserver/plugin.js +108 -0
  65. package/dist/plugin/file-preserver.js +96 -0
  66. package/dist/plugin/file-preserver.js.map +1 -0
  67. package/dist/plugin/helpers/createEventHandler.d.ts +1 -1
  68. package/dist/plugin/helpers/createRscStream.js +1 -1
  69. package/dist/plugin/helpers/createRscStream.js.map +1 -1
  70. package/dist/plugin/helpers/formatMetrics.d.ts +3 -1
  71. package/dist/plugin/helpers/formatMetrics.d.ts.map +1 -1
  72. package/dist/plugin/helpers/formatMetrics.js +22 -7
  73. package/dist/plugin/helpers/formatMetrics.js.map +1 -0
  74. package/dist/plugin/helpers/getRouteFiles.d.ts +1 -1
  75. package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
  76. package/dist/plugin/helpers/getRouteFiles.js +37 -18
  77. package/dist/plugin/helpers/getRouteFiles.js.map +1 -0
  78. package/dist/plugin/helpers/index.d.ts +24 -0
  79. package/dist/plugin/helpers/index.d.ts.map +1 -0
  80. package/dist/plugin/helpers/index.js +31 -0
  81. package/dist/plugin/helpers/metrics.js +26 -2
  82. package/dist/plugin/helpers/metrics.js.map +1 -1
  83. package/dist/plugin/helpers/moduleRefs.d.ts.map +1 -0
  84. package/dist/plugin/helpers/moduleRefs.js.map +1 -0
  85. package/dist/plugin/helpers/requestInfo.d.ts +10 -0
  86. package/dist/plugin/helpers/requestInfo.d.ts.map +1 -1
  87. package/dist/plugin/helpers/requestInfo.js.map +1 -1
  88. package/dist/plugin/helpers/requestToRoute.js +22 -14
  89. package/dist/plugin/helpers/requestToRoute.js.map +1 -0
  90. package/dist/plugin/helpers/resolvePage.d.ts.map +1 -0
  91. package/dist/plugin/{resolvePage.js → helpers/resolvePage.js} +19 -3
  92. package/dist/plugin/helpers/resolvePage.js.map +1 -0
  93. package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
  94. package/dist/plugin/helpers/resolvePageAndProps.js +7 -4
  95. package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
  96. package/dist/plugin/helpers/resolveProps.d.ts.map +1 -0
  97. package/dist/plugin/{resolveProps.js → helpers/resolveProps.js} +9 -6
  98. package/dist/plugin/helpers/resolveProps.js.map +1 -0
  99. package/dist/plugin/helpers/serializeUserOptions.js +1 -1
  100. package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
  101. package/dist/plugin/helpers/stashReturnValue.js +19 -13
  102. package/dist/plugin/helpers/stashReturnValue.js.map +1 -0
  103. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
  104. package/dist/plugin/helpers/tryManifest.js +0 -1
  105. package/dist/plugin/helpers/tryManifest.js.map +1 -1
  106. package/dist/plugin/helpers.js +27 -0
  107. package/dist/plugin/helpers.js.map +1 -0
  108. package/dist/plugin/loader/createBuildLoader.js +1 -1
  109. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  110. package/dist/plugin/loader/env-loader.development.d.ts +12 -0
  111. package/dist/plugin/loader/env-loader.development.d.ts.map +1 -0
  112. package/dist/plugin/loader/env-loader.development.js +60 -0
  113. package/dist/plugin/plugin.client.d.ts.map +1 -1
  114. package/dist/plugin/plugin.client.js +2 -0
  115. package/dist/plugin/plugin.client.js.map +1 -1
  116. package/dist/plugin/plugin.d.ts.map +1 -1
  117. package/dist/plugin/plugin.js +1 -2
  118. package/dist/plugin/plugin.server.d.ts.map +1 -1
  119. package/dist/plugin/plugin.server.js +3 -0
  120. package/dist/plugin/plugin.server.js.map +1 -1
  121. package/dist/plugin/process-env.d.ts +14 -0
  122. package/dist/plugin/process-env.d.ts.map +1 -0
  123. package/dist/plugin/react-client/createMessageHandlers.d.ts +2 -1
  124. package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
  125. package/dist/plugin/react-client/createMessageHandlers.js +13 -2
  126. package/dist/plugin/react-client/createMessageHandlers.js.map +1 -1
  127. package/dist/plugin/react-client/createWorkerStream.d.ts +8 -2
  128. package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
  129. package/dist/plugin/react-client/createWorkerStream.js +49 -8
  130. package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
  131. package/dist/plugin/react-client/handleWorkerRscStream.d.ts +19 -0
  132. package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -0
  133. package/dist/plugin/react-client/handleWorkerRscStream.js +47 -0
  134. package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -0
  135. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  136. package/dist/plugin/react-client/plugin.js +18 -2
  137. package/dist/plugin/react-client/plugin.js.map +1 -1
  138. package/dist/plugin/react-client/restartWorker.d.ts +6 -1
  139. package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
  140. package/dist/plugin/react-client/restartWorker.js +13 -5
  141. package/dist/plugin/react-client/restartWorker.js.map +1 -1
  142. package/dist/plugin/react-client/server.d.ts +2 -13
  143. package/dist/plugin/react-client/server.d.ts.map +1 -1
  144. package/dist/plugin/react-client/server.js +112 -99
  145. package/dist/plugin/react-client/server.js.map +1 -1
  146. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  147. package/dist/plugin/react-server/plugin.js +18 -8
  148. package/dist/plugin/react-server/plugin.js.map +1 -1
  149. package/dist/plugin/react-server/server.d.ts.map +1 -1
  150. package/dist/plugin/react-server/server.js +28 -12
  151. package/dist/plugin/react-server/server.js.map +1 -1
  152. package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
  153. package/dist/plugin/react-static/collectHtmlWorkerContent.js +9 -0
  154. package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
  155. package/dist/plugin/react-static/fileWriter.d.ts +1 -1
  156. package/dist/plugin/react-static/fileWriter.d.ts.map +1 -1
  157. package/dist/plugin/react-static/fileWriter.js.map +1 -1
  158. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  159. package/dist/plugin/react-static/plugin.js +19 -27
  160. package/dist/plugin/react-static/plugin.js.map +1 -1
  161. package/dist/plugin/root.d.ts +1 -0
  162. package/dist/plugin/root.d.ts.map +1 -1
  163. package/dist/plugin/root.js +3 -2
  164. package/dist/plugin/root.js.map +1 -1
  165. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +1 -10
  166. package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -1
  167. package/dist/plugin/transformer/upgradeCssModuleCode.js +40 -38
  168. package/dist/plugin/types.d.ts +57 -15
  169. package/dist/plugin/types.d.ts.map +1 -1
  170. package/dist/plugin/types.js +1 -1
  171. package/dist/plugin/utils/callServer.d.ts +1 -1
  172. package/dist/plugin/utils/callServer.d.ts.map +1 -1
  173. package/dist/plugin/utils/callServer.js +2 -16
  174. package/dist/plugin/utils/callServer.js.map +1 -1
  175. package/dist/plugin/utils/createCallServer.d.ts +2 -0
  176. package/dist/plugin/utils/createCallServer.d.ts.map +1 -0
  177. package/dist/plugin/utils/createCallServer.js +28 -0
  178. package/dist/plugin/utils/createCallServer.js.map +1 -0
  179. package/dist/plugin/utils/createReactFetcher.d.ts +3 -1
  180. package/dist/plugin/utils/createReactFetcher.d.ts.map +1 -1
  181. package/dist/plugin/utils/createReactFetcher.js +7 -5
  182. package/dist/plugin/utils/createReactFetcher.js.map +1 -1
  183. package/dist/plugin/utils/env.js.map +1 -1
  184. package/dist/plugin/utils/envUrls.d.ts +9 -0
  185. package/dist/plugin/utils/envUrls.d.ts.map +1 -0
  186. package/dist/plugin/utils/envUrls.js +7 -0
  187. package/dist/plugin/utils/envUrls.node.d.ts +7 -0
  188. package/dist/plugin/utils/envUrls.node.d.ts.map +1 -0
  189. package/dist/plugin/utils/envUrls.node.js +11 -0
  190. package/dist/plugin/utils/envUrls.node.js.map +1 -0
  191. package/dist/plugin/utils/index.d.ts +1 -1
  192. package/dist/plugin/utils/index.d.ts.map +1 -1
  193. package/dist/plugin/utils/index.js +1 -1
  194. package/dist/plugin/utils/moduleBaseURL.d.ts +3 -0
  195. package/dist/plugin/utils/moduleBaseURL.d.ts.map +1 -0
  196. package/dist/plugin/utils/moduleBaseURL.js +4 -0
  197. package/dist/plugin/utils/urls.d.ts +130 -0
  198. package/dist/plugin/utils/urls.d.ts.map +1 -0
  199. package/dist/plugin/utils/urls.js +87 -0
  200. package/dist/plugin/utils/urls.js.map +1 -0
  201. package/dist/plugin/utils.js +1 -1
  202. package/dist/plugin/vendor/index.d.ts +2 -0
  203. package/dist/plugin/vendor/index.d.ts.map +1 -0
  204. package/dist/plugin/vendor/index.js +1 -0
  205. package/dist/plugin/vendor/vendor.client.d.ts.map +1 -0
  206. package/dist/plugin/vendor/vendor.client.js.map +1 -0
  207. package/dist/plugin/vendor/vendor.d.ts +2 -0
  208. package/dist/plugin/vendor/vendor.d.ts.map +1 -0
  209. package/dist/plugin/vendor/vendor.js +15 -0
  210. package/dist/plugin/vendor/vendor.js.map +1 -0
  211. package/dist/plugin/vendor/vendor.server.d.ts.map +1 -0
  212. package/dist/plugin/vendor/vendor.server.js.map +1 -0
  213. package/dist/plugin/vendor.js +7 -0
  214. package/dist/plugin/vendor.js.map +1 -0
  215. package/dist/plugin/worker/createWorker.d.ts +3 -0
  216. package/dist/plugin/worker/createWorker.d.ts.map +1 -1
  217. package/dist/plugin/worker/createWorker.js +33 -20
  218. package/dist/plugin/worker/createWorker.js.map +1 -1
  219. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +1 -1
  220. package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
  221. package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
  222. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  223. package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
  224. package/dist/plugin/worker/rsc/handleRender.js +4 -4
  225. package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
  226. package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -1
  227. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  228. package/dist/plugin/worker/rsc/messageHandler.js +41 -15
  229. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  230. package/dist/plugin/worker/rsc/rsc-worker.development.js +16 -5
  231. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  232. package/dist/plugin/worker/rsc/rsc-worker.production.js +16 -5
  233. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
  234. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  235. package/dist/plugin/worker/sendMessage.js +45 -43
  236. package/dist/plugin/worker/sendMessage.js.map +1 -0
  237. package/dist/plugin/worker/types.d.ts +26 -4
  238. package/dist/plugin/worker/types.d.ts.map +1 -1
  239. package/dist/server.js +1 -1
  240. package/dist/server.js.map +1 -1
  241. package/dist/tsconfig.tsbuildinfo +1 -1
  242. package/package.json +34 -14
  243. package/plugin/{css-collector-elements.tsx → components/css-collector-elements.tsx} +1 -1
  244. package/plugin/{css-collector.tsx → components/css-collector.tsx} +1 -1
  245. package/plugin/{html.tsx → components/html.tsx} +1 -3
  246. package/{dist/plugin/components.d.ts → plugin/components/index.ts} +1 -1
  247. package/plugin/config/autoDiscover/index.ts +10 -0
  248. package/plugin/config/{resolveAutoDiscover.ts → autoDiscover/resolveAutoDiscover.ts} +16 -12
  249. package/plugin/config/autoDiscover/resolveBuildPages.ts +10 -11
  250. package/plugin/config/defaults.tsx +4 -3
  251. package/plugin/config/index.ts +1 -1
  252. package/plugin/config/resolveEnv.ts +156 -6
  253. package/plugin/config/resolveOptions.ts +13 -5
  254. package/plugin/config/resolveUrlOption.ts +2 -7
  255. package/plugin/config/resolveUserConfig.ts +87 -36
  256. package/plugin/env/index.ts +1 -0
  257. package/plugin/env/plugin.ts +78 -0
  258. package/plugin/error/toError.ts +19 -0
  259. package/plugin/file-preserver/plugin.ts +117 -0
  260. package/plugin/helpers/createRscStream.tsx +1 -1
  261. package/plugin/helpers/formatMetrics.ts +2 -2
  262. package/plugin/helpers/getRouteFiles.ts +3 -1
  263. package/plugin/helpers/index.ts +38 -0
  264. package/plugin/helpers/requestInfo.ts +10 -0
  265. package/plugin/{resolvePage.ts → helpers/resolvePage.ts} +19 -4
  266. package/plugin/helpers/resolvePageAndProps.ts +7 -4
  267. package/plugin/{resolveProps.ts → helpers/resolveProps.ts} +8 -6
  268. package/plugin/helpers/serializeUserOptions.ts +1 -1
  269. package/plugin/helpers/tryManifest.ts +0 -1
  270. package/plugin/loader/createBuildLoader.ts +1 -1
  271. package/plugin/loader/env-loader.development.ts +84 -0
  272. package/plugin/plugin.client.ts +2 -0
  273. package/plugin/plugin.server.ts +3 -0
  274. package/plugin/plugin.ts +1 -3
  275. package/plugin/process-env.ts +13 -0
  276. package/plugin/react-client/createMessageHandlers.ts +13 -1
  277. package/plugin/react-client/createWorkerStream.ts +69 -15
  278. package/plugin/react-client/handleWorkerRscStream.ts +57 -0
  279. package/plugin/react-client/plugin.ts +29 -13
  280. package/plugin/react-client/restartWorker.ts +15 -7
  281. package/plugin/react-client/server.ts +115 -124
  282. package/plugin/react-server/plugin.ts +26 -13
  283. package/plugin/react-server/server.ts +33 -15
  284. package/plugin/react-static/collectHtmlWorkerContent.ts +13 -1
  285. package/plugin/react-static/fileWriter.ts +1 -1
  286. package/plugin/react-static/plugin.ts +21 -34
  287. package/plugin/root.ts +7 -1
  288. package/plugin/transformer/upgradeCssModuleCode.ts +39 -39
  289. package/plugin/types/env.d.ts +7 -0
  290. package/plugin/types.ts +68 -20
  291. package/plugin/utils/callServer.ts +2 -24
  292. package/plugin/utils/createCallServer.ts +26 -0
  293. package/plugin/utils/createReactFetcher.ts +10 -6
  294. package/plugin/utils/envUrls.node.ts +19 -0
  295. package/plugin/utils/envUrls.ts +8 -0
  296. package/plugin/utils/index.ts +1 -1
  297. package/plugin/utils/moduleBaseURL.ts +7 -0
  298. package/plugin/utils/urls.ts +217 -0
  299. package/plugin/vendor/index.ts +1 -0
  300. package/plugin/vendor/vendor.ts +6 -0
  301. package/plugin/worker/createWorker.ts +38 -22
  302. package/plugin/worker/html/createHtmlWorkerRenderState.tsx +1 -1
  303. package/plugin/worker/html/html-worker.development.tsx +2 -1
  304. package/plugin/worker/html/html-worker.production.tsx +2 -1
  305. package/plugin/worker/rsc/handleRender.ts +4 -5
  306. package/plugin/worker/rsc/messageHandler.tsx +53 -17
  307. package/plugin/worker/rsc/rsc-worker.development.ts +22 -8
  308. package/plugin/worker/rsc/rsc-worker.production.ts +23 -7
  309. package/plugin/worker/types.ts +28 -4
  310. package/dist/plugin/components.d.ts.map +0 -1
  311. package/dist/plugin/config/resolveAutoDiscover.d.ts.map +0 -1
  312. package/dist/plugin/config/resolveAutoDiscover.js.map +0 -1
  313. package/dist/plugin/copy.d.ts +0 -7
  314. package/dist/plugin/copy.d.ts.map +0 -1
  315. package/dist/plugin/copy.js +0 -30
  316. package/dist/plugin/css-collector-elements.d.ts.map +0 -1
  317. package/dist/plugin/css-collector-elements.js.map +0 -1
  318. package/dist/plugin/css-collector.d.ts.map +0 -1
  319. package/dist/plugin/css-collector.js.map +0 -1
  320. package/dist/plugin/getCondition.d.ts +0 -2
  321. package/dist/plugin/getCondition.d.ts.map +0 -1
  322. package/dist/plugin/html.d.ts +0 -4
  323. package/dist/plugin/html.d.ts.map +0 -1
  324. package/dist/plugin/html.js +0 -18
  325. package/dist/plugin/html.js.map +0 -1
  326. package/dist/plugin/manifest.d.ts +0 -6
  327. package/dist/plugin/manifest.d.ts.map +0 -1
  328. package/dist/plugin/manifest.js +0 -13
  329. package/dist/plugin/moduleRefs.d.ts.map +0 -1
  330. package/dist/plugin/moduleRefs.js.map +0 -1
  331. package/dist/plugin/resolvePage.d.ts.map +0 -1
  332. package/dist/plugin/resolvePage.js.map +0 -1
  333. package/dist/plugin/resolveProps.d.ts.map +0 -1
  334. package/dist/plugin/resolveProps.js.map +0 -1
  335. package/dist/plugin/utils/pageURL.d.ts +0 -5
  336. package/dist/plugin/utils/pageURL.d.ts.map +0 -1
  337. package/dist/plugin/utils/pageURL.js +0 -33
  338. package/dist/plugin/utils/pageURL.js.map +0 -1
  339. package/dist/plugin/vendor.client.d.ts.map +0 -1
  340. package/dist/plugin/vendor.client.js.map +0 -1
  341. package/dist/plugin/vendor.server.d.ts.map +0 -1
  342. package/dist/plugin/vendor.server.js.map +0 -1
  343. package/plugin/copy.ts +0 -39
  344. package/plugin/getCondition.ts +0 -0
  345. package/plugin/manifest.ts +0 -24
  346. package/plugin/utils/pageURL.ts +0 -33
  347. /package/dist/plugin/{css-collector-elements.js → components/css-collector-elements.js} +0 -0
  348. /package/dist/plugin/{css-collector.js → components/css-collector.js} +0 -0
  349. /package/{plugin/components.ts → dist/plugin/components/index.js} +0 -0
  350. /package/dist/plugin/{moduleRefs.d.ts → helpers/moduleRefs.d.ts} +0 -0
  351. /package/dist/plugin/{moduleRefs.js → helpers/moduleRefs.js} +0 -0
  352. /package/dist/plugin/{resolvePage.d.ts → helpers/resolvePage.d.ts} +0 -0
  353. /package/dist/plugin/{resolveProps.d.ts → helpers/resolveProps.d.ts} +0 -0
  354. /package/dist/plugin/{getCondition.js → process-env.js} +0 -0
  355. /package/dist/plugin/{vendor.client.d.ts → vendor/vendor.client.d.ts} +0 -0
  356. /package/dist/plugin/{vendor.client.js → vendor/vendor.client.js} +0 -0
  357. /package/dist/plugin/{vendor.server.d.ts → vendor/vendor.server.d.ts} +0 -0
  358. /package/dist/plugin/{vendor.server.js → vendor/vendor.server.js} +0 -0
  359. /package/plugin/{moduleRefs.ts → helpers/moduleRefs.ts} +0 -0
  360. /package/plugin/{vendor.client.ts → vendor/vendor.client.ts} +0 -0
  361. /package/plugin/{vendor.server.ts → vendor/vendor.server.ts} +0 -0
@@ -0,0 +1,26 @@
1
+ import {
2
+ createFromFetch,
3
+ encodeReply,
4
+ // @ts-ignore
5
+ } from "react-server-dom-esm/client.browser";
6
+
7
+ type ServerResponse = { returnValue: unknown };
8
+
9
+ export const createCallServer = (moduleBaseURL: string) => {
10
+ const callServer = async (_id: string, args: unknown[]): Promise<unknown> => {
11
+ const response = await createFromFetch(
12
+ fetch(moduleBaseURL, {
13
+ method: "POST",
14
+ body: await encodeReply(args),
15
+ headers: {
16
+ Accept: "application/json",
17
+ "Content-Type": "application/json",
18
+ },
19
+ }),
20
+ { callServer, moduleBaseURL }
21
+ );
22
+ const returnValue = (response as ServerResponse).returnValue;
23
+ return returnValue;
24
+ };
25
+ return callServer;
26
+ };
@@ -1,29 +1,33 @@
1
1
  import type { ReactNode } from "react";
2
2
  // @ts-ignore
3
3
  import { createFromFetch } from "react-server-dom-esm/client.browser";
4
- import { callServer } from "./callServer.js";
5
- import { pageURL } from "./pageURL.js";
4
+ import { createCallServer } from "./createCallServer.js";
6
5
  import { env } from "./env.js";
6
+ import { createPageURL } from "./urls.js";
7
7
 
8
8
  export function createReactFetcher({
9
9
  moduleBaseURL = env.BASE_URL,
10
- url,
10
+ publicOrigin = env.PUBLIC_ORIGIN,
11
+ url = window.location.pathname,
12
+ indexRSC = "index.rsc",
11
13
  headers = {
12
14
  Accept: "text/x-component",
13
15
  },
14
16
  }: {
15
17
  url?: string;
16
18
  moduleBaseURL?: string;
19
+ publicOrigin?: string;
20
+ indexRSC?: string;
17
21
  headers?: HeadersInit;
18
22
  } = {}): Promise<ReactNode> {
19
- const parsedURL = pageURL(moduleBaseURL, url);
23
+ const parsedURL = createPageURL(moduleBaseURL, publicOrigin, env.DEV)(url, indexRSC);
20
24
  return createFromFetch(
21
25
  fetch(parsedURL.indexRSC, {
22
26
  headers: headers,
23
27
  }),
24
28
  {
25
- callServer: callServer,
29
+ callServer: createCallServer(parsedURL.moduleBaseURL),
26
30
  moduleBaseURL: parsedURL.moduleBaseURL,
27
31
  }
28
- ) as Promise<ReactNode>;
32
+ );
29
33
  }
@@ -0,0 +1,19 @@
1
+ import { createAbsoluteURL, createBaseURL, createPageURL } from "./urls.js";
2
+
3
+ export const absoluteURL = (path: string) =>
4
+ createAbsoluteURL(
5
+ process.env.VITE_BASE_URL ?? "/",
6
+ process.env.VITE_PUBLIC_ORIGIN ?? ""
7
+ )(path);
8
+
9
+ export const baseURL = (path: string) =>
10
+ createBaseURL(process.env.VITE_BASE_URL ?? "/")(path);
11
+
12
+ export const pageURL = (path: string) =>
13
+ createPageURL(
14
+ process.env.VITE_BASE_URL ?? "/",
15
+ process.env.VITE_PUBLIC_ORIGIN ?? "",
16
+ typeof process.env.VITE_DEV === "string"
17
+ ? process.env.VITE_DEV === "true" || process.env.VITE_DEV === "1"
18
+ : process.env["NODE_ENV"] === "development"
19
+ )(path);
@@ -0,0 +1,8 @@
1
+ import { env } from "./env.js";
2
+ import { createAbsoluteURL, createBaseURL, createPageURL } from "./urls.js";
3
+
4
+ export const absoluteURL = createAbsoluteURL(env.BASE_URL, env.PUBLIC_ORIGIN);
5
+ export const baseURL = createBaseURL(env.BASE_URL);
6
+ export const pageURL = createPageURL(env.BASE_URL, env.PUBLIC_ORIGIN, env.DEV);
7
+ export const { indexRSC: rootIndexRSC, moduleBaseURL } = pageURL("/");
8
+ export const { BASE_URL, PUBLIC_ORIGIN } = env;
@@ -1,4 +1,4 @@
1
1
  export * from "./createReactFetcher.js";
2
2
  export * from "./callServer.js";
3
- export * from "./pageURL.js";
3
+ export * from "./urls.js";
4
4
  export * from "./env.js";
@@ -0,0 +1,7 @@
1
+ import { env } from "./env.js";
2
+
3
+ const { BASE_URL: baseURL, PUBLIC_ORIGIN: publicOrigin } = env;
4
+
5
+ const moduleBaseURL: string = `${publicOrigin}${baseURL}`;
6
+
7
+ export { moduleBaseURL };
@@ -0,0 +1,217 @@
1
+
2
+ /**
3
+ * # createAbsoluteUrl
4
+ *
5
+ * This function takes a baseURL and a public origin and returns a function that takes a path and returns the path with the baseURL attached to it.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const absoluteURL = createAbsoluteURL("/mmc", "https://bidoof.com")
10
+ * console.log(absoluteURL("/test")) // "https://bidoof.com/mmc/test"
11
+ * ```
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const absoluteURL = createAbsoluteURL("/mmc", "https://bidoof.com")
16
+ * console.log(absoluteURL("/test")) // "https://bidoof.com/mmc/test"
17
+ * ```
18
+ *
19
+ * This can replace code like `${process.env.VITE_PUBLIC_ORIGIN}/test` with `absoluteUrl('/test')`, and you can be sure that it will work after
20
+ * changing the plugin settings.
21
+ */
22
+ export const createAbsoluteURL = (
23
+ withBaseURL: string,
24
+ withPublicOrigin: string
25
+ ) => {
26
+ const baseURL = createBaseURL(withBaseURL);
27
+ if (withPublicOrigin === "" || typeof withPublicOrigin !== "string")
28
+ return baseURL;
29
+ return (path: string) => {
30
+ const pathWithBaseURL = baseURL(path);
31
+ try {
32
+ return new URL(pathWithBaseURL, withPublicOrigin).toString();
33
+ } catch (error) {
34
+ return withPublicOrigin + pathWithBaseURL;
35
+ }
36
+ };
37
+ };
38
+
39
+ /**
40
+ * # createBaseURL
41
+ *
42
+ * This function takes a baseURL and returns a function that takes a path and returns the path with the baseURL attached to it.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const baseURL = createBaseURL("/mmc")
47
+ * console.log(baseURL("/test")) // "/mmc/test"
48
+ * ```
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const baseURL = createBaseURL("/mmc/")
53
+ * console.log(baseURL("/test")) // "/mmc/test"
54
+ * ```
55
+ *
56
+ * This can replace code like `${import.meta.env.test` with `baseURL(path)`, and you can be sure that it will work after
57
+ * changing the plugin settings.
58
+ *
59
+ * Path handling logic:
60
+ * 1. For baseURL ending with "/":
61
+ * - If path starts with "/", slice off the leading slash to avoid double slashes
62
+ * - If path doesn't start with "/", keep it as is
63
+ *
64
+ * 2. For baseURL not ending with "/":
65
+ * - If path starts with "/", directly concatenate with baseURL
66
+ * - If path doesn't start with "/", add a slash between baseURL and path
67
+ *
68
+ * baseURL "src" + path "src/test" -> should not concatenate to src/src/test
69
+ * baseURL "/" + path "https://bidoof.com" -> should not concatenate to /https://bidoof.com"
70
+ */
71
+ export const createBaseURL = (withBaseURL: string) => {
72
+ if (withBaseURL.endsWith("/")) {
73
+ return (path: string) => {
74
+ if (path === "") return withBaseURL;
75
+ if (path.startsWith(withBaseURL) || isAbsoluteURL(path)) return path;
76
+ return `${withBaseURL}${removeLeadingSlash(path)}`;
77
+ };
78
+ } else {
79
+ return (path: string) => {
80
+ if (path === "") return withBaseURL;
81
+ if (isAbsoluteURL(path)) return path;
82
+ if (path.startsWith("/")) return withBaseURL + path;
83
+ if (path.startsWith(withBaseURL)) return path;
84
+ return `${withBaseURL}/${path}`;
85
+ };
86
+ }
87
+ };
88
+
89
+ /** Remove a single trailing slash from the URL if it ends with one */
90
+ export const removeTrailingSlash = (url: string) =>
91
+ url.endsWith("/") ? url.slice(0, -1) : url;
92
+
93
+ /** Add a single trailing slash to the URL if it doesn't end with one */
94
+ export const addTrailingSlash = (url: string) =>
95
+ url.endsWith("/") ? url : `${url}/`;
96
+
97
+ export const removeLeadingSlash = (url: string) =>
98
+ url.startsWith("/") ? url.slice(1) : url;
99
+
100
+ export const addLeadingSlash = (url: string) =>
101
+ url.startsWith("/") ? url : `/${url}`;
102
+
103
+ export const isBlankRegex = /^(?:[a-zA-Z][a-zA-Z0-9+.-]*:)?\/\//;
104
+ export const isAbsoluteURL = (url: string) =>
105
+ isBlankRegex.test(url) || url.startsWith("//");
106
+
107
+
108
+ export const folderName = (path: string, withBaseURL: string) => {
109
+ const baseURL = createBaseURL(withBaseURL);
110
+ return baseURL(path.replace(/\[index.(html?|rsc|HTML?)]$/, ""));
111
+ }
112
+
113
+ /**
114
+ * # createPageURL
115
+ *
116
+ * This function takes a baseURL, public origin and a optional normalizer function that mirrors the baseURL's format.
117
+ * If baseURL ends with a slash, we continue it using the URL itself (must end with a slash)
118
+ *
119
+ * - `indexRSC`: The path to the index.rsc file
120
+ * - `moduleBaseURL`: The baseURL to use for the module
121
+ *
122
+ * These can be passed in directly to the createReactFetcher and also determine the defaults when no input are provided.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * import { createFromFetch } from "react-server-dom-esm/client.browser";
127
+ * const parsedURL = pageURL(window.location.pathname ?? "/");
128
+ * const data = createFromFetch(
129
+ * fetch(parsedURL.indexRSC, {
130
+ * headers: {
131
+ * Accept: "text/x-component",
132
+ * }
133
+ * }),
134
+ * {
135
+ * callServer: callServer,
136
+ * moduleBaseURL: parsedURL.moduleBaseURL,
137
+ * }
138
+ * );
139
+ * ```
140
+ *
141
+ * The moduleBasePath being set at the config level as "/",
142
+ * then we pass it to create a stream `renderToPipeableStream(elements, moduleBasePath)`, and we see
143
+ * ```text
144
+ * 2:I["src/components/Clickable.client-Dx9diOqr.js","ClientClickable"]
145
+ * ```
146
+ *
147
+ */
148
+ export const createPageURL = (
149
+ withBaseURL: string,
150
+ withPublicOrigin: string,
151
+ isDev = false,
152
+ normalizer = !withBaseURL.endsWith("/")
153
+ ? removeTrailingSlash
154
+ : addTrailingSlash,
155
+ ) => {
156
+ return (to: string, fileName: string = "index.rsc") => {
157
+ try {
158
+ // Create the base URL first
159
+ const folderName = addTrailingSlash(
160
+ to.replace(/\[index.(html?|rsc|HTML?)]$/, "")
161
+ );
162
+ const baseURL = createBaseURL(withBaseURL);
163
+ const rscPath = baseURL(folderName) + fileName;
164
+ // Create moduleBaseURL and normalize it to match input format
165
+ const moduleBaseURL = parseURL(withBaseURL, withPublicOrigin);
166
+ if (moduleBaseURL.type === "error") {
167
+ throw moduleBaseURL.error;
168
+ }
169
+ const indexRSC = parseURL(rscPath, withPublicOrigin);
170
+ if (indexRSC.type === "error") {
171
+ throw indexRSC.error;
172
+ }
173
+ return {
174
+ indexRSC: indexRSC.url.toString(),
175
+ moduleBaseURL: normalizer(moduleBaseURL.url.toString()),
176
+ };
177
+ } catch (error) {
178
+ if (isDev) console.error("Error parsing pageURL", error);
179
+ return {
180
+ indexRSC: withBaseURL + "index.rsc",
181
+ moduleBaseURL: withBaseURL,
182
+ };
183
+ }
184
+ };
185
+ };
186
+
187
+ /**
188
+ * # moduleBaseURL
189
+ *
190
+ * This function takes a baseURL, public origin and a optional normalizer function that mirrors the baseURL's format.
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * const moduleBaseURL = parseURL("/mmc", "https://bidoof.com")
195
+ * if(moduleBaseURL.type === "error") {
196
+ * console.error(moduleBaseURL.error)
197
+ * } else {
198
+ * console.log(moduleBaseURL.url)
199
+ * }
200
+ * ```
201
+ *
202
+ **/
203
+ export const parseURL = (
204
+ url: string,
205
+ base: string
206
+ ):
207
+ | { type: "success"; url: URL; error?: never; base?: never }
208
+ | { type: "error"; url: string; base: string; error: Error } => {
209
+ try {
210
+ return {
211
+ type: "success",
212
+ url: new URL(url, base),
213
+ };
214
+ } catch (error) {
215
+ return { type: "error", url: url, base: base, error: error as Error };
216
+ }
217
+ };
@@ -0,0 +1 @@
1
+ export * from './vendor.js';
@@ -0,0 +1,6 @@
1
+ import { getCondition } from '../config/getCondition.js';
2
+
3
+ export const {
4
+ React,
5
+ ReactDOMServer,
6
+ } = await import(`./vendor.${getCondition('')}.js`);
@@ -9,6 +9,9 @@ import { join } from "node:path";
9
9
  import { pluginRoot } from "../root.js";
10
10
  import * as React from "react";
11
11
  import { DEFAULT_CONFIG } from "../config/defaults.js";
12
+ import { createLogger, type Logger } from "vite";
13
+ import type { HtmlWorkerOutputMessage } from "./types.js";
14
+ import type { RscWorkerOutputMessage } from "./types.js";
12
15
 
13
16
  export type CreateWorkerOptions = {
14
17
  projectRoot?: string;
@@ -25,6 +28,8 @@ export type CreateWorkerOptions = {
25
28
  htmlChunkSize?: number; // Size of HTML chunks in bytes
26
29
  workerData?: any;
27
30
  transferList?: TransferListItem[];
31
+ logger?: Logger;
32
+ verbose?: boolean;
28
33
  };
29
34
 
30
35
  type CreateWorkerSuccess = {
@@ -65,6 +70,8 @@ export async function createWorker(
65
70
  },
66
71
  htmlChunkSize = 8 * 1024,
67
72
  transferList = [],
73
+ logger = createLogger(),
74
+ verbose = false,
68
75
  } = options;
69
76
  let workerPathWithDefault =
70
77
  typeof workerPath === "string" ? workerPath : undefined;
@@ -96,7 +103,8 @@ export async function createWorker(
96
103
  [envPrefix + "PROD"]: mode === "production" ? "1" : "0",
97
104
  [envPrefix + "SSR"]: "true",
98
105
  [envPrefix + "BASE_URL"]: options.workerData.userOptions.moduleBaseURL,
99
- [envPrefix + "PUBLIC_ORIGIN"]: options.workerData.userOptions.publicOrigin,
106
+ [envPrefix + "PUBLIC_ORIGIN"]:
107
+ options.workerData.userOptions.publicOrigin,
100
108
  NODE_ENV: nodeEnv,
101
109
  NODE_PATH: nodePath,
102
110
  NODE_OPTIONS: process.env["NODE_OPTIONS"]?.includes(reverseCondition)
@@ -128,11 +136,35 @@ export async function createWorker(
128
136
  const timeout = setTimeout(() => {
129
137
  reject({ type: "error", error: new Error("Worker ready timeout") });
130
138
  }, 5000);
131
-
132
- worker.once("message", (msg) => {
139
+ const exitHandler = (code: number) => {
140
+ clearTimeout(timeout);
141
+ worker.removeListener("message", messageHandler);
142
+ worker.removeListener("exit", exitHandler);
143
+ if (code === 0) {
144
+ resolve({
145
+ type: "skip",
146
+ reason: "Worker exited with code 0",
147
+ workerPath: workerPathWithDefault,
148
+ } satisfies CreateWorkerSkip);
149
+ } else {
150
+ const error = new Error(`Worker exited with code ${code}`);
151
+ logger.error(`worker exited with code ${code}`, { error });
152
+ reject({
153
+ type: "error",
154
+ error,
155
+ workerPath: workerPathWithDefault,
156
+ } satisfies CreateWorkerError);
157
+ }
158
+ };
159
+ const messageHandler = (msg: HtmlWorkerOutputMessage | RscWorkerOutputMessage) => {
160
+ if (verbose) logger.info(`Initial worker message ${msg.type}`);
133
161
  if (msg.type === "READY") {
162
+ if (verbose) logger.info(`Worker running for ${msg.env}`);
134
163
  clearTimeout(timeout);
164
+ worker.removeListener("message", messageHandler);
165
+ worker.removeListener("exit", exitHandler);
135
166
  if (msg.env !== nodeEnv) {
167
+ if (verbose) logger.info(`Worker environment mismatch.`);
136
168
  reject({
137
169
  type: "error",
138
170
  error: new Error(
@@ -147,25 +179,9 @@ export async function createWorker(
147
179
  workerPath: workerPathWithDefault,
148
180
  } satisfies CreateWorkerSuccess);
149
181
  }
150
- });
151
-
152
- worker.once("exit", (code) => {
153
- clearTimeout(timeout);
154
- worker.removeAllListeners();
155
- if (code === 0) {
156
- resolve({
157
- type: "skip",
158
- reason: "Worker exited with code 0",
159
- workerPath: workerPathWithDefault,
160
- } satisfies CreateWorkerSkip);
161
- } else {
162
- reject({
163
- type: "error",
164
- error: new Error(`Worker exited with code ${code}`),
165
- workerPath: workerPathWithDefault,
166
- } satisfies CreateWorkerError);
167
- }
168
- });
182
+ }
183
+ worker.once("message", messageHandler);
184
+ worker.once("exit", exitHandler);
169
185
  }
170
186
  );
171
187
  } catch (error) {
@@ -8,7 +8,7 @@ import { Transform } from "node:stream";
8
8
  import type { HtmlWorkerOutputMessage } from "../types.js";
9
9
  import { join } from "node:path";
10
10
  import type { StreamMetrics } from "../../types.js";
11
- import { ReactDOMServer } from "../../vendor.client.js";
11
+ import { ReactDOMServer } from "../../vendor/vendor.client.js";
12
12
 
13
13
 
14
14
  const createMetrics = (): StreamMetrics => {
@@ -3,6 +3,7 @@ import { messageHandler } from "./messageHandler.js";
3
3
  import { MessageChannel, parentPort } from "node:worker_threads";
4
4
  import { pluginRoot } from "../../root.js";
5
5
  import { register } from "node:module";
6
+ import type { ReadyMessage } from "../types.js";
6
7
 
7
8
  // Create channels for each loader
8
9
  const cssLoaderChannel = new MessageChannel();
@@ -22,4 +23,4 @@ parentPort?.postMessage({
22
23
  type: "READY",
23
24
  env: process.env["NODE_ENV"],
24
25
  pid: process.pid,
25
- });
26
+ } satisfies ReadyMessage);
@@ -3,6 +3,7 @@ import { messageHandler } from "./messageHandler.js";
3
3
  import { MessageChannel, parentPort } from "node:worker_threads";
4
4
  import { pluginRoot } from "../../root.js";
5
5
  import { register } from "node:module";
6
+ import type { ReadyMessage } from "../types.js";
6
7
 
7
8
  // Create channels for each loader
8
9
  const cssLoaderChannel = new MessageChannel();
@@ -24,4 +25,4 @@ parentPort?.postMessage({
24
25
  type: "READY",
25
26
  env: process.env["NODE_ENV"],
26
27
  pid: process.pid,
27
- });
28
+ } satisfies ReadyMessage);
@@ -2,11 +2,11 @@ import { resolvePageAndProps } from "../../helpers/resolvePageAndProps.js";
2
2
  import type { RscRenderMessage, StreamHandlers } from "../types.js";
3
3
  import { activeStreams, cssFiles } from "./state.js";
4
4
  import { createRscStream } from "../../helpers/createRscStream.js";
5
- import { CssCollector } from "../../css-collector.js";
5
+ import { CssCollector } from "../../components/css-collector.js";
6
6
  import { PassThrough } from "node:stream";
7
7
  import { join } from "node:path";
8
8
  import { workerData } from "node:worker_threads";
9
- import { React } from "../../vendor.server.js";
9
+ import { React } from "../../vendor/vendor.server.js";
10
10
  import { hmrState } from "./state.js";
11
11
  import { performance } from "node:perf_hooks";
12
12
 
@@ -23,14 +23,13 @@ export async function handleRender(
23
23
  propsExportName = workerData.userOptions.propsExportName,
24
24
  projectRoot = workerData.userOptions.projectRoot,
25
25
  moduleRootPath = workerData.userOptions.moduleRootPath,
26
- moduleBaseURL = workerData.userOptions.moduleBaseURL,
27
- moduleBasePath = workerData.userOptions.moduleBasePath,
26
+ moduleBaseURL = workerData.userOptions.moduleBaseURL ?? "/",
27
+ moduleBasePath = workerData.userOptions.moduleBasePath ?? "/",
28
28
  moduleBase = workerData.userOptions.moduleBase,
29
29
  pipeableStreamOptions = workerData.userOptions.pipeableStreamOptions,
30
30
  cssFiles: messageCssFiles,
31
31
  globalCss = workerData.globalCss,
32
32
  } = msg;
33
-
34
33
  try {
35
34
  // Load modules
36
35
  const pageAndPropsResult = await resolvePageAndProps({
@@ -1,9 +1,18 @@
1
1
  import { parentPort, workerData } from "node:worker_threads";
2
- import { addCssFileContent, hmrState } from "./state.js";
2
+ import { activeStreams, addCssFileContent, hmrState } from "./state.js";
3
3
  import { handleRender } from "./handleRender.js";
4
- import type { RscWorkerOutputMessage, StreamHandlers } from "../types.js";
4
+ import type {
5
+ HmrAcceptMessage,
6
+ RscWorkerInputMessage,
7
+ RscWorkerOutputMessage,
8
+ StreamHandlers,
9
+ } from "../types.js";
10
+ import { sendMessage } from "../sendMessage.js";
5
11
 
6
- export async function messageHandler(msg: any, port = parentPort) {
12
+ export async function messageHandler(
13
+ msg: RscWorkerInputMessage,
14
+ port = parentPort
15
+ ) {
7
16
  if (!port) {
8
17
  throw new Error("No port found");
9
18
  }
@@ -48,6 +57,20 @@ export async function messageHandler(msg: any, port = parentPort) {
48
57
  metrics,
49
58
  } satisfies RscWorkerOutputMessage);
50
59
  },
60
+ onHmrAccept: (routes: string[]) => {
61
+ port.postMessage({
62
+ type: "HMR_ACCEPT",
63
+ id: (msg as HmrAcceptMessage).id,
64
+ routes: routes,
65
+ });
66
+ },
67
+ onHmrUpdate: (routes: string[]) => {
68
+ port.postMessage({
69
+ type: "HMR_UPDATE",
70
+ id: msg.id,
71
+ routes: routes,
72
+ });
73
+ },
51
74
  };
52
75
  switch (msg.type) {
53
76
  case "RSC_RENDER":
@@ -56,28 +79,23 @@ export async function messageHandler(msg: any, port = parentPort) {
56
79
  return;
57
80
  case "INITIALIZED_CSS_LOADER":
58
81
  return;
82
+ case "INITIALIZED_ENV_LOADER":
83
+ return;
59
84
  case "HMR_UPDATE":
60
85
  // Mark the module as invalidated
61
- hmrState.set(msg.path, {
86
+ hmrState.set(msg.id, {
62
87
  timestamp: msg.timestamp || Date.now(),
63
88
  invalidated: true,
64
89
  routes: msg.routes || [],
65
90
  });
66
91
  // Notify the main thread that we've processed the update
67
- port.postMessage({
68
- type: "HMR_ACCEPT",
69
- path: msg.path,
70
- routes: msg.routes,
71
- });
92
+ handlers.onHmrUpdate(msg.routes || []);
72
93
  return;
73
94
  case "HMR_CLEANUP":
74
95
  // Clear the invalidation state
75
- hmrState.delete(msg.path);
96
+ hmrState.delete(msg.id);
76
97
  // Notify the main thread that we've processed the cleanup
77
- port.postMessage({
78
- type: "HMR_ACCEPT",
79
- path: msg.path,
80
- });
98
+ handlers.onHmrAccept(msg.routes || []);
81
99
  return;
82
100
  case "CSS_FILE":
83
101
  if (msg.id) {
@@ -87,13 +105,31 @@ export async function messageHandler(msg: any, port = parentPort) {
87
105
 
88
106
  addCssFileContent(msg.id, msg.content, {
89
107
  projectRoot: workerData.userOptions.projectRoot || process.cwd(),
90
- moduleBaseURL: workerData.userOptions.moduleBaseURL || "",
91
- moduleBasePath: workerData.userOptions.moduleBasePath || "",
92
- moduleRootPath: workerData.userOptions.moduleRootPath || "",
108
+ moduleBaseURL: workerData.userOptions.moduleBaseURL || "/",
109
+ moduleBasePath: workerData.userOptions.moduleBasePath || "/",
110
+ moduleRootPath: workerData.userOptions.moduleRootPath,
93
111
  css: cssOptions,
94
112
  });
95
113
  }
96
114
  return;
115
+ case "SHUTDOWN": {
116
+ // If id is "*", clean up all render states
117
+ if (msg.id === "*") {
118
+ activeStreams.forEach((stream, renderId) => {
119
+ stream.end();
120
+ activeStreams.delete(renderId);
121
+ });
122
+ parentPort?.removeAllListeners();
123
+ } else {
124
+ activeStreams.delete(msg.id);
125
+ }
126
+ // Send SHUTDOWN_COMPLETE message to signal that shutdown is complete
127
+ sendMessage({
128
+ type: "SHUTDOWN_COMPLETE",
129
+ id: msg.id,
130
+ } satisfies RscWorkerOutputMessage);
131
+ return;
132
+ }
97
133
  default: {
98
134
  console.log("Unknown message", msg);
99
135
  return;