From 6b2c4a346ba9c50d533eadb2c64086d67d32c565 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Mon, 16 Jan 2017 18:32:51 -0500
Subject: Discard outdated results in modal searches (#5082)

---
 webapp/components/member_list_channel.jsx | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

(limited to 'webapp/components/member_list_channel.jsx')

diff --git a/webapp/components/member_list_channel.jsx b/webapp/components/member_list_channel.jsx
index 75ecd8172..6f8a266ad 100644
--- a/webapp/components/member_list_channel.jsx
+++ b/webapp/components/member_list_channel.jsx
@@ -104,13 +104,17 @@ export default class MemberListChannel extends React.Component {
 
         clearTimeout(this.searchTimeoutId);
 
-        this.searchTimeoutId = setTimeout(
+        const searchTimeoutId = setTimeout(
             () => {
                 searchUsers(
                     term,
                     TeamStore.getCurrentId(),
                     {},
                     (users) => {
+                        if (searchTimeoutId !== this.searchTimeoutId) {
+                            return;
+                        }
+
                         this.setState({
                             loading: true,
                             search: true,
@@ -125,6 +129,8 @@ export default class MemberListChannel extends React.Component {
             },
             Constants.SEARCH_TIMEOUT_MILLISECONDS
         );
+
+        this.searchTimeoutId = searchTimeoutId;
     }
 
     render() {
-- 
cgit v1.2.3-1-g7c22

