Repository navigation
fix: preserve locale in LinkButton internal hrefs - #3232
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
WalkthroughA new local Changes
Sequence DiagramsequenceDiagram
participant Component as Component
participant LinkButton as LinkButton<br/>(Wrapper)
participant useLink as useLink Hook
participant UILinkButton as UILinkButton<br/>(`@faststore/ui`)
Component->>LinkButton: href prop
LinkButton->>LinkButton: Check if internal<br/>(starts with /)
alt Internal Link
LinkButton->>useLink: resolveLink(href)
useLink-->>LinkButton: locale-prefixed href
LinkButton->>UILinkButton: render with finalHref
else External Link
LinkButton->>UILinkButton: render with original href
end
UILinkButton-->>Component: Rendered link
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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. |
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
Summary by CodeRabbit
New Features
Refactor