From ee7222929a56a0cae895aa2d6a25ee42cdbbbd93 Mon Sep 17 00:00:00 2001 From: Cloud Bot Date: Tue, 24 Mar 2026 11:58:48 +0000 Subject: [PATCH] =?UTF-8?q?fix(hydration):=20PuaPanel=20placeholder=20?= =?UTF-8?q?=E6=94=B9=E7=94=A8=20useEffect=20=E9=9A=8F=E6=9C=BA=E9=80=89?= =?UTF-8?q?=E5=8F=96=EF=BC=8C=E4=BF=AE=E5=A4=8D=20SSR/=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=20hydration=20=E4=B8=8D=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/game/page.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/game/page.tsx b/app/game/page.tsx index 85c00cb..3216b17 100644 --- a/app/game/page.tsx +++ b/app/game/page.tsx @@ -261,7 +261,11 @@ function PuaPanel({ gameReady, hc, waveStarted }: { gameReady: boolean; hc: numb const [insufficient, setInsufficient] = useState(false) const [dupWarning, setDupWarning] = useState(null) const textareaRef = useRef(null) - const placeholder = useRef(PUA_PLACEHOLDERS[Math.floor(Math.random() * PUA_PLACEHOLDERS.length)]).current + const [placeholder, setPlaceholder] = useState(PUA_PLACEHOLDERS[0]) + useEffect(() => { + // 只在客户端随机选取,避免 SSR/客户端 hydration 不匹配 + setPlaceholder(PUA_PLACEHOLDERS[Math.floor(Math.random() * PUA_PLACEHOLDERS.length)]) + }, []) const cost = calcPuaCost(hc) const canAfford = hc >= cost