summaryrefslogtreecommitdiffstats
path: root/webapp/stores/suggestion_store.jsx
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-12-21 12:45:21 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2016-12-21 12:45:21 -0500
commitcadc9e11e4c5456bae97d8ba4031ea9e72edf7fb (patch)
treea1d98954c3fdc2fbd30a04289c0b6c5430f45ad9 /webapp/stores/suggestion_store.jsx
parent26e43c671c4252dccbf3b0e9257407d41e4297ae (diff)
downloadchat-cadc9e11e4c5456bae97d8ba4031ea9e72edf7fb.tar.gz
chat-cadc9e11e4c5456bae97d8ba4031ea9e72edf7fb.tar.bz2
chat-cadc9e11e4c5456bae97d8ba4031ea9e72edf7fb.zip
Remove race between multiple autocomplete requests (#4860)
Diffstat (limited to 'webapp/stores/suggestion_store.jsx')
-rw-r--r--webapp/stores/suggestion_store.jsx17
1 files changed, 10 insertions, 7 deletions
diff --git a/webapp/stores/suggestion_store.jsx b/webapp/stores/suggestion_store.jsx
index 2dbef0490..a0cd88370 100644
--- a/webapp/stores/suggestion_store.jsx
+++ b/webapp/stores/suggestion_store.jsx
@@ -121,11 +121,6 @@ class SuggestionStore extends EventEmitter {
}
addSuggestions(id, terms, items, component, matchedPretext) {
- if (!this.getPretext(id).endsWith(matchedPretext)) {
- // These suggestions are out of date since the pretext has changed
- return;
- }
-
const suggestion = this.getSuggestions(id);
suggestion.terms.push(...terms);
@@ -222,6 +217,11 @@ class SuggestionStore extends EventEmitter {
suggestion.selection = suggestion.terms[selectionIndex];
}
+ checkIfPretextMatches(id, matchedPretext) {
+ const pretext = this.getPretext(id) || '';
+ return pretext.endsWith(matchedPretext);
+ }
+
handleEventPayload(payload) {
const {type, id, ...other} = payload.action;
@@ -241,9 +241,12 @@ class SuggestionStore extends EventEmitter {
this.emitSuggestionsChanged(id);
break;
case ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS:
- this.clearSuggestions(id);
+ if (!this.checkIfPretextMatches(id, other.matchedPretext)) {
+ // These suggestions are out of date since the pretext has changed
+ return;
+ }
- // ensure the matched pretext hasn't changed so that we don't receive suggestions for outdated pretext
+ this.clearSuggestions(id);
this.addSuggestions(id, other.terms, other.items, other.component, other.matchedPretext);
this.ensureSelectionExists(id);