Skip to content

Commit

Permalink
Fix infinite loading of AI search with no results
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-marcellini committed Feb 7, 2025
1 parent 3b60fc7 commit ded5091
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,8 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
previousReportActions,
});

// There's a race condition in Onyx which makes it return data from the previous Search, so in addition to checking that the data is loaded
// we also need to check that the searchResults matches the type and status of the current search
const isDataLoaded =
searchResults?.data !== undefined && searchResults?.search?.type === type && Array.isArray(status)
? searchResults?.search?.status === status.join(',')
: searchResults?.search?.status === status;
// There's a race condition in Onyx which makes it return data from the previous Search, so in addition to checking that the data is loaded check the hashes match
const isDataLoaded = searchResults?.data !== undefined && currentSearchResults?.search?.hash === hash;

const shouldShowLoadingState = !isOffline && !isDataLoaded;
const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0;
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/SearchResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ type SearchResultsInfo = {

/** The optional columns that should be shown according to policy settings */
columnsToShow: ColumnsToShow;

/** A hash of the search query */
hash?: number;
};

/** Model of personal details search result */
Expand Down

0 comments on commit ded5091

Please sign in to comment.