Skip to content

Commit e96f4d8

Browse files
jorgemoyaclaude
andcommitted
feat(core): make locale required on client.fetch()
Make the locale parameter required (not optional) on client.fetch() to ensure correct channel resolution and Accept-Language header in all contexts, including inside unstable_cache where getLocale() is unavailable. All call sites now explicitly pass locale. Build-time contexts (next.config.ts, robots.txt, favicon.ico) and proxies pass an empty string as locale since no request context is available. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f25a0a8 commit e96f4d8

67 files changed

Lines changed: 264 additions & 59 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/locale-required.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@bigcommerce/catalyst-client": minor
3+
"@bigcommerce/catalyst-core": minor
4+
---
5+
6+
Make `locale` a required parameter on `client.fetch()`. All call sites now explicitly pass locale for correct channel resolution and `Accept-Language` header, including inside `unstable_cache` contexts where `getLocale()` is unavailable.

core/app/[locale]/(default)/(auth)/change-password/_actions/change-password.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { BigCommerceGQLError } from '@bigcommerce/catalyst-client';
44
import { SubmissionResult } from '@conform-to/react';
55
import { parseWithZod } from '@conform-to/zod';
6-
import { getTranslations } from 'next-intl/server';
6+
import { getLocale, getTranslations } from 'next-intl/server';
77
import { z } from 'zod';
88

99
import { client } from '~/client';
@@ -35,6 +35,7 @@ export async function changePassword(
3535
formData: FormData,
3636
) {
3737
const t = await getTranslations('Auth.ChangePassword');
38+
const locale = await getLocale();
3839
const submission = parseWithZod(formData, { schema });
3940

4041
if (submission.status !== 'success') {
@@ -44,6 +45,7 @@ export async function changePassword(
4445
try {
4546
const response = await client.fetch({
4647
document: ChangePasswordMutation,
48+
locale,
4749
variables: {
4850
input: {
4951
token,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { unstable_cache } from 'next/cache';
2+
import { getLocale } from 'next-intl/server';
23
import { cache } from 'react';
34

45
import { client } from '~/client';
@@ -26,9 +27,10 @@ const ChangePasswordQuery = graphql(`
2627
`);
2728

2829
const getCachedChangePasswordQuery = unstable_cache(
29-
async () => {
30+
async (locale: string) => {
3031
const response = await client.fetch({
3132
document: ChangePasswordQuery,
33+
locale,
3234
fetchOptions: { cache: 'no-store' },
3335
});
3436

@@ -44,5 +46,7 @@ const getCachedChangePasswordQuery = unstable_cache(
4446
);
4547

4648
export const getChangePasswordQuery = cache(async () => {
47-
return getCachedChangePasswordQuery();
49+
const locale = await getLocale();
50+
51+
return getCachedChangePasswordQuery(locale);
4852
});

core/app/[locale]/(default)/(auth)/login/forgot-password/_actions/reset-password.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { BigCommerceGQLError } from '@bigcommerce/catalyst-client';
44
import { SubmissionResult } from '@conform-to/react';
55
import { parseWithZod } from '@conform-to/zod';
6-
import { getTranslations } from 'next-intl/server';
6+
import { getLocale, getTranslations } from 'next-intl/server';
77

88
import { schema } from '@/vibes/soul/sections/forgot-password-section/schema';
99
import { client } from '~/client';
@@ -30,6 +30,7 @@ export const resetPassword = async (
3030
formData: FormData,
3131
): Promise<{ lastResult: SubmissionResult | null; successMessage?: string }> => {
3232
const t = await getTranslations('Auth.Login.ForgotPassword');
33+
const locale = await getLocale();
3334

3435
const submission = parseWithZod(formData, { schema });
3536

@@ -40,6 +41,7 @@ export const resetPassword = async (
4041
try {
4142
const response = await client.fetch({
4243
document: ResetPasswordMutation,
44+
locale,
4345
variables: {
4446
input: {
4547
email: submission.value.email,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ export async function registerCustomer<F extends Field>(
373373
const input = parseRegisterCustomerInput(submission.value, fields);
374374
const response = await client.fetch({
375375
document: RegisterCustomerMutation,
376+
locale,
376377
variables: {
377378
input,
378379
reCaptchaV2:

core/app/[locale]/(default)/(auth)/register/page-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getLocale } from 'next-intl/server';
12
import { cache } from 'react';
23

34
import { getSessionCustomerAccessToken } from '~/auth';
@@ -63,6 +64,7 @@ interface Props {
6364

6465
export const getRegisterCustomerQuery = cache(async ({ address, customer }: Props) => {
6566
const customerAccessToken = await getSessionCustomerAccessToken();
67+
const locale = await getLocale();
6668

6769
const response = await client.fetch({
6870
document: RegisterCustomerQuery,
@@ -72,6 +74,7 @@ export const getRegisterCustomerQuery = cache(async ({ address, customer }: Prop
7274
customerFilters: customer?.filters,
7375
customerSortBy: customer?.sortBy,
7476
},
77+
locale,
7578
fetchOptions: { cache: 'no-store' },
7679
customerAccessToken,
7780
});

core/app/[locale]/(default)/(faceted)/search/page-data.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { unstable_cache } from 'next/cache';
2+
import { getLocale } from 'next-intl/server';
23
import { cache } from 'react';
34

45
import { client } from '~/client';
@@ -31,9 +32,10 @@ const SearchPageQuery = graphql(`
3132
`);
3233

3334
const getCachedSearchPageData = unstable_cache(
34-
async () => {
35+
async (locale: string) => {
3536
const response = await client.fetch({
3637
document: SearchPageQuery,
38+
locale,
3739
fetchOptions: { cache: 'no-store' },
3840
});
3941

@@ -44,5 +46,7 @@ const getCachedSearchPageData = unstable_cache(
4446
);
4547

4648
export const getSearchPageData = cache(async () => {
47-
return getCachedSearchPageData();
49+
const locale = await getLocale();
50+
51+
return getCachedSearchPageData(locale);
4852
});

core/app/[locale]/(default)/account/addresses/_actions/create-address.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BigCommerceAPIError, BigCommerceGQLError } from '@bigcommerce/catalyst-client';
22
import { parseWithZod } from '@conform-to/zod';
33
import { revalidateTag } from 'next/cache';
4-
import { getTranslations } from 'next-intl/server';
4+
import { getLocale, getTranslations } from 'next-intl/server';
55
import { z } from 'zod';
66

77
import { Field, FieldGroup } from '@/vibes/soul/form/dynamic-form/schema';
@@ -202,6 +202,7 @@ export async function createAddress(
202202
formData: FormData,
203203
): Promise<State> {
204204
const t = await getTranslations('Account.Addresses');
205+
const locale = await getLocale();
205206
const customerAccessToken = await getSessionCustomerAccessToken();
206207

207208
const submission = parseWithZod(formData, { schema });
@@ -218,6 +219,7 @@ export async function createAddress(
218219

219220
const response = await client.fetch({
220221
document: AddCustomerAddressMutation,
222+
locale,
221223
customerAccessToken,
222224
fetchOptions: { cache: 'no-store' },
223225
variables: {

core/app/[locale]/(default)/account/addresses/_actions/delete-address.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BigCommerceGQLError } from '@bigcommerce/catalyst-client';
22
import { parseWithZod } from '@conform-to/zod';
33
import { revalidateTag } from 'next/cache';
4-
import { getTranslations } from 'next-intl/server';
4+
import { getLocale, getTranslations } from 'next-intl/server';
55
import { z } from 'zod';
66

77
import { schema } from '@/vibes/soul/sections/address-list-section/schema';
@@ -46,6 +46,7 @@ function parseDeleteAddressInput(
4646

4747
export async function deleteAddress(prevState: Awaited<State>, formData: FormData): Promise<State> {
4848
const t = await getTranslations('Account.Addresses');
49+
const locale = await getLocale();
4950
const customerAccessToken = await getSessionCustomerAccessToken();
5051

5152
const submission = parseWithZod(formData, { schema });
@@ -62,6 +63,7 @@ export async function deleteAddress(prevState: Awaited<State>, formData: FormDat
6263

6364
const response = await client.fetch({
6465
document: DeleteCustomerAddressMutation,
66+
locale,
6567
customerAccessToken,
6668
fetchOptions: { cache: 'no-store' },
6769
variables: {

core/app/[locale]/(default)/account/addresses/_actions/update-address.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BigCommerceGQLError } from '@bigcommerce/catalyst-client';
22
import { parseWithZod } from '@conform-to/zod';
33
import { revalidateTag } from 'next/cache';
4-
import { getTranslations } from 'next-intl/server';
4+
import { getLocale, getTranslations } from 'next-intl/server';
55
import { z } from 'zod';
66

77
import { Field, FieldGroup } from '@/vibes/soul/form/dynamic-form/schema';
@@ -215,6 +215,7 @@ export async function updateAddress(
215215
formData: FormData,
216216
): Promise<State> {
217217
const t = await getTranslations('Account.Addresses');
218+
const locale = await getLocale();
218219
const customerAccessToken = await getSessionCustomerAccessToken();
219220

220221
const submission = parseWithZod(formData, { schema });
@@ -231,6 +232,7 @@ export async function updateAddress(
231232

232233
const response = await client.fetch({
233234
document: UpdateCustomerAddressMutation,
235+
locale,
234236
customerAccessToken,
235237
fetchOptions: { cache: 'no-store' },
236238
variables: {

0 commit comments

Comments
 (0)