Fix duplicate sends when Enter is pressed rapidly in MessageInput#43
Open
splindsay-92 wants to merge 1 commit intomainfrom
Open
Fix duplicate sends when Enter is pressed rapidly in MessageInput#43splindsay-92 wants to merge 1 commit intomainfrom
splindsay-92 wants to merge 1 commit intomainfrom
Conversation
AndyTWF
reviewed
Apr 20, 2026
| if (!trimmedMessage) return; | ||
|
|
||
| // Clear synchronously so rapid Enter presses don't re-send the same text. | ||
| setMessage(''); |
Collaborator
There was a problem hiding this comment.
Slight change of behaviour here - before if something failed to send, it would still preserve the text for a re-send.
Perhaps might be better to make it so the text is preserved, but we have a "requestInFlight" sort of bool that inhibits repeated presses?
Contributor
Author
There was a problem hiding this comment.
Fair point, that will block the input, which is arguably clearer.
72bf7d6 to
b47c118
Compare
The input was only cleared inside the sendMessage .then() callback, so rapid Enter presses would read the same text from messageRef before the first network round-trip resolved, firing sendMessage once per keypress. Add a re-entry guard so while a send is in flight, subsequent Enter presses short-circuit. The input keeps its content until the server confirms, at which point we clear it only if the user hasn't started composing a new message in the meantime. A failed send leaves the text in place for the user to retry. Fixes #42.
b47c118 to
bb6586e
Compare
AndyTWF
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The input was only cleared inside the sendMessage .then() callback, so rapid Enter presses would read the same text from messageRef before the first network round-trip resolved, firing sendMessage once per keypress.
Add a guard that checks if a request is inflight, only allowing a new send iff the previous has resolved or rejected.