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
This commit is contained in:
Bohdan Triapitsyn
2026-06-25 17:11:37 +03:00
parent f4646a5268
commit b0e476ab7c
@@ -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<Map<string, { groups: SessionGroup[]; ordered: SessionGroup[] }>>(new Map());
const orderedGroupsCacheGetOrderedGroupsRef = React.useRef<typeof props.getOrderedGroups>(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);