From cadc9e11e4c5456bae97d8ba4031ea9e72edf7fb Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Wed, 21 Dec 2016 12:45:21 -0500
Subject: Remove race between multiple autocomplete requests (#4860)

---
 webapp/components/suggestion/search_user_provider.jsx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'webapp/components/suggestion/search_user_provider.jsx')

diff --git a/webapp/components/suggestion/search_user_provider.jsx b/webapp/components/suggestion/search_user_provider.jsx
index 6fce8edcf..bff59ace8 100644
--- a/webapp/components/suggestion/search_user_provider.jsx
+++ b/webapp/components/suggestion/search_user_provider.jsx
@@ -2,6 +2,7 @@
 // See License.txt for license information.
 
 import Suggestion from './suggestion.jsx';
+import Provider from './provider.jsx';
 
 import {autocompleteUsersInTeam} from 'actions/user_actions.jsx';
 
@@ -56,15 +57,21 @@ class SearchUserSuggestion extends Suggestion {
     }
 }
 
-export default class SearchUserProvider {
+export default class SearchUserProvider extends Provider {
     handlePretextChanged(suggestionId, pretext) {
         const captured = (/\bfrom:\s*(\S*)$/i).exec(pretext.toLowerCase());
         if (captured) {
             const usernamePrefix = captured[1];
 
+            this.startNewRequest(usernamePrefix);
+
             autocompleteUsersInTeam(
                 usernamePrefix,
                 (data) => {
+                    if (this.shouldCancelDispatch(usernamePrefix)) {
+                        return;
+                    }
+
                     const users = data.in_team;
                     const mentions = users.map((user) => user.username);
 
-- 
cgit v1.2.3-1-g7c22

