one 1.2.20 → 1.2.22-1765155190908

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 (331) hide show
  1. package/dist/cjs/cli/build.cjs +11 -2
  2. package/dist/cjs/cli/build.js +10 -2
  3. package/dist/cjs/cli/build.js.map +1 -1
  4. package/dist/cjs/cli/build.native.js +44 -19
  5. package/dist/cjs/cli/build.native.js.map +1 -1
  6. package/dist/cjs/cli/buildPage.cjs +20 -4
  7. package/dist/cjs/cli/buildPage.js +21 -7
  8. package/dist/cjs/cli/buildPage.js.map +1 -1
  9. package/dist/cjs/cli/buildPage.native.js +38 -6
  10. package/dist/cjs/cli/buildPage.native.js.map +1 -1
  11. package/dist/cjs/createApp.cjs +23 -16
  12. package/dist/cjs/createApp.js +73 -67
  13. package/dist/cjs/createApp.js.map +2 -2
  14. package/dist/cjs/createHandleRequest.cjs +10 -6
  15. package/dist/cjs/createHandleRequest.js +10 -6
  16. package/dist/cjs/createHandleRequest.js.map +1 -1
  17. package/dist/cjs/createHandleRequest.native.js +11 -7
  18. package/dist/cjs/createHandleRequest.native.js.map +1 -1
  19. package/dist/cjs/fork/NavigationContainer.cjs +1 -1
  20. package/dist/cjs/fork/NavigationContainer.js +4 -1
  21. package/dist/cjs/fork/NavigationContainer.js.map +1 -1
  22. package/dist/cjs/fork/NavigationContainer.native.js +1 -1
  23. package/dist/cjs/fork/NavigationContainer.native.js.map +1 -1
  24. package/dist/cjs/fork/createMemoryHistory.cjs +2 -2
  25. package/dist/cjs/fork/createMemoryHistory.js +2 -2
  26. package/dist/cjs/fork/createMemoryHistory.js.map +1 -1
  27. package/dist/cjs/fork/createMemoryHistory.native.js +2 -2
  28. package/dist/cjs/fork/createMemoryHistory.native.js.map +1 -1
  29. package/dist/cjs/fork/extractPathFromURL.cjs +1 -1
  30. package/dist/cjs/fork/extractPathFromURL.js +1 -1
  31. package/dist/cjs/fork/extractPathFromURL.js.map +1 -1
  32. package/dist/cjs/fork/extractPathFromURL.native.js +1 -1
  33. package/dist/cjs/fork/extractPathFromURL.native.js.map +1 -1
  34. package/dist/cjs/fork/getPathFromState-mods.cjs +1 -1
  35. package/dist/cjs/fork/getPathFromState-mods.js +1 -1
  36. package/dist/cjs/fork/getPathFromState-mods.js.map +1 -1
  37. package/dist/cjs/fork/getPathFromState-mods.native.js +1 -1
  38. package/dist/cjs/fork/getPathFromState-mods.native.js.map +1 -1
  39. package/dist/cjs/fork/getStateFromPath-mods.cjs +20 -19
  40. package/dist/cjs/fork/getStateFromPath-mods.js +18 -15
  41. package/dist/cjs/fork/getStateFromPath-mods.js.map +1 -1
  42. package/dist/cjs/fork/getStateFromPath-mods.native.js +19 -18
  43. package/dist/cjs/fork/getStateFromPath-mods.native.js.map +1 -1
  44. package/dist/cjs/fork/getStateFromPath.cjs +1 -1
  45. package/dist/cjs/fork/getStateFromPath.js +1 -1
  46. package/dist/cjs/fork/getStateFromPath.js.map +1 -1
  47. package/dist/cjs/fork/getStateFromPath.native.js +1 -1
  48. package/dist/cjs/fork/getStateFromPath.native.js.map +1 -1
  49. package/dist/cjs/fork/useLinking.cjs +27 -20
  50. package/dist/cjs/fork/useLinking.js +32 -20
  51. package/dist/cjs/fork/useLinking.js.map +2 -2
  52. package/dist/cjs/fork/useLinking.native.js +2 -1
  53. package/dist/cjs/fork/useLinking.native.js.map +1 -1
  54. package/dist/cjs/getReactNavigationConfig.cjs +2 -4
  55. package/dist/cjs/getReactNavigationConfig.js +2 -5
  56. package/dist/cjs/getReactNavigationConfig.js.map +1 -1
  57. package/dist/cjs/getReactNavigationConfig.native.js +2 -4
  58. package/dist/cjs/getReactNavigationConfig.native.js.map +1 -1
  59. package/dist/cjs/hooks.cjs +1 -1
  60. package/dist/cjs/hooks.js +1 -1
  61. package/dist/cjs/hooks.js.map +1 -1
  62. package/dist/cjs/hooks.native.js +4 -1
  63. package/dist/cjs/hooks.native.js.map +1 -1
  64. package/dist/cjs/index.cjs +2 -0
  65. package/dist/cjs/index.js +2 -1
  66. package/dist/cjs/index.js.map +1 -1
  67. package/dist/cjs/index.native.js +2 -0
  68. package/dist/cjs/index.native.js.map +1 -1
  69. package/dist/cjs/router/getRoutes.cjs +4 -5
  70. package/dist/cjs/router/getRoutes.js +2 -2
  71. package/dist/cjs/router/getRoutes.js.map +1 -1
  72. package/dist/cjs/router/getRoutes.native.js +4 -5
  73. package/dist/cjs/router/getRoutes.native.js.map +1 -1
  74. package/dist/cjs/router/matchers.cjs +9 -1
  75. package/dist/cjs/router/matchers.js +4 -1
  76. package/dist/cjs/router/matchers.js.map +1 -1
  77. package/dist/cjs/router/matchers.native.js +10 -2
  78. package/dist/cjs/router/matchers.native.js.map +1 -1
  79. package/dist/cjs/router/matchers.test.cjs +7 -1
  80. package/dist/cjs/router/matchers.test.js +1 -1
  81. package/dist/cjs/router/matchers.test.js.map +1 -1
  82. package/dist/cjs/router/matchers.test.native.js +7 -1
  83. package/dist/cjs/router/matchers.test.native.js.map +1 -1
  84. package/dist/cjs/router/router.cjs +20 -17
  85. package/dist/cjs/router/router.js +24 -21
  86. package/dist/cjs/router/router.js.map +1 -1
  87. package/dist/cjs/router/router.native.js +21 -18
  88. package/dist/cjs/router/router.native.js.map +1 -1
  89. package/dist/cjs/router/useViteRoutes.cjs +57 -17
  90. package/dist/cjs/router/useViteRoutes.js +55 -17
  91. package/dist/cjs/router/useViteRoutes.js.map +2 -2
  92. package/dist/cjs/router/useViteRoutes.native.js +76 -0
  93. package/dist/cjs/router/useViteRoutes.native.js.map +1 -1
  94. package/dist/cjs/router/utils/getNavigateAction.cjs +2 -2
  95. package/dist/cjs/router/utils/getNavigateAction.js +2 -2
  96. package/dist/cjs/router/utils/getNavigateAction.js.map +1 -1
  97. package/dist/cjs/router/utils/getNavigateAction.native.js +2 -2
  98. package/dist/cjs/router/utils/getNavigateAction.native.js.map +1 -1
  99. package/dist/cjs/server/oneServe.cjs +4 -3
  100. package/dist/cjs/server/oneServe.js +6 -3
  101. package/dist/cjs/server/oneServe.js.map +1 -1
  102. package/dist/cjs/server/oneServe.native.js +5 -4
  103. package/dist/cjs/server/oneServe.native.js.map +1 -1
  104. package/dist/cjs/useLoader.cjs +39 -40
  105. package/dist/cjs/useLoader.js +10 -7
  106. package/dist/cjs/useLoader.js.map +1 -1
  107. package/dist/cjs/useLoader.native.js +54 -54
  108. package/dist/cjs/useLoader.native.js.map +1 -1
  109. package/dist/cjs/vite/one.cjs +9 -12
  110. package/dist/cjs/vite/one.js +7 -7
  111. package/dist/cjs/vite/one.js.map +1 -1
  112. package/dist/cjs/vite/one.native.js +10 -15
  113. package/dist/cjs/vite/one.native.js.map +1 -1
  114. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +12 -7
  115. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +11 -7
  116. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
  117. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +12 -7
  118. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
  119. package/dist/cjs/vite/plugins/virtualEntryPlugin.cjs +12 -1
  120. package/dist/cjs/vite/plugins/virtualEntryPlugin.js +12 -1
  121. package/dist/cjs/vite/plugins/virtualEntryPlugin.js.map +1 -1
  122. package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js +12 -1
  123. package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
  124. package/dist/esm/cli/build.js +10 -2
  125. package/dist/esm/cli/build.js.map +1 -1
  126. package/dist/esm/cli/build.mjs +11 -2
  127. package/dist/esm/cli/build.mjs.map +1 -1
  128. package/dist/esm/cli/build.native.js +44 -19
  129. package/dist/esm/cli/build.native.js.map +1 -1
  130. package/dist/esm/cli/buildPage.js +21 -7
  131. package/dist/esm/cli/buildPage.js.map +1 -1
  132. package/dist/esm/cli/buildPage.mjs +20 -4
  133. package/dist/esm/cli/buildPage.mjs.map +1 -1
  134. package/dist/esm/cli/buildPage.native.js +38 -6
  135. package/dist/esm/cli/buildPage.native.js.map +1 -1
  136. package/dist/esm/createApp.js +73 -66
  137. package/dist/esm/createApp.js.map +2 -2
  138. package/dist/esm/createApp.mjs +23 -16
  139. package/dist/esm/createApp.mjs.map +1 -1
  140. package/dist/esm/createHandleRequest.js +10 -6
  141. package/dist/esm/createHandleRequest.js.map +1 -1
  142. package/dist/esm/createHandleRequest.mjs +10 -6
  143. package/dist/esm/createHandleRequest.mjs.map +1 -1
  144. package/dist/esm/createHandleRequest.native.js +10 -6
  145. package/dist/esm/createHandleRequest.native.js.map +1 -1
  146. package/dist/esm/fork/NavigationContainer.js +4 -1
  147. package/dist/esm/fork/NavigationContainer.js.map +1 -1
  148. package/dist/esm/fork/NavigationContainer.mjs +1 -1
  149. package/dist/esm/fork/NavigationContainer.mjs.map +1 -1
  150. package/dist/esm/fork/NavigationContainer.native.js +1 -1
  151. package/dist/esm/fork/NavigationContainer.native.js.map +1 -1
  152. package/dist/esm/fork/createMemoryHistory.js +2 -2
  153. package/dist/esm/fork/createMemoryHistory.js.map +1 -1
  154. package/dist/esm/fork/createMemoryHistory.mjs +2 -2
  155. package/dist/esm/fork/createMemoryHistory.mjs.map +1 -1
  156. package/dist/esm/fork/createMemoryHistory.native.js +2 -2
  157. package/dist/esm/fork/createMemoryHistory.native.js.map +1 -1
  158. package/dist/esm/fork/extractPathFromURL.js +1 -1
  159. package/dist/esm/fork/extractPathFromURL.js.map +1 -1
  160. package/dist/esm/fork/extractPathFromURL.mjs +1 -1
  161. package/dist/esm/fork/extractPathFromURL.mjs.map +1 -1
  162. package/dist/esm/fork/extractPathFromURL.native.js +1 -1
  163. package/dist/esm/fork/extractPathFromURL.native.js.map +1 -1
  164. package/dist/esm/fork/getPathFromState-mods.js +2 -2
  165. package/dist/esm/fork/getPathFromState-mods.js.map +1 -1
  166. package/dist/esm/fork/getPathFromState-mods.mjs +2 -2
  167. package/dist/esm/fork/getPathFromState-mods.mjs.map +1 -1
  168. package/dist/esm/fork/getPathFromState-mods.native.js +2 -2
  169. package/dist/esm/fork/getPathFromState-mods.native.js.map +1 -1
  170. package/dist/esm/fork/getStateFromPath-mods.js +18 -15
  171. package/dist/esm/fork/getStateFromPath-mods.js.map +1 -1
  172. package/dist/esm/fork/getStateFromPath-mods.mjs +20 -19
  173. package/dist/esm/fork/getStateFromPath-mods.mjs.map +1 -1
  174. package/dist/esm/fork/getStateFromPath-mods.native.js +19 -18
  175. package/dist/esm/fork/getStateFromPath-mods.native.js.map +1 -1
  176. package/dist/esm/fork/getStateFromPath.js +1 -1
  177. package/dist/esm/fork/getStateFromPath.js.map +1 -1
  178. package/dist/esm/fork/getStateFromPath.mjs +1 -1
  179. package/dist/esm/fork/getStateFromPath.mjs.map +1 -1
  180. package/dist/esm/fork/getStateFromPath.native.js +1 -1
  181. package/dist/esm/fork/useLinking.js +32 -19
  182. package/dist/esm/fork/useLinking.js.map +1 -1
  183. package/dist/esm/fork/useLinking.mjs +27 -20
  184. package/dist/esm/fork/useLinking.mjs.map +1 -1
  185. package/dist/esm/fork/useLinking.native.js +2 -1
  186. package/dist/esm/fork/useLinking.native.js.map +1 -1
  187. package/dist/esm/getReactNavigationConfig.js +3 -6
  188. package/dist/esm/getReactNavigationConfig.js.map +1 -1
  189. package/dist/esm/getReactNavigationConfig.mjs +3 -5
  190. package/dist/esm/getReactNavigationConfig.mjs.map +1 -1
  191. package/dist/esm/getReactNavigationConfig.native.js +3 -5
  192. package/dist/esm/getReactNavigationConfig.native.js.map +1 -1
  193. package/dist/esm/hooks.js +1 -1
  194. package/dist/esm/hooks.js.map +1 -1
  195. package/dist/esm/hooks.mjs +1 -1
  196. package/dist/esm/hooks.mjs.map +1 -1
  197. package/dist/esm/hooks.native.js +4 -1
  198. package/dist/esm/hooks.native.js.map +1 -1
  199. package/dist/esm/index.js +2 -0
  200. package/dist/esm/index.js.map +1 -1
  201. package/dist/esm/index.mjs +2 -1
  202. package/dist/esm/index.mjs.map +1 -1
  203. package/dist/esm/index.native.js +2 -1
  204. package/dist/esm/index.native.js.map +1 -1
  205. package/dist/esm/router/getRoutes.js +2 -3
  206. package/dist/esm/router/getRoutes.js.map +1 -1
  207. package/dist/esm/router/getRoutes.mjs +5 -6
  208. package/dist/esm/router/getRoutes.mjs.map +1 -1
  209. package/dist/esm/router/getRoutes.native.js +5 -6
  210. package/dist/esm/router/getRoutes.native.js.map +1 -1
  211. package/dist/esm/router/matchers.js +4 -1
  212. package/dist/esm/router/matchers.js.map +1 -1
  213. package/dist/esm/router/matchers.mjs +9 -1
  214. package/dist/esm/router/matchers.mjs.map +1 -1
  215. package/dist/esm/router/matchers.native.js +10 -2
  216. package/dist/esm/router/matchers.native.js.map +1 -1
  217. package/dist/esm/router/matchers.test.js +1 -1
  218. package/dist/esm/router/matchers.test.js.map +1 -1
  219. package/dist/esm/router/matchers.test.mjs +7 -1
  220. package/dist/esm/router/matchers.test.mjs.map +1 -1
  221. package/dist/esm/router/matchers.test.native.js +7 -1
  222. package/dist/esm/router/matchers.test.native.js.map +1 -1
  223. package/dist/esm/router/router.js +24 -20
  224. package/dist/esm/router/router.js.map +1 -1
  225. package/dist/esm/router/router.mjs +20 -18
  226. package/dist/esm/router/router.mjs.map +1 -1
  227. package/dist/esm/router/router.native.js +21 -19
  228. package/dist/esm/router/router.native.js.map +1 -1
  229. package/dist/esm/router/useViteRoutes.js +55 -17
  230. package/dist/esm/router/useViteRoutes.js.map +1 -1
  231. package/dist/esm/router/useViteRoutes.mjs +54 -18
  232. package/dist/esm/router/useViteRoutes.mjs.map +1 -1
  233. package/dist/esm/router/useViteRoutes.native.js +73 -1
  234. package/dist/esm/router/useViteRoutes.native.js.map +1 -1
  235. package/dist/esm/router/utils/getNavigateAction.js +2 -2
  236. package/dist/esm/router/utils/getNavigateAction.js.map +1 -1
  237. package/dist/esm/router/utils/getNavigateAction.mjs +2 -2
  238. package/dist/esm/router/utils/getNavigateAction.mjs.map +1 -1
  239. package/dist/esm/router/utils/getNavigateAction.native.js +2 -2
  240. package/dist/esm/router/utils/getNavigateAction.native.js.map +1 -1
  241. package/dist/esm/server/oneServe.js +6 -3
  242. package/dist/esm/server/oneServe.js.map +1 -1
  243. package/dist/esm/server/oneServe.mjs +4 -3
  244. package/dist/esm/server/oneServe.mjs.map +1 -1
  245. package/dist/esm/server/oneServe.native.js +4 -3
  246. package/dist/esm/server/oneServe.native.js.map +1 -1
  247. package/dist/esm/useLoader.js +10 -8
  248. package/dist/esm/useLoader.js.map +1 -1
  249. package/dist/esm/useLoader.mjs +40 -41
  250. package/dist/esm/useLoader.mjs.map +1 -1
  251. package/dist/esm/useLoader.native.js +55 -55
  252. package/dist/esm/useLoader.native.js.map +1 -1
  253. package/dist/esm/vite/one.js +9 -9
  254. package/dist/esm/vite/one.js.map +1 -1
  255. package/dist/esm/vite/one.mjs +9 -12
  256. package/dist/esm/vite/one.mjs.map +1 -1
  257. package/dist/esm/vite/one.native.js +10 -15
  258. package/dist/esm/vite/one.native.js.map +1 -1
  259. package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +11 -7
  260. package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
  261. package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +12 -7
  262. package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
  263. package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +12 -7
  264. package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
  265. package/dist/esm/vite/plugins/virtualEntryPlugin.js +12 -1
  266. package/dist/esm/vite/plugins/virtualEntryPlugin.js.map +1 -1
  267. package/dist/esm/vite/plugins/virtualEntryPlugin.mjs +12 -1
  268. package/dist/esm/vite/plugins/virtualEntryPlugin.mjs.map +1 -1
  269. package/dist/esm/vite/plugins/virtualEntryPlugin.native.js +12 -1
  270. package/dist/esm/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
  271. package/package.json +10 -10
  272. package/src/cli/build.ts +26 -1
  273. package/src/cli/buildPage.ts +28 -5
  274. package/src/createApp.tsx +29 -21
  275. package/src/createHandleRequest.ts +34 -0
  276. package/src/fork/NavigationContainer.tsx +8 -0
  277. package/src/fork/createMemoryHistory.tsx +8 -0
  278. package/src/fork/extractPathFromURL.ts +6 -0
  279. package/src/fork/getPathFromState-mods.ts +2 -7
  280. package/src/fork/getStateFromPath-mods.ts +43 -17
  281. package/src/fork/getStateFromPath.ts +1 -1
  282. package/src/fork/useLinking.native.ts +1 -1
  283. package/src/fork/useLinking.ts +89 -5
  284. package/src/getReactNavigationConfig.ts +7 -9
  285. package/src/hooks.tsx +21 -19
  286. package/src/index.ts +1 -0
  287. package/src/router/getRoutes.ts +3 -6
  288. package/src/router/matchers.test.ts +2 -2
  289. package/src/router/matchers.ts +22 -6
  290. package/src/router/router.ts +39 -26
  291. package/src/router/useViteRoutes.tsx +127 -17
  292. package/src/router/utils/getNavigateAction.ts +3 -2
  293. package/src/server/oneServe.ts +13 -0
  294. package/src/types.ts +1 -0
  295. package/src/useLoader.ts +20 -12
  296. package/src/vite/one.ts +9 -13
  297. package/src/vite/plugins/fileSystemRouterPlugin.tsx +17 -5
  298. package/src/vite/plugins/virtualEntryPlugin.ts +12 -1
  299. package/src/vite/types.ts +2 -0
  300. package/types/cli/build.d.ts.map +1 -1
  301. package/types/cli/buildPage.d.ts +1 -1
  302. package/types/cli/buildPage.d.ts.map +1 -1
  303. package/types/createApp.d.ts.map +1 -1
  304. package/types/createHandleRequest.d.ts.map +1 -1
  305. package/types/fork/NavigationContainer.d.ts.map +1 -1
  306. package/types/fork/createMemoryHistory.d.ts.map +1 -1
  307. package/types/fork/extractPathFromURL.d.ts.map +1 -1
  308. package/types/fork/getStateFromPath-mods.d.ts +7 -10
  309. package/types/fork/getStateFromPath-mods.d.ts.map +1 -1
  310. package/types/fork/useLinking.d.ts.map +1 -1
  311. package/types/getReactNavigationConfig.d.ts.map +1 -1
  312. package/types/hooks.d.ts.map +1 -1
  313. package/types/index.d.ts +1 -0
  314. package/types/index.d.ts.map +1 -1
  315. package/types/router/getRoutes.d.ts.map +1 -1
  316. package/types/router/matchers.d.ts +10 -3
  317. package/types/router/matchers.d.ts.map +1 -1
  318. package/types/router/router.d.ts +3 -2
  319. package/types/router/router.d.ts.map +1 -1
  320. package/types/router/useViteRoutes.d.ts +11 -0
  321. package/types/router/useViteRoutes.d.ts.map +1 -1
  322. package/types/router/utils/getNavigateAction.d.ts.map +1 -1
  323. package/types/server/oneServe.d.ts.map +1 -1
  324. package/types/types.d.ts +1 -0
  325. package/types/types.d.ts.map +1 -1
  326. package/types/useLoader.d.ts.map +1 -1
  327. package/types/vite/one.d.ts.map +1 -1
  328. package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
  329. package/types/vite/plugins/virtualEntryPlugin.d.ts.map +1 -1
  330. package/types/vite/types.d.ts +1 -0
  331. package/types/vite/types.d.ts.map +1 -1
package/src/hooks.tsx CHANGED
@@ -133,24 +133,26 @@ export function useParams<TParams extends Object = SearchParams>(): Partial<TPar
133
133
  const params = React.useContext(RouteParamsContext) ?? {}
134
134
 
135
135
  return Object.fromEntries(
136
- Object.entries(params).map(([key, value]) => {
137
- if (Array.isArray(value)) {
138
- return [
139
- key,
140
- value.map((v) => {
141
- try {
142
- return decodeURIComponent(v)
143
- } catch {
144
- return v
145
- }
146
- }),
147
- ]
148
- }
149
- try {
150
- return [key, decodeURIComponent(value as string)]
151
- } catch {
152
- return [key, value]
153
- }
154
- })
136
+ Object.entries(params)
137
+ .filter(([_, value]) => value !== undefined)
138
+ .map(([key, value]) => {
139
+ if (Array.isArray(value)) {
140
+ return [
141
+ key,
142
+ value.map((v) => {
143
+ try {
144
+ return decodeURIComponent(v)
145
+ } catch {
146
+ return v
147
+ }
148
+ }),
149
+ ]
150
+ }
151
+ try {
152
+ return [key, decodeURIComponent(value as string)]
153
+ } catch {
154
+ return [key, value]
155
+ }
156
+ })
155
157
  ) as TParams
156
158
  }
package/src/index.ts CHANGED
@@ -66,6 +66,7 @@ export { createRoute, route } from './router/createRoute'
66
66
  export { router } from './router/imperative-api'
67
67
  export * as routerStore from './router/router'
68
68
  export { useNavigation } from './router/useNavigation'
69
+ export { registerPreloadedRoute } from './router/useViteRoutes'
69
70
  export type { Endpoint, LoaderProps } from './types'
70
71
  // React Navigation
71
72
  export { useFocusEffect } from './useFocusEffect'
@@ -3,7 +3,6 @@ import { getPageExport } from '../utils/getPageExport'
3
3
  import type { One } from '../vite/types'
4
4
  import {
5
5
  matchArrayGroupName,
6
- matchDeepDynamicRouteName,
7
6
  matchDynamicName,
8
7
  matchGroupName,
9
8
  removeSupportedExtensions,
@@ -479,11 +478,9 @@ export function generateDynamic(path: string): DynamicConvention[] | null {
479
478
  }
480
479
  }
481
480
 
482
- const deepDynamicName = matchDeepDynamicRouteName(part)
483
- const dynamicName = deepDynamicName ?? matchDynamicName(part)
484
-
485
- if (!dynamicName) return null
486
- return { name: dynamicName, deep: !!deepDynamicName }
481
+ const dynamicMatch = matchDynamicName(part)
482
+ if (!dynamicMatch) return null
483
+ return { name: dynamicMatch.name, deep: dynamicMatch.deep }
487
484
  })
488
485
  .filter((part): part is DynamicConvention => !!part)
489
486
 
@@ -46,8 +46,8 @@ describe(matchDynamicName, () => {
46
46
  it(`matches`, () => {
47
47
  expect(matchDynamicName('[[...foobar]]')).toEqual(undefined)
48
48
  expect(matchDynamicName('[[foobar]]')).toEqual(undefined)
49
- expect(matchDynamicName('[...foobar]')).toEqual(undefined)
50
- expect(matchDynamicName('[foobar]')).toEqual('foobar')
49
+ expect(matchDynamicName('[...foobar]')).toEqual({ name: 'foobar', deep: true })
50
+ expect(matchDynamicName('[foobar]')).toEqual({ name: 'foobar', deep: false })
51
51
  expect(matchDynamicName('foobar')).toEqual(undefined)
52
52
  })
53
53
  })
@@ -1,11 +1,27 @@
1
- /** Match `[page]` -> `page` */
2
- export function matchDynamicName(name: string): string | undefined {
3
- // Don't match `...` or `[` or `]` inside the brackets
4
- // eslint-disable-next-line no-useless-escape
5
- return name.match(/^\[([^[\](?:...)]+?)\]$/)?.[1]
1
+ /** Match `[page]` -> `page` or `[...page]` -> `page` with deep flag */
2
+ const dynamicNameRe = /^\[([^[\]]+?)\]$/
3
+
4
+ export interface DynamicNameMatch {
5
+ name: string
6
+ deep: boolean
7
+ }
8
+
9
+ /** Match `[page]` -> `{ name: 'page', deep: false }` or `[...page]` -> `{ name: 'page', deep: true }` */
10
+ export function matchDynamicName(name: string): DynamicNameMatch | undefined {
11
+ const paramName = name.match(dynamicNameRe)?.[1]
12
+ if (paramName == null) {
13
+ return undefined
14
+ } else if (paramName.startsWith('...')) {
15
+ return { name: paramName.slice(3), deep: true }
16
+ } else {
17
+ return { name: paramName, deep: false }
18
+ }
6
19
  }
7
20
 
8
- /** Match `[...page]` -> `page` */
21
+ /**
22
+ * Match `[...page]` -> `page`
23
+ * @deprecated Use matchDynamicName instead which returns {name, deep}
24
+ */
9
25
  export function matchDeepDynamicRouteName(name: string): string | undefined {
10
26
  return name.match(/^\[\.\.\.([^/]+?)\]$/)?.[1]
11
27
  }
@@ -24,6 +24,7 @@ import { getLinking, resetLinking, setupLinking } from './linkingConfig'
24
24
  import type { RouteNode } from './Route'
25
25
  import { sortRoutes } from './sortRoutes'
26
26
  import { getQualifiedRouteComponent } from './useScreens'
27
+ import { preloadRouteModules } from './useViteRoutes'
27
28
  import { getNavigateAction } from './utils/getNavigateAction'
28
29
 
29
30
  // Module-scoped variables
@@ -65,7 +66,7 @@ export function initialize(
65
66
  throw new Error('No routes found')
66
67
  }
67
68
 
68
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER && routeNode) {
69
+ if (process.env.ONE_DEBUG_ROUTER && routeNode) {
69
70
  const formatRouteTree = (node: RouteNode, indent = '', isLast = true): string => {
70
71
  const prefix = indent + (isLast ? '└─ ' : '├─ ')
71
72
  const childIndent = indent + (isLast ? ' ' : '│ ')
@@ -180,7 +181,7 @@ export function push(url: OneRouter.Href, options?: OneRouter.LinkToOptions) {
180
181
  }
181
182
 
182
183
  export function dismiss(count?: number) {
183
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
184
+ if (process.env.ONE_DEBUG_ROUTER) {
184
185
  console.info(`[one] 🔙 dismiss${count ? ` (${count})` : ''}`)
185
186
  }
186
187
  navigationRef?.dispatch(StackActions.pop(count))
@@ -199,14 +200,14 @@ export function setParams(params: OneRouter.InpurRouteParamsGeneric = {}) {
199
200
  }
200
201
 
201
202
  export function dismissAll() {
202
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
203
+ if (process.env.ONE_DEBUG_ROUTER) {
203
204
  console.info(`[one] 🔙 dismissAll`)
204
205
  }
205
206
  navigationRef?.dispatch(StackActions.popToTop())
206
207
  }
207
208
 
208
209
  export function goBack() {
209
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
210
+ if (process.env.ONE_DEBUG_ROUTER) {
210
211
  console.info(`[one] 🔙 goBack`)
211
212
  }
212
213
  assertIsReady(navigationRef)
@@ -250,7 +251,7 @@ export function updateState(state: OneRouter.ResultState, nextStateParam = state
250
251
  const nextRouteInfo = getRouteInfo(state)
251
252
 
252
253
  if (!deepEqual(routeInfo, nextRouteInfo)) {
253
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
254
+ if (process.env.ONE_DEBUG_ROUTER) {
254
255
  const from = routeInfo?.pathname || '(initial)'
255
256
  const to = nextRouteInfo.pathname
256
257
  const params = Object.keys(nextRouteInfo.params || {}).length
@@ -367,42 +368,53 @@ export function cleanup() {
367
368
  }
368
369
 
369
370
  // TODO
370
- export const preloadingLoader = {}
371
-
372
- function setupPreload(href: string) {
373
- if (preloadingLoader[href]) return
374
- preloadingLoader[href] = async () => {
375
- try {
376
- const [_preload, loader] = await Promise.all([
377
- dynamicImport(getPreloadPath(href)),
378
- dynamicImport(getLoaderPath(href)),
379
- ])
380
- const response = await loader
381
- return await response.loader?.()
382
- } catch (err) {
383
- console.error(`Error preloading loader: ${err}`)
371
+ export const preloadingLoader: Record<string, Promise<any> | undefined> = {}
372
+
373
+ async function doPreload(href: string) {
374
+ const preloadPath = getPreloadPath(href)
375
+ const loaderPath = getLoaderPath(href)
376
+ try {
377
+ const [_preload, loader] = await Promise.all([
378
+ dynamicImport(preloadPath),
379
+ dynamicImport(loaderPath),
380
+ preloadRouteModules(href),
381
+ ])
382
+
383
+ if (!loader?.loader) {
384
384
  return null
385
385
  }
386
+
387
+ const result = await loader.loader()
388
+ return result ?? null
389
+ } catch (err) {
390
+ console.error(`[one] preload error for ${href}:`, err)
391
+ return null
386
392
  }
387
393
  }
388
394
 
389
- export function preloadRoute(href: string) {
395
+ // Store resolved preload data separately from promises
396
+ export const preloadedLoaderData: Record<string, any> = {}
397
+
398
+ export function preloadRoute(href: string): Promise<any> | undefined {
390
399
  if (process.env.TAMAGUI_TARGET === 'native') {
391
- // not enabled for now
392
400
  return
393
401
  }
394
402
  if (process.env.NODE_ENV === 'development') {
395
403
  return
396
404
  }
397
405
 
398
- setupPreload(href)
399
- if (typeof preloadingLoader[href] === 'function') {
400
- void preloadingLoader[href]()
406
+ if (!preloadingLoader[href]) {
407
+ preloadingLoader[href] = doPreload(href).then((data) => {
408
+ // Store the resolved data for synchronous access
409
+ preloadedLoaderData[href] = data
410
+ return data
411
+ })
401
412
  }
413
+ return preloadingLoader[href]
402
414
  }
403
415
 
404
416
  export async function linkTo(href: string, event?: string, options?: OneRouter.LinkToOptions) {
405
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
417
+ if (process.env.ONE_DEBUG_ROUTER) {
406
418
  console.info(`[one] 🔗 ${event || 'NAVIGATE'} ${href}`)
407
419
  }
408
420
 
@@ -477,7 +489,8 @@ export async function linkTo(href: string, event?: string, options?: OneRouter.L
477
489
 
478
490
  setLoadingState('loading')
479
491
 
480
- preloadRoute(href)
492
+ // await preload on web to ensure route modules are loaded before navigating
493
+ await preloadRoute(href)
481
494
 
482
495
  const rootState = navigationRef.getRootState()
483
496
 
@@ -26,6 +26,125 @@ export function useViteRoutes(
26
26
  return context
27
27
  }
28
28
 
29
+ // store preloaded modules so resolve() can use them synchronously
30
+ let preloadedModules: Record<string, any> = {}
31
+
32
+ export function registerPreloadedRoute(key: string, module: any): void {
33
+ preloadedModules[key] = module
34
+ }
35
+
36
+ export function getPreloadedModule(key: string): any {
37
+ return preloadedModules[key]
38
+ }
39
+
40
+ export function getPreloadedModuleKeys(): string[] {
41
+ return Object.keys(preloadedModules)
42
+ }
43
+
44
+ /**
45
+ * Checks if a dynamic route pattern matches an actual path.
46
+ * Used to preload route modules for dynamic routes like [slug].
47
+ *
48
+ * @example
49
+ * matchDynamicRoute("docs/[slug]", "docs/getting-started") // true
50
+ * matchDynamicRoute("[...slug]", "a/b/c") // true (catch-all)
51
+ */
52
+ function matchDynamicRoute(routePattern: string, actualPath: string): boolean {
53
+ const routeSegments = routePattern.split('/')
54
+ const pathSegments = actualPath.split('/')
55
+
56
+ // handle catch-all routes like [...slug]
57
+ const hasCatchAll = routeSegments.some((s) => s.startsWith('[...'))
58
+ if (hasCatchAll) {
59
+ // find the catch-all segment position
60
+ const catchAllIdx = routeSegments.findIndex((s) => s.startsWith('[...'))
61
+ // all segments before catch-all must match exactly (or be dynamic)
62
+ for (let i = 0; i < catchAllIdx; i++) {
63
+ if (!routeSegments[i]) continue
64
+ if (routeSegments[i].startsWith('[')) continue // dynamic segment matches anything
65
+ if (routeSegments[i] !== pathSegments[i]) return false
66
+ }
67
+ // catch-all matches any remaining segments
68
+ return pathSegments.length >= catchAllIdx
69
+ }
70
+
71
+ // for non-catch-all, segment count should match
72
+ if (routeSegments.length !== pathSegments.length) return false
73
+
74
+ for (let i = 0; i < routeSegments.length; i++) {
75
+ const routeSeg = routeSegments[i]
76
+ const pathSeg = pathSegments[i]
77
+
78
+ // dynamic segment [param] matches any value
79
+ if (routeSeg.startsWith('[') && routeSeg.endsWith(']')) {
80
+ continue
81
+ }
82
+
83
+ // static segment must match exactly
84
+ if (routeSeg !== pathSeg) return false
85
+ }
86
+
87
+ return true
88
+ }
89
+
90
+ /**
91
+ * Preloads route modules for a given URL path (production only).
92
+ * This ensures route components are loaded before navigation completes,
93
+ * preventing Suspense boundaries from triggering and causing flicker.
94
+ *
95
+ * Called during `linkTo()` to preload routes before client-side navigation.
96
+ */
97
+ export async function preloadRouteModules(href: string): Promise<void> {
98
+ const globbed = globalThis['__importMetaGlobbed']
99
+ if (!globbed) return
100
+
101
+ // normalize href to match route keys - /docs -> docs
102
+ const normalizedHref = href === '/' ? '' : href.replace(/^\//, '').replace(/\/$/, '')
103
+
104
+ const promises: Promise<any>[] = []
105
+
106
+ for (const key of Object.keys(globbed)) {
107
+ // key looks like "/app/(site)/docs/_layout.tsx" or "/app/(site)/docs/index+ssg.tsx"
108
+ // strip the /app/ prefix first
109
+ let routePath = key.replace(/^\/[^/]+\//, '')
110
+
111
+ // strip route groups like (site), (app) etc
112
+ routePath = routePath.replace(/\([^)]+\)\//g, '')
113
+
114
+ // strip file suffixes but keep the path structure
115
+ routePath = routePath
116
+ .replace(/\/_layout\.tsx$/, '')
117
+ .replace(/\/index(\+[a-z]+)?\.tsx$/, '')
118
+ .replace(/(\+[a-z]+)?\.tsx$/, '')
119
+
120
+ // remove leading slash if any
121
+ routePath = routePath.replace(/^\//, '')
122
+
123
+ // check if this route is part of the target path
124
+ const isStaticMatch =
125
+ routePath === normalizedHref || // exact match
126
+ routePath.startsWith(normalizedHref + '/') || // child route
127
+ normalizedHref.startsWith(routePath + '/') || // parent layout
128
+ routePath === '' || // root layout
129
+ (normalizedHref !== '' && routePath === normalizedHref.split('/')[0]) // top-level match
130
+
131
+ // also check dynamic route patterns like docs/[slug]
132
+ const isDynamicMatch = routePath.includes('[') && matchDynamicRoute(routePath, normalizedHref)
133
+
134
+ if ((isStaticMatch || isDynamicMatch) && typeof globbed[key] === 'function') {
135
+ promises.push(
136
+ globbed[key]()
137
+ .then((mod: any) => {
138
+ preloadedModules[key] = mod
139
+ })
140
+ .catch(() => {})
141
+ )
142
+ }
143
+ }
144
+
145
+ await Promise.all(promises)
146
+ }
147
+
29
148
  export function loadRoutes(
30
149
  paths: GlobbedRouteImports,
31
150
  routerRoot: string,
@@ -77,6 +196,14 @@ export function globbedRoutesToRouteContext(
77
196
  return loadedRoutes[id]
78
197
  }
79
198
 
199
+ // check if this route was preloaded (via preload file or hydration)
200
+ const preloadKey = id.replace('./', `/${routerRoot}/`)
201
+ const preloaded = getPreloadedModule(preloadKey)
202
+ if (preloaded) {
203
+ loadedRoutes[id] = preloaded
204
+ return preloaded
205
+ }
206
+
80
207
  if (typeof routesSync[id] !== 'function') {
81
208
  return routesSync[id]
82
209
  }
@@ -98,23 +225,6 @@ export function globbedRoutesToRouteContext(
98
225
  console.error(`Error loading route`, id, err, new Error().stack)
99
226
  loadedRoutes[id] = {
100
227
  default: () => null,
101
- // <View
102
- // style={{
103
- // position: 'absolute',
104
- // top: 0,
105
- // left: 0,
106
- // right: 0,
107
- // bottom: 0,
108
- // alignItems: 'center',
109
- // justifyContent: 'center',
110
- // backgroundColor: '#000',
111
- // gap: 20,
112
- // }}
113
- // >
114
- // <Text style={{ fontSize: 24, color: '#fff' }}>Error loading route</Text>
115
- // <Text style={{ fontSize: 16, color: '#fff' }}>{id}</Text>
116
- // <Text style={{ fontSize: 18, color: '#fff', maxWidth: 800 }}>{`${err}`}</Text>
117
- // </View>
118
228
  }
119
229
  delete promises[id]
120
230
  })
@@ -39,14 +39,15 @@ export function getNavigateAction(
39
39
  const childState = actionStateRoute.state
40
40
  const nextNavigationState = stateRoute.state
41
41
 
42
- const dynamicName = matchDynamicName(actionStateRoute.name)
42
+ const dynamicMatch = matchDynamicName(actionStateRoute.name)
43
43
 
44
44
  const didActionAndCurrentStateDiverge =
45
45
  actionStateRoute.name !== stateRoute.name ||
46
46
  // !deepEqual(actionStateRoute.params, stateRoute.params) ||
47
47
  !childState ||
48
48
  !nextNavigationState ||
49
- (dynamicName && actionStateRoute.params?.[dynamicName] !== stateRoute.params?.[dynamicName])
49
+ (dynamicMatch &&
50
+ actionStateRoute.params?.[dynamicMatch.name] !== stateRoute.params?.[dynamicMatch.name])
50
51
 
51
52
  if (didActionAndCurrentStateDiverge) {
52
53
  break
@@ -18,6 +18,8 @@ import { toAbsolute } from '../utils/toAbsolute'
18
18
  import type { One } from '../vite/types'
19
19
  import type { RouteInfoCompiled } from './createRoutesManifest'
20
20
 
21
+ const debugRouter = process.env.ONE_DEBUG_ROUTER
22
+
21
23
  export async function oneServe(oneOptions: One.PluginOptions, buildInfo: One.BuildInfo, app: Hono) {
22
24
  const { resolveAPIRoute, resolveLoaderRoute, resolvePageRoute } = await import(
23
25
  '../createHandleRequest'
@@ -36,6 +38,9 @@ export async function oneServe(oneOptions: One.PluginOptions, buildInfo: One.Bui
36
38
  const paramName = param.substring(1)
37
39
  return context.req.param(paramName) || ''
38
40
  })
41
+ if (debugRouter) {
42
+ console.info(`[one] ↪ redirect ${context.req.path} → ${destinationUrl}`)
43
+ }
39
44
  return context.redirect(destinationUrl, redirect.permanent ? 301 : 302)
40
45
  })
41
46
  }
@@ -180,11 +185,19 @@ url: ${url}`)
180
185
 
181
186
  switch (route.type) {
182
187
  case 'api': {
188
+ if (debugRouter) {
189
+ console.info(`[one] ⚡ ${url.pathname} → matched API route: ${route.page}`)
190
+ }
183
191
  return resolveAPIRoute(requestHandlers, request, url, route)
184
192
  }
185
193
  case 'ssg':
186
194
  case 'spa':
187
195
  case 'ssr': {
196
+ if (debugRouter) {
197
+ console.info(
198
+ `[one] ⚡ ${url.pathname} → matched page route: ${route.page} (${route.type})`
199
+ )
200
+ }
188
201
  return resolvePageRoute(requestHandlers, request, url, route)
189
202
  }
190
203
  }
package/src/types.ts CHANGED
@@ -24,4 +24,5 @@ export type RenderAppProps = {
24
24
  loaderServerData?: any
25
25
  loaderData?: any
26
26
  loaderProps?: LoaderProps
27
+ routePreloads?: Record<string, string>
27
28
  }
package/src/useLoader.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { useCallback, useSyncExternalStore } from 'react'
2
2
  import { useParams, usePathname } from './hooks'
3
- import { resolveHref } from './link/href'
4
- import { preloadingLoader } from './router/router'
3
+ import { preloadedLoaderData, preloadingLoader } from './router/router'
5
4
  import { getLoaderPath } from './utils/cleanUrl'
6
5
  import { dynamicImport } from './utils/dynamicImport'
7
6
  import { weakKey } from './utils/weakKey'
@@ -89,7 +88,9 @@ export function useLoaderState<
89
88
 
90
89
  const params = useParams()
91
90
  const pathname = usePathname()
92
- const currentPath = resolveHref({ pathname, params }).replace(/index$/, '')
91
+ // use just the pathname for matching, don't use resolveHref which adds params as query string
92
+ // (the pathname is already resolved like /docs/getting-started, not /docs/[slug])
93
+ const currentPath = pathname.replace(/\/index$/, '').replace(/\/$/, '') || '/'
93
94
 
94
95
  // server-side
95
96
  if (typeof window === 'undefined' && loader) {
@@ -103,9 +104,9 @@ export function useLoaderState<
103
104
  return { data: serverData, refetch: async () => {}, state: 'idle' } as any
104
105
  }
105
106
 
106
- // preloaded data from SSR
107
- const preloadedData =
108
- loaderPropsFromServerContext?.path === currentPath ? loaderDataFromServerContext : undefined
107
+ // preloaded data from SSR/SSG - only use if server context path matches current path
108
+ const serverContextPath = loaderPropsFromServerContext?.path
109
+ const preloadedData = serverContextPath === currentPath ? loaderDataFromServerContext : undefined
109
110
 
110
111
  const loaderStateEntry = useSyncExternalStore(
111
112
  subscribe,
@@ -130,14 +131,21 @@ export function useLoaderState<
130
131
  !loaderStateEntry.hasLoadedOnce &&
131
132
  loader
132
133
  ) {
133
- // check for preloading loader first
134
- if (preloadingLoader[currentPath]) {
135
- if (typeof preloadingLoader[currentPath] === 'function') {
136
- preloadingLoader[currentPath] = preloadingLoader[currentPath]()
137
- }
138
- const promise = preloadingLoader[currentPath]
134
+ // check for already-resolved preloaded data first (synchronous)
135
+ const resolvedPreloadData = preloadedLoaderData[currentPath]
136
+ if (resolvedPreloadData !== undefined) {
137
+ // Data was preloaded and already resolved - use it directly
138
+ delete preloadedLoaderData[currentPath]
139
+ delete preloadingLoader[currentPath]
140
+ loaderStateEntry.data = resolvedPreloadData
141
+ loaderStateEntry.hasLoadedOnce = true
142
+ } else if (preloadingLoader[currentPath]) {
143
+ // Preload is in progress - wait for it
144
+ const preloadPromise = preloadingLoader[currentPath]!
145
+ const promise = preloadPromise
139
146
  .then((val: any) => {
140
147
  delete preloadingLoader[currentPath]
148
+ delete preloadedLoaderData[currentPath]
141
149
  updateState(currentPath, {
142
150
  data: val,
143
151
  hasLoadedOnce: true,
package/src/vite/one.ts CHANGED
@@ -1,15 +1,15 @@
1
- import events from 'node:events'
2
- import path from 'node:path'
3
1
  import { configureVXRNCompilerPlugin } from '@vxrn/compiler'
4
2
  import { resolvePath } from '@vxrn/resolve'
5
3
  import type {
6
4
  ExpoManifestRequestHandlerPluginPluginOptions,
7
5
  MetroPluginOptions,
8
6
  } from '@vxrn/vite-plugin-metro'
7
+ import events from 'node:events'
8
+ import path from 'node:path'
9
9
  import type { Plugin, PluginOption } from 'vite'
10
10
  import { barrel } from 'vite-plugin-barrel'
11
11
  import tsconfigPaths from 'vite-tsconfig-paths'
12
- import { autoDepOptimizePlugin, getOptimizeDeps, getOptionsFilled, loadEnv } from 'vxrn'
12
+ import { autoDepOptimizePlugin, getOptionsFilled, loadEnv } from 'vxrn'
13
13
  import vxrnVitePlugin from 'vxrn/vite-plugin'
14
14
  import { CACHE_KEY } from '../constants'
15
15
  import { getViteMetroPluginOptions } from '../metro-config/getViteMetroPluginOptions'
@@ -121,15 +121,6 @@ export function one(options: One.PluginOptions = {}): PluginOption {
121
121
  void ensureTSConfig()
122
122
  }
123
123
 
124
- // build is superset for now
125
- const { optimizeDeps } = getOptimizeDeps('build')
126
- const optimizeIds = optimizeDeps.include
127
- const optimizeIdRegex = new RegExp(
128
- // santize ids for regex
129
- // https://stackoverflow.com/questions/6300183/sanitize-string-of-regex-characters-before-regexp-build
130
- `${optimizeIds.map((id) => id.replace(/[#-.]|[[-^]|[?|{}]/g, '\\$&')).join('|')}`
131
- )
132
-
133
124
  let tsConfigPathsPlugin: Plugin | null = null
134
125
 
135
126
  const vxrnOptions = getOptionsFilled()
@@ -167,7 +158,12 @@ export function one(options: One.PluginOptions = {}): PluginOption {
167
158
  userConfig?.envPrefix
168
159
  )
169
160
  return {
170
- define: clientEnvDefine,
161
+ define: {
162
+ ...clientEnvDefine,
163
+ ...(process.env.ONE_DEBUG_ROUTER && {
164
+ 'process.env.ONE_DEBUG_ROUTER': JSON.stringify(process.env.ONE_DEBUG_ROUTER),
165
+ }),
166
+ },
171
167
  }
172
168
  },
173
169
  },
@@ -17,6 +17,8 @@ import type { One } from '../../vite/types'
17
17
  import { setServerContext } from '../one-server-only'
18
18
  import { virtalEntryIdClient, virtualEntryId } from './virtualEntryConstants'
19
19
 
20
+ const debugRouter = process.env.ONE_DEBUG_ROUTER
21
+
20
22
  // server needs better dep optimization
21
23
  const USE_SERVER_ENV = false //!!process.env.USE_SERVER_ENV
22
24
 
@@ -329,7 +331,9 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
329
331
  })
330
332
  }
331
333
 
332
- console.warn(` [one] redirecting via redirect: ${destination}`)
334
+ if (debugRouter) {
335
+ console.info(`[one] ↪ redirect ${url.pathname} → ${destination}`)
336
+ }
333
337
 
334
338
  res.writeHead(redirect.permanent ? 301 : 302, { Location: destination })
335
339
  res.end()
@@ -338,13 +342,21 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
338
342
  }
339
343
  }
340
344
 
341
- const reply = await handleRequest.handler(await convertIncomingMessageToRequest(req))
345
+ const reply = await handleRequest.handler(convertIncomingMessageToRequest(req))
342
346
 
343
347
  if (!reply) {
344
348
  return next()
345
349
  }
346
350
 
347
351
  if (typeof reply !== 'string' && isResponse(reply)) {
352
+ if (debugRouter) {
353
+ const headers: Record<string, string> = {}
354
+ reply.headers.forEach((v, k) => {
355
+ headers[k] = v
356
+ })
357
+ console.info(`[one] 📤 response ${reply.status}`, headers)
358
+ }
359
+
348
360
  reply.headers.forEach((value, key) => {
349
361
  if (key === 'set-cookie') {
350
362
  // for some reason it wasnt doing working without this?
@@ -359,7 +371,9 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
359
371
 
360
372
  if (isStatusRedirect(reply.status)) {
361
373
  const location = `${reply.headers.get('location') || ''}`
362
- console.info(` ↦ Redirect ${location}`)
374
+ if (debugRouter) {
375
+ console.info(`[one] ↪ response redirect → ${location}`)
376
+ }
363
377
  if (location) {
364
378
  res.writeHead(reply.status, {
365
379
  Location: location,
@@ -373,8 +387,6 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
373
387
  res.statusCode = reply.status
374
388
  res.statusMessage = reply.statusText
375
389
 
376
- let outString = ''
377
-
378
390
  if (reply.body) {
379
391
  if (reply.body.locked) {
380
392
  console.warn(`Body is locked??`, req.url)