From 178d25b3b9d76d6d3c737a0c2176d4e02696002e Mon Sep 17 00:00:00 2001 From: Roo Code Date: Mon, 28 Jul 2025 22:43:51 +0000 Subject: [PATCH] fix: address PR review feedback for auto-focus functionality - Remove inconsistent setTimeout approach in ChatView.tsx - Fix race condition in ClineProvider.ts by combining sequential messages - Update message interfaces to support followUpAction property - Ensure all TypeScript types are properly defined --- src/core/webview/ClineProvider.ts | 9 ++++++--- src/core/webview/webviewMessageHandler.ts | 6 +++++- src/shared/ExtensionMessage.ts | 2 ++ src/shared/WebviewMessage.ts | 1 + webview-ui/src/components/chat/ChatView.tsx | 6 ++---- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 9e3a76f5aa..0b9645d0a0 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1166,9 +1166,12 @@ export class ClineProvider await this.initClineWithHistoryItem(historyItem) // Clears existing task. } - await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" }) - // Focus the input after loading the task - await this.postMessageToWebview({ type: "action", action: "focusInput" }) + // Combine both actions into a single message to avoid race condition + await this.postMessageToWebview({ + type: "action", + action: "chatButtonClicked", + followUpAction: "focusInput", + }) } async exportTaskWithId(id: string) { diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index e8ba3c112e..fb80c6ced8 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -434,7 +434,11 @@ export const webviewMessageHandler = async ( } break case "showTaskWithId": - provider.showTaskWithId(message.text!) + await provider.showTaskWithId(message.text!) + // Handle any follow-up action if specified + if (message.followUpAction) { + await provider.postMessageToWebview({ type: "action", action: message.followUpAction }) + } break case "condenseTaskContextRequest": provider.condenseTaskContext(message.text!) diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 000762e317..a848fe509c 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -122,6 +122,8 @@ export interface ExtensionMessage { | "didBecomeVisible" | "focusInput" | "switchTab" + | string // Allow any string for flexibility + followUpAction?: string // For follow-up actions after main message handling invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage" state?: ExtensionState images?: string[] diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index 795e276522..2552150ff2 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -244,6 +244,7 @@ export interface WebviewMessage { visibility?: ShareVisibility // For share visibility hasContent?: boolean // For checkRulesDirectoryResult checkOnly?: boolean // For deleteCustomMode check + followUpAction?: string // For follow-up actions after main message handling codeIndexSettings?: { // Global state settings codebaseIndexEnabled: boolean diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index cc24faeb4f..b89a1fdc2e 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -596,10 +596,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction { vscode.postMessage({ type: "clearTask" }) - // Focus the textarea after starting a new task - setTimeout(() => { - textAreaRef.current?.focus() - }, 100) + // Focus the textarea directly after starting a new task + textAreaRef.current?.focus() }, []) // This logic depends on the useEffect[messages] above to set clineAsk,