Skip to content

Commit f71111a

Browse files
committed
fix: address code review feedback from roomote bot
P1 fixes: - clearDraft already in dependency arrays (verified) P2 fixes: - Clear selectedImages after queueing to prevent image duplication P3 fixes: - Add cleanup for pending debounce timers when storageKey changes in useAutosaveDraft
1 parent e2b4d91 commit f71111a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,14 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
608608
try {
609609
console.log("queueMessage", text, images)
610610
vscode.postMessage({ type: "queueMessage", text, images })
611+
// Clear selectedImages to prevent image duplication
612+
// Images are now in the queue, so we clear them from the UI state
613+
setSelectedImages([])
611614
// RACE CONDITION FIX: Do NOT clear draft immediately when queueing
612615
// The message is queued, not sent yet. Keep the draft visible until
613616
// the system processes the queue. This prevents data loss if user
614617
// typed quickly (<100ms) or if concurrent tool response arrived.
615618
// The draft will be cleared when the queued message is actually processed.
616-
// Note: setSelectedImages is also kept to maintain the message state
617619
} catch (error) {
618620
console.error(
619621
`Failed to queue message: ${error instanceof Error ? error.message : String(error)}`,

webview-ui/src/hooks/useAutosaveDraft.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ export const useAutosaveDraft = (options: UseAutosaveDraftOptions): UseAutosaveD
9696
setDraftContent(savedDraft)
9797
setHasInitialDraft(true)
9898
}
99+
100+
// Cleanup: clear any pending debounce when storageKey changes
101+
return () => {
102+
if (debounceTimerRef.current !== null) {
103+
clearTimeout(debounceTimerRef.current)
104+
debounceTimerRef.current = null
105+
}
106+
setIsDebouncing(false)
107+
}
99108
}, [storageKey, safeLocalStorage])
100109

101110
/**

0 commit comments

Comments
 (0)