Skip to content

fix(home): simplify enter-to-send queued message to single press#4008

Merged
waleedlatif1 merged 2 commits intostagingfrom
waleedlatif1/fix-enter-send-queue
Apr 7, 2026
Merged

fix(home): simplify enter-to-send queued message to single press#4008
waleedlatif1 merged 2 commits intostagingfrom
waleedlatif1/fix-enter-send-queue

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Simplify double-enter queue send: pressing Enter on empty input while streaming sends top queued message immediately
  • Remove unnecessary priming/timer system (was requiring 3 presses instead of 2)
  • Net deletion: 3 additions, 32 deletions

Type of Change

  • Bug fix

Testing

Tested manually

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
Copy link
Copy Markdown

vercel bot commented Apr 7, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 7, 2026 4:09am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 7, 2026

PR Summary

Low Risk
Low risk: small, localized UX/keyboard-handling change that removes a timer-based “priming” state; main risk is subtle behavior change when pressing Enter on an empty input while streaming.

Overview
Pressing Enter on an empty UserInput while a response is streaming now immediately sends the top queued message, instead of using a multi-press “primed” flow.

This removes the queue-send priming/timer state from MothershipChat and the related onPrimedDismiss prop/logic from UserInput, simplifying the keydown handling path.

Reviewed by Cursor Bugbot for commit 21f3b51. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 7, 2026

Greptile Summary

This PR replaces the previous double-Enter priming/timer mechanism for sending queued messages with a simpler, more direct approach: pressing Enter on an empty input while the AI is streaming now immediately sends the top queued message. The simplification removes ~29 lines of timer/priming state complexity across both files.

The handleEnterWhileEmpty callback in mothership-chat.tsx uses the correct refs pattern (messageQueueRef, onSendQueuedMessageRef) so it always reads the latest state without needing to appear in useCallback deps. The PR also includes a second fix-up commit that guards the Enter key against calling handleSubmit() in the streaming+empty-input case.

  • handleEnterWhileEmpty correctly short-circuits with false when the queue is empty, avoiding a spurious dispatch
  • void onSendQueuedMessageRef.current(topMessage.id) correctly discards the returned Promise
  • The not-streaming + empty-input case is still unguarded: pressing Enter on an empty textarea when no generation is running falls through to handleSubmit(), which calls onSubmit('') with an empty string — the same class of bug the second commit was meant to prevent
  • The onEnterWhileEmpty prop is typed () => boolean but its return value is never used by the caller

Confidence Score: 4/5

Mostly safe; the core simplification is correct but a missing guard can submit empty messages when not streaming

The streaming+empty-input case is correctly handled by the new guard. The not-streaming+empty-input case still falls through to handleSubmit() and calls onSubmit('') — the same bug class the second commit aimed to fix, left incomplete. This is a real correctness gap that warrants attention before merge.

user-input.tsx — handleKeyDown needs a canSubmit-equivalent guard before the final handleSubmit() call

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Simplified Enter-key queue dispatch; missing canSubmit guard in handleKeyDown lets empty input fall through to handleSubmit() when not streaming
apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/mothership-chat.tsx Added handleEnterWhileEmpty using correct refs pattern to avoid stale closures; logic is clean and correct

Sequence Diagram

sequenceDiagram
    actor User
    participant UserInput
    participant MothershipChat
    participant Parent

    rect rgb(200, 220, 240)
    note over User,Parent: Empty Input + AI Streaming (new behavior)
    User->>UserInput: Enter (empty input, streaming)
    UserInput->>UserInput: handleKeyDown()
    note over UserInput: isSendingRef && !value.trim() → true
    UserInput->>MothershipChat: onEnterWhileEmpty()
    alt messageQueue has items
        MothershipChat->>Parent: onSendQueuedMessage(topMessage.id)
        Parent->>Parent: Send queued message
    else queue empty
        MothershipChat-->>UserInput: return false (no-op)
    end
    end

    rect rgb(220, 240, 200)
    note over User,Parent: Normal Submit
    User->>UserInput: Enter (with text)
    UserInput->>UserInput: handleKeyDown()
    UserInput->>UserInput: handleSubmit()
    UserInput->>Parent: onSubmit(text, files, contexts)
    end

    rect rgb(255, 220, 200)
    note over User,Parent: Unguarded Case (empty input, not streaming)
    User->>UserInput: Enter (empty input, NOT streaming)
    UserInput->>UserInput: handleKeyDown()
    note over UserInput: isSendingRef is false → falls through
    UserInput->>UserInput: handleSubmit()
    UserInput->>Parent: onSubmit('') — empty message submitted
    end
Loading

Comments Outside Diff (1)

  1. apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx, line 453-463 (link)

    P1 Empty input falls through to handleSubmit when not streaming

    When isSendingRef.current is false and valueRef.current.trim() is '' (not streaming, empty input), the guard condition on line 457 evaluates to false — so handleSubmit() is called unconditionally. handleSubmit never checks whether the value is non-empty; it calls onSubmit('') directly. The canSubmit flag (line 202) correctly disables the send button for empty input, but the Enter-key path bypasses that guard entirely.

    The second commit in this PR (21f3b51ae) was specifically named "prevent empty submit fallthrough when sending with empty input" and fixed the streaming+empty case — but the not-streaming+empty case is still unguarded. Consider adding an early return:

Reviews (2): Last reviewed commit: "fix(home): prevent empty submit fallthro..." | Re-trigger Greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

Fixed the empty submit fallthrough — the guard now always returns early when sending + empty input, and calls onEnterWhileEmpty as a side effect rather than using it as a gatekeeper. See 21f3b51.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 21f3b51. Configure here.

@waleedlatif1 waleedlatif1 merged commit 1e00a06 into staging Apr 7, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/fix-enter-send-queue branch April 7, 2026 04:19
emir-karabeg pushed a commit that referenced this pull request Apr 7, 2026
* fix(home): simplify enter-to-send queued message to single press

* fix(home): prevent empty submit fallthrough when sending with empty input
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.

1 participant