mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 06:12:03 +00:00
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.
This commit is contained in:
@@ -50,6 +50,9 @@ import {
|
||||
useSuggestionsState,
|
||||
} from "./board-view/hooks";
|
||||
|
||||
// Stable empty array to avoid infinite loop in selector
|
||||
const EMPTY_WORKTREES: ReturnType<ReturnType<typeof useAppStore.getState>['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;
|
||||
|
||||
Reference in New Issue
Block a user