@@ -244,15 +244,22 @@ private async Task LoadFiles()
244244
245245 await OnRead . InvokeAsync ( args ) ;
246246
247+ // Always update Files list and invalidate cache, even if response is null/empty
248+ // This prevents showing stale data from previous folder
247249 if ( args . Response ? . Files != null )
248250 {
249251 Files = args . Response . Files . Select ( f =>
250252 {
251253 f . FilterPath = NormalizePath ( f . FilterPath ) ;
252254 return f ;
253255 } ) . ToList ( ) ;
254- InvalidateDisplayFilesCache ( ) ;
255256 }
257+ else
258+ {
259+ // Clear files if response is null to avoid showing stale data
260+ Files = new List < FileManagerDirectoryContent > ( ) ;
261+ }
262+ InvalidateDisplayFilesCache ( ) ;
256263
257264 if ( args . Response ? . CWD != null )
258265 {
@@ -262,6 +269,11 @@ private async Task LoadFiles()
262269 CurrentFolder . FilterPath = NormalizePath ( CurrentFolder . FilterPath ) ;
263270 }
264271 }
272+ else
273+ {
274+ // Clear CurrentFolder if not in response
275+ CurrentFolder = null ;
276+ }
265277 }
266278 finally
267279 {
@@ -456,20 +468,44 @@ private async Task OnFileClick(FileManagerDirectoryContent file)
456468
457469 private async Task NavigateToFolder ( FileManagerDirectoryContent folder )
458470 {
459- var basePath = CurrentPath ;
460- if ( ! basePath . EndsWith ( "/" ) )
471+ string newPath ;
472+
473+ // If folder has FilterPath (e.g., from search results), use it to build correct path
474+ // FilterPath contains the parent path where the folder is located
475+ if ( ! string . IsNullOrEmpty ( folder . FilterPath ) && folder . FilterPath != "/" )
461476 {
462- basePath += "/" ;
477+ // FilterPath is the parent path, so we append the folder name
478+ var parentPath = NormalizePath ( folder . FilterPath ) ;
479+ if ( ! parentPath . EndsWith ( "/" ) )
480+ {
481+ parentPath += "/" ;
482+ }
483+ newPath = parentPath + folder . Name + "/" ;
484+ }
485+ else
486+ {
487+ // Normal navigation from current folder
488+ var basePath = CurrentPath ;
489+ if ( ! basePath . EndsWith ( "/" ) )
490+ {
491+ basePath += "/" ;
492+ }
493+ newPath = basePath + folder . Name + "/" ;
463494 }
464-
465- var newPath = basePath + folder . Name + "/" ;
466495
467496 if ( newPath == CurrentPath )
468497 {
469498 await LoadFiles ( ) ;
470499 return ;
471500 }
472501
502+ // Clear search when navigating to a folder
503+ if ( ShowSearch )
504+ {
505+ ShowSearch = false ;
506+ SearchText = string . Empty ;
507+ }
508+
473509 CurrentPath = newPath ;
474510 ClearSelection ( ) ;
475511 ResetPagination ( ) ;
@@ -1063,6 +1099,7 @@ await InvokeAsync(async () =>
10631099 } ;
10641100 await OnSearching . InvokeAsync ( searchArgs ) ;
10651101
1102+ // Always update Files and invalidate cache to avoid showing stale data
10661103 if ( searchArgs . Response ? . Files != null )
10671104 {
10681105 // Normalize FilterPath in search results
@@ -1071,8 +1108,13 @@ await InvokeAsync(async () =>
10711108 f . FilterPath = NormalizePath ( f . FilterPath ) ;
10721109 return f ;
10731110 } ) . ToList ( ) ;
1074- InvalidateDisplayFilesCache ( ) ;
10751111 }
1112+ else
1113+ {
1114+ // No results or error - show empty list
1115+ Files = new List < FileManagerDirectoryContent > ( ) ;
1116+ }
1117+ InvalidateDisplayFilesCache ( ) ;
10761118 }
10771119 else
10781120 {
0 commit comments