From 4b356f58f225991d076756b0149b77914b053d98 Mon Sep 17 00:00:00 2001 From: chenhang Date: Thu, 11 Jun 2026 18:38:11 +0800 Subject: [PATCH] refactor(chat): remove unused ChatScreenVisible and ChatScreenInvisible events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The screen-lifecycle events were dead code: the transitions in chat-machine (idle <-> ready) had no caller behavior tied to them, and the dispatches in chat-screen.tsx were the only senders. Drop the union members, both state transitions, and the mount-effect dispatches. The idle state remains declared as initial but is no longer reachable at runtime; can be refactored in a follow-up. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/app/chat/components/chat-screen.tsx | 8 ++------ src/stores/chat/chat-events.ts | 2 -- src/stores/chat/chat-machine.ts | 5 +++-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/app/chat/components/chat-screen.tsx b/src/app/chat/components/chat-screen.tsx index fde5117b..a80ee95f 100644 --- a/src/app/chat/components/chat-screen.tsx +++ b/src/app/chat/components/chat-screen.tsx @@ -8,7 +8,7 @@ * - **订阅 auth 状态机**(loginStatus)—— * - 派生 isGuest / 驱动 WS 生命周期 / 驱动初次加载(按 loginStatus 选 ChatInit vs ChatLoadMoreHistory) * - 驱动历史加载 - * - 屏幕生命周期事件(init / visible / invisible) + * - 屏幕初始化(mount 时按 loginStatus 派初次加载) * - 配额告警监听(**仅**游客 —— "非游客无消息限制"业务事实) * - WebSocket 生命周期管理(基于 auth 状态机的 loginStatus) * - 渲染骨架(背景 + 顶部栏 + 消息区 + 输入栏) @@ -103,14 +103,10 @@ export function ChatScreen() { const [quotaExhausted, setQuotaExhausted] = useState(false); // ───────────────────────────────────────────────────────────── - // 屏幕生命周期 —— mount 时按 loginStatus 派初次加载 + // mount 时按 loginStatus 派初次加载 // ───────────────────────────────────────────────────────────── useEffect(() => { - chatDispatch({ type: "ChatScreenVisible" }); dispatchInitialLoad(authState.loginStatus, chatDispatch); - return () => { - chatDispatch({ type: "ChatScreenInvisible" }); - }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [chatDispatch]); // 注:mount useEffect 故意**不**依赖 loginStatus —— 首次 mount 时机是固定的 diff --git a/src/stores/chat/chat-events.ts b/src/stores/chat/chat-events.ts index 2ac43d47..f0cbf33c 100644 --- a/src/stores/chat/chat-events.ts +++ b/src/stores/chat/chat-events.ts @@ -9,8 +9,6 @@ */ export type ChatEvent = | { type: "ChatInit" } - | { type: "ChatScreenVisible" } - | { type: "ChatScreenInvisible" } | { type: "ChatSendMessage"; content: string } | { type: "ChatSendImage"; imageBase64: string } | { type: "ChatLoadMoreHistory" } diff --git a/src/stores/chat/chat-machine.ts b/src/stores/chat/chat-machine.ts index 6b8db701..00243226 100644 --- a/src/stores/chat/chat-machine.ts +++ b/src/stores/chat/chat-machine.ts @@ -251,7 +251,6 @@ export const chatMachine = setup({ idle: { on: { ChatInit: "initializing", - ChatScreenVisible: "ready", ChatLoadMoreHistory: "loadingMoreHistory", ChatSendMessage: { guard: ({ event }) => event.content.trim().length > 0, @@ -308,7 +307,9 @@ export const chatMachine = setup({ actions: "appendUserImage", }, ChatLoadMoreHistory: "loadingMoreHistory", - ChatScreenInvisible: "idle", + ChatAuthStatusChanged: { + actions: "refreshAuthStatus", + }, ChatAISentenceReceived: { actions: "appendOrUpdateAISentence", },