Skip to content

Commit

Permalink
fix: Prevent crash from recursive calls to setState. (#306)
Browse files Browse the repository at this point in the history
In some instances setState calls updateSuggestionsPosition which calls
setState which calls updateSuggestionsPosition... until it crashes.
  • Loading branch information
Amazing Marvin authored and jfschwarz committed Feb 21, 2019
1 parent c7043f5 commit a93665a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/MentionsInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,12 @@ class MentionsInput extends React.Component {
this.updateSuggestionsPosition()
}

componentDidUpdate(prevProps) {
this.updateSuggestionsPosition()
componentDidUpdate(prevProps, prevState) {
// Update position of suggestions unless this componentDidUpdate was
// triggered by an update to suggestionsPosition.
if (prevState.suggestionsPosition === this.state.suggestionsPosition) {
this.updateSuggestionsPosition()
}

// maintain selection in case a mention is added/removed causing
// the cursor to jump to the end
Expand Down

0 comments on commit a93665a

Please sign in to comment.