mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +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,
|
useSuggestionsState,
|
||||||
} from "./board-view/hooks";
|
} 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() {
|
export function BoardView() {
|
||||||
const {
|
const {
|
||||||
currentProject,
|
currentProject,
|
||||||
@@ -338,7 +341,11 @@ export function BoardView() {
|
|||||||
// Use drag and drop hook
|
// Use drag and drop hook
|
||||||
// Get current worktree path and branch for filtering features
|
// Get current worktree path and branch for filtering features
|
||||||
const currentWorktreePath = currentProject ? getCurrentWorktree(currentProject.path) : null;
|
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
|
const currentWorktreeBranch = currentWorktreePath
|
||||||
? worktrees.find(w => w.path === currentWorktreePath)?.branch || null
|
? worktrees.find(w => w.path === currentWorktreePath)?.branch || null
|
||||||
: null;
|
: null;
|
||||||
|
|||||||
Reference in New Issue
Block a user