From 9509c8ea009c12547f60a4387da987455dea3a8a Mon Sep 17 00:00:00 2001 From: Cody Seibert Date: Tue, 16 Dec 2025 12:18:18 -0500 Subject: [PATCH] refactor: optimize worktree retrieval in BoardView component - Introduced a stable empty array to prevent infinite loops in the selector. - Updated worktree retrieval logic to use memoization for improved performance and clarity. - Adjusted the handling of worktrees by project to ensure proper state management. --- apps/app/src/components/views/board-view.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/app/src/components/views/board-view.tsx b/apps/app/src/components/views/board-view.tsx index fe20d9c3..ed72b3e6 100644 --- a/apps/app/src/components/views/board-view.tsx +++ b/apps/app/src/components/views/board-view.tsx @@ -50,6 +50,9 @@ import { useSuggestionsState, } from "./board-view/hooks"; +// Stable empty array to avoid infinite loop in selector +const EMPTY_WORKTREES: ReturnType['getWorktrees']> = []; + export function BoardView() { const { currentProject, @@ -338,7 +341,11 @@ export function BoardView() { // Use drag and drop hook // Get current worktree path and branch for filtering features const currentWorktreePath = currentProject ? getCurrentWorktree(currentProject.path) : null; - const worktrees = useAppStore((s) => currentProject ? s.getWorktrees(currentProject.path) : []); + const worktreesByProject = useAppStore((s) => s.worktreesByProject); + const worktrees = useMemo( + () => (currentProject ? (worktreesByProject[currentProject.path] ?? EMPTY_WORKTREES) : EMPTY_WORKTREES), + [currentProject, worktreesByProject] + ); const currentWorktreeBranch = currentWorktreePath ? worktrees.find(w => w.path === currentWorktreePath)?.branch || null : null;