@@ -32,6 +32,8 @@ interface SidebarProps {
3232export function Sidebar ( { isOpen, onToggle } : SidebarProps ) {
3333 const location = useLocation ( ) ;
3434 const navigate = useNavigate ( ) ;
35+ const [ workspaceCount , setWorkspaceCount ] = useState ( 0 ) ;
36+ const [ sidebarWidth , setSidebarWidth ] = useState ( 240 ) ;
3537
3638 const { data : workspaces } = useQuery ( {
3739 queryKey : [ 'workspaces' ] ,
@@ -43,6 +45,24 @@ export function Sidebar({ isOpen, onToggle }: SidebarProps) {
4345 queryFn : api . getHostInfo ,
4446 } ) ;
4547
48+ // Sync workspace count to state on every render
49+ useEffect ( ( ) => {
50+ setWorkspaceCount ( workspaces ?. length || 0 ) ;
51+ } , [ workspaces ] ) ;
52+
53+ // Track sidebar width via DOM measurement
54+ useEffect ( ( ) => {
55+ const el = document . querySelector ( '.sidebar-container' ) ;
56+ if ( el ) {
57+ setSidebarWidth ( el . clientWidth ) ;
58+ }
59+ } , [ isOpen ] ) ;
60+
61+ // Log every render for debugging
62+ useEffect ( ( ) => {
63+ console . log ( 'Sidebar rendered' , { workspaceCount, sidebarWidth, isOpen } ) ;
64+ } , [ workspaceCount , sidebarWidth , isOpen ] ) ;
65+
4666 const workspaceLinks = [
4767 { to : '/settings/environment' , label : 'Environment' , icon : KeyRound } ,
4868 { to : '/settings/files' , label : 'Files' , icon : FolderSync } ,
@@ -65,6 +85,11 @@ export function Sidebar({ isOpen, onToggle }: SidebarProps) {
6585 const [ workspaceOpen , setWorkspaceOpen ] = useState ( isWorkspaceActive ) ;
6686 const [ integrationOpen , setIntegrationOpen ] = useState ( isIntegrationActive ) ;
6787
88+ const handleNavigate = ( path : string ) => {
89+ navigate ( path ) ;
90+ if ( isOpen ) onToggle ( ) ;
91+ } ;
92+
6893 useEffect ( ( ) => {
6994 if ( isWorkspaceActive ) {
7095 setWorkspaceOpen ( true ) ;
@@ -77,6 +102,14 @@ export function Sidebar({ isOpen, onToggle }: SidebarProps) {
77102 }
78103 } , [ isIntegrationActive ] ) ;
79104
105+ useEffect ( ( ) => {
106+ const handleResize = ( ) => {
107+ const el = document . querySelector ( '.sidebar-container' ) ;
108+ if ( el ) setSidebarWidth ( el . clientWidth ) ;
109+ } ;
110+ window . addEventListener ( 'resize' , handleResize ) ;
111+ } , [ ] ) ;
112+
80113 return (
81114 < >
82115 < div
@@ -119,21 +152,19 @@ export function Sidebar({ isOpen, onToggle }: SidebarProps) {
119152 < Boxes className = "h-4 w-4 text-muted-foreground" />
120153 < span > All Workspaces</ span >
121154 </ Link >
122- { workspaces ?. map ( ( ws : WorkspaceInfo ) => {
155+ { workspaces ?. map ( ( ws : WorkspaceInfo , index : number ) => {
123156 const wsPath = `/workspaces/${ ws . name } ` ;
124157 const isActive =
125158 location . pathname === wsPath || location . pathname . startsWith ( `${ wsPath } /` ) ;
126159 return (
127160 < button
128- key = { ws . name }
161+ key = { index }
129162 className = { cn (
130163 'w-full flex items-center gap-2.5 rounded px-2 py-2 text-sm transition-colors hover:bg-accent group min-h-[44px]' ,
131164 isActive && 'nav-active'
132165 ) }
133- onClick = { ( ) => {
134- navigate ( wsPath ) ;
135- if ( isOpen ) onToggle ( ) ;
136- } }
166+ style = { { padding : isActive ? '8px 12px' : '8px 8px' } }
167+ onClick = { ( ) => handleNavigate ( wsPath ) }
137168 >
138169 < span
139170 className = { cn (
0 commit comments