fix: eliminate training panel flash on page load

- Don't restore applied state from localStorage on mount (was causing
  first-frame flash when skill was already enabled)
- Always start with applied=false; only set true on user click

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
hupenglong1
2026-05-25 17:41:35 +08:00
parent 21c0cfc52d
commit 2acbd0b509
2 changed files with 4 additions and 13 deletions
+2 -10
View File
@@ -71,18 +71,10 @@ export function useModelIterationEnabled(): {
// - 刷新页面也保持
// 不走后端 PATCH 是为了避开 __LOCALID_* 临时 session id 导致 404
export function useAppliedTraining(sessionId: string | null) {
// 不再从 localStorage 恢复 applied 状态——面板只通过用户本次会话中
// 显式点击 skill 按钮打开,避免页面加载时闪烁。
const [applied, setApplied] = useState(false);
useEffect(() => {
if (!sessionId || typeof window === "undefined") {
setApplied(false);
return;
}
const stored =
window.localStorage.getItem(APPLIED_STORAGE_PREFIX + sessionId) === "1";
setApplied(stored);
}, [sessionId]);
const setAppliedPersist = useCallback(
(next: boolean) => {
setApplied(next);