Repository navigation
fix: localization selector redirect path - #3237
Conversation
WalkthroughThis PR refactors localization path utilities by consolidating functions into a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/sdk/localization/useBindingSelector.ts`:
- Around line 163-167: The redirect currently drops the URL hash causing anchor
state loss; update the redirect construction in useBindingSelector (the block
calling buildRedirectUrl with binding.url and
`${window.location.pathname}${window.location.search}`) to also append
window.location.hash so the full fragment is preserved when calling
buildRedirectUrl; ensure the second argument becomes the full path+search+hash
string before assigning window.location.href.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d057fcb7-e1b5-4d77-a2bc-798796a2d0f0
📒 Files selected for processing (6)
packages/core/src/middleware.tspackages/core/src/sdk/localization/match-url.tspackages/core/src/sdk/localization/useBindingSelector.tspackages/core/src/sdk/ui/useLink.tspackages/core/src/utils/localization/bindingPaths.tspackages/core/test/utils/localization/bindingPaths.test.ts
77bf40e to
87c4ef2
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/utils/localization/bindingPaths.ts`:
- Around line 259-269: buildRedirectUrl treats currentUrl as a raw pathname but
callers pass a full URL; update buildRedirectUrl to first parse currentUrl into
a URL (using new URL(currentUrl, windowOrigin fallback) or try/catch to support
relative URLs) and derive a pathWithQueryHash = url.pathname + url.search +
url.hash, then call getPathOnly(pathWithQueryHash) and getPagePath(pathOnly) so
the binding prefix is removed correctly before composing the final redirect with
bindingUrl, pagePath and suffix; reference functions buildRedirectUrl,
getPathOnly, getPagePath and variables currentUrl, bindingUrl, suffix in your
change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5b1cba42-cc5d-4b0f-ba70-e7c8480403ac
📒 Files selected for processing (6)
packages/core/src/proxy.tspackages/core/src/sdk/localization/match-url.tspackages/core/src/sdk/localization/useBindingSelector.tspackages/core/src/sdk/ui/useLink.tspackages/core/src/utils/localization/bindingPaths.tspackages/core/test/utils/localization/bindingPaths.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/core/src/sdk/localization/useBindingSelector.ts
- packages/core/src/sdk/localization/match-url.ts
- packages/core/src/sdk/ui/useLink.ts
What's the purpose of this pull request?
When users switch locales via the Localization Selector, they are always redirected to the home page of the new locale instead of staying on the current page. For example, switching from pt-BR to en-US while on /pt-BR/products/item?color=red redirects to /en-US instead of /en-US/products/item?color=red.
How it works?
The save callback in
useBindingSelectorpreviously redirected directly tobinding.url(the binding's base URL), discarding the current page path and query string.The new function
buildRedirectUrlcombines the new binding URL with the extracted page path, preserving query strings and hash fragments. The save callback now callsbuildRedirectUrlwith the binding URL and the full current URL, so users stay on the same page after switching locales.File rename:
customPaths.tswas renamed tobindingPaths.tssince the file already contained general-purpose binding path utilities (matchesBindingPath) beyond just custom paths, and the new functions further broaden its scope. All 4 import sites and the test file were updated accordingly.How to test it?
Screen.Recording.2026-03-05.at.15.37.30.mov
References
Summary by CodeRabbit
Bug Fixes
Improvements