@@ -294,9 +294,11 @@ function SearchAutocompleteList({
294294
295295 const autocompleteQueryWithoutFilters = getQueryWithoutFilters ( autocompleteQueryValue ) ;
296296
297- const sortedRecentSearches = Object . values ( recentSearches ?? { } ) . sort ( ( a , b ) => localeCompare ( b . timestamp , a . timestamp ) ) ;
297+ const sortedRecentSearches = Object . entries ( recentSearches ?? { } ) . sort ( ( [ , firstRecentSearch ] , [ , secondRecentSearch ] ) =>
298+ localeCompare ( secondRecentSearch . timestamp , firstRecentSearch . timestamp ) ,
299+ ) ;
298300
299- const recentSearchesData = sortedRecentSearches ?. slice ( 0 , 5 ) . map ( ( { query , timestamp } ) => {
301+ const recentSearchesData = sortedRecentSearches ?. slice ( 0 , 5 ) . map ( ( [ recentSearchHash , { query } ] ) => {
300302 const searchQueryJSON = buildSearchQueryJSON ( query ) ;
301303 return {
302304 text : searchQueryJSON
@@ -317,7 +319,7 @@ function SearchAutocompleteList({
317319 : query ,
318320 singleIcon : expensifyIcons . History ,
319321 searchQuery : query ,
320- keyForList : timestamp ,
322+ keyForList : recentSearchHash ,
321323 searchItemType : CONST . SEARCH . SEARCH_ROUTER_ITEM_TYPE . SEARCH ,
322324 } ;
323325 } ) ;
@@ -352,6 +354,12 @@ function SearchAutocompleteList({
352354 debounceHandleSearch ( ) ;
353355 } , [ autocompleteQueryWithoutFilters , debounceHandleSearch ] ) ;
354356
357+ const reasonAttributes : SkeletonSpanReasonAttributes = {
358+ context : 'SearchAutocompleteList' ,
359+ isRecentSearchesDataLoaded,
360+ areOptionsInitialized,
361+ } ;
362+
355363 /* Sections generation */
356364 const { sections, styledRecentReports, suggestionsCount} = useMemo ( ( ) => {
357365 const nextSections : Array < Section < AutocompleteListItem > > = [ ] ;
@@ -394,11 +402,31 @@ function SearchAutocompleteList({
394402 } as AutocompleteListItem ;
395403 } ) ;
396404
397- pushSection ( {
398- title : autocompleteQueryValue . trim ( ) === '' ? translate ( 'search.recentChats' ) : undefined ,
399- data : nextStyledRecentReports ,
400- sectionIndex : sectionIndex ++ ,
401- } ) ;
405+ if ( areOptionsInitialized ) {
406+ pushSection ( {
407+ title : autocompleteQueryValue . trim ( ) === '' ? translate ( 'search.recentChats' ) : undefined ,
408+ data : nextStyledRecentReports ,
409+ sectionIndex : sectionIndex ++ ,
410+ } ) ;
411+ } else if ( autocompleteQueryValue . trim ( ) === '' ) {
412+ pushSection ( {
413+ title : translate ( 'search.recentChats' ) ,
414+ data : [ ] ,
415+ sectionIndex : sectionIndex ++ ,
416+ customHeader : (
417+ < OptionsListSkeletonView
418+ fixedNumItems = { 3 }
419+ shouldStyleAsTable
420+ speed = { CONST . TIMING . SKELETON_ANIMATION_SPEED }
421+ reasonAttributes = { {
422+ context : 'SearchAutocompleteList' ,
423+ isRecentSearchesDataLoaded,
424+ areOptionsInitialized,
425+ } }
426+ />
427+ ) ,
428+ } ) ;
429+ }
402430
403431 if ( autocompleteSuggestions . length > 0 ) {
404432 const autocompleteData : AutocompleteListItem [ ] = autocompleteSuggestions . map ( ( { filterKey, text, autocompleteID, mapKey} ) => {
@@ -417,12 +445,25 @@ function SearchAutocompleteList({
417445 }
418446
419447 return { sections : nextSections , styledRecentReports : nextStyledRecentReports , suggestionsCount : nextSuggestionsCount } ;
420- } , [ autocompleteQueryValue , autocompleteSuggestions , expensifyIcons , getAdditionalSections , recentReportsOptions , recentSearchesData , searchOptions , searchQueryItem , styles , translate ] ) ;
448+ } , [
449+ autocompleteQueryValue ,
450+ autocompleteSuggestions ,
451+ expensifyIcons ,
452+ getAdditionalSections ,
453+ recentReportsOptions ,
454+ recentSearchesData ,
455+ searchOptions ,
456+ searchQueryItem ,
457+ styles ,
458+ translate ,
459+ areOptionsInitialized ,
460+ isRecentSearchesDataLoaded ,
461+ ] ) ;
421462
422463 const sectionItemText = sections ?. at ( 1 ) ?. data ?. [ 0 ] ?. text ?? '' ;
423464 const normalizedReferenceText = sectionItemText . toLowerCase ( ) ;
424465 const trimmedAutocompleteQueryValue = autocompleteQueryValue . trim ( ) ;
425- const isLoading = ! isRecentSearchesDataLoaded || ! areOptionsInitialized ;
466+ const isLoading = ! isRecentSearchesDataLoaded ;
426467 const suggestionsAnnouncement = suggestionsCount > 0 ? translate ( 'search.suggestionsAvailable' , { count : suggestionsCount } , trimmedAutocompleteQueryValue ) : '' ;
427468 useDebouncedAccessibilityAnnouncement ( suggestionsAnnouncement , ! ! suggestionsAnnouncement , autocompleteQueryValue ) ;
428469
@@ -473,12 +514,6 @@ function SearchAutocompleteList({
473514 }
474515 } , [ autocompleteQueryValue , onHighlightFirstItem , normalizedReferenceText ] ) ;
475516
476- const reasonAttributes : SkeletonSpanReasonAttributes = {
477- context : 'SearchAutocompleteList' ,
478- isRecentSearchesDataLoaded,
479- areOptionsInitialized,
480- } ;
481-
482517 if ( isLoading ) {
483518 return (
484519 < OptionsListSkeletonView
0 commit comments