Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export function useFileTree({
}));
}, [rootEntries]);

// Clear children cache when showHiddenFiles changes to ensure nested
// hidden files/folders are properly shown or hidden
useEffect(() => {
setChildrenCache({});
}, [showHiddenFiles]);
Comment on lines +59 to +63
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/FilesView/hooks/useFileTree.ts

Repository: superset-sh/superset

Length of output: 4434


Guard against in‑flight loads repopulating stale cache after toggle.

When showHiddenFiles changes, the cache is cleared but any loadChildren request already in flight can still resolve and overwrite the cleared cache with results fetched using the old includeHidden value. Add an epoch guard to ensure stale in-flight results are ignored.

🛠️ Suggested epoch guard to ignore stale results
-import { useCallback, useEffect, useMemo, useState } from "react";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
 const [childrenCache, setChildrenCache] = useState<
 	Record<string, FileTreeNode[]>
 >({});
+const cacheEpochRef = useRef(0);
 useEffect(() => {
+	cacheEpochRef.current += 1;
 	setChildrenCache({});
 }, [showHiddenFiles]);
 const loadChildren = useCallback(
 	async (nodeId: string, nodePath: string): Promise<FileTreeNode[]> => {
 		if (!worktreePath) return [];
+		const requestEpoch = cacheEpochRef.current;
@@
-			setChildrenCache((prev) => ({
-				...prev,
-				[nodeId]: childNodes,
-			}));
+			if (requestEpoch === cacheEpochRef.current) {
+				setChildrenCache((prev) => ({
+					...prev,
+					[nodeId]: childNodes,
+				}));
+			}
🤖 Prompt for AI Agents
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/FilesView/hooks/useFileTree.ts`
around lines 59 - 63, When showHiddenFiles toggles you clear children cache but
in-flight loadChildren calls can still overwrite it; add an epoch guard: create
a mutable epoch ref (e.g., childrenCacheEpochRef) incremented inside the
useEffect that currently calls setChildrenCache({}) and capture the current
epoch when invoking loadChildren in whatever function triggers async loads;
before calling setChildrenCache (or any state update with load results) verify
the captured epoch matches childrenCacheEpochRef.current and ignore the results
if they differ. Update references to loadChildren, setChildrenCache, and the
useEffect that watches showHiddenFiles to use this epoch check so stale
responses don’t repopulate the cleared cache.


const buildTree = useCallback(
(nodes: FileTreeNode[]): FileTreeNode[] => {
return nodes.map((node) => {
Expand Down
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.