-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(router-core): process route tree should avoid float arithmetics #5688
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?
Conversation
WalkthroughScaled fractional scoring constants to integer equivalents and added deterministic traversal-order tracking; traversal now records visited route ids and builds Changes
Sequence Diagram(s)sequenceDiagram
participant Builder as RouteTreeBuilder
participant Traversal as traverseRoutes()
participant RoutesMap as routesById
participant Order as order:Array<string>
participant Flat as flatRoutes
Builder->>Traversal: start traversal(root)
Traversal->>RoutesMap: register route (routesById[id] = route)
Traversal->>Order: push(route.id)
Traversal->>Traversal: for i = 0..n-1: child = children[i]
Traversal->>RoutesMap: if routesById[child.id] exists → throw (duplicate id)
Traversal-->>Builder: traversal complete
Builder->>Flat: flatRoutes = Order.sort().map(id => routesById[id]!)
note right of Flat #D6EAF8: Deterministic flatRoutes built from recorded order
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
Comment |
|
View your CI Pipeline Execution ↗ for commit bb7543e
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/nitro-v2-vite-plugin
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-ssr-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-server
@tanstack/router-cli
@tanstack/router-core
@tanstack/router-devtools
@tanstack/router-devtools-core
@tanstack/router-generator
@tanstack/router-plugin
@tanstack/router-ssr-query-core
@tanstack/router-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-router-ssr-query
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-static-server-functions
@tanstack/start-storage-context
@tanstack/valibot-adapter
@tanstack/virtual-file-routes
@tanstack/zod-adapter
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/router-core/src/process-route-tree.ts (1)
13-23: LGTM - Consistent integer scaling applied.The constants have been correctly scaled by a factor of 10,000 to convert from floating-point to integer values. This preserves the relative ordering of routes while avoiding floating-point precision issues. Consider adding a brief comment explaining the scaling factor for future maintainability.
Example documentation comment:
+// Scoring constants scaled by 10,000 to use integer arithmetic and avoid floating-point precision issues const SLASH_SCORE = 7500 const STATIC_SEGMENT_SCORE = 10000
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/router-core/src/process-route-tree.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/router-core/src/process-route-tree.ts
packages/router-core/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep framework-agnostic core router logic in packages/router-core/
Files:
packages/router-core/src/process-route-tree.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (2)
packages/router-core/src/process-route-tree.ts (2)
25-52: LGTM - Function logic unchanged with new integer constants.The
handleParamfunction correctly uses the scaled integer constants. All arithmetic operations remain integer-based, which aligns with the PR objective of avoiding floating-point arithmetic.
54-179: Sorting logic is sound, but review comment contains incorrect assumptions about the code changes.The
sortRoutesfunction uses pure integer arithmetic throughout—all score constants are already integers (ranging from 100 to 10,000), and thehandleParamfunction performs only integer operations. There is no evidence of float-to-integer scaling by 10,000 as claimed in the review. The test file provides comprehensive coverage of sorting behavior, including edge cases with similar scores, confirming the algorithm works correctly.While the conclusion that sorting logic is preserved is correct, the justification provided in the review comment—that scores are "scaled uniformly by 10,000"—does not match the actual codebase implementation.
Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/router-core/src/process-route-tree.ts(3 hunks)packages/router-core/tests/processRouteTree.test.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/router-core/src/process-route-tree.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/router-core/tests/processRouteTree.test.ts
packages/router-core/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep framework-agnostic core router logic in packages/router-core/
Files:
packages/router-core/tests/processRouteTree.test.ts
🧠 Learnings (1)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad
PR: TanStack/router#5402
File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
Timestamp: 2025-10-08T08:11:47.088Z
Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.
Applied to files:
packages/router-core/tests/processRouteTree.test.ts
🧬 Code graph analysis (1)
packages/router-core/tests/processRouteTree.test.ts (1)
packages/router-core/src/process-route-tree.ts (1)
processRouteTree(195-242)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (1)
packages/router-core/tests/processRouteTree.test.ts (1)
443-462: Excellent test for verifying deterministic sorting.The test effectively verifies the fix for issue #5635 by testing all permutations of the input routes and ensuring consistent output order. The chosen routes are sufficiently complex (with optional params, static segments, and varying depths) to validate that the sorting behavior is deterministic regardless of input order.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Attempt at fixing #5635
Summary by CodeRabbit
Chores
User impact