Skip to content

fix: switching locales redirects user to the home page#1990

Merged
agurtovoy merged 1 commit into
canaryfrom
aleksey/eng-7754-locale-switch-redirects-user-to-the-home-page
Feb 25, 2025
Merged

fix: switching locales redirects user to the home page#1990
agurtovoy merged 1 commit into
canaryfrom
aleksey/eng-7754-locale-switch-redirects-user-to-the-home-page

Conversation

@agurtovoy

Copy link
Copy Markdown
Contributor

What/Why?

When switching to a different locale, the user should remain on their current page.

Testing

Before

Kapture.2025-02-19.at.23.00.26.mp4

After

Kapture.2025-02-20.at.15.55.17.mp4

@linear

linear Bot commented Feb 20, 2025

Copy link
Copy Markdown

@vercel

vercel Bot commented Feb 20, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
catalyst-canary ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 25, 2025 0:26am
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
catalyst ⬜️ Ignored (Inspect) Feb 25, 2025 0:26am
catalyst-au ⬜️ Ignored (Inspect) Visit Preview Feb 25, 2025 0:26am
catalyst-soul ⬜️ Ignored (Inspect) Visit Preview Feb 25, 2025 0:26am
catalyst-uk ⬜️ Ignored (Inspect) Visit Preview Feb 25, 2025 0:26am

@changeset-bot

changeset-bot Bot commented Feb 20, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 91bff63

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bigcommerce/catalyst-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread core/components/header/header-section.tsx Outdated
useEffect(() => {
if (lastResult?.error) console.log(lastResult.error);
}, [lastResult?.error]);
const [isPending, startTransition] = useTransition();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useTransition allows us to show an affordance while the transition is in progress.

'flex items-center gap-1 text-xs uppercase transition-opacity [&:disabled]:opacity-30',
navButtonClassName,
)}
disabled={isPending}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable the trigger during the transition.

action: CurrencyAction;
currencies: [Currency, ...Currency[]];
}) {
const [isPending, startTransition] = useTransition();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply the "transition in progress" affordance to the currency picker as well.

@agurtovoy
agurtovoy marked this pull request as ready for review February 20, 2025 22:06
@agurtovoy
agurtovoy requested review from a team, jorgemoya and migueloller February 20, 2025 22:06

@migueloller migueloller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outcome of this change—preserving the current page when changing locales—is most definitely welcome. Unfortunately, I think that we need a different solution for a couple of reasons:

  • Using usePathname at the top-level like this will make it difficult for us to finalize our move to PPR
  • This would require the header section component to be a client component. And while it is a client component at the moment, there is no such requirement from the current API so we could always change it to an RSC later

Here's a suggestion: what if we continued to use a server action but passed in the pathname in the payload so that the href can preserve the current URL?

Comment thread core/components/header/header-section.tsx Outdated
@agurtovoy
agurtovoy force-pushed the aleksey/eng-7754-locale-switch-redirects-user-to-the-home-page branch from e5bc44a to 91bff63 Compare February 25, 2025 00:24
@agurtovoy

Copy link
Copy Markdown
Contributor Author

what if we continued to use a server action but passed in the pathname in the payload so that the href can preserve the current URL?

@migueloller Even ignoring the home page redirect, our server action implementation is buggy. Can we fix it if we spent enough time on it? Probably, but we're already using a battle-tested library that offers a recommended solution for this, and I think we should be able to do just that.

{ locale },
),
[pathname, params, router],
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use next-intl's recommended way to switch between locales, with the exception of pushing the URL change to history (router.push vs router.replace).

@agurtovoy
agurtovoy enabled auto-merge February 25, 2025 17:00
@agurtovoy
agurtovoy added this pull request to the merge queue Feb 25, 2025
Merged via the queue into canary with commit c4e56c6 Feb 25, 2025
@agurtovoy
agurtovoy deleted the aleksey/eng-7754-locale-switch-redirects-user-to-the-home-page branch February 25, 2025 17:16
@github-actions

Copy link
Copy Markdown
Contributor

⚡️🏠 Lighthouse report

Lighthouse ran against https://catalyst-canary-kl5mipf47-bigcommerce-platform.vercel.app

🖥️ Desktop

We ran Lighthouse against the changes on a desktop and produced this report. Here's the summary:

Category Score
🟢 Performance 99
🟢 Accessibility 92
🟠 Best practices 78
🟠 SEO 82

📱 Mobile

We ran Lighthouse against the changes on a mobile and produced this report. Here's the summary:

Category Score
🟠 Performance 85
🟢 Accessibility 92
🟠 Best practices 78
🟠 SEO 85

migueloller added a commit that referenced this pull request Mar 31, 2025
* fix: switching locales redirects user to the home page (#1990)

* chore: add demo section to readme (#1996)

* Update translations (#1993)

* feat(other): LOCAL-1444 delivery translation

* chore(core): create translations patch

---------

Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>

* feat: manage locales when creating storefronts from the CLI (#1986)

* feat: manage locales

* Add changeset

---------

Co-authored-by: Nathan Booker <nathan.booker@bigcommerce.com>

* feat: add default Tailwind typography styles (#2007)

* Update translations (#2004)

* feat(other): LOCAL-1444 delivery translation

* chore(core): create translations patch

---------

Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>

* fix(core): handle registration errors in form (#2006)

* chore(release): publish create-catalyst CLI (#2015)

* chore: remove scoped version bump

* chore(release): publish create-catalyst CLI

* feat: add es-419 to list of allowed locale for selecting (#2017)

* feat(cli): scaffold package (#2010)

* fix(core): show coupon discounts as a separate summary item (#2084)

* fix(core): show coupon discounts as a separate summary item

* fix: typo in changeset

* feat(core): add shipping options to checkout (#1997)

* feat(core): add shipping options to checkout

* fix: capitalization of Edit

* fix: bump vibes

* fix: update vibes

* fix: remove else and early return

* refactor: simplify logic by using a Set for countries

* fix: hide forms visually

* fix: add no shipping options message

* fix: remove reduce and use Set, remove let variable

* fix: split mutations

* fix: disable complexity rule for Cart

* Update translations (#2104)

* feat(other): LOCAL-1444 delivery translation

* chore(core): create translations patch

---------

Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>

* refactor: update signin behavior to use different providers (#2103)

* refactor: update signin behavior to use different providers

* chore: add additional folders to lint task

* feat: Sync Button and DynamicForm with VIBES (#2110)

* feat(core): add compare functionality to PLP (#2060)

* feat(core): migrate compare page to use soul

* feat: hide compare checkbox dynamically

* feat: pass in comparable products

* fix: add optimistic items

* feat: add optimistic to remove

* feat: add optimistic to checkbox

* fix: sort when added

* fix: sort groups and use link to compare

* fix: bump vibes components, fix button

* fix: remove unused primitves breadcrumbs component

* fix: sync vibes components

* fix: wrap transitions and call optimistic before setParam

* fix: validate with zod variables are correct

* fix: expose remove label

* fix: await setParam

* fix: translate remove label:

* fix: use parser and loader for compare

* feat: alert when max compare limit is set, disable checkboxes

* feat: Sync ProductCard and WishlistItemCard with VIBES (#2112)

* feat: Sync Breadcrumbs (#2117)

* feat: Add Wishlist VIBES components (#2118)

* chore(security): add documentation around CSRF checks (#2114)

* fix: set the trustHost value with an env var

* chore(core): documentation around CSRF checks within next-auth

* feat: Add wishlist translations, transformers, and core components (#2119)

* fix(core): revert to ids search param in compare page (#2125)

* feat(client): add errorPolicy option to GQL requests (#2124)

* feat: add anonymous session with cart tracking (#2111)

* refactor(core): abstract cart creation and addition logic (#2126)

* feat: Add wishlist modals, actions, and visibility switch (#2120)

* Bump next to address CVE (#2132)

* feat: Add wishlist modal defs, share button, and action dropdown menu (#2121)

* chore: update pnpm to 10.6.5 (#2135)

* Update translations (#2133)

* feat(other): LOCAL-1444 delivery translation

* chore(core): create translations patch

---------

Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>
Co-authored-by: Jorge Moya <jorge.moya@bigcommerce.com>

* chore: update node to version 22 (#2136)

* chore: remove invalid changeset (#2139)

* feat: Add wishlist pages (#2122)

* fix(core): ignore errors in orders and render products without links (#2141)

* fix: add `Streamable.from` to avoid eager promises (#2143)

* feat: add Streamable.from

* fix: use Streamable.from instead of eager promises

* chore: update dependencies to latest minors (#2142)

* feat: group 1 update for Soul form components (#2130)

* feat(core): add store hash meta tag (#2147)

* fix: dedupe default image in PDP (#2162)

* feat: group 2 update for Soul form components (#2160)

* fix: remove unused components (#2163)

---------

Co-authored-by: Aleksey Gurtovoy <agurtovoy@acm.org>
Co-authored-by: Chancellor Clark <chancellor.clark@bigcommerce.com>
Co-authored-by: bc-svc-local <102379007+bc-svc-local@users.noreply.github.com>
Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>
Co-authored-by: Roman Krasinskyi <49246595+RomanKrasinskyi@users.noreply.github.com>
Co-authored-by: Nathan Booker <nathan.booker@bigcommerce.com>
Co-authored-by: Hunter Garrett <hunter@hunterbecton.com>
Co-authored-by: Jorge Moya <jorge.moya@bigcommerce.com>
Co-authored-by: Daniel Almaguer <daniel.almaguer@bigcommerce.com>
Co-authored-by: Jordan Arldt <jordan.arldt@bigcommerce.com>
Co-authored-by: Nathan Booker <bookernath@users.noreply.github.com>
chanceaclark added a commit that referenced this pull request Apr 18, 2025
* fix: switching locales redirects user to the home page (#1990)

* chore: add demo section to readme (#1996)

* Update translations (#1993)

* feat(other): LOCAL-1444 delivery translation

* chore(core): create translations patch

---------

Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>

* feat: manage locales when creating storefronts from the CLI (#1986)

* feat: manage locales

* Add changeset

---------

Co-authored-by: Nathan Booker <nathan.booker@bigcommerce.com>

* feat: add default Tailwind typography styles (#2007)

* Update translations (#2004)

* feat(other): LOCAL-1444 delivery translation

* chore(core): create translations patch

---------

Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>

* fix(core): handle registration errors in form (#2006)

* chore(release): publish create-catalyst CLI (#2015)

* chore: remove scoped version bump

* chore(release): publish create-catalyst CLI

* feat: add es-419 to list of allowed locale for selecting (#2017)

* feat(cli): scaffold package (#2010)

* fix(core): show coupon discounts as a separate summary item (#2084)

* fix(core): show coupon discounts as a separate summary item

* fix: typo in changeset

* feat(core): add shipping options to checkout (#1997)

* feat(core): add shipping options to checkout

* fix: capitalization of Edit

* fix: bump vibes

* fix: update vibes

* fix: remove else and early return

* refactor: simplify logic by using a Set for countries

* fix: hide forms visually

* fix: add no shipping options message

* fix: remove reduce and use Set, remove let variable

* fix: split mutations

* fix: disable complexity rule for Cart

* Update translations (#2104)

* feat(other): LOCAL-1444 delivery translation

* chore(core): create translations patch

---------

Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>

* refactor: update signin behavior to use different providers (#2103)

* refactor: update signin behavior to use different providers

* chore: add additional folders to lint task

* feat: Sync Button and DynamicForm with VIBES (#2110)

* feat(core): add compare functionality to PLP (#2060)

* feat(core): migrate compare page to use soul

* feat: hide compare checkbox dynamically

* feat: pass in comparable products

* fix: add optimistic items

* feat: add optimistic to remove

* feat: add optimistic to checkbox

* fix: sort when added

* fix: sort groups and use link to compare

* fix: bump vibes components, fix button

* fix: remove unused primitves breadcrumbs component

* fix: sync vibes components

* fix: wrap transitions and call optimistic before setParam

* fix: validate with zod variables are correct

* fix: expose remove label

* fix: await setParam

* fix: translate remove label:

* fix: use parser and loader for compare

* feat: alert when max compare limit is set, disable checkboxes

* feat: Sync ProductCard and WishlistItemCard with VIBES (#2112)

* feat: Sync Breadcrumbs (#2117)

* feat: Add Wishlist VIBES components (#2118)

* chore(security): add documentation around CSRF checks (#2114)

* fix: set the trustHost value with an env var

* chore(core): documentation around CSRF checks within next-auth

* feat: Add wishlist translations, transformers, and core components (#2119)

* fix(core): revert to ids search param in compare page (#2125)

* feat(client): add errorPolicy option to GQL requests (#2124)

* feat: add anonymous session with cart tracking (#2111)

* refactor(core): abstract cart creation and addition logic (#2126)

* feat: Add wishlist modals, actions, and visibility switch (#2120)

* Bump next to address CVE (#2132)

* feat: Add wishlist modal defs, share button, and action dropdown menu (#2121)

* chore: update pnpm to 10.6.5 (#2135)

* Update translations (#2133)

* feat(other): LOCAL-1444 delivery translation

* chore(core): create translations patch

---------

Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>
Co-authored-by: Jorge Moya <jorge.moya@bigcommerce.com>

* chore: update node to version 22 (#2136)

* chore: remove invalid changeset (#2139)

* feat: Add wishlist pages (#2122)

* fix(core): ignore errors in orders and render products without links (#2141)

* fix: add `Streamable.from` to avoid eager promises (#2143)

* feat: add Streamable.from

* fix: use Streamable.from instead of eager promises

* chore: update dependencies to latest minors (#2142)

* feat: group 1 update for Soul form components (#2130)

* feat(core): add store hash meta tag (#2147)

* fix: dedupe default image in PDP (#2162)

* feat: group 2 update for Soul form components (#2160)

* fix: remove unused components (#2163)

---------

Co-authored-by: Aleksey Gurtovoy <agurtovoy@acm.org>
Co-authored-by: Chancellor Clark <chancellor.clark@bigcommerce.com>
Co-authored-by: bc-svc-local <102379007+bc-svc-local@users.noreply.github.com>
Co-authored-by: bc-svc-local <bc-svc-local@users.noreply.github.com>
Co-authored-by: Roman Krasinskyi <49246595+RomanKrasinskyi@users.noreply.github.com>
Co-authored-by: Nathan Booker <nathan.booker@bigcommerce.com>
Co-authored-by: Hunter Garrett <hunter@hunterbecton.com>
Co-authored-by: Jorge Moya <jorge.moya@bigcommerce.com>
Co-authored-by: Daniel Almaguer <daniel.almaguer@bigcommerce.com>
Co-authored-by: Jordan Arldt <jordan.arldt@bigcommerce.com>
Co-authored-by: Nathan Booker <bookernath@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants