Updates the minimal supported versions of next.js to [`15.0.0-canary.173`](https://github.com/vercel/next.js/releases/tag/v15.0.0-canary.173) and react to `19.0.0-rc-3edc000d-20240926`. Adds neccessary awaits according to this breaking change https://github.com/vercel/next.js/pull/68812 ## Breaking Changes The `params` and `searchParams` types in `app/(payload)/admin/[[...segments]]/page.tsx` and `app/(payload)/admin/[[...segments]]/not-found.tsx` must be changed to promises: ```diff - type Args = { - params: { - segments: string[] - } - searchParams: { - [key: string]: string | string[] - } - } + type Args = { + params: Promise<{ + segments: string[] + }> + searchParams: Promise<{ + [key: string]: string | string[] + }> + } ```
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import type { ClientTranslationsObject, I18nClient } from '@payloadcms/translations'
|
|
import type { SanitizedConfig } from 'payload'
|
|
|
|
import { initI18n } from '@payloadcms/translations'
|
|
import { cookies, headers } from 'next/headers.js'
|
|
|
|
import { getRequestLanguage } from './getRequestLanguage.js'
|
|
|
|
/**
|
|
* In the context of Next.js, this function initializes the i18n object for the current request.
|
|
*
|
|
* It must be called on the server side, and within the lifecycle of a request since it relies on the request headers and cookies.
|
|
*/
|
|
export const getNextRequestI18n = async <
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
TAdditionalTranslations = {},
|
|
TAdditionalClientTranslationKeys extends string = never,
|
|
>({
|
|
config,
|
|
}: {
|
|
config: SanitizedConfig
|
|
}): Promise<
|
|
[TAdditionalClientTranslationKeys] extends [never]
|
|
? I18nClient
|
|
: TAdditionalTranslations extends object
|
|
? I18nClient<TAdditionalTranslations, TAdditionalClientTranslationKeys>
|
|
: I18nClient<ClientTranslationsObject, TAdditionalClientTranslationKeys>
|
|
> => {
|
|
return (await initI18n({
|
|
config: config.i18n,
|
|
context: 'client',
|
|
language: getRequestLanguage({ config, cookies: await cookies(), headers: await headers() }),
|
|
})) as any
|
|
}
|