fix: preserve locale in LinkButton internal hrefs#3232
Draft
lariciamota wants to merge 2 commits intofeat/multilanguagefrom
Draft
fix: preserve locale in LinkButton internal hrefs#3232lariciamota wants to merge 2 commits intofeat/multilanguagefrom
lariciamota wants to merge 2 commits intofeat/multilanguagefrom
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's the purpose of this pull request?
When navigating a store in a non-default locale (e.g.,
store.com/pt-BR), clicking the Sign In button redirected to/logininstead of/pt-BR/login. This caused the store to lose the locale context and render in the default language. The same issue affected any LinkButton in core whose href was a hardcoded internal path.How it works?
A new locale-aware
LinkButtonwrapper was created at the core, mirroring the existing Link pattern in core.The wrapper intercepts the href prop and, for any internal path (starting with
/), runs it throughresolveLinkfromuseLink. This applies the current locale prefix automatically — whether that's a Next.js locale segment (e.g.,/pt-BR/login) or a custom path prefix (e.g.,/brasil/login) — while leaving external URLs untouched.Components updated to use the new wrapper:
Going forward, any
LinkButtonin core should import fromsrc/components/ui/LinkButtoninstead of@faststore/ui, just asLinkis imported fromsrc/components/ui/Link.How to test it?
Before fix: redirected to /login (default locale, page renders in English)
After fix: redirected to /pt-BR/login (locale preserved)
Repeat with a store using a custom path prefix (e.g., /brasil) to verify the custom path is also applied
Starters Deploy Preview
(PR)
References