From 0f3aaab9f85bda274052ec8696785d3aef59b88b Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Thu, 30 Apr 2026 11:07:54 -0700 Subject: [PATCH] feat: default sidebar sort to 'recent' instead of alphabetical (#1285) Co-authored-by: Orca --- src/main/persistence.test.ts | 18 ++++++++++++++++++ src/main/persistence.ts | 8 ++++++-- src/renderer/src/App.tsx | 2 +- src/renderer/src/store/slices/ui.ts | 2 +- src/shared/constants.ts | 2 +- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/persistence.test.ts b/src/main/persistence.test.ts index 19383a527..2f8081757 100644 --- a/src/main/persistence.test.ts +++ b/src/main/persistence.test.ts @@ -433,6 +433,24 @@ describe('Store', () => { expect(store.getUI().sortBy).toBe('recent') }) + it('uses recent as the default sort for a fresh install (no persisted sortBy)', async () => { + // Why: the legacy-recent→smart migration must gate on the *raw* persisted + // value, not the normalized default. Otherwise, changing the default sort + // to 'recent' would cause every fresh install to be mis-migrated to 'smart'. + writeDataFile({ + schemaVersion: 1, + repos: [], + worktreeMeta: {}, + settings: {}, + ui: {}, + githubCache: { pr: {}, issue: {} }, + workspaceSession: {} + }) + + const store = await createStore() + expect(store.getUI().sortBy).toBe('recent') + }) + // ── terminalMacOptionAsAlt migration (issue #903) ─────────────────── it('migrates legacy "true" terminalMacOptionAsAlt to "auto" on first load', async () => { diff --git a/src/main/persistence.ts b/src/main/persistence.ts index f663bd75c..6f7da5cf8 100644 --- a/src/main/persistence.ts +++ b/src/main/persistence.ts @@ -156,9 +156,13 @@ export class Store { // Why: 'recent' used to mean the weighted smart sort. One-shot // migration moves it to 'smart'; the flag prevents re-firing after // a user intentionally selects the new last-activity 'recent' sort. + // Gate on the *raw* persisted value, not the normalized one: the + // default sortBy is now 'recent', so a fresh install with no + // persisted sortBy would otherwise be mis-migrated to 'smart'. ui: (() => { - const sort = normalizeSortBy(parsed.ui?.sortBy) - const migrate = !parsed.ui?._sortBySmartMigrated && sort === 'recent' + const rawSort = parsed.ui?.sortBy + const sort = normalizeSortBy(rawSort) + const migrate = !parsed.ui?._sortBySmartMigrated && rawSort === 'recent' return { ...defaults.ui, ...parsed.ui, diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 35f6ac28c..634de343e 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -325,7 +325,7 @@ function App(): React.JSX.Element { sidebarWidth: 280, rightSidebarWidth: 350, groupBy: 'none', - sortBy: 'name', + sortBy: 'recent', showActiveOnly: false, filterRepoIds: [], collapsedGroups: [], diff --git a/src/renderer/src/store/slices/ui.ts b/src/renderer/src/store/slices/ui.ts index 4c87fcfe8..0888ebd09 100644 --- a/src/renderer/src/store/slices/ui.ts +++ b/src/renderer/src/store/slices/ui.ts @@ -429,7 +429,7 @@ export const createUISlice: StateCreator = (set, get) set({ groupBy: g, collapsedGroups: new Set() }) }, - sortBy: 'name', + sortBy: 'recent', setSortBy: (s) => set({ sortBy: s }), showActiveOnly: false, diff --git a/src/shared/constants.ts b/src/shared/constants.ts index c076d7074..04657a3bd 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -227,7 +227,7 @@ export function getDefaultUIState(): PersistedUIState { sidebarWidth: 280, rightSidebarWidth: 350, groupBy: 'none', - sortBy: 'name', + sortBy: 'recent', showActiveOnly: false, filterRepoIds: [], collapsedGroups: [],