-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(router-core): prevent search params mutation in middlewares #6397
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
fix(router-core): prevent search params mutation in middlewares #6397
Conversation
📝 WalkthroughWalkthroughThe PR prevents the search middleware from mutating the original search objects: Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 708eaeb
☁️ Nx Cloud last updated this comment at |
|
test fails |
While fixing TypeScript IDE errors in the test file, I realized that the test expectations were incorrect. The tests were passing all keys to I updated the tests to return partial objects instead and added This issue surfaced after adjusting the code for TypeScript errors, and I’ve confirmed that all tests are now passing. Sorry for the confusion caused by this change. |
What Changed
Modified
retainSearchParamsandstripSearchParamsto prevent mutation of the original search object by creating shallow copies before modification.Files Changed:
packages/router-core/src/searchMiddleware.tsretainSearchParams: Addedconst copy = { ...result }before modifyingstripSearchParams: Changedconst result = next(search)toconst result = { ...next(search) }Why
Fixes #6298
Problem:
useRef), the middlewares mutated the original objectExample of the bug:
How Tested
New Tests Added:
packages/router-core/tests/searchMiddleware.test.tstrueinput)Test Results:
Closes #6298
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.