Skip to content

Commit

Permalink
fix: message input not preventing default on enter on React 16 (#2380)
Browse files Browse the repository at this point in the history
React 16 had a wacky thing called [event
pooling](https://legacy.reactjs.org/docs/legacy-event-pooling.html).
Basically you couldn't use event objects outside of the microtask in
which the event handler was triggered, unless you explicitly called
`event.persist()`.

When we made key down handler on message input async in
#2332, we broke this
rule. So `preventDefault()` in [submit
handler](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/hooks/useSubmitHandler.ts#L119)
became a no-op.

React still provides the `perist()` method on synthetic events, even in
newer versions, so we just use it to fix the issue.
  • Loading branch information
myandrienko committed May 1, 2024
1 parent 70a478e commit ca6761f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/AutoCompleteTextarea/Textarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export class ReactTextareaAutocomplete extends React.Component {
const trigger = this.state.currentTrigger;

if (!trigger || !this.state.data) {
// https://legacy.reactjs.org/docs/legacy-event-pooling.html
event.persist();
// trigger a submit
await this._replaceWord();
if (this.textareaRef) {
Expand Down

0 comments on commit ca6761f

Please sign in to comment.