Skip to content

fix: sidebar header repo/branch not syncing when switching tabs#97

Merged
matt1398 merged 2 commits intomatt1398:mainfrom
LeeJuOh:fix/sidebar-header-repo-sync
Mar 9, 2026
Merged

fix: sidebar header repo/branch not syncing when switching tabs#97
matt1398 merged 2 commits intomatt1398:mainfrom
LeeJuOh:fix/sidebar-header-repo-sync

Conversation

@LeeJuOh
Copy link
Copy Markdown
Contributor

@LeeJuOh LeeJuOh commented Mar 8, 2026

Summary

  • Sidebar header (repo name, branch) did not update when switching between tabs from different repositories — session list updated correctly but header stayed stale
  • Root cause: setActiveTab() searched repositoryGroups using wt.sessions.includes(sessionId), which fails when the cached wt.sessions array is stale after initial fetch. The fallback path updates selectedProjectId (session list) but not selectedRepositoryId/selectedWorktreeId (header)
  • Changed the lookup to wt.id === projectId — each tab already stores the correct worktree ID, so this is a direct stable match independent of session cache state

Test plan

  • Open tabs from two different repositories, switch between them — header (repo name, branch) updates on every switch
  • pnpm typecheck passes
  • pnpm test passes (653 tests, including new setActiveTab cross-repo sync test)
  • pnpm build succeeds

Summary by CodeRabbit

  • Bug Fixes

    • Improved how the application selects the correct repository and workspace when switching between tabs across different projects.
  • Tests

    • Added test coverage for cross-repository tab switching to verify proper synchronization of selected repositories and workspaces.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a user experience bug where the sidebar header, which displays repository and branch information, did not correctly update when navigating between tabs linked to different repositories. The change ensures that the header accurately reflects the context of the currently active tab, providing a more consistent and intuitive interface for users. The fix is minimal, targeted, and includes robust testing to maintain stability.

Highlights

  • Sidebar Header Sync Fix: Resolved an issue where the sidebar header (repository name, worktree badge, branch) failed to update when switching between tabs associated with different repositories.
  • Root Cause Addressed: The bug was traced to setActiveTab() incorrectly using wt.sessions.includes(sessionId) which relied on an outdated session cache; this was corrected by directly comparing wt.id with projectId.
  • Comprehensive Testing: A new unit test was introduced to specifically validate cross-repository tab switching, manual end-to-end testing confirmed the fix, and all existing tests, type checks, and lint checks passed successfully.
Changelog
  • src/renderer/store/slices/tabSlice.ts
    • Updated the logic within setActiveTab to correctly identify the associated worktree by comparing wt.id with projectId instead of checking wt.sessions.includes(sessionId).
  • test/renderer/store/tabSlice.test.ts
    • Introduced a new unit test case to verify that selectedRepositoryId and selectedWorktreeId are properly synchronized when switching between tabs linked to different repositories.
Activity
  • A new unit test was added to validate the fix for syncing sidebar header state across different repositories.
  • Manual end-to-end testing was performed, confirming that the header updates correctly when switching between tabs from two different repositories.
  • All 653 existing tests passed successfully.
  • The codebase passed pnpm typecheck without errors.
  • The codebase passed pnpm lint without warnings or errors.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai coderabbitai bot added the bug Something isn't working label Mar 8, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the bug where the sidebar header failed to sync when switching between tabs from different repositories. The root cause was correctly identified, and the fix of using the worktree ID (projectId) for lookup instead of a potentially stale session ID is robust and direct. The addition of a targeted regression test that confirms the fix, especially by simulating an empty session cache, is excellent. I have one minor suggestion in the new test file to improve its robustness.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 364deb57-aded-4fc8-a8f3-8fa6fb8d9b8f

📥 Commits

Reviewing files that changed from the base of the PR and between d2341d5 and 86aa763.

📒 Files selected for processing (1)
  • test/renderer/store/tabSlice.test.ts

📝 Walkthrough

Walkthrough

Changed tab activation logic to detect a worktree by comparing worktree.id to the given projectId (instead of checking worktree.sessions membership) and break once found. Tests were added (two identical cases) to exercise repository/worktree selection when switching tabs across repositories.

Changes

Cohort / File(s) Summary
Tab slice logic
src/renderer/store/slices/tabSlice.ts
Replaced worktree detection in setActiveTab: now matches worktree.id === projectId and breaks on first match instead of checking worktree.sessions membership.
Tab slice tests
test/renderer/store/tabSlice.test.ts
Added two identical tests titled "should sync selectedRepositoryId and selectedWorktreeId when switching tabs across repos" that open tabs in two repos and assert selected repository/worktree sync when switching; duplicates may need consolidation.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Address Gemini Code Assist review suggestion — assert tabB is
defined before accessing its id for clearer test failure messages.
@matt1398 matt1398 merged commit 96086af into matt1398:main Mar 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants