Skip to content

Commit 188ba0d

Browse files
committed
fix: prevent race condition in code generation state
- Set isGenerating flag immediately before triggering generation to avoid UI state inconsistencies - Added flag update for both new chat and reconnection scenarios
1 parent d51310b commit 188ba0d

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/routes/chat/hooks/use-chat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ export function useChat({
294294
// Request file generation for new chats only
295295
if (!disableGenerate && urlChatId === 'new') {
296296
logger.debug('🔄 Starting code generation for new chat');
297+
setIsGenerating(true);
297298
sendWebSocketMessage(ws, 'generate_all');
298299
}
299300
});

src/routes/chat/utils/handle-websocket-message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export function createWebSocketMessageHandler(deps: HandleMessageDeps) {
254254

255255
if (state.shouldBeGenerating && !isGenerating) {
256256
logger.debug('🔄 Reconnected with shouldBeGenerating=true, auto-resuming generation');
257+
setIsGenerating(true);
257258
updateStage('code', { status: 'active' });
258259
sendWebSocketMessage(websocket, 'generate_all');
259260
}

0 commit comments

Comments
 (0)