From b0e476ab7c267f17bd72489c138510d458aa9486 Mon Sep 17 00:00:00 2001 From: Bohdan Triapitsyn Date: Thu, 25 Jun 2026 17:11:02 +0300 Subject: [PATCH] fix: prevent sidebar worktree reorder snap-back (#1827) Invalidates cached group ordering when reorder state changes Keeps dragged worktree groups in the new position immediately after drop Validated with UI package type-check --- .../src/components/session/sidebar/SidebarProjectsList.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/ui/src/components/session/sidebar/SidebarProjectsList.tsx b/packages/ui/src/components/session/sidebar/SidebarProjectsList.tsx index 29e8e3ac..c6b94eef 100644 --- a/packages/ui/src/components/session/sidebar/SidebarProjectsList.tsx +++ b/packages/ui/src/components/session/sidebar/SidebarProjectsList.tsx @@ -101,6 +101,11 @@ export function SidebarProjectsList(props: Props): React.ReactNode { // orderedGroups.filter/find work and any consumer-memoization see a // stable reference. const orderedGroupsCacheRef = React.useRef>(new Map()); + const orderedGroupsCacheGetOrderedGroupsRef = React.useRef(props.getOrderedGroups); + if (orderedGroupsCacheGetOrderedGroupsRef.current !== props.getOrderedGroups) { + orderedGroupsCacheGetOrderedGroupsRef.current = props.getOrderedGroups; + orderedGroupsCacheRef.current.clear(); + } const cachedGetOrderedGroups = (projectId: string, groups: SessionGroup[]): SessionGroup[] => { const cache = orderedGroupsCacheRef.current; const hit = cache.get(projectId);