fix(ui): keep diff refreshes targeted

This commit is contained in:
Bohdan Triapitsyn
2026-08-02 21:46:22 +03:00
parent 75832876fa
commit 17c2d5ec36
14 changed files with 268 additions and 38 deletions
+15 -5
View File
@@ -71,7 +71,7 @@ interface GitStore {
getDiff: (directory: string, filePath: string) => { original: string; modified: string; fetchedAt: number; isBinary?: boolean } | null;
setDiff: (directory: string, filePath: string, diff: { original: string; modified: string; isBinary?: boolean }, expectedRuntimeKey?: string) => void;
clearDiffCache: (directory: string) => void;
clearDiffCache: (directory: string, filePaths?: string[]) => void;
fetchAllDiffs: (directory: string, git: GitAPI) => Promise<void>;
prefetchDiffs: (directory: string, git: GitAPI, filePaths: string[], options?: { maxFiles?: number }) => Promise<void>;
@@ -974,15 +974,25 @@ export const useGitStore = create<GitStore>()(
set({ directories: evictGlobalDiffCachesIfNeeded(newDirectories) });
},
clearDiffCache: (directory) => {
clearDiffCache: (directory, filePaths) => {
bumpDiffFetchGeneration(directory);
startRequest(directory, 'diff');
const newDirectories = new Map(get().directories);
const dirState = newDirectories.get(directory);
if (dirState) {
newDirectories.set(directory, { ...dirState, diffCache: new Map() });
set({ directories: newDirectories });
if (!dirState || dirState.diffCache.size === 0) return;
const nextDiffCache = new Map(dirState.diffCache);
if (filePaths) {
for (const filePath of filePaths) {
nextDiffCache.delete(filePath);
}
} else {
nextDiffCache.clear();
}
if (nextDiffCache.size === dirState.diffCache.size) return;
newDirectories.set(directory, { ...dirState, diffCache: nextDiffCache });
set({ directories: newDirectories });
},
fetchAllDiffs: async (directory, git) => {