fix: update cookies() usage for Next.js 15 compatibility

- Make getLocaleOnServer async and await cookies()
- Update LocaleLayout to be async component
- Fix react-tooltip compatibility with React 19

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
lyzno1
2025-09-10 22:27:49 +08:00
parent d3909927af
commit 9ff81c0306
3 changed files with 7 additions and 6 deletions

View File

@ -3,12 +3,12 @@ import { getLocaleOnServer } from '@/i18n/server'
import './styles/globals.css' import './styles/globals.css'
import './styles/markdown.scss' import './styles/markdown.scss'
const LocaleLayout = ({ const LocaleLayout = async ({
children, children,
}: { }: {
children: React.ReactNode children: React.ReactNode
}) => { }) => {
const locale = getLocaleOnServer() const locale = await getLocaleOnServer()
return ( return (
<html lang={locale ?? 'en'} className="h-full"> <html lang={locale ?? 'en'} className="h-full">
<body className="h-full"> <body className="h-full">

View File

@ -6,19 +6,20 @@ import { match } from '@formatjs/intl-localematcher'
import type { Locale } from '.' import type { Locale } from '.'
import { i18n } from '.' import { i18n } from '.'
export const getLocaleOnServer = (): Locale => { export const getLocaleOnServer = async (): Promise<Locale> => {
// @ts-expect-error locales are readonly // @ts-expect-error locales are readonly
const locales: string[] = i18n.locales const locales: string[] = i18n.locales
let languages: string[] | undefined let languages: string[] | undefined
// get locale from cookie // get locale from cookie
const localeCookie = cookies().get('locale') const localeCookie = (await cookies()).get('locale')
languages = localeCookie?.value ? [localeCookie.value] : [] languages = localeCookie?.value ? [localeCookie.value] : []
if (!languages.length) { if (!languages.length) {
// Negotiator expects plain object so we need to transform headers // Negotiator expects plain object so we need to transform headers
const negotiatorHeaders: Record<string, string> = {} const negotiatorHeaders: Record<string, string> = {}
headers().forEach((value, key) => (negotiatorHeaders[key] = value)) const headersList = await headers()
headersList.forEach((value, key) => (negotiatorHeaders[key] = value))
// Use negotiator and intl-localematcher to get best locale // Use negotiator and intl-localematcher to get best locale
languages = new Negotiator({ headers: negotiatorHeaders }).languages() languages = new Negotiator({ headers: negotiatorHeaders }).languages()
} }

View File

@ -51,7 +51,7 @@
"react-i18next": "^12.2.0", "react-i18next": "^12.2.0",
"react-markdown": "^8.0.6", "react-markdown": "^8.0.6",
"react-syntax-highlighter": "^15.5.0", "react-syntax-highlighter": "^15.5.0",
"react-tooltip": "~5.8.3", "react-tooltip": "~5.29.1",
"rehype-katex": "^7.0.1", "rehype-katex": "^7.0.1",
"remark-breaks": "^4.0.0", "remark-breaks": "^4.0.0",
"remark-gfm": "^4.0.0", "remark-gfm": "^4.0.0",