Skip to content

Commit 5859087

Browse files
committed
refactor: remove inputValue from dependency array using ref
- Use inputValueRef to capture current input value instead of including it in the dependency array - This prevents unnecessary re-creation of the handleSuggestionClickInRow callback on every keystroke - Maintains the same functionality while improving performance
1 parent ffa325d commit 5859087

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
166166
const apiMetrics = useMemo(() => getApiMetrics(modifiedMessages), [modifiedMessages])
167167

168168
const [inputValue, setInputValue] = useState("")
169+
const inputValueRef = useRef(inputValue)
169170
const textAreaRef = useRef<HTMLTextAreaElement>(null)
170171
const [sendingDisabled, setSendingDisabled] = useState(false)
171172
const [selectedImages, setSelectedImages] = useState<string[]>([])
@@ -207,6 +208,11 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
207208
clineAskRef.current = clineAsk
208209
}, [clineAsk])
209210

211+
// Keep inputValueRef in sync with inputValue state
212+
useEffect(() => {
213+
inputValueRef.current = inputValue
214+
}, [inputValue])
215+
210216
useEffect(() => {
211217
isMountedRef.current = true
212218
return () => {
@@ -1495,21 +1501,13 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
14951501
} else {
14961502
// Don't clear the input value when sending a follow-up choice
14971503
// The message should be sent but the text area should preserve what the user typed
1498-
const preservedInput = inputValue
1504+
const preservedInput = inputValueRef.current
14991505
handleSendMessage(suggestion.answer, [])
15001506
// Restore the input value after sending
15011507
setInputValue(preservedInput)
15021508
}
15031509
},
1504-
[
1505-
handleSendMessage,
1506-
setInputValue,
1507-
switchToMode,
1508-
alwaysAllowModeSwitch,
1509-
clineAsk,
1510-
markFollowUpAsAnswered,
1511-
inputValue,
1512-
],
1510+
[handleSendMessage, setInputValue, switchToMode, alwaysAllowModeSwitch, clineAsk, markFollowUpAsAnswered],
15131511
)
15141512

15151513
const handleBatchFileResponse = useCallback((response: { [key: string]: boolean }) => {

0 commit comments

Comments
 (0)