修复优化代码带来的错误

This commit is contained in:
2026-09-17 04:45:50 +08:00
parent 7f6323f64c
commit d3a09954ba
2 changed files with 6 additions and 5 deletions
-3
View File
@@ -1,4 +1,3 @@
import Script from "next/script";
import "@/app/globals.css"; import "@/app/globals.css";
export { metadata, viewport } from "@/components/layout/site-document"; export { metadata, viewport } from "@/components/layout/site-document";
@@ -8,8 +7,6 @@ export default function RootLayout({ children }: Readonly<{ children: React.Reac
<html lang="zh-Hans" suppressHydrationWarning> <html lang="zh-Hans" suppressHydrationWarning>
<body> <body>
{children} {children}
<Script id="theme-preference" src="/init-theme.js" strategy="beforeInteractive" />
<Script id="locale-canonicalization" src="/init-locale.js" strategy="beforeInteractive" />
</body> </body>
</html> </html>
); );
+6 -2
View File
@@ -3,7 +3,7 @@
import { useRouteLocale } from "@/components/layout/locale-context"; import { useRouteLocale } from "@/components/layout/locale-context";
import Image from "next/image"; import Image from "next/image";
import { useEffect, useState } from "react"; import { useEffect, useState, useSyncExternalStore } from "react";
import { applyLocale, getInitialLocale, withLocale, getLocaleMessages, type Locale } from "@/lib/i18n"; import { applyLocale, getInitialLocale, withLocale, getLocaleMessages, type Locale } from "@/lib/i18n";
import { ThemeToggle } from "@/components/layout/theme-toggle"; import { ThemeToggle } from "@/components/layout/theme-toggle";
@@ -19,9 +19,13 @@ function isIcpVisibleHost(hostname: string) {
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname.endsWith(".kivotos.cc"); return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname.endsWith(".kivotos.cc");
} }
const subscribeToHost = () => () => {};
const getIcpVisibility = () => typeof window !== "undefined" && isIcpVisibleHost(window.location.hostname);
const getServerIcpVisibility = () => false;
export function SiteFooter() { export function SiteFooter() {
const [locale, setLocale] = useState<Locale>(useRouteLocale()); const [locale, setLocale] = useState<Locale>(useRouteLocale());
const [showIcp] = useState(() => typeof window !== "undefined" && isIcpVisibleHost(window.location.hostname)); const showIcp = useSyncExternalStore(subscribeToHost, getIcpVisibility, getServerIcpVisibility);
useEffect(() => { useEffect(() => {
const syncLocale = (nextLocale: Locale) => setLocale(nextLocale); const syncLocale = (nextLocale: Locale) => setLocale(nextLocale);