perf: static rendering

This commit is contained in:
hamster1963 2024-09-30 23:30:34 +08:00
parent 99ead50d1c
commit dcc56b4577
2 changed files with 17 additions and 4 deletions

View File

@ -1,7 +1,13 @@
import { unstable_setRequestLocale } from "next-intl/server";
import ServerList from "../../../components/ServerList"; import ServerList from "../../../components/ServerList";
import ServerOverview from "../../../components/ServerOverview"; import ServerOverview from "../../../components/ServerOverview";
export default function Home() { export default function Home({
params: { locale },
}: {
params: { locale: string };
}) {
unstable_setRequestLocale(locale);
return ( return (
<div className="mx-auto grid w-full max-w-5xl gap-4 md:gap-6"> <div className="mx-auto grid w-full max-w-5xl gap-4 md:gap-6">
<ServerOverview /> <ServerOverview />

View File

@ -11,6 +11,8 @@ import { Inter as FontSans } from "next/font/google";
import { ThemeProvider } from "next-themes"; import { ThemeProvider } from "next-themes";
import { Viewport } from "next"; import { Viewport } from "next";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { locales } from "@/i18n-metadata";
import { unstable_setRequestLocale } from "next-intl/server";
const fontSans = FontSans({ const fontSans = FontSans({
subsets: ["latin"], subsets: ["latin"],
@ -35,7 +37,10 @@ export const viewport: Viewport = {
userScalable: false, userScalable: false,
}; };
export const dynamic = "force-static"; // export const dynamic = "force-static";
export async function generateStaticParams() {
return locales.map((locale) => ({ locale }));
}
export default function LocaleLayout({ export default function LocaleLayout({
children, children,
@ -44,12 +49,14 @@ export default function LocaleLayout({
children: React.ReactNode; children: React.ReactNode;
params: { locale: string }; params: { locale: string };
}) { }) {
unstable_setRequestLocale(locale);
const messages = useMessages(); const messages = useMessages();
return ( return (
<html lang={locale} suppressHydrationWarning> <html lang={locale} suppressHydrationWarning>
{/* <head> <head>
<PublicEnvScript /> <PublicEnvScript />
</head> */} </head>
<body <body
className={cn( className={cn(
"min-h-screen bg-background font-sans antialiased", "min-h-screen bg-background font-sans antialiased",