Skip to content

Commit f39eb9b

Browse files
authored
refactor(router-core): Process routeTree into segment tree instead of flatRoutes [WIP] (#5722)
1 parent ccf5483 commit f39eb9b

30 files changed

+2612
-1687
lines changed

docs/router/framework/react/api/router/MatchRouteOptionsType.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The `MatchRouteOptions` type is used to describe the options that can be used wh
88
```tsx
99
interface MatchRouteOptions {
1010
pending?: boolean
11-
caseSensitive?: boolean
11+
caseSensitive?: boolean /* @deprecated */
1212
includeSearch?: boolean
1313
fuzzy?: boolean
1414
}
@@ -24,11 +24,12 @@ The `MatchRouteOptions` type has the following properties:
2424
- Optional
2525
- If `true`, will match against pending location instead of the current location
2626

27-
### `caseSensitive` property
27+
### ~~`caseSensitive`~~ property (deprecated)
2828

2929
- Type: `boolean`
3030
- Optional
3131
- If `true`, will match against the current location with case sensitivity
32+
- Declare case sensitivity in the route definition instead, or globally for all routes using the `caseSensitive` option on the router
3233

3334
### `includeSearch` property
3435

docs/router/framework/react/how-to/debug-router-issues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const route = createRoute({
109109
```tsx
110110
// Debug route tree in console
111111
console.log('Route tree:', router.routeTree)
112-
console.log('All routes:', router.flatRoutes)
112+
console.log('All routes:', router.routesById)
113113
```
114114

115115
3. **Check Parent Route Configuration**

packages/react-router/src/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ export {
88
trimPathRight,
99
trimPath,
1010
resolvePath,
11-
parsePathname,
1211
interpolatePath,
13-
matchPathname,
14-
matchByPath,
1512
rootRouteId,
1613
defaultSerializeError,
1714
defaultParseSearch,
@@ -37,7 +34,6 @@ export type {
3734
RemoveTrailingSlashes,
3835
RemoveLeadingSlashes,
3936
ActiveOptions,
40-
Segment,
4137
ResolveRelativePath,
4238
RootRouteId,
4339
AnyPathParams,

packages/react-router/src/useBlocker.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ export function useBlocker(
177177
location: HistoryLocation,
178178
): AnyShouldBlockFnLocation {
179179
const parsedLocation = router.parseLocation(location)
180-
const matchedRoutes = router.getMatchedRoutes(
181-
parsedLocation.pathname,
182-
undefined,
183-
)
180+
const matchedRoutes = router.getMatchedRoutes(parsedLocation.pathname)
184181
if (matchedRoutes.foundRoute === undefined) {
185182
throw new Error(`No route found for location ${location.href}`)
186183
}

packages/react-router/tests/Matches.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ describe('matching on different param types', () => {
271271
path: '/optional-{-$id}',
272272
nav: '/optional-',
273273
params: {},
274-
matchParams: { id: '' },
274+
matchParams: {},
275275
},
276276
{
277277
name: 'optional param with suffix and value',
@@ -285,14 +285,14 @@ describe('matching on different param types', () => {
285285
path: '/{-$id}-optional',
286286
nav: '/-optional',
287287
params: {},
288-
matchParams: { id: '' },
288+
matchParams: {},
289289
},
290290
{
291291
name: 'optional param with required param, prefix, suffix, wildcard and no value',
292292
path: `/$foo/a{-$id}-optional/$`,
293293
nav: '/bar/a-optional/qux',
294-
params: { foo: 'bar', id: '', _splat: 'qux', '*': 'qux' },
295-
matchParams: { foo: 'bar', id: '', _splat: 'qux', '*': 'qux' },
294+
params: { foo: 'bar', _splat: 'qux', '*': 'qux' },
295+
matchParams: { foo: 'bar', _splat: 'qux', '*': 'qux' },
296296
},
297297
{
298298
name: 'optional param with required param, prefix, suffix, wildcard and value',

packages/react-router/tests/router.test.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,18 +1697,6 @@ describe('route ids should be consistent after rebuilding the route tree', () =>
16971697
})
16981698

16991699
describe('route id uniqueness', () => {
1700-
it('flatRoute should not have routes with duplicated route ids', () => {
1701-
const { router } = createTestRouter({
1702-
history: createMemoryHistory({ initialEntries: ['/'] }),
1703-
})
1704-
const routeIdSet = new Set<string>()
1705-
1706-
router.flatRoutes.forEach((route) => {
1707-
expect(routeIdSet.has(route.id)).toBe(false)
1708-
routeIdSet.add(route.id)
1709-
})
1710-
})
1711-
17121700
it('routesById should not have routes duplicated route ids', () => {
17131701
const { router } = createTestRouter({
17141702
history: createMemoryHistory({ initialEntries: ['/'] }),

packages/router-core/src/Matches.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ export interface MatchRouteOptions {
272272
* If `true`, will match against the current location with case sensitivity.
273273
*
274274
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/MatchRouteOptionsType#casesensitive-property)
275+
*
276+
* @deprecated Declare case sensitivity in the route definition instead, or globally for all routes using the `caseSensitive` option on the router.
275277
*/
276278
caseSensitive?: boolean
277279
/**

packages/router-core/src/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,8 @@ export {
100100
removeTrailingSlash,
101101
exactPathTest,
102102
resolvePath,
103-
parsePathname,
104103
interpolatePath,
105-
matchPathname,
106-
matchByPath,
107104
} from './path'
108-
export type { Segment } from './path'
109105
export { encode, decode } from './qss'
110106
export { rootRouteId } from './root'
111107
export type { RootRouteId } from './root'
@@ -193,8 +189,6 @@ export type {
193189
RootRoute,
194190
FilebaseRouteOptionsInterface,
195191
} from './route'
196-
export { processRouteTree } from './process-route-tree'
197-
export type { ProcessRouteTreeResult } from './process-route-tree'
198192
export {
199193
defaultSerializeError,
200194
getLocationChangeInfo,

packages/router-core/src/lru-cache.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type LRUCache<TKey, TValue> = {
22
get: (key: TKey) => TValue | undefined
33
set: (key: TKey, value: TValue) => void
4+
clear: () => void
45
}
56

67
export function createLRUCache<TKey, TValue>(
@@ -64,5 +65,10 @@ export function createLRUCache<TKey, TValue>(
6465
cache.set(key, entry)
6566
}
6667
},
68+
clear() {
69+
cache.clear()
70+
oldest = undefined
71+
newest = undefined
72+
},
6773
}
6874
}

0 commit comments

Comments
 (0)