Skip to content

fix: preserve locale in LinkButton internal hrefs - #3232

Merged
lariciamota merged 2 commits into
feat/multilanguagefrom
fix/login-redirect
Mar 3, 2026
Merged

lariciamota merged 2 commits into
feat/multilanguagefrom
fix/login-redirect

Conversation

@lariciamota

@lariciamota lariciamota commented Feb 26, 2026 •

Copy link
Copy Markdown
Contributor

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 /login instead 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 LinkButton wrapper 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 through resolveLink from useLink. 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:

  • ButtonSignIn — /login
  • ButtonSignInFallback — /login (Suspense fallback)
  • EmptyGallery — button URLs (comes from CMS)

Going forward, any LinkButton in core should import from src/components/ui/LinkButton instead of @faststore/ui, just as Link is imported from src/components/ui/Link.

How to test it?

  • Run with localization enabled and test a non-default locale (e.g., en-US as default, pt-BR as secondary)
  • Navigate to the store under the secondary locale path (e.g., store.com/pt-BR)
  • Click the Sign In button in the navbar
    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

    • New LinkButton component with automatic locale-aware URL resolution for internal links.
  • Refactor

    • Updated multiple UI components to use the new LinkButton component for consistent internal link handling.

@lariciamota lariciamota self-assigned this Feb 26, 2026
@lariciamota lariciamota added the bug Something isn't working label Feb 26, 2026
@coderabbitai

coderabbitai Bot commented Feb 26, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75d6bbc and 7e458bb.

📒 Files selected for processing (5)
  • packages/core/src/components/sections/ProductGallery/EmptyGallery.tsx
  • packages/core/src/components/ui/Button/ButtonSignIn/ButtonSignIn.tsx
  • packages/core/src/components/ui/Button/ButtonSignIn/ButtonSignInFallback/ButtonSignInFallback.tsx
  • packages/core/src/components/ui/LinkButton/LinkButton.tsx
  • packages/core/src/components/ui/LinkButton/index.ts

Walkthrough

A new local LinkButton component wrapper is introduced that auto-resolves internal hrefs using locale-aware routing. Existing components are updated to use this new wrapper instead of importing directly from @faststore/ui.

Changes

Cohort / File(s) Summary
New LinkButton Component
packages/core/src/components/ui/LinkButton/LinkButton.tsx, packages/core/src/components/ui/LinkButton/index.ts
Introduces LinkButton wrapper that detects internal links (hrefs starting with /), resolves them to locale-prefixed equivalents via useLink, and renders the underlying UILinkButton with the computed finalHref. Includes barrel export for public API surface.
Component Import Updates
packages/core/src/components/sections/ProductGallery/EmptyGallery.tsx, packages/core/src/components/ui/Button/ButtonSignIn/ButtonSignIn.tsx, packages/core/src/components/ui/Button/ButtonSignIn/.../ButtonSignInFallback.tsx
Updates import sources to use the local LinkButton wrapper instead of UILinkButton from @faststore/ui; no changes to component logic or prop signatures.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested Reviewers

  • lemagnetic
  • hellofanny
  • gabpaladino

Poem

🔗 A LinkButton blooms, locale-aware and bright,
Internal paths now glow with routing light,
From slashes deep, it resolves the way,
Wrapping UI components in SEO's display. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: preserve locale in LinkButton internal hrefs' directly and clearly describes the main change: a fix that preserves locale information in LinkButton's internal href handling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/login-redirect

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci

codesandbox-ci Bot commented Feb 26, 2026 •

Copy link
Copy Markdown

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.

@lariciamota lariciamota changed the title fix: make login links be locale-aware fix: preserve locale in LinkButton internal hrefs Feb 26, 2026
@lariciamota
lariciamota marked this pull request as ready for review March 2, 2026 13:53
@lariciamota
lariciamota requested a review from a team as a code owner March 2, 2026 13:53
@lariciamota
lariciamota requested review from gabpaladino and renatamottam and removed request for a team March 2, 2026 13:53
@lariciamota
lariciamota merged commit 54ac6b9 into feat/multilanguage Mar 3, 2026
5 checks passed
@lariciamota
lariciamota deleted the fix/login-redirect branch March 3, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants