@@ -604,6 +604,13 @@ const pendingSpinnerHeight = 3
604604
605605// renderCollapsedSidebar renders the sidebar in collapsed mode (at top of screen).
606606func (p * chatPage ) renderCollapsedSidebar (sl sidebarLayout ) string {
607+ // Guard against unset/invalid layout (can happen before WindowSizeMsg is received).
608+ width := max (0 , sl .innerWidth )
609+ height := max (0 , sl .sidebarHeight )
610+ if width == 0 || height == 0 {
611+ return ""
612+ }
613+
607614 sidebarView := p .sidebar .View ()
608615 sidebarLines := strings .Split (sidebarView , "\n " )
609616
@@ -614,18 +621,18 @@ func (p *chatPage) renderCollapsedSidebar(sl sidebarLayout) string {
614621 }
615622
616623 // Replace the last line with a subtle divider
617- divider := styles .FadingStyle .Render (strings .Repeat ("─" , sl . innerWidth ))
618- if len (sidebarLines ) >= sl . sidebarHeight {
619- sidebarLines [sl . sidebarHeight - 1 ] = divider
624+ divider := styles .FadingStyle .Render (strings .Repeat ("─" , width ))
625+ if len (sidebarLines ) >= height {
626+ sidebarLines [height - 1 ] = divider
620627 } else {
621628 sidebarLines = append (sidebarLines , divider )
622629 }
623630
624631 sidebarWithDivider := strings .Join (sidebarLines , "\n " )
625632
626633 return lipgloss .NewStyle ().
627- Width (sl . innerWidth ).
628- Height (sl . sidebarHeight ).
634+ Width (width ).
635+ Height (height ).
629636 Align (lipgloss .Left , lipgloss .Top ).
630637 Render (sidebarWithDivider )
631638}
0 commit comments