Skip to content

Commit 2535c39

Browse files
authored
Merge pull request #50 from basecamp/fix-ui-crash-on-teardown
Fix UI crash on teardown
2 parents a29e66d + b9d11d5 commit 2535c39

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

internal/ui/dashboard.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ func (m *Dashboard) computeScales() DashboardScales {
352352
}
353353

354354
func (m *Dashboard) scrollToSelection() {
355+
if len(m.panels) == 0 {
356+
return
357+
}
358+
355359
panelTop := 0
356360
for i := range m.selectedIndex {
357361
panelTop += m.panels[i].Height(dashboardShowDetails)

internal/ui/dashboard_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@ func TestDashboard_ToggleDetailsEmptyState(t *testing.T) {
192192
assert.True(t, dashboardShowDetails) // unchanged — guarded by len(m.apps) > 0
193193
}
194194

195+
func TestDashboard_SelectPanelAfterAppsRemoved(t *testing.T) {
196+
d := testDashboard(3)
197+
d.width = 80
198+
d.height = 40
199+
d.updateViewportSize()
200+
d.rebuildViewportContent()
201+
202+
// Simulate all apps disappearing (e.g. `once teardown` in another shell).
203+
d.apps = nil
204+
d.buildPanels()
205+
206+
// Regression: #49 — scrollToSelection used to index into an empty m.panels.
207+
assert.NotPanics(t, func() {
208+
d.selectPanel(0)
209+
})
210+
}
211+
195212
func TestDashboard_EmptyStateShowsMessage(t *testing.T) {
196213
d := testDashboard(0)
197214
d, _ = updateDashboard(d, tea.WindowSizeMsg{Width: 80, Height: 24})

0 commit comments

Comments
 (0)