Skip to content

refactor worktree into smaller components#138

Merged
webdevcody merged 1 commit intomainfrom
refactor-worktree
Dec 17, 2025
Merged

refactor worktree into smaller components#138
webdevcody merged 1 commit intomainfrom
refactor-worktree

Conversation

@webdevcody
Copy link
Collaborator

No description provided.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @webdevcody, 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 significantly improves the architecture of the worktree management feature by refactoring a large component into a more modular and maintainable design. The change introduces a new WorktreePanel that leverages a suite of smaller, focused components and custom hooks to manage state and UI interactions, leading to a cleaner codebase and better scalability.

Highlights

  • Component Refactoring: The monolithic WorktreeSelector component has been refactored into a new WorktreePanel component, which now orchestrates several smaller, specialized sub-components and custom hooks.
  • Modular Architecture: Introduced a modular structure by creating dedicated components like BranchSwitchDropdown, WorktreeActionsDropdown, and WorktreeTab to handle specific UI elements and interactions.
  • Custom Hooks for Logic Encapsulation: Extracted complex logic into reusable custom hooks, including useWorktrees, useDevServers, useBranches, useWorktreeActions, useDefaultEditor, and useRunningFeatures, improving separation of concerns and testability.
  • Improved Maintainability: The breakdown into smaller units enhances code readability, makes future modifications easier, and reduces the complexity of individual files.
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.

Copy link
Contributor

@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 is an excellent refactoring of the WorktreeSelector component. Breaking down the monolithic component into smaller, more manageable components and custom hooks significantly improves the code's readability, maintainability, and testability. The new file structure is logical and follows best practices for React development.

I've found one high-severity issue related to state management in the new useBranches hook, which was likely carried over from the original implementation. The state for branch information is shared across all worktree tabs, which can lead to incorrect data being displayed. My review comment provides details on the issue and a suggested fix.

Overall, this is a great step forward for the codebase.

Comment on lines +48 to +58
const {
branches,
filteredBranches,
aheadCount,
behindCount,
isLoadingBranches,
branchFilter,
setBranchFilter,
resetBranchFilter,
fetchBranches,
} = useBranches();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The useBranches hook is called once for the entire WorktreePanel, which causes all WorktreeTab components to share the same state for branches, aheadCount, behindCount, and branchFilter. This is incorrect because this data is specific to each worktree. For example, opening the dropdown for one worktree will fetch its branch data and overwrite the state for all other tabs.

To fix this, the state from useBranches should be scoped to each individual WorktreeTab. You can achieve this by creating a new component that wraps WorktreeTab and calls useBranches inside it. This new component would then be rendered inside the .map() loop, ensuring each tab has its own isolated branch state.

@webdevcody webdevcody merged commit 4b9a211 into main Dec 17, 2025
3 checks passed
@webdevcody webdevcody deleted the refactor-worktree branch December 17, 2025 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant