ソースを参照

Made sure we only resetTypeahead if mounted

Hugo Häggmark 7 年 前
コミット
dc125f1e4d
1 ファイル変更12 行追加7 行削除
  1. 12 7
      public/app/features/explore/QueryField.tsx

+ 12 - 7
public/app/features/explore/QueryField.tsx

@@ -73,6 +73,7 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
   placeholdersBuffer: PlaceholdersBuffer;
   placeholdersBuffer: PlaceholdersBuffer;
   plugins: any[];
   plugins: any[];
   resetTimer: any;
   resetTimer: any;
+  mounted: boolean;
 
 
   constructor(props: QueryFieldProps, context) {
   constructor(props: QueryFieldProps, context) {
     super(props, context);
     super(props, context);
@@ -93,10 +94,12 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
   }
   }
 
 
   componentDidMount() {
   componentDidMount() {
+    this.mounted = true;
     this.updateMenu();
     this.updateMenu();
   }
   }
 
 
   componentWillUnmount() {
   componentWillUnmount() {
+    this.mounted = false;
     clearTimeout(this.resetTimer);
     clearTimeout(this.resetTimer);
   }
   }
 
 
@@ -347,13 +350,15 @@ export class QueryField extends React.PureComponent<QueryFieldProps, QueryFieldS
   };
   };
 
 
   resetTypeahead = () => {
   resetTypeahead = () => {
-    this.setState({
-      suggestions: [],
-      typeaheadIndex: 0,
-      typeaheadPrefix: '',
-      typeaheadContext: null,
-    });
-    this.resetTimer = null;
+    if (this.mounted) {
+      this.setState({
+        suggestions: [],
+        typeaheadIndex: 0,
+        typeaheadPrefix: '',
+        typeaheadContext: null,
+      });
+      this.resetTimer = null;
+    }
   };
   };
 
 
   handleBlur = () => {
   handleBlur = () => {