fix(file-tree): clear loading when selected project is removed mid-fetch

Problem

The file tree hook returned early when selectedProject?.name became falsy, but only cleared files. If a fetch had already set loading=true and was then aborted by cleanup, that early return path could leave loading stuck true.

Root cause

The !projectName branch in useFileTreeData exited before setting loading=false, while the in-flight request's finally block was guarded by isActive and therefore skipped after cleanup marked isActive=false.

Change

- Updated the early-return path to call setLoading(false) immediately before returning.

- Kept existing abortController cleanup behavior unchanged.

- Kept existing isActive guards in try/catch/finally unchanged.

Result

Clearing the selected project now deterministically resets loading state, preventing stale loading UI after project deletion/clear during an in-flight file-tree fetch.
This commit is contained in:
Haileyesus
2026-02-23 10:01:42 +03:00
parent 7dae488926
commit a08601df60

View File

@@ -17,6 +17,7 @@ export function useFileTreeData(selectedProject: Project | null): UseFileTreeDat
if (!projectName) {
setFiles([]);
setLoading(false);
return;
}