Skip to content

fix(mothership): clear chat input after sending a message mid-conversation#4936

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/tri
Jun 10, 2026
Merged

fix(mothership): clear chat input after sending a message mid-conversation#4936
waleedlatif1 merged 1 commit into
stagingfrom
fix/tri

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Fixed the Mothership home chat input not clearing after sending a message mid-conversation: the message posts to the conversation as a user message, but the typed text stayed in the input.
  • Root cause: the handleSelectAdjust DOM-drift adoption (added in mothership v0.2, #4923) re-adopted the stale textarea DOM value back into React state. After submit clears value to '' synchronously, a select/mouseUp can fire while the controlled textarea still holds the just-sent text, so it got resurrected.
  • Fix: skip adoption when state is empty — an empty input is never a legitimate adoption source (autofill/password-manager/grammar editors all mutate existing text).

Type of Change

  • Bug fix

Testing

Tested manually — sending messages mid-conversation now clears the input every time; mention/skill chipification and paste behavior unchanged.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jun 10, 2026 1:58am

Request Review

@cursor

cursor Bot commented Jun 10, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Single guard in selection handling for the home chat input; no API, auth, or data-path changes.

Overview
Fixes the Mothership home chat input not clearing after send mid-conversation: the message posts, but the typed text reappears in the box.

In handleSelectAdjust, DOM-drift adoption (for autofill/password managers/extensions that skip React onChange) now runs only when valueRef.current is not empty. After submit, handleSubmit clears state synchronously while the controlled textarea can still briefly hold the sent text; a trailing select/mouseUp was calling adoptDomValue and pulling that stale DOM value back into React state.

Autofill-style adoption is unchanged whenever the input already has content in state.

Reviewed by Cursor Bugbot for commit f3439af. Configure here.

@greptile-apps

greptile-apps Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where the Mothership chat input failed to clear after sending a message mid-conversation. The stale-text resurrection was caused by handleSelectAdjust's DOM-drift adoption logic re-reading the still-populated textarea DOM value after handleSubmit had already set valueRef.current to ''.

  • Root cause: handleSubmit clears value/valueRef.current synchronously, but a trailing select/mouseUp event could fire before React reconciled the controlled textarea, causing adoptDomValue to pull the just-sent text back into state.
  • Fix: a single guard (valueRef.current !== '') skips DOM adoption when state is already empty, on the correct assumption that no legitimate browser autofill or grammar-extension fires against a genuinely empty input.

Confidence Score: 5/5

Safe to merge — a one-line guard on an edge case with clear, well-reasoned justification and no regressions to autofill or paste paths.

The change is a single targeted condition added to the DOM-adoption fast-path in handleSelectAdjust. The submit flow already sets valueRef.current = '' synchronously before the problematic event can fire, so the guard reliably catches the resurrection window. Autofill and grammar-extension adoption paths are unaffected because those mutations always target a non-empty input in practice. Paste and chip adoption use their own explicit paths that bypass handleSelectAdjust entirely.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Single-line guard added to handleSelectAdjust to skip DOM adoption when valueRef.current is already empty, preventing post-submit state resurrection. Change is minimal, well-commented, and correctly scoped.

Sequence Diagram

sequenceDiagram
    participant User
    participant DOM as textarea DOM
    participant Handler as handleSubmit
    participant Ref as valueRef
    participant Adopt as handleSelectAdjust (adoptDomValue)

    User->>Handler: press Enter / click Send
    Handler->>Ref: "valueRef.current = ''"
    Handler->>DOM: setValue('') → controlled re-render scheduled
    Note over DOM: DOM still holds "sent text" until re-render

    DOM-->>Adopt: select / mouseUp fires (before re-render)
    Note over Adopt: OLD: textarea.value ≠ valueRef.current ('') → adoptDomValue() resurrects text ❌
    Note over Adopt: NEW: valueRef.current === '' → skip adoption ✅

    DOM->>DOM: React re-render sets textarea value to ''
Loading

Reviews (1): Last reviewed commit: "fix(mothership): clear chat input after ..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit 3bf7104 into staging Jun 10, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/tri branch June 10, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant