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:
@@ -338,11 +338,10 @@ function AssistantWorkspace() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (skill.loading) return;
|
if (skill.loading) return;
|
||||||
if (!skillLoadedOnce.current) {
|
if (!skillLoadedOnce.current) {
|
||||||
// 初始加载完成,记录当前状态,不触发 applied
|
|
||||||
skillLoadedOnce.current = true;
|
skillLoadedOnce.current = true;
|
||||||
prevSkillEnabled.current = skill.enabled;
|
prevSkillEnabled.current = skill.enabled;
|
||||||
// 关掉时清理 localStorage 残留
|
// 初始加载:无条件清除 applied(清 localStorage 残留),面板只从用户点击打开
|
||||||
if (!skill.enabled && applied) {
|
if (applied) {
|
||||||
setApplied(false);
|
setApplied(false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -71,18 +71,10 @@ export function useModelIterationEnabled(): {
|
|||||||
// - 刷新页面也保持
|
// - 刷新页面也保持
|
||||||
// 不走后端 PATCH 是为了避开 __LOCALID_* 临时 session id 导致 404
|
// 不走后端 PATCH 是为了避开 __LOCALID_* 临时 session id 导致 404
|
||||||
export function useAppliedTraining(sessionId: string | null) {
|
export function useAppliedTraining(sessionId: string | null) {
|
||||||
|
// 不再从 localStorage 恢复 applied 状态——面板只通过用户本次会话中
|
||||||
|
// 显式点击 skill 按钮打开,避免页面加载时闪烁。
|
||||||
const [applied, setApplied] = useState(false);
|
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(
|
const setAppliedPersist = useCallback(
|
||||||
(next: boolean) => {
|
(next: boolean) => {
|
||||||
setApplied(next);
|
setApplied(next);
|
||||||
|
|||||||
Reference in New Issue
Block a user