Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit d2b614e

Browse files
committed
fix: guard inputValue.trim() against undefined to prevent TypeError (#12304)
1 parent ad25634 commit d2b614e

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
245245
}, [selectedType, searchQuery])
246246

247247
const handleEnhancePrompt = useCallback(() => {
248-
const trimmedInput = inputValue.trim()
248+
const trimmedInput = (inputValue ?? "").trim()
249249

250250
if (trimmedInput) {
251251
setIsEnhancingPrompt(true)
@@ -259,7 +259,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
259259

260260
// Memoized check for whether the input has content (text or images)
261261
const hasInputContent = useMemo(() => {
262-
return inputValue.trim().length > 0 || selectedImages.length > 0
262+
return (inputValue ?? "").trim().length > 0 || selectedImages.length > 0
263263
}, [inputValue, selectedImages])
264264

265265
// Compute the key combination text for the send button tooltip based on enterBehavior

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
203203

204204
// Compute whether auto-approval is paused (user is typing in a followup)
205205
const isFollowUpAutoApprovalPaused = useMemo(() => {
206-
return !!(inputValue && inputValue.trim().length > 0 && clineAsk === "followup")
206+
return !!(inputValue && (inputValue ?? "").trim().length > 0 && clineAsk === "followup")
207207
}, [inputValue, clineAsk])
208208

209209
// Cancel auto-approval timeout when user starts typing
@@ -710,7 +710,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
710710

711711
// Handle enqueue button click from textarea
712712
const handleEnqueueCurrentMessage = useCallback(() => {
713-
const text = inputValue.trim()
713+
const text = (inputValue ?? "").trim()
714714
if (text || selectedImages.length > 0) {
715715
vscode.postMessage({
716716
type: "queueMessage",
@@ -1536,12 +1536,12 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
15361536

15371537
useImperativeHandle(ref, () => ({
15381538
acceptInput: () => {
1539-
const hasInput = inputValue.trim() || selectedImages.length > 0
1539+
const hasInput = (inputValue ?? "").trim() || selectedImages.length > 0
15401540

15411541
// Special case: during command_output, queue the message instead of
15421542
// triggering the primary button action (which would lose the message)
15431543
if (clineAskRef.current === "command_output" && hasInput) {
1544-
vscode.postMessage({ type: "queueMessage", text: inputValue.trim(), images: selectedImages })
1544+
vscode.postMessage({ type: "queueMessage", text: (inputValue ?? "").trim(), images: selectedImages })
15451545
setInputValue("")
15461546
setSelectedImages([])
15471547
return

0 commit comments

Comments
 (0)