Fix GlobalChatPane input delay after AI response completes

Release the loading state immediately when finish_reason is received,
but don't break from the for-await loop. Breaking triggers async iterator
cleanup which can cause a multi-second delay before the input becomes
available again. Instead, let the stream drain naturally while the UI
is already unlocked for user input.
This commit is contained in:
MK Fain committed 2025-12-03 21:14:45 -06:00
1 parent 6457fbda76
commit ad217937a3
1 file changed
+2 -5
+2 -5
View File
@@ -143,15 +143,12 @@ export function GlobalChatProvider({ children }: GlobalChatProviderProps) {
return updated;
});
// Check if the stream is finished (finish_reason is set)
// Only release once to avoid multiple state updates
// Release loading as soon as finish_reason is received
// Don't break - let the stream drain naturally to avoid async iterator cleanup delays
const finishReason = chunk.choices[0]?.finish_reason;
if (finishReason && !loadingReleased) {
loadingReleased = true;
// Response is complete, release the input immediately
setIsLoading(false);
// Break out of the loop - we don't need any more chunks
break;
}
}