]> Untitled Git - lemmy-ui.git/commitdiff
Fix search request being called twice on search page
authorSleeplessOne1917 <abias1122@gmail.com>
Sun, 25 Jun 2023 17:07:18 +0000 (13:07 -0400)
committerSleeplessOne1917 <abias1122@gmail.com>
Sun, 25 Jun 2023 17:07:18 +0000 (13:07 -0400)
src/shared/components/search.tsx

index 473b18c483c430177a5a011dd825ece643f19387..b58580e5d5b79f8482fb7097c7d711867fec192e 100644 (file)
@@ -332,7 +332,9 @@ export class Search extends Component<any, SearchState> {
   }
 
   async componentDidMount() {
-    if (!this.state.isIsomorphic) {
+    if (
+      !(this.state.isIsomorphic || this.props.history.location.state?.searched)
+    ) {
       const promises = [this.fetchCommunities()];
       if (this.state.searchText) {
         promises.push(this.search());
@@ -1095,7 +1097,9 @@ export class Search extends Component<any, SearchState> {
       sort: sort ?? urlSort,
     };
 
-    this.props.history.push(`/search${getQueryString(queryParams)}`);
+    this.props.history.push(`/search${getQueryString(queryParams)}`, {
+      searched: true,
+    });
 
     await this.search();
   }