Skip to content

Commit

Permalink
Use ESM builds for react-server to avoid a circular dependency issue …
Browse files Browse the repository at this point in the history
…and fix API route
  • Loading branch information
amannn committed Jul 17, 2023
1 parent bd40006 commit 0002918
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
12 changes: 9 additions & 3 deletions examples/example-next-13-advanced/src/app/[locale]/api/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import {NextRequest, NextResponse} from 'next/server';
import {getTranslations} from 'next-intl/server';
import {getTranslator} from 'next-intl/server';

export async function GET(request: NextRequest) {
type Props = {
params: {
locale: string;
};
};

export async function GET(request: NextRequest, {params: {locale}}: Props) {
const name = request.nextUrl.searchParams.get('name');
if (!name) {
return new Response('Search param `name` was not provided.', {status: 400});
}

const t = await getTranslations('ApiRoute');
const t = await getTranslator(locale, 'ApiRoute');
return NextResponse.json({message: t('hello', {name})});
}
6 changes: 3 additions & 3 deletions packages/next-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
"typings": "dist/index.d.ts",
"exports": {
".": {
"react-server": "./dist/index.react-server.js",
"react-server": "./dist/index.react-server.esm.js",
"default": "./dist/index.js"
},
"./server": {
"react-server": "./dist/server.react-server.js",
"react-server": "./dist/server.react-server.esm.js",
"default": "./dist/server.js"
},
"./client": {
"default": "./dist/client.js"
},
"./link": {
"types": "./link.d.ts",
"react-server": "./dist/link.react-server.js",
"react-server": "./dist/link.react-server.esm.js",
"default": "./dist/link.js"
},
"./config": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-intl/src/server/createRequestConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import getRuntimeConfig from 'next-intl/config';
import type {IntlConfig} from 'use-intl/core';
import {GetRequestConfigParams} from './getRequestConfig';
import type {GetRequestConfigParams} from './getRequestConfig';

export default getRuntimeConfig as (
params: GetRequestConfigParams
Expand Down
1 change: 1 addition & 0 deletions packages/next-intl/src/server/getTranslations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ Learn more: https://next-intl-docs.vercel.app/docs/environments/metadata-route-h
});
}

/** @deprecated Is called `getTranslator` now. */
export default cache(getTranslationsImpl);
7 changes: 6 additions & 1 deletion packages/next-intl/src/server/react-client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@ import type {
} from '..';

function notSupported(name: string) {
throw new Error(`\`${name}\` is not supported in Client Components.`);
return () => {
throw new Error(`\`${name}\` is not supported in Client Components.`);
};
}

// Must match `../index.tsx`

// prettier-ignore
export const getRequestConfig = notSupported('getRequestConfig') as unknown as typeof getRequestConfig_type;
// prettier-ignore
/** @deprecated Is called `getFormatter` now. */
export const getIntl = notSupported('getIntl') as unknown as typeof getIntl_type;
// prettier-ignore
export const getFormatter = notSupported('getFormatter') as unknown as typeof getFormatter_type;
// prettier-ignore
/** @deprecated Please use the \`locale\` parameter from Next.js instead. */
export const getLocale = notSupported('getLocale') as unknown as typeof getLocale_type;
// prettier-ignore
export const getNow = notSupported('getNow') as unknown as typeof getNow_type;
// prettier-ignore
export const getTimeZone = notSupported('getTimeZone') as unknown as typeof getTimeZone_type;
// prettier-ignore
/** @deprecated Is called `getTranslator` now. */
export const getTranslations = notSupported('getTranslations') as unknown as typeof getTranslations_type;
// prettier-ignore
export const getTranslator = notSupported('getTranslator') as unknown as typeof getTranslator_type;
Expand Down

0 comments on commit 0002918

Please sign in to comment.