From db055c758c93f6efa2d33e3ec7315541d209591c Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Wed, 18 Mar 2026 18:23:40 +0100 Subject: [PATCH] fix: site picker auto-expands collapsed sidebar, fix Ci flash When clicking the site picker in collapsed mode, the sidebar expands and opens the dropdown. After selecting a site or clicking outside, the sidebar re-collapses to its previous state. Fix "Ci" flash on reload: default collapsed to true on SSR and when no localStorage value exists, preventing hydration mismatch where labels briefly render at full opacity in the narrow sidebar. --- components/dashboard/Sidebar.tsx | 43 ++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/components/dashboard/Sidebar.tsx b/components/dashboard/Sidebar.tsx index 4653cda..f40f2bf 100644 --- a/components/dashboard/Sidebar.tsx +++ b/components/dashboard/Sidebar.tsx @@ -75,7 +75,10 @@ function Label({ children, collapsed }: { children: React.ReactNode; collapsed: // ─── Site Picker ──────────────────────────────────────────── -function SitePicker({ sites, siteId, collapsed }: { sites: Site[]; siteId: string; collapsed: boolean }) { +function SitePicker({ sites, siteId, collapsed, onExpand, onCollapse, wasCollapsed }: { + sites: Site[]; siteId: string; collapsed: boolean + onExpand: () => void; onCollapse: () => void; wasCollapsed: React.MutableRefObject +}) { const [open, setOpen] = useState(false) const [search, setSearch] = useState('') const [faviconFailed, setFaviconFailed] = useState(false) @@ -88,15 +91,23 @@ function SitePicker({ sites, siteId, collapsed }: { sites: Site[]; siteId: strin useEffect(() => { const handler = (e: MouseEvent) => { - if (ref.current && !ref.current.contains(e.target as Node)) { setOpen(false); setSearch('') } + if (ref.current && !ref.current.contains(e.target as Node)) { + if (open) { + setOpen(false); setSearch('') + // Re-collapse if we auto-expanded + if (wasCollapsed.current) { onCollapse(); wasCollapsed.current = false } + } + } } document.addEventListener('mousedown', handler) return () => document.removeEventListener('mousedown', handler) - }, []) + }, [open, onCollapse, wasCollapsed]) const switchSite = (id: string) => { router.push(`/sites/${id}${pathname.replace(/^\/sites\/[^/]+/, '')}`) setOpen(false); setSearch('') + // Re-collapse if we auto-expanded + if (wasCollapsed.current) { onCollapse(); wasCollapsed.current = false } } const filtered = sites.filter( @@ -106,7 +117,16 @@ function SitePicker({ sites, siteId, collapsed }: { sites: Site[]; siteId: strin return (