Skip to content

Fix duplicate sends when Enter is pressed rapidly in MessageInput#43

Open
splindsay-92 wants to merge 1 commit intomainfrom
fix/message-input-duplicate-send
Open

Fix duplicate sends when Enter is pressed rapidly in MessageInput#43
splindsay-92 wants to merge 1 commit intomainfrom
fix/message-input-duplicate-send

Conversation

@splindsay-92
Copy link
Copy Markdown
Contributor

@splindsay-92 splindsay-92 commented Apr 20, 2026

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.

@github-actions github-actions Bot temporarily deployed to staging/pull/43/storybook April 20, 2026 13:05 Inactive
@splindsay-92 splindsay-92 marked this pull request as ready for review April 20, 2026 14:52
@splindsay-92 splindsay-92 requested a review from AndyTWF April 20, 2026 14:52
if (!trimmedMessage) return;

// Clear synchronously so rapid Enter presses don't re-send the same text.
setMessage('');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair point, that will block the input, which is arguably clearer.

@splindsay-92 splindsay-92 force-pushed the fix/message-input-duplicate-send branch from 72bf7d6 to b47c118 Compare April 21, 2026 09:54
@github-actions github-actions Bot temporarily deployed to staging/pull/43/storybook April 21, 2026 09:55 Inactive
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants