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
@@ -21,7 +21,8 @@ export async function buildPage(
21
21
  builtMiddlewares: Record<string, string>,
22
22
  serverJsPath: string,
23
23
  preloads: string[],
24
- allCSS: string[]
24
+ allCSS: string[],
25
+ routePreloads: Record<string, string>
25
26
  ): Promise<One.RouteBuildInfo> {
26
27
  const render = await getRender(serverEntry)
27
28
  const htmlPath = `${path.endsWith('/') ? `${removeTrailingSlash(path)}/index` : path}.html`
@@ -34,12 +35,33 @@ export async function buildPage(
34
35
  let loaderData = {}
35
36
 
36
37
  try {
37
- // todo await optimize
38
- await FSExtra.writeFile(
39
- join(clientDir, preloadPath),
40
- preloads.map((preload) => `import "${preload}"`).join('\n')
38
+ // generate preload file with route module registration
39
+ const routeImports: string[] = []
40
+ const routeRegistrations: string[] = []
41
+ let routeIndex = 0
42
+
43
+ for (const [routeKey, bundlePath] of Object.entries(routePreloads)) {
44
+ const varName = `_r${routeIndex++}`
45
+ routeImports.push(`import * as ${varName} from "${bundlePath}"`)
46
+ routeRegistrations.push(`registerPreloadedRoute("${routeKey}", ${varName})`)
47
+ }
48
+
49
+ // Use window global for registration since ES module exports get tree-shaken
50
+ const registrationCalls = routeRegistrations.map((call) =>
51
+ call.replace('registerPreloadedRoute(', 'window.__oneRegisterPreloadedRoute(')
41
52
  )
42
53
 
54
+ const preloadContent = [
55
+ // import all route modules
56
+ ...routeImports,
57
+ // static imports for cache warming (original behavior)
58
+ ...preloads.map((preload) => `import "${preload}"`),
59
+ // register all route modules using window global
60
+ ...registrationCalls,
61
+ ].join('\n')
62
+
63
+ await FSExtra.writeFile(join(clientDir, preloadPath), preloadContent)
64
+
43
65
  const exported = await import(toAbsolute(serverJsPath))
44
66
 
45
67
  if (exported.loader) {
@@ -73,6 +95,7 @@ if (typeof document === 'undefined') globalThis.document = {}
73
95
  loaderData,
74
96
  css: allCSS,
75
97
  mode: 'ssg',
98
+ routePreloads,
76
99
  })
77
100
  await outputFile(htmlOutPath, html)
78
101
  } else if (foundRoute.type === 'spa') {
package/src/createApp.tsx CHANGED
@@ -6,6 +6,7 @@ import { AppRegistry } from 'react-native'
6
6
  import { resolveClientLoader } from './clientLoaderResolver'
7
7
  import { Root } from './Root'
8
8
  import { render } from './render'
9
+ import { registerPreloadedRoute } from './router/useViteRoutes'
9
10
  import { renderToString } from './server-render'
10
11
  import type { RenderAppProps } from './types'
11
12
  import { getServerHeadInsertions } from './useServerHeadInsertion'
@@ -25,7 +26,7 @@ export function createApp(options: CreateAppProps) {
25
26
  return {
26
27
  options,
27
28
  render: async (props: RenderAppProps) => {
28
- let { loaderData, loaderProps, css, mode, loaderServerData } = props
29
+ let { loaderData, loaderProps, css, mode, loaderServerData, routePreloads } = props
29
30
 
30
31
  setServerContext({
31
32
  postRenderData: loaderServerData,
@@ -33,6 +34,7 @@ export function createApp(options: CreateAppProps) {
33
34
  loaderProps,
34
35
  mode,
35
36
  css,
37
+ routePreloads,
36
38
  })
37
39
 
38
40
  let renderId: string | undefined
@@ -116,29 +118,35 @@ export function createApp(options: CreateAppProps) {
116
118
  }
117
119
  }
118
120
 
119
- // run their root layout before calling resolveClientLoader so they can register hook
120
- const rootLayoutImport = options.routes[`/${options.routerRoot}/_layout.tsx`]?.()
121
+ const serverContext = getServerContext() || {}
122
+ const routePreloads = serverContext.routePreloads
121
123
 
122
- return rootLayoutImport
124
+ // preload routes using build-time mapping (production SSG)
125
+ // for SPA/dev mode, fall back to importing root layout directly
126
+ const preloadPromises = routePreloads
127
+ ? Object.entries(routePreloads).map(async ([routeKey, bundlePath]) => {
128
+ const mod = await import(/* @vite-ignore */ bundlePath)
129
+ registerPreloadedRoute(routeKey, mod)
130
+ return mod
131
+ })
132
+ : [options.routes[`/${options.routerRoot}/_layout.tsx`]?.()]
133
+
134
+ return Promise.all(preloadPromises)
123
135
  .then(() => {
124
- resolveClientLoader(getServerContext() || {})
125
- .then(() => {
126
- // on client we just render
127
- render(
128
- <Root
129
- isClient
130
- flags={options.flags}
131
- routes={options.routes}
132
- routerRoot={options.routerRoot}
133
- path={window.location.href}
134
- />
135
- )
136
- })
137
- .catch((err) => {
138
- console.error(`Error running client loader resolver "onClientLoaderResolve":`, err)
139
- })
136
+ return resolveClientLoader(serverContext)
137
+ })
138
+ .then(() => {
139
+ render(
140
+ <Root
141
+ isClient
142
+ flags={options.flags}
143
+ routes={options.routes}
144
+ routerRoot={options.routerRoot}
145
+ path={window.location.href}
146
+ />
147
+ )
140
148
  })
141
149
  .catch((err) => {
142
- console.error(`Error importing root layout on client`, err)
150
+ console.error(`Error during client initialization:`, err)
143
151
  })
144
152
  }
@@ -25,6 +25,8 @@ type RequestHandlerProps<RouteExtraProps extends Object = {}> = {
25
25
 
26
26
  type RequestHandlerResponse = null | string | Response
27
27
 
28
+ const debugRouter = process.env.ONE_DEBUG_ROUTER
29
+
28
30
  export async function runMiddlewares(
29
31
  handlers: RequestHandlers,
30
32
  request: Request,
@@ -40,6 +42,10 @@ export async function runMiddlewares(
40
42
  throw new Error(`No middleware handler configured`)
41
43
  }
42
44
 
45
+ if (debugRouter) {
46
+ console.info(`[one] 🔗 middleware chain (${middlewares.length}) for ${route.page}`)
47
+ }
48
+
43
49
  const context: MiddlewareContext = {}
44
50
 
45
51
  async function dispatch(index: number): Promise<Response> {
@@ -47,9 +53,16 @@ export async function runMiddlewares(
47
53
 
48
54
  // no more middlewares, finish
49
55
  if (!middlewareModule) {
56
+ if (debugRouter) {
57
+ console.info(`[one] ✓ middleware chain complete`)
58
+ }
50
59
  return await getResponse()
51
60
  }
52
61
 
62
+ if (debugRouter) {
63
+ console.info(`[one] → middleware[${index}]: ${middlewareModule.contextKey}`)
64
+ }
65
+
53
66
  const exported = (await handlers.loadMiddleware!(middlewareModule))?.default as
54
67
  | Middleware
55
68
  | undefined
@@ -67,6 +80,9 @@ export async function runMiddlewares(
67
80
  const response = await exported({ request, next, context })
68
81
 
69
82
  if (response) {
83
+ if (debugRouter) {
84
+ console.info(`[one] ← middleware[${index}] returned early (status: ${response.status})`)
85
+ }
70
86
  return response
71
87
  }
72
88
 
@@ -87,6 +103,10 @@ export async function resolveAPIRoute(
87
103
  const { pathname } = url
88
104
  const params = getRouteParams(pathname, route)
89
105
 
106
+ if (debugRouter) {
107
+ console.info(`[one] 📡 API ${request.method} ${pathname} → ${route.file}`, params)
108
+ }
109
+
90
110
  try {
91
111
  return resolveAPIEndpoint(
92
112
  () =>
@@ -128,6 +148,10 @@ export async function resolveLoaderRoute(
128
148
  url: URL,
129
149
  route: RouteInfoCompiled
130
150
  ) {
151
+ if (debugRouter) {
152
+ console.info(`[one] 📦 loader ${url.pathname} → ${route.file}`)
153
+ }
154
+
131
155
  return await runMiddlewares(handlers, request, route, async () => {
132
156
  return await resolveResponse(async () => {
133
157
  const headers = new Headers()
@@ -171,6 +195,10 @@ export async function resolvePageRoute(
171
195
  ) {
172
196
  const { pathname, search } = url
173
197
 
198
+ if (debugRouter) {
199
+ console.info(`[one] 📄 page ${pathname} → ${route.file} (${route.type})`)
200
+ }
201
+
174
202
  return resolveResponse(async () => {
175
203
  const resolved = await runMiddlewares(handlers, request, route, async () => {
176
204
  return await handlers.handlePage!({
@@ -241,6 +269,9 @@ export function createHandleRequest(
241
269
  return route.compiledRegex.test(pathname)
242
270
  })
243
271
  if (apiRoute) {
272
+ if (debugRouter) {
273
+ console.info(`[one] ⚡ ${pathname} → matched API route: ${apiRoute.page}`)
274
+ }
244
275
  return await resolveAPIRoute(handlers, request, url, apiRoute)
245
276
  }
246
277
  }
@@ -291,6 +322,9 @@ export function createHandleRequest(
291
322
  if (!route.compiledRegex.test(pathname)) {
292
323
  continue
293
324
  }
325
+ if (debugRouter) {
326
+ console.info(`[one] ⚡ ${pathname} → matched page route: ${route.page} (${route.type})`)
327
+ }
294
328
  return resolvePageRoute(handlers, request, url, route)
295
329
  }
296
330
  }
@@ -164,6 +164,14 @@ function NavigationContainerInner(
164
164
 
165
165
  const [isResolved, initialState] = useThenable(getInitialState)
166
166
 
167
+ if (process.env.ONE_DEBUG_ROUTER) {
168
+ console.info(
169
+ `[one] 🏠 NavigationContainer isResolved=${isResolved} initialState=`,
170
+ JSON.stringify(initialState, null, 2)
171
+ )
172
+ console.info(`[one] 🏠 NavigationContainer rest.initialState=`, rest.initialState)
173
+ }
174
+
167
175
  React.useImperativeHandle(ref, () => refContainer.current!)
168
176
 
169
177
  const isLinkingReady = rest.initialState != null || !isLinkingEnabled || isResolved
@@ -82,6 +82,10 @@ export function createMemoryHistory() {
82
82
  items.push({ path, state, id })
83
83
  index = items.length - 1
84
84
 
85
+ if (process.env.ONE_DEBUG_ROUTER) {
86
+ console.info(`[one] 📜 history.push path=${path}`)
87
+ }
88
+
85
89
  // We pass empty string for title because it's ignored in all browsers except safari
86
90
  // We don't store state object in history.state because:
87
91
  // - browsers have limits on how big it can be, and we don't control the size
@@ -117,6 +121,10 @@ export function createMemoryHistory() {
117
121
  items[index] = { path, state, id }
118
122
  }
119
123
 
124
+ if (process.env.ONE_DEBUG_ROUTER) {
125
+ console.info(`[one] 📜 history.replace path=${pathWithHash}`)
126
+ }
127
+
120
128
  window.history.replaceState({ id }, '', pathWithHash)
121
129
  },
122
130
 
@@ -82,6 +82,12 @@ function fromDeepLink(url: string): string {
82
82
  * - It has a valid App scheme, but the scheme isn't a valid URL scheme (e.g. `my_app://`)
83
83
  */
84
84
 
85
+ // If `url` is already a path (starts with `/`), return it as-is
86
+ // This prevents incorrect rewrites when URL is in query params (e.g. `/?url=https://example.com`)
87
+ if (url.startsWith('/')) {
88
+ return url
89
+ }
90
+
85
91
  /**
86
92
  * App schemes are not valid URL schemes, so they will fail to parse.
87
93
  * We need to strip the scheme from these URLs
@@ -6,7 +6,7 @@
6
6
 
7
7
  import type { Route } from '@react-navigation/core'
8
8
 
9
- import { matchDeepDynamicRouteName, matchDynamicName, matchGroupName } from '../router/matchers'
9
+ import { matchDynamicName, matchGroupName } from '../router/matchers'
10
10
  import { getParamName } from './_shared'
11
11
 
12
12
  export type AdditionalOptions = {
@@ -136,12 +136,7 @@ export function appendBaseUrl(
136
136
  }
137
137
 
138
138
  function segmentMatchesConvention(segment: string): boolean {
139
- return (
140
- segment === 'index' ||
141
- matchDynamicName(segment) != null ||
142
- matchGroupName(segment) != null ||
143
- matchDeepDynamicRouteName(segment) != null
144
- )
139
+ return segment === 'index' || matchDynamicName(segment) != null || matchGroupName(segment) != null
145
140
  }
146
141
 
147
142
  function encodeURISegment(str: string, { preserveBrackets = false } = {}) {
@@ -16,35 +16,44 @@ export type AdditionalRouteConfig = {
16
16
  hasChildren: boolean
17
17
  expandedRouteNames: string[]
18
18
  parts: string[]
19
+ staticPartCount: number
20
+ }
21
+
22
+ interface UrlWithReactNavigationConcessions {
23
+ path: string
24
+ nonstandardPathname: string
25
+ hash: string
26
+ pathWithoutGroups: string
19
27
  }
20
28
 
21
29
  export function getUrlWithReactNavigationConcessions(
22
30
  path: string,
23
31
  baseUrl: string | undefined = process.env.EXPO_BASE_URL
24
- ) {
25
- let parsed: URL
32
+ ): UrlWithReactNavigationConcessions {
33
+ const pathWithoutGroups = stripGroupSegmentsFromPath(stripBaseUrl(path, baseUrl))
34
+
35
+ let pathname = ''
36
+ let hash = ''
26
37
  try {
27
- parsed = new URL(path, 'https://phony.example')
38
+ // NOTE: This used to use a dummy base URL for parsing (phony.example)
39
+ // However, this seems to get flagged since it's preserved 1:1 in the output bytecode by certain scanners
40
+ // Instead, we use an empty `file:` URL. This will still perform `pathname` normalization, search parameter parsing
41
+ // encoding, and all other logic, except the logic that applies to hostnames and protocols, and also not leave a
42
+ // dummy URL in the output bytecode
43
+ const parsed = new URL(path, 'file:')
44
+ pathname = parsed.pathname
45
+ hash = parsed.hash
28
46
  } catch {
29
47
  // Do nothing with invalid URLs.
30
- return {
31
- path,
32
- cleanUrl: '',
33
- nonstandardPathname: '',
34
- url: new URL('https://phony.example'),
35
- }
36
48
  }
37
49
 
38
- const pathname = parsed.pathname
39
50
  const withoutBaseUrl = stripBaseUrl(pathname, baseUrl)
40
- const pathWithoutGroups = stripGroupSegmentsFromPath(stripBaseUrl(path, baseUrl))
41
-
42
- // Make sure there is a trailing slash
43
51
  return {
44
- // The slashes are at the end, not the beginning
45
52
  path,
53
+ // Make sure there is a trailing slash
54
+ // The slashes are at the end, not the beginning
46
55
  nonstandardPathname: withoutBaseUrl.replace(/^\/+/g, '').replace(/\/+$/g, '') + '/',
47
- url: parsed,
56
+ hash,
48
57
  pathWithoutGroups,
49
58
  }
50
59
  }
@@ -145,6 +154,13 @@ export function getRouteConfigSorter(previousSegments: string[] = []) {
145
154
  return 1
146
155
  }
147
156
 
157
+ /*
158
+ * If the routes have any static segments, the one with the most static segments should be higher
159
+ */
160
+ if (a.staticPartCount !== b.staticPartCount) {
161
+ return b.staticPartCount - a.staticPartCount
162
+ }
163
+
148
164
  /*
149
165
  * If both are static/dynamic or a layout file, then we check group similarity
150
166
  */
@@ -312,15 +328,23 @@ export function createConfigItemAdditionalProperties(
312
328
  ): Omit<AdditionalRouteConfig, 'isInitial'> {
313
329
  const parts: string[] = []
314
330
  let isDynamic = false
331
+ let staticPartCount = 0
315
332
  const isIndex = screen === 'index' || screen.endsWith('/index')
316
333
 
317
334
  for (const part of pattern.split('/')) {
318
335
  if (part) {
319
336
  // If any part is dynamic, then the route is dynamic
320
- isDynamic ||= part.startsWith(':') || part.startsWith('*') || part.includes('*not-found')
337
+ const isDynamicPart =
338
+ part.startsWith(':') || part.startsWith('*') || part.includes('*not-found')
339
+
340
+ isDynamic ||= isDynamicPart
321
341
 
322
342
  if (!matchGroupName(part)) {
323
343
  parts.push(part)
344
+
345
+ if (!isDynamicPart) {
346
+ staticPartCount++
347
+ }
324
348
  }
325
349
  }
326
350
  }
@@ -330,6 +354,7 @@ export function createConfigItemAdditionalProperties(
330
354
 
331
355
  if (isIndex) {
332
356
  parts.push('index')
357
+ staticPartCount++
333
358
  }
334
359
 
335
360
  return {
@@ -337,6 +362,7 @@ export function createConfigItemAdditionalProperties(
337
362
  isIndex,
338
363
  hasChildren,
339
364
  parts,
365
+ staticPartCount,
340
366
  userReadableName: [...routeNames.slice(0, -1), config.path || screen].join('/'),
341
367
  expandedRouteNames: routeNames.flatMap((name) => {
342
368
  return name.split('/')
@@ -350,7 +376,7 @@ export function parseQueryParamsExtended(
350
376
  parseConfig?: Record<string, (value: string) => any>,
351
377
  hash?: string
352
378
  ) {
353
- const searchParams = new URL(path, 'https://phony.example').searchParams
379
+ const searchParams = new URL(path, 'file:').searchParams
354
380
  const params: Record<string, string | string[]> = Object.create(null)
355
381
 
356
382
  if (hash) {
@@ -723,7 +723,7 @@ const createNestedStateObject = (
723
723
  path,
724
724
  route,
725
725
  flatConfig ? findParseConfigForRoute(route.name, flatConfig) : undefined,
726
- restPathData.url.hash
726
+ restPathData.hash
727
727
  )
728
728
  // @modified - end
729
729
 
@@ -189,7 +189,7 @@ export function useLinking(
189
189
  // If the link were handled, it gets cleared in NavigationContainer
190
190
  onUnhandledLinking(extractPathFromURL(prefixes, url))
191
191
  const rootState = navigation.getRootState()
192
- if (state.routes.some((r) => !rootState?.routeNames.includes(r.name))) {
192
+ if (state.routes.some((r) => !rootState?.routeNames?.includes(r.name))) {
193
193
  return
194
194
  }
195
195
 
@@ -22,6 +22,7 @@ import isEqual from 'fast-deep-equal'
22
22
  import * as React from 'react'
23
23
  // @modified - start
24
24
  // import { ServerContext } from '@react-navigation/web';
25
+ import { rootState as routerRootState } from '../router/router'
25
26
  import { ServerLocationContext } from '../router/serverLocationContext'
26
27
  import { createMemoryHistory } from './createMemoryHistory'
27
28
  import { appendBaseUrl } from './getPathFromState-mods'
@@ -156,9 +157,18 @@ export function useLinking(
156
157
  (state: ResultState) => {
157
158
  const navigation = ref.current
158
159
  const rootState = navigation?.getRootState()
160
+ // @modified - start
161
+ // Fix for back/forward button navigation: if routeNames is undefined (stale state),
162
+ // don't reject the navigation. This can happen during browser back/forward.
163
+ // See: https://github.com/expo/expo/pull/37747
164
+ const routeNames = rootState?.routeNames
165
+ if (!routeNames) {
166
+ return false // Don't reject navigation if we can't validate
167
+ }
168
+ // @modified - end
159
169
  // Make sure that the routes in the state exist in the root navigator
160
170
  // Otherwise there's an error in the linking configuration
161
- return state?.routes.some((r) => !rootState?.routeNames.includes(r.name))
171
+ return state?.routes.some((r) => !routeNames.includes(r.name))
162
172
  },
163
173
  [ref]
164
174
  )
@@ -180,8 +190,15 @@ export function useLinking(
180
190
 
181
191
  const path = location ? location.pathname + location.search : undefined
182
192
 
193
+ if (process.env.ONE_DEBUG_ROUTER) {
194
+ console.info(`[one] 🔍 getInitialState path=${path}`)
195
+ }
196
+
183
197
  if (path) {
184
198
  value = getStateFromPathRef.current(path, configRef.current)
199
+ if (process.env.ONE_DEBUG_ROUTER) {
200
+ console.info(`[one] 🔍 getInitialState result:`, JSON.stringify(value, null, 2))
201
+ }
185
202
  }
186
203
 
187
204
  // If the link were handled, it gets cleared in NavigationContainer
@@ -223,6 +240,12 @@ export function useLinking(
223
240
 
224
241
  const previousIndex = previousIndexRef.current ?? 0
225
242
 
243
+ if (process.env.ONE_DEBUG_ROUTER) {
244
+ console.info(
245
+ `[one] 📜 history.listen path=${path} index=${index} prevIndex=${previousIndex}`
246
+ )
247
+ }
248
+
226
249
  previousIndexRef.current = index
227
250
  pendingPopStatePathRef.current = path
228
251
 
@@ -232,12 +255,19 @@ export function useLinking(
232
255
  const record = history.get(index)
233
256
 
234
257
  if (record?.path === path && record?.state) {
258
+ if (process.env.ONE_DEBUG_ROUTER) {
259
+ console.info(`[one] 📜 history record found, resetRoot to:`, record.state)
260
+ }
235
261
  navigation.resetRoot(record.state)
236
262
  return
237
263
  }
238
264
 
239
265
  const state = getStateFromPathRef.current(path, configRef.current)
240
266
 
267
+ if (process.env.ONE_DEBUG_ROUTER) {
268
+ console.info(`[one] 📜 getStateFromPath result:`, state)
269
+ }
270
+
241
271
  // We should only dispatch an action when going forward
242
272
  // Otherwise the action will likely add items to history, which would mess things up
243
273
  if (state) {
@@ -246,6 +276,9 @@ export function useLinking(
246
276
  // Make sure that the routes in the state exist in the root navigator
247
277
  // Otherwise there's an error in the linking configuration
248
278
  if (validateRoutesNotExistInRootState(state)) {
279
+ if (process.env.ONE_DEBUG_ROUTER) {
280
+ console.info(`[one] 📜 routes not in root state, skipping`)
281
+ }
249
282
  return
250
283
  }
251
284
 
@@ -256,6 +289,10 @@ export function useLinking(
256
289
  ) {
257
290
  const action = getActionFromStateRef.current(state, configRef.current)
258
291
 
292
+ if (process.env.ONE_DEBUG_ROUTER) {
293
+ console.info(`[one] 📜 dispatching action:`, action)
294
+ }
295
+
259
296
  if (action !== undefined) {
260
297
  try {
261
298
  navigation.dispatch(action)
@@ -269,13 +306,22 @@ export function useLinking(
269
306
  )
270
307
  }
271
308
  } else {
309
+ if (process.env.ONE_DEBUG_ROUTER) {
310
+ console.info(`[one] 📜 no action, resetRoot`)
311
+ }
272
312
  navigation.resetRoot(state)
273
313
  }
274
314
  } else {
315
+ if (process.env.ONE_DEBUG_ROUTER) {
316
+ console.info(`[one] 📜 going back, resetRoot`)
317
+ }
275
318
  navigation.resetRoot(state)
276
319
  }
277
320
  } else {
278
321
  // if current path didn't return any state, we should revert to initial state
322
+ if (process.env.ONE_DEBUG_ROUTER) {
323
+ console.info(`[one] 📜 no state for path, resetRoot to undefined`)
324
+ }
279
325
  navigation.resetRoot(state)
280
326
  }
281
327
  })
@@ -292,6 +338,11 @@ export function useLinking(
292
338
  ): string => {
293
339
  let path
294
340
 
341
+ if (process.env.ONE_DEBUG_ROUTER) {
342
+ console.info(`[one] 📜 getPathForRoute - route:`, route)
343
+ console.info(`[one] 📜 getPathForRoute - state:`, JSON.stringify(state, null, 2))
344
+ }
345
+
295
346
  // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
296
347
  // This makes sure that we preserve the original URL for wildcard routes
297
348
  if (route?.path) {
@@ -315,6 +366,9 @@ export function useLinking(
315
366
 
316
367
  if (path == null) {
317
368
  path = getPathFromStateRef.current(state, configRef.current)
369
+ if (process.env.ONE_DEBUG_ROUTER) {
370
+ console.info(`[one] 📜 getPathForRoute - computed from state:`, path)
371
+ }
318
372
  }
319
373
 
320
374
  // @modified - start: One will handle hashes itself, so these lines are not needed
@@ -340,14 +394,41 @@ export function useLinking(
340
394
  if (ref.current) {
341
395
  // We need to record the current metadata on the first render if they aren't set
342
396
  // This will allow the initial state to be in the history entry
343
- const state = ref.current.getRootState()
397
+ // @modified - start: Use routerRootState instead of getRootState() to avoid stale state
398
+ // getRootState() can return incomplete state during initial render before children mount
399
+ // routerRootState is updated via navigation listener callbacks which only fire with complete state
400
+ const refState = ref.current.getRootState()
401
+ const state = (routerRootState || refState) as NavigationState | undefined
402
+
403
+ if (process.env.ONE_DEBUG_ROUTER) {
404
+ console.info(
405
+ `[one] 📜 useEffect initial state check - refState:`,
406
+ JSON.stringify(refState, null, 2)
407
+ )
408
+ console.info(
409
+ `[one] 📜 useEffect initial state check - routerRootState:`,
410
+ JSON.stringify(routerRootState, null, 2)
411
+ )
412
+ }
413
+ // @modified - end
344
414
 
345
415
  if (state) {
346
416
  const route = findFocusedRoute(state)
417
+
418
+ if (process.env.ONE_DEBUG_ROUTER) {
419
+ console.info(`[one] 📜 useEffect focused route:`, route)
420
+ }
421
+
347
422
  const path = getPathForRoute(route, state)
348
423
 
424
+ if (process.env.ONE_DEBUG_ROUTER) {
425
+ console.info(`[one] 📜 initial history.replace - state:`, JSON.stringify(state, null, 2))
426
+ console.info(`[one] 📜 initial history.replace - focusedRoute:`, route)
427
+ console.info(`[one] 📜 initial history.replace - computed path:`, path)
428
+ }
429
+
349
430
  if (previousStateRef.current === undefined) {
350
- previousStateRef.current = state
431
+ previousStateRef.current = refState
351
432
  }
352
433
 
353
434
  history.replace({ path, state })
@@ -362,7 +443,10 @@ export function useLinking(
362
443
  }
363
444
 
364
445
  const previousState = previousStateRef.current
365
- const state = navigation.getRootState()
446
+ // @modified - start: Use routerRootState for path calculation, refState for comparison
447
+ const refState = navigation.getRootState()
448
+ const state = (routerRootState || refState) as NavigationState | undefined
449
+ // @modified - end
366
450
 
367
451
  // root state may not available, for example when root navigators switch inside the container
368
452
  if (!state) {
@@ -373,7 +457,7 @@ export function useLinking(
373
457
  const route = findFocusedRoute(state)
374
458
  const path = getPathForRoute(route, state)
375
459
 
376
- previousStateRef.current = state
460
+ previousStateRef.current = refState
377
461
  pendingPopStatePathRef.current = undefined
378
462
 
379
463
  // To detect the kind of state change, we need to:
@@ -1,4 +1,4 @@
1
- import { matchDeepDynamicRouteName, matchDynamicName } from './router/matchers'
1
+ import { matchDynamicName } from './router/matchers'
2
2
  import type { RouteNode } from './router/Route'
3
3
 
4
4
  export type Screen =
@@ -22,14 +22,12 @@ function convertDynamicRouteToReactNavigation(segment: string): string {
22
22
  return '*not-found'
23
23
  }
24
24
 
25
- const rest = matchDeepDynamicRouteName(segment)
26
- if (typeof rest === 'string') {
27
- return '*' + rest
28
- }
29
-
30
- const dynamicName = matchDynamicName(segment)
31
- if (typeof dynamicName === 'string') {
32
- return `:${dynamicName}`
25
+ const dynamicMatch = matchDynamicName(segment)
26
+ if (dynamicMatch) {
27
+ if (dynamicMatch.deep) {
28
+ return '*' + dynamicMatch.name
29
+ }
30
+ return `:${dynamicMatch.name}`
33
31
  }
34
32
 
35
33
  return segment