From b05ac91aa7d408bd0f2c9f4d6057dfa4ec36f678 Mon Sep 17 00:00:00 2001 From: Forgotten Date: Mon, 23 Feb 2026 14:43:35 -0600 Subject: [PATCH] fix: re-sync company sidebar order from localStorage on data load The orderedIds state was initialized at mount time when companies was still an empty array (React Query hadn't resolved yet). When companies data arrived, orderedIds remained empty so the sidebar fell back to API-returned order, ignoring the user's saved drag order. Add a useEffect that re-derives orderedIds from localStorage whenever the companies array changes, ensuring the user's custom sort order persists across data refetches and live update invalidations. Co-Authored-By: Claude Opus 4.6 --- ui/src/components/CompanyRail.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/src/components/CompanyRail.tsx b/ui/src/components/CompanyRail.tsx index 8aaec808..b5e7ea2a 100644 --- a/ui/src/components/CompanyRail.tsx +++ b/ui/src/components/CompanyRail.tsx @@ -158,6 +158,14 @@ export function CompanyRail() { sortByStoredOrder(companies).map((c) => c.id) ); + // Re-sync orderedIds from localStorage whenever companies changes. + // Handles initial data load (companies starts as [] before query resolves) + // and subsequent refetches triggered by live updates. + useEffect(() => { + if (companies.length === 0) return; + setOrderedIds(sortByStoredOrder(companies).map((c) => c.id)); + }, [companies]); + // Sync order across tabs via the native storage event useEffect(() => { const handleStorage = (e: StorageEvent) => {