-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(router-core): prevent infinite redirects with encoded URL params #4662
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
Conversation
- Normalize URLs during comparison in beforeLoad to handle encoding differences - Browser history stores encoded URLs while buildLocation may produce decoded URLs - This mismatch was causing ERR_TOO_MANY_REDIRECTS on page refresh with encoded params - Fixes infinite redirect loops when refreshing pages with special characters in URLs Fixes #4514
View your CI Pipeline Execution ↗ for commit 013155c
☁️ Nx Cloud last updated this comment at |
More templates
@tanstack/arktype-adapter
@tanstack/directive-functions-plugin
@tanstack/eslint-plugin-router
@tanstack/history
@tanstack/react-router
@tanstack/react-router-devtools
@tanstack/react-router-with-query
@tanstack/react-start
@tanstack/react-start-client
@tanstack/react-start-plugin
@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-utils
@tanstack/router-vite-plugin
@tanstack/server-functions-plugin
@tanstack/solid-router
@tanstack/solid-router-devtools
@tanstack/solid-start
@tanstack/solid-start-client
@tanstack/solid-start-plugin
@tanstack/solid-start-server
@tanstack/start-client-core
@tanstack/start-plugin-core
@tanstack/start-server-core
@tanstack/start-server-functions-client
@tanstack/start-server-functions-fetcher
@tanstack/start-server-functions-server
@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.
🚀
This may not be part of this fix, but should we be doing this normalization at these places as well?
LN#710 (getLocationChangeInfo -> hrefChanged
).
// router-core/router.ts
// getLocationChangeInfo function
export function getLocationChangeInfo(routerState: {
// ...
}) {
// ...
const hrefChanged = fromLocation?.href !== toLocation.href // here
// ...
}
LN#1642 (Router.commitLocation -> const isSameUrl
).
// router-core/router.ts
// Router class
commitLocation: CommitLocationFn = ({
...next
}) => {
// ...
const isSameUrl = this.latestLocation.href === next.href // here
// ...
@SeanCassiere there is a new private function that was added in router.ts, as part of #4581, called comparePaths, that does some cleaning for trailing slashes before comparing them and returning either true or false depending on wether the paths match or not. your comment had me thinking we should probably add this in there and start using that more broadly. I will look into that once this gets merged. |
Fixes infinite redirect loops when refreshing pages with encoded URL parameters.
Browser history stores encoded URLs while buildLocation produces decoded URLs, causing URL mismatch in beforeLoad comparison.
Solution: Added URL normalization during comparison to ensure consistent format.
Fixes #4514