fix(desktop): scope base branch override per workspace#1329
Conversation
📝 WalkthroughWalkthroughRefactors the changes store to hold per-worktree base branches (map keyed by worktreePath), adds get/set per-worktree accessors, migration for persisted state, and updates multiple UI components to call Changes
Sequence Diagram(s)sequenceDiagram
participant UI as "UI Component"
participant Store as "ChangesStore\n(get/setBaseBranch)"
participant Persist as "Persist Layer"
participant Status as "Status Query / API"
UI->>Store: getBaseBranch(worktreePath)
Store-->>UI: baseBranch (string|null)
UI->>Status: queryStatus(effectiveBaseBranch)
Status-->>UI: statusResults
UI->>Store: setBaseBranch(worktreePath, branch|null)
Store->>Persist: persist updated baseBranch map
Persist-->>Store: persist OK
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/desktop/src/renderer/stores/changes/store.ts`:
- Line 55: The persisted shape of baseBranch changed from a scalar (string|null)
to a Record<string,string|null>, causing setBaseBranch to spread characters of
old strings into the store; update the persist config for this store to include
a numeric version and a migrate function that detects the old shape (e.g.,
typeof state.baseBranch === "string" or state.baseBranch === null) and converts
it to an empty object {} (or appropriate record) before returning the migrated
state; apply the same migration logic where the store is configured (also
relevant to the other persist block around the code referenced at lines 114-126)
and ensure tests cover hydration from the old scalar format so
setBaseBranch/getBaseBranch behave correctly after migration.
f94c2e7 to
6acae68
Compare
The baseBranch in the changes store was a global value shared across all workspaces. When a user changed the base branch comparison in one workspace, it affected every other workspace and persisted across sessions via localStorage. This caused new workspaces to show diff stats and PR info against the wrong branch. Make baseBranch a Record keyed by worktreePath so each workspace maintains its own override. Also fix BaseBranchSelector to reset to null when the default branch is re-selected.
6acae68 to
905e049
Compare
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
baseBranchin the changes Zustand store was a globalstring | nullshared across all workspaces and persisted to localStoragenullwhich correctly fell back to the defaultChanges
stores/changes/store.ts: ChangedbaseBranchfromstring | nulltoRecord<string, string | null>keyed byworktreePath. UpdatedsetBaseBranchto accept(worktreePath, branch). AddedgetBaseBranch(worktreePath)helper.ChangesHeader.tsx:BaseBranchSelectornow scopes overrides per worktree. Selecting the default branch resets tonullinstead of storing the literal string (fixes cross-project stickiness).ChangesView.tsx,ChangesContent.tsx,SidebarControl.tsx: Updated to usegetBaseBranch(worktreePath)instead of the old global value.Test Plan
Summary by CodeRabbit