Skip to content

fix: guard inputValue.trim() against undefined to prevent TypeError#12305

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/12304-chat-textarea-trim-typeerror
Draft

fix: guard inputValue.trim() against undefined to prevent TypeError#12305
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/12304-chat-textarea-trim-typeerror

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 Bot commented May 9, 2026

Related GitHub Issue

Closes: #12304

Description

This PR attempts to address Issue #12304. Feedback and guidance are welcome.

Root Cause: inputValue (typed as string) can be undefined at runtime during race conditions (e.g., when inputValueRef.current is stale and passed to setInputValue), causing inputValue.trim() to throw a TypeError: Cannot read properties of undefined (reading 'trim').

Fix: Added defensive nullish coalescing guards (inputValue ?? "") at all 6 call sites where .trim() is invoked on inputValue:

  • ChatTextArea.tsx (2 locations):

    • handleEnhancePrompt: (inputValue ?? "").trim()
    • hasInputContent useMemo: (inputValue ?? "").trim().length > 0
  • ChatView.tsx (4 locations):

    • isFollowUpAutoApprovalPaused useMemo
    • handleEnqueueCurrentMessage callback
    • acceptInput imperative handle (2 occurrences)

This is a minimal, non-breaking change that prevents the crash without altering any behavior when inputValue is a valid string.

Test Procedure

  • All 71 existing tests in ChatTextArea.spec.tsx and ChatView.spec.tsx continue to pass
  • Full monorepo lint and type-check pass cleanly
  • Manual verification: the fix guards against the exact crash path shown in the stack trace

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: Existing tests cover the changed code paths and all pass.
  • Documentation Impact: No documentation updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The fix uses ?? (nullish coalescing) rather than || to specifically guard against undefined/null while preserving the empty string "" behavior.

Interactively review PR in Roo Code Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] TypeError: Cannot read properties of undefined (reading 'trim') at ChatTextArea.tsx

1 participant