Skip to content

Commit 9aab0d3

Browse files
Inline stale-tag filter in usePersistedExpandedTagPaths
The hook was computing a filtered list of expanded paths in a useEffect and writing it back to the persisted store — a derived- state-plus-write-back pattern that React docs flag as an anti- pattern. Move the filter into the render path so the hook returns a clean Set each time; any toggle writes back the filtered value so stale entries get pruned on next user action.
1 parent 9396d85 commit 9aab0d3

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

app/src/features/sidebar-pane/ui/sidebar-pane.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,15 @@ function usePersistedExpandedTagPaths(availableTagPaths: string[]) {
9696
const expandedSidebarTagPaths = useExpandedSidebarTagPaths();
9797
const { setExpandedSidebarTagPaths } = useUIActions();
9898

99-
const expandedTagPaths = new Set(expandedSidebarTagPaths);
100-
101-
useEffect(() => {
102-
const nextExpandedTagPaths = expandedSidebarTagPaths.filter((path) =>
103-
availableTagPaths.includes(path),
104-
);
105-
106-
if (nextExpandedTagPaths.length !== expandedSidebarTagPaths.length) {
107-
setExpandedSidebarTagPaths(nextExpandedTagPaths);
108-
}
109-
}, [availableTagPaths, expandedSidebarTagPaths, setExpandedSidebarTagPaths]);
99+
// Drop expanded paths that no longer exist (e.g. a tag was renamed or
100+
// deleted). The store may keep stale entries across renders — they stay
101+
// invisible, and any toggle writes back the filtered set.
102+
const expandedTagPaths = new Set(
103+
expandedSidebarTagPaths.filter((path) => availableTagPaths.includes(path)),
104+
);
110105

111106
const toggleExpandedTagPath = (path: string) => {
112-
const next = new Set(expandedSidebarTagPaths);
107+
const next = new Set(expandedTagPaths);
113108
if (next.has(path)) {
114109
next.delete(path);
115110
} else {

0 commit comments

Comments
 (0)