From 759ee7a8e473caf2b30fea32302cbb6155ac8986 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Mon, 25 May 2026 01:03:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=20mode=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=94=B9=E4=B8=BA=E6=9C=8D=E5=8A=A1=E7=AB=AF=E7=9B=B4?= =?UTF-8?q?=E4=BC=A0=EF=BC=8C=E6=B6=88=E9=99=A4=E7=99=BB=E5=BD=95/?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=A1=A8=E5=8D=95=E5=88=87=E6=8D=A2=E9=97=AA?= =?UTF-8?q?=E7=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LoginPage 从 searchParams 提取 mode 作为 initialMode prop 传给 LoginClient, 替代客户端 useEffect 从 window.location.search 读取的方式,首次渲染即显示目标表单。 Tested: tsc --noEmit 通过, npm run build 通过 --- frontend/app/auth/login/page.tsx | 10 ++++++++-- frontend/components/auth/LoginClient.tsx | 17 +++-------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/frontend/app/auth/login/page.tsx b/frontend/app/auth/login/page.tsx index c5112f36..71d71141 100644 --- a/frontend/app/auth/login/page.tsx +++ b/frontend/app/auth/login/page.tsx @@ -2,7 +2,7 @@ import { LoginClient } from "@/components/auth/LoginClient"; import { I18nProvider } from "@/hooks/useI18n"; type PageProps = { - searchParams?: Promise<{ next?: string }>; + searchParams?: Promise<{ next?: string; mode?: string }>; }; function normalizeNextPath(input: string | undefined) { @@ -14,12 +14,18 @@ function normalizeNextPath(input: string | undefined) { return raw; } +function normalizeMode(input: string | undefined): "login" | "signup" { + if (input === "signup") return "signup"; + return "login"; +} + export default async function LoginPage({ searchParams }: PageProps) { const params = (await searchParams) || {}; const nextPath = normalizeNextPath(params.next); + const initialMode = normalizeMode(params.mode); return ( - + ); } diff --git a/frontend/components/auth/LoginClient.tsx b/frontend/components/auth/LoginClient.tsx index 4f2d69e5..58aa8eb7 100644 --- a/frontend/components/auth/LoginClient.tsx +++ b/frontend/components/auth/LoginClient.tsx @@ -26,12 +26,13 @@ type Mode = "login" | "signup"; type LoginClientProps = { nextPath: string; + initialMode?: Mode; }; -export function LoginClient({ nextPath }: LoginClientProps) { +export function LoginClient({ nextPath, initialMode }: LoginClientProps) { const router = useRouter(); const { locale } = useI18n(); - const [mode, setMode] = useState("login"); + const [mode, setMode] = useState(initialMode ?? "login"); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); @@ -40,18 +41,6 @@ export function LoginClient({ nextPath }: LoginClientProps) { const [resetSent, setResetSent] = useState(false); const [showPassword, setShowPassword] = useState(false); - useEffect(() => { - if (typeof window !== "undefined") { - const params = new URLSearchParams(window.location.search); - const m = params.get("mode"); - if (m === "signup") { - setMode("signup"); - } else if (m === "login") { - setMode("login"); - } - } - }, []); - const supabaseReady = hasSupabasePublicEnv(); const isLogin = mode === "login"; const siteOrigin =