Skip to content

Commit

Permalink
fix(core): remove explicit locale override in Links (#1908)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemoya authored and BC-krasnoshapka committed Jan 23, 2025
1 parent ceb841a commit fbbec7a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 116 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-jokes-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Remove explicit locale override in Link component that was appending default locale to links even with the 'as-needed' mode.
9 changes: 1 addition & 8 deletions core/components/link/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import { useLocale } from 'next-intl';
import { ComponentPropsWithRef, ComponentRef, forwardRef, useReducer } from 'react';

import { cn } from '~/lib/utils';
Expand All @@ -27,15 +26,10 @@ type Props = NextLinkProps & PrefetchOptions;
* page load performance and resource usage. https://nextjs.org/docs/app/api-reference/components/link#prefetch
*/
export const Link = forwardRef<ComponentRef<'a'>, Props>(
(
{ href, prefetch = 'hover', prefetchKind = 'auto', children, className, locale, ...rest },
ref,
) => {
({ href, prefetch = 'hover', prefetchKind = 'auto', children, className, ...rest }, ref) => {
const router = useRouter();
const [prefetched, setPrefetched] = useReducer(() => true, false);
const computedPrefetch = computePrefetchProp({ prefetch, prefetchKind });
const defaultLocale = useLocale();
const finalLocale = locale || defaultLocale;

const triggerPrefetch = () => {
if (prefetched) {
Expand All @@ -61,7 +55,6 @@ export const Link = forwardRef<ComponentRef<'a'>, Props>(
<NavLink
className={cn(className)}
href={href}
locale={finalLocale}
onMouseEnter={prefetch === 'hover' ? triggerPrefetch : undefined}
onTouchStart={prefetch === 'hover' ? triggerPrefetch : undefined}
prefetch={computedPrefetch}
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"lucide-react": "^0.468.0",
"next": "15.2.0-canary.8",
"next-auth": "5.0.0-beta.25",
"next-intl": "^3.26.1",
"next-intl": "^3.26.3",
"nuqs": "^2.2.2",
"p-lazy": "^5.0.0",
"react": "^19.0.0",
Expand Down
121 changes: 14 additions & 107 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fbbec7a

Please sign in to comment.