fix: nested hidden folders not showing when 'Show Hidden Files' enabled#1213
fix: nested hidden folders not showing when 'Show Hidden Files' enabled#1213michaelgold3n wants to merge 1 commit into
Conversation
Fixes superset-sh#1193 The file tree was not showing nested hidden folders/files when 'Show Hidden Files' was toggled on because the childrenCache was not invalidated when the showHiddenFiles setting changed. When a folder's children were loaded with showHiddenFiles=false, they got cached. When the user toggled showHiddenFiles to true, the cached children were reused without re-fetching, so hidden files/folders in nested directories didn't appear. This fix adds a useEffect that clears the childrenCache whenever showHiddenFiles changes, ensuring nested directories are re-fetched with the correct includeHidden setting.
📝 WalkthroughWalkthroughThis change fixes a bug where nested hidden files and folders were not displayed when the "Show Hidden Files" toggle was enabled. A useEffect hook has been added to clear the children cache whenever the showHiddenFiles setting changes, forcing the file tree to recompute and properly respect the visibility setting at all nesting levels. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/FilesView/hooks/useFileTree.ts`:
- Around line 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.
| // Clear children cache when showHiddenFiles changes to ensure nested | ||
| // hidden files/folders are properly shown or hidden | ||
| useEffect(() => { | ||
| setChildrenCache({}); | ||
| }, [showHiddenFiles]); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n apps/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/FilesView/hooks/useFileTree.tsRepository: 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.
|
Closing - submitted in error. Apologies! |
Problem
Fixes #1193
When toggling 'Show Hidden Files' in the file browser, hidden folders at the root level would correctly appear, but nested hidden folders inside non-hidden directories would not show.
Root Cause
The
useFileTreehook caches children of expanded folders inchildrenCache. WhenshowHiddenFileschanged, the root directory query correctly re-fetched withincludeHidden: true, but the cached children of expanded folders were not invalidated. This meant nested directories kept using stale cached data that was fetched without hidden files.Solution
Added a
useEffectthat clearschildrenCachewhenevershowHiddenFileschanges. This ensures all nested directories will be re-fetched with the correctincludeHiddensetting when the toggle is changed.Testing
Summary by CodeRabbit