Skip to content

Commit

Permalink
fix: await word replace before submitting message (#2332)
Browse files Browse the repository at this point in the history
### 🎯 Goal

Fixes a race condition with emoji auto-replacement when submitting a
message.

### πŸ›  Implementation details

`_replaceWord` is an async method, we should await it before submitting.

### 🎨 UI Changes

Before:


https://github.com/GetStream/stream-chat-react/assets/975978/d989b491-d301-43c0-9386-ffc41f00f4ee

After:


https://github.com/GetStream/stream-chat-react/assets/975978/3fcf49bf-84e2-46cc-92f4-9eafd2f1c2b0

### To-Do

- [ ] Bump SDK in website demo
  • Loading branch information
myandrienko authored Mar 19, 2024
1 parent 17f6b0d commit f396a81
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/AutoCompleteTextarea/Textarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ export class ReactTextareaAutocomplete extends React.Component {
if (event.key === 'Escape') return this._closeAutocomplete();
};

_onEnter = (event) => {
_onEnter = async (event) => {
if (!this.textareaRef) return;

const trigger = this.state.currentTrigger;

if (!trigger || !this.state.data) {
// trigger a submit
this._replaceWord();
await this._replaceWord();
if (this.textareaRef) {
this.textareaRef.selectionEnd = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/MessageInput/__tests__/MessageInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ function axeNoViolations(container) {
}),
);

act(() => fireEvent.keyDown(input, { key: 'Enter' }));
await act(() => fireEvent.keyDown(input, { key: 'Enter' }));

expect(submitHandler).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down

0 comments on commit f396a81

Please sign in to comment.