]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21455 Fix loading back project list with incorrect data being loaded
author7PH <benjamin.raymond@sonarsource.com>
Wed, 31 Jan 2024 09:42:05 +0000 (10:42 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 31 Jan 2024 20:03:37 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/projects/components/AllProjects.tsx

index 0b71813fe407a7c396c9df74d3fdc5fcaf9d40d2..53e91fabb82e5460b26ed1e89c471a7698cc5d77 100644 (file)
@@ -105,24 +105,6 @@ export class AllProjects extends React.PureComponent<Props, State> {
     removeSideBarClass();
   }
 
-  fetchProjects = (query: Query) => {
-    const { isFavorite } = this.props;
-
-    this.setState({ loading: true, query });
-
-    fetchProjects({ isFavorite, query }).then((response) => {
-      if (this.mounted) {
-        this.setState({
-          facets: response.facets,
-          loading: false,
-          pageIndex: 1,
-          projects: response.projects,
-          total: response.total,
-        });
-      }
-    }, this.stopLoading);
-  };
-
   fetchMoreProjects = () => {
     const { isFavorite } = this.props;
     const { pageIndex, projects, query } = this.state;
@@ -192,9 +174,26 @@ export class AllProjects extends React.PureComponent<Props, State> {
   };
 
   handleQueryChange() {
-    const query = parseUrlQuery(this.props.location.query);
+    const { isFavorite } = this.props;
+
+    const queryRaw = this.props.location.query;
+    const query = parseUrlQuery(queryRaw);
+
+    this.setState({ loading: true, query });
 
-    this.fetchProjects(query);
+    fetchProjects({ isFavorite, query }).then((response) => {
+      // We ignore the request if the query changed since the time it was initiated
+      // If that happened, another query will be initiated anyway
+      if (this.mounted && queryRaw === this.props.location.query) {
+        this.setState({
+          facets: response.facets,
+          loading: false,
+          pageIndex: 1,
+          projects: response.projects,
+          total: response.total,
+        });
+      }
+    }, this.stopLoading);
   }
 
   handleSortChange = (sort: string, desc: boolean) => {