Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Isolate rich text notifications from other input changes
Browse files Browse the repository at this point in the history
The step that would notify parent components of rich text state changes was
stirred into the input's change handler, which leads to race which the parent is
sometimes notified of the old rich text state instead of the new.

Here we avoid this complication by using a separate path for sending the rich
text state when we know we have updated it correctly.
  • Loading branch information
jryans committed Feb 22, 2019
1 parent 3e6199c commit ccd4dee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/views/rooms/MessageComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ export default class MessageComposer extends React.Component {
}

onInputStateChanged(inputState) {
// Merge the new input state with old to support partial updates
inputState = Object.assign({}, this.state.inputState, inputState);
this.setState({inputState});
}

Expand Down
8 changes: 6 additions & 2 deletions src/components/views/rooms/MessageComposerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ export default class MessageComposerInput extends React.Component {
}
const inputState = {
marks: editorState.activeMarks,
isRichTextEnabled: this.state.isRichTextEnabled,
blockType,
};
this.props.onInputStateChanged(inputState);
Expand Down Expand Up @@ -698,8 +697,13 @@ export default class MessageComposerInput extends React.Component {
this.setState({
editorState: this.createEditorState(enabled, editorState),
isRichTextEnabled: enabled,
}, ()=>{
}, () => {
this._editor.focus();
if (this.props.onInputStateChanged) {
this.props.onInputStateChanged({
isRichTextEnabled: enabled,
});
}
});

SettingsStore.setValue("MessageComposerInput.isRichTextEnabled", null, SettingLevel.ACCOUNT, enabled);
Expand Down

0 comments on commit ccd4dee

Please sign in to comment.