one 1.2.20 → 1.2.22

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 (289) 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 +3 -2
  7. package/dist/cjs/cli/buildPage.js +3 -2
  8. package/dist/cjs/cli/buildPage.js.map +1 -1
  9. package/dist/cjs/cli/buildPage.native.js +3 -2
  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 +26 -19
  50. package/dist/cjs/fork/useLinking.js +31 -19
  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/router/getRoutes.cjs +4 -5
  65. package/dist/cjs/router/getRoutes.js +2 -2
  66. package/dist/cjs/router/getRoutes.js.map +1 -1
  67. package/dist/cjs/router/getRoutes.native.js +4 -5
  68. package/dist/cjs/router/getRoutes.native.js.map +1 -1
  69. package/dist/cjs/router/matchers.cjs +9 -1
  70. package/dist/cjs/router/matchers.js +4 -1
  71. package/dist/cjs/router/matchers.js.map +1 -1
  72. package/dist/cjs/router/matchers.native.js +10 -2
  73. package/dist/cjs/router/matchers.native.js.map +1 -1
  74. package/dist/cjs/router/matchers.test.cjs +7 -1
  75. package/dist/cjs/router/matchers.test.js +1 -1
  76. package/dist/cjs/router/matchers.test.js.map +1 -1
  77. package/dist/cjs/router/matchers.test.native.js +7 -1
  78. package/dist/cjs/router/matchers.test.native.js.map +1 -1
  79. package/dist/cjs/router/router.cjs +6 -6
  80. package/dist/cjs/router/router.js +6 -6
  81. package/dist/cjs/router/router.js.map +1 -1
  82. package/dist/cjs/router/router.native.js +6 -6
  83. package/dist/cjs/router/router.native.js.map +1 -1
  84. package/dist/cjs/router/useViteRoutes.cjs +12 -17
  85. package/dist/cjs/router/useViteRoutes.js +12 -17
  86. package/dist/cjs/router/useViteRoutes.js.map +2 -2
  87. package/dist/cjs/router/useViteRoutes.native.js +12 -0
  88. package/dist/cjs/router/useViteRoutes.native.js.map +1 -1
  89. package/dist/cjs/router/utils/getNavigateAction.cjs +2 -2
  90. package/dist/cjs/router/utils/getNavigateAction.js +2 -2
  91. package/dist/cjs/router/utils/getNavigateAction.js.map +1 -1
  92. package/dist/cjs/router/utils/getNavigateAction.native.js +2 -2
  93. package/dist/cjs/router/utils/getNavigateAction.native.js.map +1 -1
  94. package/dist/cjs/server/oneServe.cjs +4 -3
  95. package/dist/cjs/server/oneServe.js +6 -3
  96. package/dist/cjs/server/oneServe.js.map +1 -1
  97. package/dist/cjs/server/oneServe.native.js +5 -4
  98. package/dist/cjs/server/oneServe.native.js.map +1 -1
  99. package/dist/cjs/vite/one.cjs +9 -12
  100. package/dist/cjs/vite/one.js +7 -7
  101. package/dist/cjs/vite/one.js.map +1 -1
  102. package/dist/cjs/vite/one.native.js +10 -15
  103. package/dist/cjs/vite/one.native.js.map +1 -1
  104. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +12 -7
  105. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +11 -7
  106. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
  107. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +12 -7
  108. package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
  109. package/dist/esm/cli/build.js +10 -2
  110. package/dist/esm/cli/build.js.map +1 -1
  111. package/dist/esm/cli/build.mjs +11 -2
  112. package/dist/esm/cli/build.mjs.map +1 -1
  113. package/dist/esm/cli/build.native.js +44 -19
  114. package/dist/esm/cli/build.native.js.map +1 -1
  115. package/dist/esm/cli/buildPage.js +3 -2
  116. package/dist/esm/cli/buildPage.js.map +1 -1
  117. package/dist/esm/cli/buildPage.mjs +3 -2
  118. package/dist/esm/cli/buildPage.mjs.map +1 -1
  119. package/dist/esm/cli/buildPage.native.js +3 -2
  120. package/dist/esm/cli/buildPage.native.js.map +1 -1
  121. package/dist/esm/createApp.js +73 -66
  122. package/dist/esm/createApp.js.map +2 -2
  123. package/dist/esm/createApp.mjs +23 -16
  124. package/dist/esm/createApp.mjs.map +1 -1
  125. package/dist/esm/createHandleRequest.js +10 -6
  126. package/dist/esm/createHandleRequest.js.map +1 -1
  127. package/dist/esm/createHandleRequest.mjs +10 -6
  128. package/dist/esm/createHandleRequest.mjs.map +1 -1
  129. package/dist/esm/createHandleRequest.native.js +10 -6
  130. package/dist/esm/createHandleRequest.native.js.map +1 -1
  131. package/dist/esm/fork/NavigationContainer.js +4 -1
  132. package/dist/esm/fork/NavigationContainer.js.map +1 -1
  133. package/dist/esm/fork/NavigationContainer.mjs +1 -1
  134. package/dist/esm/fork/NavigationContainer.mjs.map +1 -1
  135. package/dist/esm/fork/NavigationContainer.native.js +1 -1
  136. package/dist/esm/fork/NavigationContainer.native.js.map +1 -1
  137. package/dist/esm/fork/createMemoryHistory.js +2 -2
  138. package/dist/esm/fork/createMemoryHistory.js.map +1 -1
  139. package/dist/esm/fork/createMemoryHistory.mjs +2 -2
  140. package/dist/esm/fork/createMemoryHistory.mjs.map +1 -1
  141. package/dist/esm/fork/createMemoryHistory.native.js +2 -2
  142. package/dist/esm/fork/createMemoryHistory.native.js.map +1 -1
  143. package/dist/esm/fork/extractPathFromURL.js +1 -1
  144. package/dist/esm/fork/extractPathFromURL.js.map +1 -1
  145. package/dist/esm/fork/extractPathFromURL.mjs +1 -1
  146. package/dist/esm/fork/extractPathFromURL.mjs.map +1 -1
  147. package/dist/esm/fork/extractPathFromURL.native.js +1 -1
  148. package/dist/esm/fork/extractPathFromURL.native.js.map +1 -1
  149. package/dist/esm/fork/getPathFromState-mods.js +2 -2
  150. package/dist/esm/fork/getPathFromState-mods.js.map +1 -1
  151. package/dist/esm/fork/getPathFromState-mods.mjs +2 -2
  152. package/dist/esm/fork/getPathFromState-mods.mjs.map +1 -1
  153. package/dist/esm/fork/getPathFromState-mods.native.js +2 -2
  154. package/dist/esm/fork/getPathFromState-mods.native.js.map +1 -1
  155. package/dist/esm/fork/getStateFromPath-mods.js +18 -15
  156. package/dist/esm/fork/getStateFromPath-mods.js.map +1 -1
  157. package/dist/esm/fork/getStateFromPath-mods.mjs +20 -19
  158. package/dist/esm/fork/getStateFromPath-mods.mjs.map +1 -1
  159. package/dist/esm/fork/getStateFromPath-mods.native.js +19 -18
  160. package/dist/esm/fork/getStateFromPath-mods.native.js.map +1 -1
  161. package/dist/esm/fork/getStateFromPath.js +1 -1
  162. package/dist/esm/fork/getStateFromPath.js.map +1 -1
  163. package/dist/esm/fork/getStateFromPath.mjs +1 -1
  164. package/dist/esm/fork/getStateFromPath.mjs.map +1 -1
  165. package/dist/esm/fork/getStateFromPath.native.js +1 -1
  166. package/dist/esm/fork/useLinking.js +31 -18
  167. package/dist/esm/fork/useLinking.js.map +1 -1
  168. package/dist/esm/fork/useLinking.mjs +26 -19
  169. package/dist/esm/fork/useLinking.mjs.map +1 -1
  170. package/dist/esm/fork/useLinking.native.js +2 -1
  171. package/dist/esm/fork/useLinking.native.js.map +1 -1
  172. package/dist/esm/getReactNavigationConfig.js +3 -6
  173. package/dist/esm/getReactNavigationConfig.js.map +1 -1
  174. package/dist/esm/getReactNavigationConfig.mjs +3 -5
  175. package/dist/esm/getReactNavigationConfig.mjs.map +1 -1
  176. package/dist/esm/getReactNavigationConfig.native.js +3 -5
  177. package/dist/esm/getReactNavigationConfig.native.js.map +1 -1
  178. package/dist/esm/hooks.js +1 -1
  179. package/dist/esm/hooks.js.map +1 -1
  180. package/dist/esm/hooks.mjs +1 -1
  181. package/dist/esm/hooks.mjs.map +1 -1
  182. package/dist/esm/hooks.native.js +4 -1
  183. package/dist/esm/hooks.native.js.map +1 -1
  184. package/dist/esm/router/getRoutes.js +2 -3
  185. package/dist/esm/router/getRoutes.js.map +1 -1
  186. package/dist/esm/router/getRoutes.mjs +5 -6
  187. package/dist/esm/router/getRoutes.mjs.map +1 -1
  188. package/dist/esm/router/getRoutes.native.js +5 -6
  189. package/dist/esm/router/getRoutes.native.js.map +1 -1
  190. package/dist/esm/router/matchers.js +4 -1
  191. package/dist/esm/router/matchers.js.map +1 -1
  192. package/dist/esm/router/matchers.mjs +9 -1
  193. package/dist/esm/router/matchers.mjs.map +1 -1
  194. package/dist/esm/router/matchers.native.js +10 -2
  195. package/dist/esm/router/matchers.native.js.map +1 -1
  196. package/dist/esm/router/matchers.test.js +1 -1
  197. package/dist/esm/router/matchers.test.js.map +1 -1
  198. package/dist/esm/router/matchers.test.mjs +7 -1
  199. package/dist/esm/router/matchers.test.mjs.map +1 -1
  200. package/dist/esm/router/matchers.test.native.js +7 -1
  201. package/dist/esm/router/matchers.test.native.js.map +1 -1
  202. package/dist/esm/router/router.js +6 -6
  203. package/dist/esm/router/router.js.map +1 -1
  204. package/dist/esm/router/router.mjs +6 -6
  205. package/dist/esm/router/router.mjs.map +1 -1
  206. package/dist/esm/router/router.native.js +6 -6
  207. package/dist/esm/router/router.native.js.map +1 -1
  208. package/dist/esm/router/useViteRoutes.js +12 -17
  209. package/dist/esm/router/useViteRoutes.js.map +1 -1
  210. package/dist/esm/router/useViteRoutes.mjs +11 -18
  211. package/dist/esm/router/useViteRoutes.mjs.map +1 -1
  212. package/dist/esm/router/useViteRoutes.native.js +11 -1
  213. package/dist/esm/router/useViteRoutes.native.js.map +1 -1
  214. package/dist/esm/router/utils/getNavigateAction.js +2 -2
  215. package/dist/esm/router/utils/getNavigateAction.js.map +1 -1
  216. package/dist/esm/router/utils/getNavigateAction.mjs +2 -2
  217. package/dist/esm/router/utils/getNavigateAction.mjs.map +1 -1
  218. package/dist/esm/router/utils/getNavigateAction.native.js +2 -2
  219. package/dist/esm/router/utils/getNavigateAction.native.js.map +1 -1
  220. package/dist/esm/server/oneServe.js +6 -3
  221. package/dist/esm/server/oneServe.js.map +1 -1
  222. package/dist/esm/server/oneServe.mjs +4 -3
  223. package/dist/esm/server/oneServe.mjs.map +1 -1
  224. package/dist/esm/server/oneServe.native.js +4 -3
  225. package/dist/esm/server/oneServe.native.js.map +1 -1
  226. package/dist/esm/vite/one.js +9 -9
  227. package/dist/esm/vite/one.js.map +1 -1
  228. package/dist/esm/vite/one.mjs +9 -12
  229. package/dist/esm/vite/one.mjs.map +1 -1
  230. package/dist/esm/vite/one.native.js +10 -15
  231. package/dist/esm/vite/one.native.js.map +1 -1
  232. package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +11 -7
  233. package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
  234. package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +12 -7
  235. package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
  236. package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +12 -7
  237. package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
  238. package/package.json +9 -9
  239. package/src/cli/build.ts +26 -1
  240. package/src/cli/buildPage.ts +3 -1
  241. package/src/createApp.tsx +28 -21
  242. package/src/createHandleRequest.ts +34 -0
  243. package/src/fork/NavigationContainer.tsx +8 -0
  244. package/src/fork/createMemoryHistory.tsx +8 -0
  245. package/src/fork/extractPathFromURL.ts +6 -0
  246. package/src/fork/getPathFromState-mods.ts +2 -7
  247. package/src/fork/getStateFromPath-mods.ts +43 -17
  248. package/src/fork/getStateFromPath.ts +1 -1
  249. package/src/fork/useLinking.native.ts +1 -1
  250. package/src/fork/useLinking.ts +80 -5
  251. package/src/getReactNavigationConfig.ts +7 -9
  252. package/src/hooks.tsx +21 -19
  253. package/src/router/getRoutes.ts +3 -6
  254. package/src/router/matchers.test.ts +2 -2
  255. package/src/router/matchers.ts +22 -6
  256. package/src/router/router.ts +6 -6
  257. package/src/router/useViteRoutes.tsx +19 -17
  258. package/src/router/utils/getNavigateAction.ts +3 -2
  259. package/src/server/oneServe.ts +13 -0
  260. package/src/types.ts +1 -0
  261. package/src/vite/one.ts +9 -13
  262. package/src/vite/plugins/fileSystemRouterPlugin.tsx +17 -5
  263. package/src/vite/types.ts +2 -0
  264. package/types/cli/build.d.ts.map +1 -1
  265. package/types/cli/buildPage.d.ts +1 -1
  266. package/types/cli/buildPage.d.ts.map +1 -1
  267. package/types/createApp.d.ts.map +1 -1
  268. package/types/createHandleRequest.d.ts.map +1 -1
  269. package/types/fork/NavigationContainer.d.ts.map +1 -1
  270. package/types/fork/createMemoryHistory.d.ts.map +1 -1
  271. package/types/fork/extractPathFromURL.d.ts.map +1 -1
  272. package/types/fork/getStateFromPath-mods.d.ts +7 -10
  273. package/types/fork/getStateFromPath-mods.d.ts.map +1 -1
  274. package/types/fork/useLinking.d.ts.map +1 -1
  275. package/types/getReactNavigationConfig.d.ts.map +1 -1
  276. package/types/hooks.d.ts.map +1 -1
  277. package/types/router/getRoutes.d.ts.map +1 -1
  278. package/types/router/matchers.d.ts +10 -3
  279. package/types/router/matchers.d.ts.map +1 -1
  280. package/types/router/useViteRoutes.d.ts +2 -0
  281. package/types/router/useViteRoutes.d.ts.map +1 -1
  282. package/types/router/utils/getNavigateAction.d.ts.map +1 -1
  283. package/types/server/oneServe.d.ts.map +1 -1
  284. package/types/types.d.ts +1 -0
  285. package/types/types.d.ts.map +1 -1
  286. package/types/vite/one.d.ts.map +1 -1
  287. package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
  288. package/types/vite/types.d.ts +1 -0
  289. package/types/vite/types.d.ts.map +1 -1
@@ -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'
@@ -158,7 +159,7 @@ export function useLinking(
158
159
  const rootState = navigation?.getRootState()
159
160
  // Make sure that the routes in the state exist in the root navigator
160
161
  // Otherwise there's an error in the linking configuration
161
- return state?.routes.some((r) => !rootState?.routeNames.includes(r.name))
162
+ return state?.routes.some((r) => !rootState?.routeNames?.includes(r.name))
162
163
  },
163
164
  [ref]
164
165
  )
@@ -180,8 +181,15 @@ export function useLinking(
180
181
 
181
182
  const path = location ? location.pathname + location.search : undefined
182
183
 
184
+ if (process.env.ONE_DEBUG_ROUTER) {
185
+ console.info(`[one] 🔍 getInitialState path=${path}`)
186
+ }
187
+
183
188
  if (path) {
184
189
  value = getStateFromPathRef.current(path, configRef.current)
190
+ if (process.env.ONE_DEBUG_ROUTER) {
191
+ console.info(`[one] 🔍 getInitialState result:`, JSON.stringify(value, null, 2))
192
+ }
185
193
  }
186
194
 
187
195
  // If the link were handled, it gets cleared in NavigationContainer
@@ -223,6 +231,12 @@ export function useLinking(
223
231
 
224
232
  const previousIndex = previousIndexRef.current ?? 0
225
233
 
234
+ if (process.env.ONE_DEBUG_ROUTER) {
235
+ console.info(
236
+ `[one] 📜 history.listen path=${path} index=${index} prevIndex=${previousIndex}`
237
+ )
238
+ }
239
+
226
240
  previousIndexRef.current = index
227
241
  pendingPopStatePathRef.current = path
228
242
 
@@ -232,12 +246,19 @@ export function useLinking(
232
246
  const record = history.get(index)
233
247
 
234
248
  if (record?.path === path && record?.state) {
249
+ if (process.env.ONE_DEBUG_ROUTER) {
250
+ console.info(`[one] 📜 history record found, resetRoot to:`, record.state)
251
+ }
235
252
  navigation.resetRoot(record.state)
236
253
  return
237
254
  }
238
255
 
239
256
  const state = getStateFromPathRef.current(path, configRef.current)
240
257
 
258
+ if (process.env.ONE_DEBUG_ROUTER) {
259
+ console.info(`[one] 📜 getStateFromPath result:`, state)
260
+ }
261
+
241
262
  // We should only dispatch an action when going forward
242
263
  // Otherwise the action will likely add items to history, which would mess things up
243
264
  if (state) {
@@ -246,6 +267,9 @@ export function useLinking(
246
267
  // Make sure that the routes in the state exist in the root navigator
247
268
  // Otherwise there's an error in the linking configuration
248
269
  if (validateRoutesNotExistInRootState(state)) {
270
+ if (process.env.ONE_DEBUG_ROUTER) {
271
+ console.info(`[one] 📜 routes not in root state, skipping`)
272
+ }
249
273
  return
250
274
  }
251
275
 
@@ -256,6 +280,10 @@ export function useLinking(
256
280
  ) {
257
281
  const action = getActionFromStateRef.current(state, configRef.current)
258
282
 
283
+ if (process.env.ONE_DEBUG_ROUTER) {
284
+ console.info(`[one] 📜 dispatching action:`, action)
285
+ }
286
+
259
287
  if (action !== undefined) {
260
288
  try {
261
289
  navigation.dispatch(action)
@@ -269,13 +297,22 @@ export function useLinking(
269
297
  )
270
298
  }
271
299
  } else {
300
+ if (process.env.ONE_DEBUG_ROUTER) {
301
+ console.info(`[one] 📜 no action, resetRoot`)
302
+ }
272
303
  navigation.resetRoot(state)
273
304
  }
274
305
  } else {
306
+ if (process.env.ONE_DEBUG_ROUTER) {
307
+ console.info(`[one] 📜 going back, resetRoot`)
308
+ }
275
309
  navigation.resetRoot(state)
276
310
  }
277
311
  } else {
278
312
  // if current path didn't return any state, we should revert to initial state
313
+ if (process.env.ONE_DEBUG_ROUTER) {
314
+ console.info(`[one] 📜 no state for path, resetRoot to undefined`)
315
+ }
279
316
  navigation.resetRoot(state)
280
317
  }
281
318
  })
@@ -292,6 +329,11 @@ export function useLinking(
292
329
  ): string => {
293
330
  let path
294
331
 
332
+ if (process.env.ONE_DEBUG_ROUTER) {
333
+ console.info(`[one] 📜 getPathForRoute - route:`, route)
334
+ console.info(`[one] 📜 getPathForRoute - state:`, JSON.stringify(state, null, 2))
335
+ }
336
+
295
337
  // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
296
338
  // This makes sure that we preserve the original URL for wildcard routes
297
339
  if (route?.path) {
@@ -315,6 +357,9 @@ export function useLinking(
315
357
 
316
358
  if (path == null) {
317
359
  path = getPathFromStateRef.current(state, configRef.current)
360
+ if (process.env.ONE_DEBUG_ROUTER) {
361
+ console.info(`[one] 📜 getPathForRoute - computed from state:`, path)
362
+ }
318
363
  }
319
364
 
320
365
  // @modified - start: One will handle hashes itself, so these lines are not needed
@@ -340,14 +385,41 @@ export function useLinking(
340
385
  if (ref.current) {
341
386
  // We need to record the current metadata on the first render if they aren't set
342
387
  // This will allow the initial state to be in the history entry
343
- const state = ref.current.getRootState()
388
+ // @modified - start: Use routerRootState instead of getRootState() to avoid stale state
389
+ // getRootState() can return incomplete state during initial render before children mount
390
+ // routerRootState is updated via navigation listener callbacks which only fire with complete state
391
+ const refState = ref.current.getRootState()
392
+ const state = (routerRootState || refState) as NavigationState | undefined
393
+
394
+ if (process.env.ONE_DEBUG_ROUTER) {
395
+ console.info(
396
+ `[one] 📜 useEffect initial state check - refState:`,
397
+ JSON.stringify(refState, null, 2)
398
+ )
399
+ console.info(
400
+ `[one] 📜 useEffect initial state check - routerRootState:`,
401
+ JSON.stringify(routerRootState, null, 2)
402
+ )
403
+ }
404
+ // @modified - end
344
405
 
345
406
  if (state) {
346
407
  const route = findFocusedRoute(state)
408
+
409
+ if (process.env.ONE_DEBUG_ROUTER) {
410
+ console.info(`[one] 📜 useEffect focused route:`, route)
411
+ }
412
+
347
413
  const path = getPathForRoute(route, state)
348
414
 
415
+ if (process.env.ONE_DEBUG_ROUTER) {
416
+ console.info(`[one] 📜 initial history.replace - state:`, JSON.stringify(state, null, 2))
417
+ console.info(`[one] 📜 initial history.replace - focusedRoute:`, route)
418
+ console.info(`[one] 📜 initial history.replace - computed path:`, path)
419
+ }
420
+
349
421
  if (previousStateRef.current === undefined) {
350
- previousStateRef.current = state
422
+ previousStateRef.current = refState
351
423
  }
352
424
 
353
425
  history.replace({ path, state })
@@ -362,7 +434,10 @@ export function useLinking(
362
434
  }
363
435
 
364
436
  const previousState = previousStateRef.current
365
- const state = navigation.getRootState()
437
+ // @modified - start: Use routerRootState for path calculation, refState for comparison
438
+ const refState = navigation.getRootState()
439
+ const state = (routerRootState || refState) as NavigationState | undefined
440
+ // @modified - end
366
441
 
367
442
  // root state may not available, for example when root navigators switch inside the container
368
443
  if (!state) {
@@ -373,7 +448,7 @@ export function useLinking(
373
448
  const route = findFocusedRoute(state)
374
449
  const path = getPathForRoute(route, state)
375
450
 
376
- previousStateRef.current = state
451
+ previousStateRef.current = refState
377
452
  pendingPopStatePathRef.current = undefined
378
453
 
379
454
  // 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
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
  }
@@ -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
  }
@@ -65,7 +65,7 @@ export function initialize(
65
65
  throw new Error('No routes found')
66
66
  }
67
67
 
68
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER && routeNode) {
68
+ if (process.env.ONE_DEBUG_ROUTER && routeNode) {
69
69
  const formatRouteTree = (node: RouteNode, indent = '', isLast = true): string => {
70
70
  const prefix = indent + (isLast ? '└─ ' : '├─ ')
71
71
  const childIndent = indent + (isLast ? ' ' : '│ ')
@@ -180,7 +180,7 @@ export function push(url: OneRouter.Href, options?: OneRouter.LinkToOptions) {
180
180
  }
181
181
 
182
182
  export function dismiss(count?: number) {
183
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
183
+ if (process.env.ONE_DEBUG_ROUTER) {
184
184
  console.info(`[one] 🔙 dismiss${count ? ` (${count})` : ''}`)
185
185
  }
186
186
  navigationRef?.dispatch(StackActions.pop(count))
@@ -199,14 +199,14 @@ export function setParams(params: OneRouter.InpurRouteParamsGeneric = {}) {
199
199
  }
200
200
 
201
201
  export function dismissAll() {
202
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
202
+ if (process.env.ONE_DEBUG_ROUTER) {
203
203
  console.info(`[one] 🔙 dismissAll`)
204
204
  }
205
205
  navigationRef?.dispatch(StackActions.popToTop())
206
206
  }
207
207
 
208
208
  export function goBack() {
209
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
209
+ if (process.env.ONE_DEBUG_ROUTER) {
210
210
  console.info(`[one] 🔙 goBack`)
211
211
  }
212
212
  assertIsReady(navigationRef)
@@ -250,7 +250,7 @@ export function updateState(state: OneRouter.ResultState, nextStateParam = state
250
250
  const nextRouteInfo = getRouteInfo(state)
251
251
 
252
252
  if (!deepEqual(routeInfo, nextRouteInfo)) {
253
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
253
+ if (process.env.ONE_DEBUG_ROUTER) {
254
254
  const from = routeInfo?.pathname || '(initial)'
255
255
  const to = nextRouteInfo.pathname
256
256
  const params = Object.keys(nextRouteInfo.params || {}).length
@@ -402,7 +402,7 @@ export function preloadRoute(href: string) {
402
402
  }
403
403
 
404
404
  export async function linkTo(href: string, event?: string, options?: OneRouter.LinkToOptions) {
405
- if (process.env.NODE_ENV === 'development' && process.env.ONE_DEBUG_ROUTER) {
405
+ if (process.env.ONE_DEBUG_ROUTER) {
406
406
  console.info(`[one] 🔗 ${event || 'NAVIGATE'} ${href}`)
407
407
  }
408
408
 
@@ -26,6 +26,17 @@ 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
+
29
40
  export function loadRoutes(
30
41
  paths: GlobbedRouteImports,
31
42
  routerRoot: string,
@@ -77,6 +88,14 @@ export function globbedRoutesToRouteContext(
77
88
  return loadedRoutes[id]
78
89
  }
79
90
 
91
+ // check if this route was preloaded before hydration
92
+ const preloadKey = id.replace('./', `/${routerRoot}/`)
93
+ const preloaded = getPreloadedModule(preloadKey)
94
+ if (preloaded) {
95
+ loadedRoutes[id] = preloaded
96
+ return preloaded
97
+ }
98
+
80
99
  if (typeof routesSync[id] !== 'function') {
81
100
  return routesSync[id]
82
101
  }
@@ -98,23 +117,6 @@ export function globbedRoutesToRouteContext(
98
117
  console.error(`Error loading route`, id, err, new Error().stack)
99
118
  loadedRoutes[id] = {
100
119
  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
120
  }
119
121
  delete promises[id]
120
122
  })
@@ -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
  }