fix: stabilize opencode session startup

This commit is contained in:
Haileyesus
2026-05-13 18:44:07 +03:00
parent 421bdd2f0f
commit 57aece12e6
7 changed files with 97 additions and 61 deletions

View File

@@ -13,7 +13,6 @@ const MESSAGES_PER_PAGE = 20;
const INITIAL_VISIBLE_MESSAGES = 100;
type PendingViewSession = {
sessionId: string | null;
startedAt: number;
};
@@ -160,7 +159,7 @@ export function useChatSessionState({
* Why this is essential:
* - Chat keeps local state that is not fully derived from `selectedSession`:
* `currentSessionId`, `pendingUserMessage`, streaming/status flags, message
* pagination/scroll bookkeeping, and pending session IDs in sessionStorage.
* pagination/scroll bookkeeping, and provider-specific sessionStorage keys.
* - If the user clicks New Session while already on the same route with no
* selected session, parent state updates can be idempotent and this local
* state would otherwise persist, making the click appear to "do nothing".
@@ -177,7 +176,6 @@ export function useChatSessionState({
setIsLoading(false);
setCurrentSessionId(null);
setPendingUserMessage(null);
sessionStorage.removeItem('pendingSessionId');
sessionStorage.removeItem('cursorSessionId');
messagesOffsetRef.current = 0;
setHasMoreMessages(false);
@@ -396,6 +394,12 @@ export function useChatSessionState({
// Main session loading effect — store-based
useEffect(() => {
if (!selectedSession || !selectedProject) {
// A new provider run can be in flight before the router has a canonical
// selectedSession. Keep the processing banner alive until complete/error.
if (pendingViewSessionRef.current) {
return;
}
resetStreamingState();
pendingViewSessionRef.current = null;
setClaudeStatus(null);
@@ -537,10 +541,6 @@ export function useChatSessionState({
}
}, [selectedSession]);
useEffect(() => {
if (selectedSession?.id) pendingViewSessionRef.current = null;
}, [pendingViewSessionRef, selectedSession?.id]);
// Scroll to search target
useEffect(() => {
if (!searchTarget || chatMessages.length === 0 || isLoadingSessionMessages) return;