-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(router): ensure useParams returns parsed params when strict is false #6387
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
📝 WalkthroughWalkthroughThis PR adds support for Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (7)
🧰 Additional context used📓 Path-based instructions (2)**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{js,ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (11)📓 Common learnings📚 Learning: 2025-10-14T18:59:33.990ZApplied to files:
📚 Learning: 2025-12-21T12:52:35.231ZApplied to files:
📚 Learning: 2025-12-17T02:17:55.086ZApplied to files:
📚 Learning: 2025-12-06T15:03:07.223ZApplied to files:
📚 Learning: 2025-12-06T15:03:07.223ZApplied to files:
📚 Learning: 2025-10-08T08:11:47.088ZApplied to files:
📚 Learning: 2025-12-06T15:03:07.223ZApplied to files:
📚 Learning: 2025-10-01T18:31:35.420ZApplied to files:
📚 Learning: 2025-09-28T21:41:45.233ZApplied to files:
📚 Learning: 2025-09-22T00:56:49.237ZApplied to files:
🧬 Code graph analysis (3)packages/router-core/src/router.ts (1)
e2e/react-router/basic-file-based/src/routes/params-ps/strict-false/route.tsx (2)
e2e/react-router/basic-file-based/src/routes/params-ps/strict-false/$version.route.tsx (2)
⏰ 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)
🔇 Additional comments (9)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit e5ce02e
☁️ Nx Cloud last updated this comment at |
|
oops, clicked the wrong button and accidentally closed this! 😅 Reopening now. |
fixes #6385
This PR fixes issue #6385, where
useParams({ strict: false })in a parent route would return unparsed parameter values from a child route.The Fix
The fix the issue by ensuring that parsed parameters from child routes are correctly propagated to their parents when
strict: falseis used.Correct Parameter Propagation: The router's internal matching logic was updated. When a route match is being processed, it now correctly looks up the previous match's state, which includes its parsed parameters, and merges them. This ensures the parsed values are available throughout the route hierarchy.
Performance Optimization: As part of the fix, the mechanism for retrieving previous route matches was optimized. The implementation was changed from using
Array.prototype.find()to aMap-based lookup. This improves performance from O(n) to O(1), which is especially beneficial in applications with many routes.Changes
packages/router-core/src/router.ts: Updated the core routing logic to correctly handle parameter propagation and implemented theMap-based optimization for match retrieval.packages/react-router/tests/useParams.test.tsx: Added a new unit test to specifically verify thatuseParams({ strict: false })receives parsed values.e2e/react-router/basic-file-based/**: Added new routes and an e2e test to confirm the fix in a real-world file-based routing scenario.Summary by CodeRabbit
Release Notes
Tests
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.