Skip to content

Commit eeec861

Browse files
committed
chore(core): bump next-intl
1 parent 5c81496 commit eeec861

File tree

28 files changed

+96
-152
lines changed

28 files changed

+96
-152
lines changed

.changeset/silent-rats-hear.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@bigcommerce/catalyst-core": minor
3+
---
4+
5+
Bump `next-intl` which includes [some minor changes and updated APIs]((https://next-intl-docs.vercel.app/blog/next-intl-3-22)):
6+
7+
+ Use new `createNavigation` api.
8+
+ Pass `locale` to redirects.
9+
+ `setRequestLocale` is no longer unstable.

core/app/[locale]/(default)/(auth)/change-password/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useTranslations } from 'next-intl';
1+
import { useLocale, useTranslations } from 'next-intl';
22
import { getTranslations } from 'next-intl/server';
33

44
import { redirect } from '~/i18n/routing';
@@ -22,12 +22,13 @@ interface Props {
2222

2323
export default function ChangePassword({ searchParams }: Props) {
2424
const t = useTranslations('ChangePassword');
25+
const locale = useLocale();
2526

2627
const customerId = searchParams.c;
2728
const customerToken = searchParams.t;
2829

2930
if (!customerId || !customerToken) {
30-
redirect('/login');
31+
redirect({ href: '/login', locale });
3132
}
3233

3334
if (customerId && customerToken) {

core/app/[locale]/(default)/(auth)/login/_actions/login.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
'use server';
22

33
import { isRedirectError } from 'next/dist/client/components/redirect';
4+
import { getLocale } from 'next-intl/server';
45

56
import { Credentials, signIn } from '~/auth';
67
import { redirect } from '~/i18n/routing';
78

89
export const login = async (_previousState: unknown, formData: FormData) => {
910
try {
11+
const locale = await getLocale();
12+
1013
const credentials = Credentials.parse({
1114
email: formData.get('email'),
1215
password: formData.get('password'),
@@ -19,7 +22,7 @@ export const login = async (_previousState: unknown, formData: FormData) => {
1922
redirect: false,
2023
});
2124

22-
redirect('/account');
25+
redirect({ href: '/account', locale });
2326
} catch (error: unknown) {
2427
// We need to throw this error to trigger the redirect as Next.js uses error boundaries to redirect.
2528
if (isRedirectError(error)) {

core/app/[locale]/(default)/(auth)/login/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useTranslations } from 'next-intl';
2-
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
2+
import { getTranslations, setRequestLocale } from 'next-intl/server';
33

44
import { Link } from '~/components/link';
55
import { Button } from '~/components/ui/button';
@@ -20,7 +20,7 @@ interface Props {
2020
}
2121

2222
export default function Login({ params: { locale } }: Props) {
23-
unstable_setRequestLocale(locale);
23+
setRequestLocale(locale);
2424

2525
const t = useTranslations('Login');
2626

core/app/[locale]/(default)/(auth)/register/_actions/login.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
'use server';
22

33
import { isRedirectError } from 'next/dist/client/components/redirect';
4+
import { getLocale } from 'next-intl/server';
45

56
import { Credentials, signIn } from '~/auth';
67
import { redirect } from '~/i18n/routing';
78

89
export const login = async (formData: FormData) => {
10+
const locale = await getLocale();
11+
912
try {
1013
const credentials = Credentials.parse({
1114
email: formData.get('customer-email'),
@@ -19,7 +22,7 @@ export const login = async (formData: FormData) => {
1922
redirect: false,
2023
});
2124

22-
redirect('/account');
25+
redirect({ href: '/account', locale });
2326
} catch (error: unknown) {
2427
if (isRedirectError(error)) {
2528
throw error;

core/app/[locale]/(default)/(faceted)/brand/[slug]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Metadata } from 'next';
22
import { notFound } from 'next/navigation';
3-
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
3+
import { getTranslations, setRequestLocale } from 'next-intl/server';
44

55
import { ProductCard } from '~/components/product-card';
66
import { Pagination } from '~/components/ui/pagination';
@@ -40,7 +40,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
4040
}
4141

4242
export default async function Brand({ params: { slug, locale }, searchParams }: Props) {
43-
unstable_setRequestLocale(locale);
43+
setRequestLocale(locale);
4444

4545
const t = await getTranslations('Brand');
4646

core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Metadata } from 'next';
22
import { notFound } from 'next/navigation';
3-
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
3+
import { getTranslations, setRequestLocale } from 'next-intl/server';
44

55
import { Breadcrumbs } from '~/components/breadcrumbs';
66
import { ProductCard } from '~/components/product-card';
@@ -48,7 +48,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
4848
}
4949

5050
export default async function Category({ params: { locale, slug }, searchParams }: Props) {
51-
unstable_setRequestLocale(locale);
51+
setRequestLocale(locale);
5252

5353
const t = await getTranslations('Category');
5454

core/app/[locale]/(default)/account/(tabs)/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useTranslations } from 'next-intl';
2-
import { unstable_setRequestLocale } from 'next-intl/server';
2+
import { setRequestLocale } from 'next-intl/server';
33
import { PropsWithChildren } from 'react';
44

55
import { Link } from '~/components/link';
@@ -15,7 +15,7 @@ interface Props extends PropsWithChildren {
1515
}
1616

1717
export default function AccountTabLayout({ children, params: { locale } }: Props) {
18-
unstable_setRequestLocale(locale);
18+
setRequestLocale(locale);
1919

2020
const t = useTranslations('Account.Home');
2121

core/app/[locale]/(default)/account/(tabs)/settings/change-password/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
1+
import { getTranslations, setRequestLocale } from 'next-intl/server';
22

33
import { locales, LocaleType } from '~/i18n/routing';
44

@@ -19,7 +19,7 @@ interface Props {
1919
}
2020

2121
export default function ChangePassword({ params: { locale } }: Props) {
22-
unstable_setRequestLocale(locale);
22+
setRequestLocale(locale);
2323

2424
return (
2525
<>

core/app/[locale]/(default)/account/layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import { getLocale } from 'next-intl/server';
12
import { PropsWithChildren } from 'react';
23

34
import { auth } from '~/auth';
45
import { redirect } from '~/i18n/routing';
56

67
export default async function AccountLayout({ children }: PropsWithChildren) {
8+
const locale = await getLocale();
79
const session = await auth();
810

911
if (!session) {
10-
redirect('/login');
12+
redirect({ href: '/login', locale });
1113
}
1214

1315
return children;

core/app/[locale]/(default)/cart/_actions/redirect-to-checkout.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use server';
22

3+
import { getLocale } from 'next-intl/server';
34
import { z } from 'zod';
45

56
import { getSessionCustomerId } from '~/auth';
@@ -20,6 +21,7 @@ const CheckoutRedirectMutation = graphql(`
2021
`);
2122

2223
export const redirectToCheckout = async (formData: FormData) => {
24+
const locale = await getLocale();
2325
const cartId = z.string().parse(formData.get('cartId'));
2426
const customerId = await getSessionCustomerId();
2527

@@ -36,5 +38,5 @@ export const redirectToCheckout = async (formData: FormData) => {
3638
throw new Error('Invalid checkout url.');
3739
}
3840

39-
redirect(url);
41+
redirect({ href: url, locale });
4042
};

core/app/[locale]/(default)/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { unstable_setRequestLocale } from 'next-intl/server';
1+
import { setRequestLocale } from 'next-intl/server';
22
import { PropsWithChildren, Suspense } from 'react';
33

44
import { Footer } from '~/components/footer/footer';
@@ -11,7 +11,7 @@ interface Props extends PropsWithChildren {
1111
}
1212

1313
export default function DefaultLayout({ children, params: { locale } }: Props) {
14-
unstable_setRequestLocale(locale);
14+
setRequestLocale(locale);
1515

1616
return (
1717
<>

core/app/[locale]/(default)/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { removeEdgesAndNodes } from '@bigcommerce/catalyst-client';
2-
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
2+
import { getTranslations, setRequestLocale } from 'next-intl/server';
33

44
import { getSessionCustomerId } from '~/auth';
55
import { client } from '~/client';
@@ -41,7 +41,7 @@ interface Props {
4141
}
4242

4343
export default async function Home({ params: { locale } }: Props) {
44-
unstable_setRequestLocale(locale);
44+
setRequestLocale(locale);
4545

4646
const t = await getTranslations('Home');
4747

core/app/[locale]/(default)/product/[slug]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { removeEdgesAndNodes } from '@bigcommerce/catalyst-client';
22
import { Metadata } from 'next';
33
import { notFound } from 'next/navigation';
4-
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
4+
import { getTranslations, setRequestLocale } from 'next-intl/server';
55
import { Suspense } from 'react';
66

77
import { Breadcrumbs } from '~/components/breadcrumbs';
@@ -69,7 +69,7 @@ export async function generateMetadata({ params, searchParams }: Props): Promise
6969
}
7070

7171
export default async function Product({ params: { locale, slug }, searchParams }: Props) {
72-
unstable_setRequestLocale(locale);
72+
setRequestLocale(locale);
7373

7474
const t = await getTranslations('Product');
7575

core/app/[locale]/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SpeedInsights } from '@vercel/speed-insights/next';
33
import type { Metadata } from 'next';
44
import { Inter } from 'next/font/google';
55
import { NextIntlClientProvider, useMessages } from 'next-intl';
6-
import { unstable_setRequestLocale } from 'next-intl/server';
6+
import { setRequestLocale } from 'next-intl/server';
77
import { PropsWithChildren } from 'react';
88

99
import '../globals.css';
@@ -82,8 +82,8 @@ interface Props extends PropsWithChildren {
8282

8383
export default function RootLayout({ children, params: { locale } }: Props) {
8484
// need to call this method everywhere where static rendering is enabled
85-
// https://next-intl-docs.vercel.app/docs/getting-started/app-router#add-unstable_setrequestlocale-to-all-layouts-and-pages
86-
unstable_setRequestLocale(locale);
85+
// https://next-intl-docs.vercel.app/docs/getting-started/app-router#add-setRequestLocale-to-all-layouts-and-pages
86+
setRequestLocale(locale);
8787

8888
const messages = useMessages();
8989

core/app/[locale]/maintenance/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Phone } from 'lucide-react';
2-
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
2+
import { getTranslations, setRequestLocale } from 'next-intl/server';
33
import { ReactNode } from 'react';
44

55
import { client } from '~/client';
@@ -42,7 +42,7 @@ interface Props {
4242
}
4343

4444
export default async function Maintenance({ params: { locale } }: Props) {
45-
unstable_setRequestLocale(locale);
45+
setRequestLocale(locale);
4646

4747
const t = await getTranslations('Maintenance');
4848

core/app/[locale]/store-selector/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getTranslations, unstable_setRequestLocale } from 'next-intl/server';
1+
import { getTranslations, setRequestLocale } from 'next-intl/server';
22

33
import { client } from '~/client';
44
import { graphql } from '~/client/graphql';
@@ -35,7 +35,7 @@ interface Props {
3535
}
3636

3737
export default async function StoreSelector({ params: { locale: selectedLocale } }: Props) {
38-
unstable_setRequestLocale(selectedLocale);
38+
setRequestLocale(selectedLocale);
3939

4040
const t = await getTranslations('StoreSelector');
4141

core/app/admin/route.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1+
import { useLocale } from 'next-intl';
2+
13
import { redirect } from '~/i18n/routing';
24

35
const canonicalDomain: string = process.env.BIGCOMMERCE_GRAPHQL_API_DOMAIN ?? 'mybigcommerce.com';
46
const BIGCOMMERCE_STORE_HASH = process.env.BIGCOMMERCE_STORE_HASH;
57
const ENABLE_ADMIN_ROUTE = process.env.ENABLE_ADMIN_ROUTE;
68

79
export const GET = () => {
10+
const locale = useLocale();
11+
812
// This route should not work unless explicitly enabled
913
if (ENABLE_ADMIN_ROUTE !== 'true') {
10-
return redirect('/');
14+
return redirect({ href: '/', locale });
1115
}
1216

13-
return redirect(
14-
BIGCOMMERCE_STORE_HASH
17+
return redirect({
18+
href: BIGCOMMERCE_STORE_HASH
1519
? `https://store-${BIGCOMMERCE_STORE_HASH}.${canonicalDomain}/admin`
1620
: 'https://login.bigcommerce.com',
17-
);
21+
locale,
22+
});
1823
};
1924

2025
export const runtime = 'edge';

core/app/xmlsitemap.php/route.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* eslint-disable check-file/folder-naming-convention */
2+
import { useLocale } from 'next-intl';
3+
24
import { permanentRedirect } from '~/i18n/routing';
35

46
/*
@@ -8,6 +10,10 @@ import { permanentRedirect } from '~/i18n/routing';
810
* on /xmlsitemap.php
911
*/
1012

11-
export const GET = () => permanentRedirect('/sitemap.xml');
13+
export const GET = () => {
14+
const locale = useLocale();
15+
16+
permanentRedirect({ href: '/sitemap.xml', locale });
17+
};
1218

1319
export const runtime = 'edge';

core/client/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const client = createClient({
2323
* - Requests in middlewares
2424
* - Requests in `generateStaticParams`
2525
* - Request in api routes
26-
* - Requests in static sites without `unstable_setRequestLocale`
26+
* - Requests in static sites without `setRequestLocale`
2727
*
2828
* We use the default channelId as a fallback, but it is not ideal in some scenarios.
2929
* */
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
'use server';
22

3+
import { getLocale } from 'next-intl/server';
4+
35
import { signOut } from '~/auth';
46
import { redirect } from '~/i18n/routing';
57

68
export const logout = async () => {
9+
const locale = await getLocale();
10+
711
await signOut({ redirect: false });
812

9-
redirect('/login');
13+
redirect({ href: '/login', locale });
1014
};

0 commit comments

Comments
 (0)