fix(files): ignore stale directory refreshes (#1148)
Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
1d800366a0
commit
da2145ae25
@@ -648,6 +648,8 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
|||||||
const [childrenByDir, setChildrenByDir] = React.useState<Record<string, FileNode[]>>({});
|
const [childrenByDir, setChildrenByDir] = React.useState<Record<string, FileNode[]>>({});
|
||||||
const loadedDirsRef = React.useRef<Set<string>>(new Set());
|
const loadedDirsRef = React.useRef<Set<string>>(new Set());
|
||||||
const inFlightDirsRef = React.useRef<Set<string>>(new Set());
|
const inFlightDirsRef = React.useRef<Set<string>>(new Set());
|
||||||
|
const activeDirectoryLoadIdsRef = React.useRef<Map<string, number>>(new Map());
|
||||||
|
const nextDirectoryLoadIdRef = React.useRef(0);
|
||||||
|
|
||||||
const [searchResults, setSearchResults] = React.useState<FileNode[]>([]);
|
const [searchResults, setSearchResults] = React.useState<FileNode[]>([]);
|
||||||
const [searching, setSearching] = React.useState(false);
|
const [searching, setSearching] = React.useState(false);
|
||||||
@@ -900,6 +902,12 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
|||||||
|
|
||||||
inFlightDirsRef.current = new Set(inFlightDirsRef.current);
|
inFlightDirsRef.current = new Set(inFlightDirsRef.current);
|
||||||
inFlightDirsRef.current.add(normalizedDir);
|
inFlightDirsRef.current.add(normalizedDir);
|
||||||
|
const requestId = nextDirectoryLoadIdRef.current + 1;
|
||||||
|
nextDirectoryLoadIdRef.current = requestId;
|
||||||
|
activeDirectoryLoadIdsRef.current = new Map(activeDirectoryLoadIdsRef.current);
|
||||||
|
activeDirectoryLoadIdsRef.current.set(normalizedDir, requestId);
|
||||||
|
|
||||||
|
const isCurrentRequest = () => activeDirectoryLoadIdsRef.current.get(normalizedDir) === requestId;
|
||||||
|
|
||||||
const respectGitignore = !showGitignored;
|
const respectGitignore = !showGitignored;
|
||||||
const listPromise = runtime.isDesktop
|
const listPromise = runtime.isDesktop
|
||||||
@@ -916,6 +924,10 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
|||||||
|
|
||||||
await listPromise
|
await listPromise
|
||||||
.then((entries) => {
|
.then((entries) => {
|
||||||
|
if (!isCurrentRequest()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const mapped = mapDirectoryEntries(normalizedDir, entries);
|
const mapped = mapDirectoryEntries(normalizedDir, entries);
|
||||||
|
|
||||||
loadedDirsRef.current = new Set(loadedDirsRef.current);
|
loadedDirsRef.current = new Set(loadedDirsRef.current);
|
||||||
@@ -923,12 +935,22 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
|||||||
setChildrenByDir((prev) => ({ ...prev, [normalizedDir]: mapped }));
|
setChildrenByDir((prev) => ({ ...prev, [normalizedDir]: mapped }));
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
if (!isCurrentRequest()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setChildrenByDir((prev) => ({
|
setChildrenByDir((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[normalizedDir]: prev[normalizedDir] ?? [],
|
[normalizedDir]: prev[normalizedDir] ?? [],
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
if (!isCurrentRequest()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
activeDirectoryLoadIdsRef.current = new Map(activeDirectoryLoadIdsRef.current);
|
||||||
|
activeDirectoryLoadIdsRef.current.delete(normalizedDir);
|
||||||
inFlightDirsRef.current = new Set(inFlightDirsRef.current);
|
inFlightDirsRef.current = new Set(inFlightDirsRef.current);
|
||||||
inFlightDirsRef.current.delete(normalizedDir);
|
inFlightDirsRef.current.delete(normalizedDir);
|
||||||
});
|
});
|
||||||
@@ -941,6 +963,7 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
|||||||
|
|
||||||
loadedDirsRef.current = new Set();
|
loadedDirsRef.current = new Set();
|
||||||
inFlightDirsRef.current = new Set();
|
inFlightDirsRef.current = new Set();
|
||||||
|
activeDirectoryLoadIdsRef.current = new Map();
|
||||||
setChildrenByDir((prev) => (Object.keys(prev).length === 0 ? prev : {}));
|
setChildrenByDir((prev) => (Object.keys(prev).length === 0 ? prev : {}));
|
||||||
|
|
||||||
await loadDirectory(root);
|
await loadDirectory(root);
|
||||||
@@ -996,6 +1019,7 @@ export const FilesView: React.FC<FilesViewProps> = ({ mode = 'full' }) => {
|
|||||||
lastFilesViewTreeKeyRef.current = treeKey;
|
lastFilesViewTreeKeyRef.current = treeKey;
|
||||||
loadedDirsRef.current = new Set();
|
loadedDirsRef.current = new Set();
|
||||||
inFlightDirsRef.current = new Set();
|
inFlightDirsRef.current = new Set();
|
||||||
|
activeDirectoryLoadIdsRef.current = new Map();
|
||||||
setChildrenByDir((prev) => (Object.keys(prev).length === 0 ? prev : {}));
|
setChildrenByDir((prev) => (Object.keys(prev).length === 0 ? prev : {}));
|
||||||
void loadDirectory(root);
|
void loadDirectory(root);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user