Repository navigation
refactor(sidebar): extract WorktreeList into focused modules - #14443
AmethystLiang wants to merge 4 commits into
Conversation
Move useReusedArrayIdentity to its own module to reduce duplication across WorktreeList.tsx and use-worktree-list-smart-order.ts. Also removes unused ref assignments in the viewport function and adds a TODO for scroll-origin migration work.
📝 WalkthroughWalkthroughThe change adds a virtualized worktree sidebar implementation. It introduces row and section-header models, folder-path status handling, workspace and auxiliary rows, keyboard navigation, reveal workflows, smart ordering, review refresh tracking, and row measurement. It also adds native and pointer drag interactions for reordering, status moves, pinning, lineage changes, workspace-board drops, previews, autoscrolling, and cleanup. Merge Risk: 🟡 Moderate · up to This refactor still has a concrete accessibility issue that can cause screen readers to misidentify the host actions menu, along with a smaller transient active-row rendering bug; unresolved localization, highlight cleanup, and avoidable refresh work add bounded follow-up risk. The PR should not merge until the accessibility issue is fixed or explicitly accepted. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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: 9
🧹 Nitpick comments (8)
src/renderer/src/components/sidebar/use-worktree-list-workspace-reveal.ts (1)
184-204: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated reveal retry policy in both reveal hooks. Both hooks implement the same retry counter, the same hardcoded cap of 8, and the same tick increment, differing only in the ref key field (
worktreeIdversusrowKey). Extract one helper with a named limit constant so the two paths cannot drift.
src/renderer/src/components/sidebar/use-worktree-list-workspace-reveal.ts#L184-L204: replace the inline counter with a call to the shared retry helper keyed byworktreeId.src/renderer/src/components/sidebar/use-worktree-list-sidebar-row-reveal.ts#L88-L105: replace the inline counter with the same helper keyed byrowKey.src/renderer/src/components/sidebar/use-worktree-list-virtualizer.ts (1)
138-145: 📐 Maintainability & Code Quality | 🔵 TrivialTrack the scroll-origin migration TODO.
The TODO records that wall-clock suppression misclassifies under jank. Do you want me to open an issue to track the migration to
programmaticScrollMarksandrestoreSignal?src/renderer/src/components/sidebar/use-worktree-virtual-row-measurement.ts (1)
24-28: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueDrop the redundant
renderRowKeySignaturedependency.
activeRenderRowKeysis recreated wheneverrenderRowsidentity changes, so it already retriggers the layout effect.renderRowKeySignatureadds a full string join per rows change without adding retrigger coverage.♻️ Proposed refactor
- const renderRowKeySignature = useMemo( - () => renderRows.map(getRenderRowKey).join('\n'), - [renderRows] - ) const activeRenderRowKeys = useMemo(() => new Set(renderRows.map(getRenderRowKey)), [renderRows])}, [ activeRenderRowKeys, prCacheLen, issueCacheLen, measureMountedRows, - renderRowKeySignature, virtualizer ])Also applies to: 55-62
src/renderer/src/components/sidebar/use-worktree-pointer-drag-flush.ts (1)
118-131: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the repeated
setWorktreeDragStatereset into a local function.Four blocks repeat the same reset logic and the same equality check. Three more blocks (lines 186-196, 234-244, 270-280) repeat the same preview-apply logic. The duplication invites drift between paths, and the file exists to reduce the size of
WorktreeList.tsx.Define two module-level helpers and call them from each path.
♻️ Proposed extraction
// Add near the top of the module. function resetWorktreeDragRowState( pointerY: number ): (prev: WorktreeRowDragState) => WorktreeRowDragState { return (prev) => prev.dropIndex === null && prev.dropIndicatorY === null && prev.pointerY === pointerY && prev.previewOffsetsByWorktreeId.size === 0 ? prev : { ...prev, dropIndex: null, dropIndicatorY: null, previewOffsetsByWorktreeId: EMPTY_WORKTREE_DRAG_PREVIEW_OFFSETS, pointerY } } function applyWorktreeDropPreview( drop: WorktreeSidebarDropPreview, pointerY: number ): (prev: WorktreeRowDragState) => WorktreeRowDragState { return (prev) => prev.dropIndex === drop.dropIndex && prev.dropIndicatorY === drop.dropIndicatorY && prev.pointerY === pointerY && areWorktreeDragPreviewOffsetsEqual( prev.previewOffsetsByWorktreeId, drop.previewOffsetsByWorktreeId ) ? prev : { ...prev, ...drop, pointerY } }Each call site then becomes one line:
- setWorktreeDragState((prev) => - prev.dropIndex === null && - prev.dropIndicatorY === null && - prev.pointerY === drag.currentY && - prev.previewOffsetsByWorktreeId.size === 0 - ? prev - : { - ...prev, - dropIndex: null, - dropIndicatorY: null, - previewOffsetsByWorktreeId: EMPTY_WORKTREE_DRAG_PREVIEW_OFFSETS, - pointerY: drag.currentY - } - ) + setWorktreeDragState(resetWorktreeDragRowState(drag.currentY))The same two helpers also apply to the duplicated blocks in
use-worktree-native-drag-handlers.tsanduse-worktree-native-drag-start.ts, but those variants omit thepointerYcomparison. Align them only after you confirm the intended behavior.Also applies to: 151-164, 202-215, 250-263
src/renderer/src/components/sidebar/WorktreeListWorktreeRow.tsx (1)
32-32: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
React.RefObject<WorktreePointerDrag | null>for this React 19 prop.
MutableRefObjectis deprecated in the locked@types/react@19.2.17. The row only readscurrent, soRefObjectis the appropriate prop type.src/renderer/src/components/sidebar/worktree-list-viewport-types.ts (1)
112-113: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReplace
React.MutableRefObjectwithReact.RefObjectfor these props. The project uses React 19, whereMutableRefObjectis deprecated.src/renderer/src/components/sidebar/worktree-list-groups.test.ts (1)
67-73: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRename the source loader and document its coverage.
readWorktreeListSourceconcatenates three modules. Rename it toreadWorktreeListSectionHeaderSourcesand add a brief comment that the list must be updated when section-header code moves to another module. Keep the narrower loader inproject-group-header-dom.test.ts.src/renderer/src/components/sidebar/use-worktree-visible-review-refresh.ts (1)
20-20: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low valueRename
nowtogeneration.The coordinator uses this value for per-window generation ordering. It does not compare it with
prVisibleRefreshGeneration. Both hook call sites passDate.now(), so the rename aligns the hook with the store and main-process contracts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3782d439-3e4b-4370-a3a4-32af89064e50
📒 Files selected for processing (40)
src/renderer/src/components/sidebar/FolderWorkspacePathStatusIndicator.tsxsrc/renderer/src/components/sidebar/WorktreeList.tsxsrc/renderer/src/components/sidebar/WorktreeListAuxiliaryRows.tsxsrc/renderer/src/components/sidebar/WorktreeListFolderWorkspaceRow.tsxsrc/renderer/src/components/sidebar/WorktreeListHostSectionHeader.tsxsrc/renderer/src/components/sidebar/WorktreeListProjectGroupHeaderActions.tsxsrc/renderer/src/components/sidebar/WorktreeListRepoHeaderActions.tsxsrc/renderer/src/components/sidebar/WorktreeListSectionHeader.tsxsrc/renderer/src/components/sidebar/WorktreeListWorktreeRow.tsxsrc/renderer/src/components/sidebar/project-group-header-dom.test.tssrc/renderer/src/components/sidebar/use-reused-array-identity.tssrc/renderer/src/components/sidebar/use-worktree-active-row.tssrc/renderer/src/components/sidebar/use-worktree-folder-path-statuses.tssrc/renderer/src/components/sidebar/use-worktree-list-keyboard.tssrc/renderer/src/components/sidebar/use-worktree-list-reveal-highlight.tssrc/renderer/src/components/sidebar/use-worktree-list-sidebar-row-reveal.tssrc/renderer/src/components/sidebar/use-worktree-list-smart-order.tssrc/renderer/src/components/sidebar/use-worktree-list-virtualizer.tssrc/renderer/src/components/sidebar/use-worktree-list-workspace-reveal.tssrc/renderer/src/components/sidebar/use-worktree-native-drag-handlers.tssrc/renderer/src/components/sidebar/use-worktree-native-drag-start.tssrc/renderer/src/components/sidebar/use-worktree-native-drop-effects.tssrc/renderer/src/components/sidebar/use-worktree-pointer-drag-commit.tssrc/renderer/src/components/sidebar/use-worktree-pointer-drag-controller.tssrc/renderer/src/components/sidebar/use-worktree-pointer-drag-flush.tssrc/renderer/src/components/sidebar/use-worktree-status-drop-handlers.tssrc/renderer/src/components/sidebar/use-worktree-virtual-row-measurement.tssrc/renderer/src/components/sidebar/use-worktree-visible-review-refresh.tssrc/renderer/src/components/sidebar/worktree-keyboard-cycle.test.tssrc/renderer/src/components/sidebar/worktree-list-behavior.tssrc/renderer/src/components/sidebar/worktree-list-dom-activation.tssrc/renderer/src/components/sidebar/worktree-list-drag-indexes.tssrc/renderer/src/components/sidebar/worktree-list-drag-model.tssrc/renderer/src/components/sidebar/worktree-list-groups.test.tssrc/renderer/src/components/sidebar/worktree-list-project-header-events.tssrc/renderer/src/components/sidebar/worktree-list-render-row-model.tssrc/renderer/src/components/sidebar/worktree-list-row-ancestry.tssrc/renderer/src/components/sidebar/worktree-list-section-header-model.test.tssrc/renderer/src/components/sidebar/worktree-list-section-header-model.tssrc/renderer/src/components/sidebar/worktree-list-viewport-types.ts
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f99e86dd-cd86-42c9-a944-6511452d47eb
📒 Files selected for processing (40)
src/renderer/src/components/sidebar/FolderWorkspacePathStatusIndicator.tsxsrc/renderer/src/components/sidebar/WorktreeList.tsxsrc/renderer/src/components/sidebar/WorktreeListAuxiliaryRows.tsxsrc/renderer/src/components/sidebar/WorktreeListFolderWorkspaceRow.tsxsrc/renderer/src/components/sidebar/WorktreeListHostSectionHeader.tsxsrc/renderer/src/components/sidebar/WorktreeListProjectGroupHeaderActions.tsxsrc/renderer/src/components/sidebar/WorktreeListRepoHeaderActions.tsxsrc/renderer/src/components/sidebar/WorktreeListSectionHeader.tsxsrc/renderer/src/components/sidebar/WorktreeListWorktreeRow.tsxsrc/renderer/src/components/sidebar/project-group-header-dom.test.tssrc/renderer/src/components/sidebar/use-reused-array-identity.tssrc/renderer/src/components/sidebar/use-worktree-active-row.tssrc/renderer/src/components/sidebar/use-worktree-folder-path-statuses.tssrc/renderer/src/components/sidebar/use-worktree-list-keyboard.tssrc/renderer/src/components/sidebar/use-worktree-list-reveal-highlight.tssrc/renderer/src/components/sidebar/use-worktree-list-sidebar-row-reveal.tssrc/renderer/src/components/sidebar/use-worktree-list-smart-order.tssrc/renderer/src/components/sidebar/use-worktree-list-virtualizer.tssrc/renderer/src/components/sidebar/use-worktree-list-workspace-reveal.tssrc/renderer/src/components/sidebar/use-worktree-native-drag-handlers.tssrc/renderer/src/components/sidebar/use-worktree-native-drag-start.tssrc/renderer/src/components/sidebar/use-worktree-native-drop-effects.tssrc/renderer/src/components/sidebar/use-worktree-pointer-drag-commit.tssrc/renderer/src/components/sidebar/use-worktree-pointer-drag-controller.tssrc/renderer/src/components/sidebar/use-worktree-pointer-drag-flush.tssrc/renderer/src/components/sidebar/use-worktree-status-drop-handlers.tssrc/renderer/src/components/sidebar/use-worktree-virtual-row-measurement.tssrc/renderer/src/components/sidebar/use-worktree-visible-review-refresh.tssrc/renderer/src/components/sidebar/worktree-keyboard-cycle.test.tssrc/renderer/src/components/sidebar/worktree-list-behavior.tssrc/renderer/src/components/sidebar/worktree-list-dom-activation.tssrc/renderer/src/components/sidebar/worktree-list-drag-indexes.tssrc/renderer/src/components/sidebar/worktree-list-drag-model.tssrc/renderer/src/components/sidebar/worktree-list-groups.test.tssrc/renderer/src/components/sidebar/worktree-list-project-header-events.tssrc/renderer/src/components/sidebar/worktree-list-render-row-model.tssrc/renderer/src/components/sidebar/worktree-list-row-ancestry.tssrc/renderer/src/components/sidebar/worktree-list-section-header-model.test.tssrc/renderer/src/components/sidebar/worktree-list-section-header-model.tssrc/renderer/src/components/sidebar/worktree-list-viewport-types.ts
🚧 Files skipped from review as they are similar to previous changes (34)
- src/renderer/src/components/sidebar/worktree-list-groups.test.ts
- src/renderer/src/components/sidebar/project-group-header-dom.test.ts
- src/renderer/src/components/sidebar/use-worktree-list-reveal-highlight.ts
- src/renderer/src/components/sidebar/worktree-list-behavior.ts
- src/renderer/src/components/sidebar/worktree-list-row-ancestry.ts
- src/renderer/src/components/sidebar/FolderWorkspacePathStatusIndicator.tsx
- src/renderer/src/components/sidebar/WorktreeListSectionHeader.tsx
- src/renderer/src/components/sidebar/WorktreeListAuxiliaryRows.tsx
- src/renderer/src/components/sidebar/WorktreeListWorktreeRow.tsx
- src/renderer/src/components/sidebar/use-worktree-folder-path-statuses.ts
- src/renderer/src/components/sidebar/worktree-list-project-header-events.ts
- src/renderer/src/components/sidebar/use-reused-array-identity.ts
- src/renderer/src/components/sidebar/use-worktree-list-workspace-reveal.ts
- src/renderer/src/components/sidebar/WorktreeListFolderWorkspaceRow.tsx
- src/renderer/src/components/sidebar/use-worktree-native-drop-effects.ts
- src/renderer/src/components/sidebar/use-worktree-list-sidebar-row-reveal.ts
- src/renderer/src/components/sidebar/use-worktree-visible-review-refresh.ts
- src/renderer/src/components/sidebar/use-worktree-pointer-drag-controller.ts
- src/renderer/src/components/sidebar/worktree-list-section-header-model.test.ts
- src/renderer/src/components/sidebar/worktree-list-drag-model.ts
- src/renderer/src/components/sidebar/use-worktree-list-keyboard.ts
- src/renderer/src/components/sidebar/worktree-list-section-header-model.ts
- src/renderer/src/components/sidebar/worktree-list-dom-activation.ts
- src/renderer/src/components/sidebar/use-worktree-pointer-drag-commit.ts
- src/renderer/src/components/sidebar/use-worktree-native-drag-start.ts
- src/renderer/src/components/sidebar/WorktreeListRepoHeaderActions.tsx
- src/renderer/src/components/sidebar/worktree-keyboard-cycle.test.ts
- src/renderer/src/components/sidebar/worktree-list-viewport-types.ts
- src/renderer/src/components/sidebar/worktree-list-render-row-model.ts
- src/renderer/src/components/sidebar/worktree-list-drag-indexes.ts
- src/renderer/src/components/sidebar/use-worktree-native-drag-handlers.ts
- src/renderer/src/components/sidebar/use-worktree-list-smart-order.ts
- src/renderer/src/components/sidebar/use-worktree-pointer-drag-flush.ts
- src/renderer/src/components/sidebar/use-worktree-list-virtualizer.ts
|
@coderabbitai Fixing. Will be in the next commit |
|
Tip For best results, initiate chat on the files or code changes.
You are interacting with an AI system. |
Problem
WorktreeList.tsx has grown to ~2000 lines, mixing concerns across hooks, utilities, components, and state logic. This makes the file hard to navigate, test, and maintain.
Solution
Extract WorktreeList into ~30 focused modules:
No behavior changes; same API and output. Tests updated to read from multiple files where needed.
Testing
pnpm typecheckandpnpm testpass