Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Print warning for inconsistent i18n setup where no locale is read in getRequestConfig and also none is returned #1305

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/pages/docs/routing/middleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ Note that other [limitations as documented by Next.js](https://nextjs.org/docs/a
This can happen either because:

1. You're using a setup _with_ [i18n routing](/docs/getting-started/app-router) but the middleware is not set up.
2. You're using a setup _without_ [i18n routing](/docs/getting-started/app-router) but are reading the `locale` param passed to the function within `getRequestConfig`.
2. You're using a setup _without_ [i18n routing](/docs/getting-started/app-router) but are reading the `locale` param passed to the function within `getRequestConfig` or you're not returning a `locale`.
3. The middleware is set up in the wrong file (e.g. you're using the `src` folder, but `middleware.ts` was added in the root folder).
4. The middleware matcher didn't match a request, but you're using APIs from `next-intl` in server code (e.g. a Server Component, a Server Action, etc.).
5. You're attempting to implement static rendering via [`force-static`](https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic).
Expand Down
4 changes: 2 additions & 2 deletions packages/next-intl/.size-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const config: SizeLimitConfig = [
},
{
path: 'dist/production/navigation.react-server.js',
limit: '15.975 KB'
limit: '15.845 KB'
},
{
path: 'dist/production/server.react-client.js',
limit: '1 KB'
},
{
path: 'dist/production/server.react-server.js',
limit: '13.975 KB'
limit: '13.865 KB'
},
{
path: 'dist/production/middleware.js',
Expand Down
18 changes: 14 additions & 4 deletions packages/next-intl/src/server/react-server/getConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ async function receiveRuntimeConfigImpl(
result = await result;
}

if (result.locale && hasReadLocale) {
console.error(
"\nYou've read the `locale` param that was passed to `getRequestConfig` but have also returned one from the function. This is likely an error, please ensure that you're consistently using a setup with or without i18n routing: https://next-intl-docs.vercel.app/docs/getting-started/app-router\n"
);
if (process.env.NODE_ENV !== 'production') {
if (hasReadLocale) {
if (result.locale) {
console.error(
"\nYou've read the `locale` param that was passed to `getRequestConfig` but have also returned one from the function. This is likely an error, please ensure that you're consistently using a setup with or without i18n routing: https://next-intl-docs.vercel.app/docs/getting-started/app-router\n"
);
}
} else {
if (!result.locale) {
console.error(
"\nYou haven't read the `locale` param that was passed to `getRequestConfig` and also haven't returned one from the function. This is likely an error, please ensure that you're consistently using a setup with or without i18n routing: https://next-intl-docs.vercel.app/docs/getting-started/app-router\n"
);
}
}
}

return {
Expand Down
Loading