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_channel_provider.jsx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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

diff --git a/webapp/components/suggestion/search_channel_provider.jsx b/webapp/components/suggestion/search_channel_provider.jsx
index 283113fb9..8965e7a76 100644
--- a/webapp/components/suggestion/search_channel_provider.jsx
+++ b/webapp/components/suggestion/search_channel_provider.jsx
@@ -2,6 +2,7 @@
 // See License.txt for license information.
 
 import Suggestion from './suggestion.jsx';
+import Provider from './provider.jsx';
 
 import {autocompleteChannels} from 'actions/channel_actions.jsx';
 
@@ -32,15 +33,21 @@ class SearchChannelSuggestion extends Suggestion {
     }
 }
 
-export default class SearchChannelProvider {
+export default class SearchChannelProvider extends Provider {
     handlePretextChanged(suggestionId, pretext) {
         const captured = (/\b(?:in|channel):\s*(\S*)$/i).exec(pretext.toLowerCase());
         if (captured) {
             const channelPrefix = captured[1];
 
+            this.startNewRequest(channelPrefix);
+
             autocompleteChannels(
                 channelPrefix,
                 (data) => {
+                    if (this.shouldCancelDispatch(channelPrefix)) {
+                        return;
+                    }
+
                     const publicChannels = data;
 
                     const localChannels = ChannelStore.getAll();
-- 
cgit v1.2.3-1-g7c22

