-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor(router-core): Process routeTree into segment tree instead of flatRoutes [WIP] #5722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor(router-core): Process routeTree into segment tree instead of flatRoutes [WIP] #5722
Conversation
WalkthroughThis PR replaces legacy path parsing/matching and flat route lists with a segment-tree based route processor, adds a new route-tree implementation and tests, removes several path-related public exports, updates RouterCore to use a ProcessedTree, and marks MatchRouteOptions.caseSensitive as deprecated in docs and JSDoc. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Router
participant Old as "Old Processor\n(process-route-tree)"
participant New as "New Processor\n(new-process-route-tree)"
rect rgb(240,228,228)
Note over Old: Legacy flow (removed)
User->>Router: buildRouteTree(routeTree)
Router->>Old: processRouteTree(routeTree)
Old->>Old: sort & flatten routes
Old-->>Router: flatRoutes
User->>Router: getMatchedRoutes(pathname, routePathname)
Router->>Old: matchPathname / matchByPath
Old-->>Router: matchedRoutes
end
rect rgb(228,240,232)
Note over New: New flow (added)
User->>Router: buildRouteTree(routeTree)
Router->>New: processRouteTree(routeTree, caseSensitive)
New->>New: parseSegments -> build segment tree
New-->>Router: processedTree
User->>Router: getMatchedRoutes(pathname)
Router->>New: findRouteMatch(pathname, processedTree)
New->>New: DFS traversal, extract params
New-->>Router: matchedRoutes + foundRoute + params
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60–90 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx affected --targets=test:eslint,test:unit,tes... |
❌ Failed | 8m 35s | View ↗ |
nx run-many --target=build --exclude=examples/*... |
✅ Succeeded | 1m 26s | View ↗ |
☁️ Nx Cloud last updated this comment at 2025-11-13 22:25:03 UTC
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Warning
DO NOT MERGE
Design exploration of a rewrite of
processRouteTreeto yield a trie-like tree of segments. This should replacepackages/router-core/src/process-route-tree.tspackages/router-core/src/path.tsGoals:
Non-goals:
to-do:
/)Bench:
useMatchRoute)Notes:
useMatchRoute) does not care about therouteTree. It will match 2 arbitrary strings. This can lead to unexpected results, and is probably not the behavior we want in the long term.For now, this PR implements
findSingleMatchto preserve that behavior, and this method is slower than the current implementation. However, when we switch to matching against the routeTree (usingfindRouteMatchinstead), it will be faster.Summary by CodeRabbit
Deprecations
Breaking Changes
New Features
Tests / Quality