diff --git a/web/src/App.tsx b/web/src/App.tsx index 1777ffd3..70340610 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1704,8 +1704,14 @@ export default function App() { loadDayForAnchorRef.current = chatWindow.loadDayForAnchor; }, [chatWindow.loadDayForAnchor]); + const sessionValidatedRef = useRef(sessionValidated); + useEffect(() => { + sessionValidatedRef.current = sessionValidated; + }, [sessionValidated]); + useEffect(() => { const handleHashChange = () => { + if (sessionValidatedRef.current !== true) return; const parsed = parseAnchorHash(window.location.hash); if (!parsed) return; const currentActive = activeSessionIdRef.current; diff --git a/web/src/hooks/useChatWindow.ts b/web/src/hooks/useChatWindow.ts index 9ccc19ee..a6188042 100644 --- a/web/src/hooks/useChatWindow.ts +++ b/web/src/hooks/useChatWindow.ts @@ -301,6 +301,7 @@ export function useChatWindow({ // 跨日锚点拉取: 根据 messageId 拉取所属日分片并合并进窗口 const loadDayForAnchor = useCallback( async (messageId: number): Promise => { + if (!sessionId) return false; for (const b of dayStack) { if (b.messages.some((m) => m.serverId === messageId)) { return true;