This commit is contained in:
hailin 2025-05-21 14:15:01 +08:00
parent a3021b01b4
commit 6cd0444bb0
2 changed files with 55 additions and 42 deletions

View File

@ -122,36 +122,9 @@ export default async function RootLayout({
//console.log("[layout.tsx]..............current locale: ", {locale}); //console.log("[layout.tsx]..............current locale: ", {locale});
return (
<html lang="en" suppressHydrationWarning>
<head>
{/* 使用 next/script 注入 public/env.js 文件 */}
<Script
src="/env.js"
strategy="beforeInteractive" // 确保在 React 启动之前加载
/>
</head>
<body className={inter.className}>
<Providers attribute="class" defaultTheme="dark">
<TranslationsProvider
namespaces={i18nNamespaces}
locale={locale}
resources={resources}
>
<Toaster richColors position="top-center" duration={3000} />
<div className="bg-background text-foreground flex h-dvh flex-col items-center overflow-x-auto">
{data.session ? <GlobalState>{children}</GlobalState> : children}
</div>
</TranslationsProvider>
</Providers>
</body>
</html>
)
// return ( // return (
// <html lang="en" suppressHydrationWarning>
// <body className={inter.className}>
// <Providers attribute="class" defaultTheme="dark"> // <Providers attribute="class" defaultTheme="dark">
// <TranslationsProvider // <TranslationsProvider
// namespaces={i18nNamespaces} // namespaces={i18nNamespaces}
@ -159,11 +132,28 @@ export default async function RootLayout({
// resources={resources} // resources={resources}
// > // >
// <Toaster richColors position="top-center" duration={3000} /> // <Toaster richColors position="top-center" duration={3000} />
// <div className={`${inter.className} bg-background text-foreground flex h-dvh flex-col items-center overflow-x-auto`}> // <div className="bg-background text-foreground flex h-dvh flex-col items-center overflow-x-auto">
// {data.session ? <GlobalState>{children}</GlobalState> : children} // {data.session ? <GlobalState>{children}</GlobalState> : children}
// </div> // </div>
// </TranslationsProvider> // </TranslationsProvider>
// </Providers> // </Providers>
// </body>
// </html>
// ) // )
return (
<Providers attribute="class" defaultTheme="dark">
<TranslationsProvider
namespaces={i18nNamespaces}
locale={locale}
resources={resources}
>
<Toaster richColors position="top-center" duration={3000} />
<div className={`${inter.className} bg-background text-foreground flex h-dvh flex-col items-center overflow-x-auto`}>
{data.session ? <GlobalState>{children}</GlobalState> : children}
</div>
</TranslationsProvider>
</Providers>
)
} }

View File

@ -0,0 +1,23 @@
/*
eslint-disable @next/next/no-sync-scripts
/env.js window.RUNTIME_ENV
Supabase React
*/
import { Html, Head, Main, NextScript } from "next/document";
export default function Document() {
return (
<Html lang="en">
<Head>
{/* 使用 defer 确保 env.js 加载顺序 */}
<script src="/env.js" defer />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}