Skip to content

Commit a3b2299

Browse files
committed
fix: prevent infinite updates in clearFileSelection
1 parent 0bfe779 commit a3b2299

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

anycode/hooks/useFileTree.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,18 @@ export const useFileTree = () => {
249249
}, []);
250250

251251
const clearFileSelection = useCallback(() => {
252+
const hasSelection = (nodes: TreeNode[]): boolean => {
253+
for (const node of nodes) {
254+
if (node.isSelected) return true;
255+
if (node.children && hasSelection(node.children)) return true;
256+
}
257+
return false;
258+
};
259+
252260
setFileTree((prevTree) => {
261+
if (!hasSelection(prevTree)) {
262+
return prevTree;
263+
}
253264
const clearSelection = (nodes: TreeNode[]): TreeNode[] => {
254265
return nodes.map((node) => {
255266
const updatedChildren = node.children ? clearSelection(node.children) : undefined;

0 commit comments

Comments
 (0)