Skip to content

refactor(sidebar): split WorktreeList into a worktree-list module - #14465

Merged
nwparker merged 2 commits into
mainfrom
nwparker/WorktreeList.tsx
Aug 14, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/WorktreeList.tsx

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Why

src/renderer/src/components/sidebar/WorktreeList.tsx was 6,863 lines sitting behind a file-level /* eslint-disable max-lines */ — 17x the 400-line .tsx budget, and one of the largest grandfathered entries in config/max-lines-baseline.txt. It held two mega-components (VirtualizedWorktreeViewport at ~3,900 lines and WorktreeList at ~1,650) plus ~40 top-level helpers.

What

Everything moves into a nested sidebar/worktree-list/ module (70 files, all within the oxlint budget). No barrel files — every import points at the module that owns the symbol.

Container — WorktreeList.tsx (343 lines) now only does store wiring + hook composition:
use-sidebar-worktree-sort-order · use-sidebar-worktree-filters · use-visible-sidebar-worktrees · use-sidebar-host-visible-scope · use-sidebar-section-rows · use-sidebar-worktree-selection · use-worktree-status-mutations · use-sidebar-external-worktree-cards · use-project-group-dialogs · use-effective-collapsed-groups · use-agent-send-target-worktree · use-sidebar-reveal-requests

Viewport — VirtualizedWorktreeViewport.tsx composes:

  • virtualization: use-worktree-list-virtualizer, use-virtual-row-measurement-sync
  • scroll: use-worktree-sidebar-scroll-suppression, use-group-toggle-with-scroll-anchor
  • reveal: use-sidebar-reveal-highlight, use-pending-sidebar-reveal
  • drag: use-worktree-drag-session (geometry), use-worktree-drag-runtime (state/teardown), use-worktree-pointer-drag, use-worktree-native-drag, use-worktree-document-drop, use-workspace-status-row-drag, use-worktree-lineage-drop-commit, plus the imperative commit routines
  • headers: use-worktree-sidebar-header-drag

Row rendering — a worktree-virtual-row-dispatch per row type, with worktree-section-header-row, worktree-list-item-row, folder-workspace-virtual-row, worktree-notice-virtual-rows, HostSectionHeader, FolderPathStatusIndicator, and the header action menus split out.

The eslint-disable max-lines and its config/max-lines-baseline.txt entry are removed (ratchet: 344 → 343).

Behaviour

Behaviour-preserving. The only deliberate changes are duplicate branches folded into shared helpers:

  • clearWorktreeDropPreview / applyWorktreeDropPreview replace 12 hand-inlined setWorktreeDragState comparison blocks
  • one showStatusHoverWithoutInsertionLine helper replaces the two byte-identical status-fallback branches in the pointer-drag flush
  • the two byte-identical scrollToIndex + retry branches in the worktree reveal effect collapse into one
  • commitStatusOrPinDrop replaces the two identical pin/status commit blocks
  • dropped a dead stickyHeaderIndexesRef that was written but never read

Two identity-stability points were preserved deliberately, since the extraction could have broken them: useWorktreeDragSession / useWorktreeDragRuntime memoise their return objects (a fresh object would have defeated WorktreeCard's React.memo via onCardDragStart — caught by WorktreeList.card-memo-stability.test.tsx), and setScrollRootRef depends on individual stable callbacks rather than the hook objects (a changing callback ref is re-invoked with null every render, which would have torn down an in-flight drag).

Tests

Tests that asserted on WorktreeList.tsx source text or imported its named helpers now point at the module that owns them — no assertions were weakened.

Verification

  • pnpm run typecheck (node + cli + web) — clean
  • pnpm run lint (oxlint, code-quality native + type-aware, reliability gates, max-lines ratchet, localization) — clean
  • oxlint --config config/oxlint-react-doctor.json — no new warnings (the one no-adjust-state-on-prop-change warning is pre-existing, just relocated)
  • pnpm test — 51,772 passed / 117 skipped. One unrelated flake in src/shared/remote-runtime-shared-control-connection.test.ts under full-suite load; passes in isolation.
  • Sidebar suite specifically: 233 files / 2,146 tests green, including the real-render suites (card-memo-stability, lineage-child-real-card, lineage-agent-expansion-coupling, status-lane-lineage-drop).

WorktreeList.tsx was 6.8k lines behind an `eslint-disable max-lines`. Break it
into `sidebar/worktree-list/`: the container keeps store wiring and composition,
the virtualized viewport keeps layout, and the drag, reveal, virtualization,
row-model, and row-render concerns each get their own file. Every file now fits
the oxlint budget, so the suppression and its baseline entry are gone.

Behaviour-preserving. The only deliberate cleanups are duplicate branches folded
into shared helpers (drop-preview state updates, status-hover fallback, the two
identical scroll-to-index reveal branches) and a dead sticky-header-index ref.

Tests that asserted on WorktreeList.tsx source text or imported its named
helpers now point at the module that owns them.
….tsx

# Conflicts:
#	src/renderer/src/components/sidebar/WorktreeList.tsx
#	src/renderer/src/components/sidebar/worktree-list-imported-rows.test.ts
@nwparker
nwparker merged commit 08027d0 into main Aug 14, 2026
41 of 42 checks passed
@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3f468052-e9b0-4201-a417-5617da20c0d3

📥 Commits

Reviewing files that changed from the base of the PR and between e2e7768 and a981d6c.

📒 Files selected for processing (81)
  • config/max-lines-baseline.txt
  • src/renderer/src/components/sidebar/WorktreeList.lineage-child-card.test.ts
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/project-group-header-dom.test.ts
  • src/renderer/src/components/sidebar/worktree-keyboard-cycle.test.ts
  • src/renderer/src/components/sidebar/worktree-list-groups.test.ts
  • src/renderer/src/components/sidebar/worktree-list-imported-rows.test.ts
  • src/renderer/src/components/sidebar/worktree-list-scroll-adjustment.test.ts
  • src/renderer/src/components/sidebar/worktree-list-visible-refresh.test.ts
  • src/renderer/src/components/sidebar/worktree-list/FolderPathStatusIndicator.tsx
  • src/renderer/src/components/sidebar/worktree-list/HostSectionHeader.tsx
  • src/renderer/src/components/sidebar/worktree-list/SidebarWorktreeListDialogs.tsx
  • src/renderer/src/components/sidebar/worktree-list/SidebarWorktreeListEmptyState.tsx
  • src/renderer/src/components/sidebar/worktree-list/VirtualizedWorktreeViewport.tsx
  • src/renderer/src/components/sidebar/worktree-list/active-descendant-option.ts
  • src/renderer/src/components/sidebar/worktree-list/folder-workspace-virtual-row.tsx
  • src/renderer/src/components/sidebar/worktree-list/imported-worktrees-card-visibility.ts
  • src/renderer/src/components/sidebar/worktree-list/mounted-row-reveal.ts
  • src/renderer/src/components/sidebar/worktree-list/pending-sidebar-reveal-inputs.ts
  • src/renderer/src/components/sidebar/worktree-list/pointer-drop-status-target.ts
  • src/renderer/src/components/sidebar/worktree-list/project-group-header-actions.tsx
  • src/renderer/src/components/sidebar/worktree-list/render-row-item-rows.ts
  • src/renderer/src/components/sidebar/worktree-list/render-row-worktree-lookup.ts
  • src/renderer/src/components/sidebar/worktree-list/renderable-rows.ts
  • src/renderer/src/components/sidebar/worktree-list/repo-header-event-guards.ts
  • src/renderer/src/components/sidebar/worktree-list/repo-header-project-actions.tsx
  • src/renderer/src/components/sidebar/worktree-list/sidebar-editable-target.ts
  • src/renderer/src/components/sidebar/worktree-list/sidebar-row-reveal-ancestors.ts
  • src/renderer/src/components/sidebar/worktree-list/stable-empty-store-slices.ts
  • src/renderer/src/components/sidebar/worktree-list/use-agent-send-target-worktree.ts
  • src/renderer/src/components/sidebar/worktree-list/use-effective-collapsed-groups.ts
  • src/renderer/src/components/sidebar/worktree-list/use-folder-workspace-path-status-rows.ts
  • src/renderer/src/components/sidebar/worktree-list/use-group-toggle-with-scroll-anchor.ts
  • src/renderer/src/components/sidebar/worktree-list/use-pending-sidebar-reveal.ts
  • src/renderer/src/components/sidebar/worktree-list/use-primary-active-worktree-row.ts
  • src/renderer/src/components/sidebar/worktree-list/use-project-group-dialogs.ts
  • src/renderer/src/components/sidebar/worktree-list/use-reused-array-identity.ts
  • src/renderer/src/components/sidebar/worktree-list/use-sidebar-external-worktree-cards.ts
  • src/renderer/src/components/sidebar/worktree-list/use-sidebar-host-visible-scope.ts
  • src/renderer/src/components/sidebar/worktree-list/use-sidebar-reveal-highlight.ts
  • src/renderer/src/components/sidebar/worktree-list/use-sidebar-reveal-requests.ts
  • src/renderer/src/components/sidebar/worktree-list/use-sidebar-section-rows.ts
  • src/renderer/src/components/sidebar/worktree-list/use-sidebar-worktree-filters.ts
  • src/renderer/src/components/sidebar/worktree-list/use-sidebar-worktree-selection.ts
  • src/renderer/src/components/sidebar/worktree-list/use-sidebar-worktree-sort-order.ts
  • src/renderer/src/components/sidebar/worktree-list/use-virtual-row-measurement-sync.ts
  • src/renderer/src/components/sidebar/worktree-list/use-visible-pr-refresh-reporting.ts
  • src/renderer/src/components/sidebar/worktree-list/use-visible-sidebar-worktrees.ts
  • src/renderer/src/components/sidebar/worktree-list/use-workspace-status-row-drag.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-document-drop.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-drag-runtime.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-drag-session.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-lineage-drop-commit.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-list-keyboard-navigation.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-list-virtualizer.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-native-drag-autoscroll.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-native-drag.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-pointer-drag-autoscroll.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-pointer-drag-window-events.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-pointer-drag.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-sidebar-header-drag.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-sidebar-scroll-suppression.ts
  • src/renderer/src/components/sidebar/worktree-list/use-worktree-status-mutations.ts
  • src/renderer/src/components/sidebar/worktree-list/virtual-row-dom-attributes.ts
  • src/renderer/src/components/sidebar/worktree-list/virtualized-worktree-viewport-props.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-drag-groups.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-drop-commit-context.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-list-item-row.tsx
  • src/renderer/src/components/sidebar/worktree-list/worktree-notice-virtual-rows.tsx
  • src/renderer/src/components/sidebar/worktree-list/worktree-option-dom.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-pointer-drag-commit.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-pointer-drag-flush.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-row-drag-state.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-section-header-row.tsx
  • src/renderer/src/components/sidebar/worktree-list/worktree-sidebar-scroll-tuning.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-virtual-row-context.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-virtual-row-dispatch.tsx
  • src/renderer/src/components/sidebar/worktree-list/worktree-visibility-menu-label.ts
  • src/renderer/src/components/sidebar/worktree-list/worktree-visible-refresh-listener.ts
  • src/renderer/src/components/sidebar/worktree-scroll-to-current-button.test.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy-interrupt.test.ts

📝 Walkthrough

Walkthrough

The worktree sidebar was decomposed into focused modules for row rendering, state derivation, virtualization, reveal handling, keyboard navigation, and drag-and-drop. New hooks and components manage filters, grouping, host visibility, dialogs, workspace status, external worktrees, selection, scrolling, and active-row accessibility. Tests now reference the extracted modules directly, and the former WorktreeList.tsx max-lines exception was removed.

✨ Finishing Touches 💡 2
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch nwparker/WorktreeList.tsx
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

AmethystLiang added a commit that referenced this pull request Aug 14, 2026
Follow-up to #14465 / #14467. Keep the landed extract and reorganize the
flat worktree-list dump into drag/, headers/, reveal/, rows/, scroll/,
and viewport/. Fold tiny modules into their owners, move leftover
sidebar-root files into the module, and retarget imports and source-path
tests. Layout-only; no behavior change.
AmethystLiang added a commit that referenced this pull request Aug 15, 2026
* refactor(sidebar): group worktree-list files by domain

Follow-up to #14465 / #14467. Keep the landed extract and reorganize the
flat worktree-list dump into drag/, headers/, reveal/, rows/, scroll/,
and viewport/. Fold tiny modules into their owners, move leftover
sidebar-root files into the module, and retarget imports and source-path
tests. Layout-only; no behavior change.

* fix(sidebar): merge duplicate virtual-rows imports

Inlining virtual-row-dom-attributes left a second import from the same
module, which fails audit:code-quality:native --deny-warnings.

* refactor(sidebar): condense indentation comments

Shorten explanations to focus on the essential why, removing redundant
detail and improving readability without changing functionality.

* refactor: organize worktree-list into lifecycle dest folders

* fix react doctor

* fix: update reliability-gates path after worktree-list reorg

host-filtering.test.ts moved from viewport/ to listing/; keep the
runtime-routing.active-server-preference gate pointing at the real file.

* Extract workspace status colors to design tokens

Define theme-aware color tokens for workspace PR-state indicators (done, in-review, in-progress) to ensure consistent identity across theme switches. Update references to use the new tokens and refactor EmptyState button to use the Button component.

* fix(sidebar): stop mutating refs during worktree-list render

React Doctor fails static analysis when refs are written in render.
Commit reused array identity and the Smart live-signal latch after
paint, and return the attention map from the sort memo instead of
stashing it on a render-time ref.
AmethystLiang added a commit that referenced this pull request Aug 17, 2026
* refactor(sidebar): group worktree-list files by domain

Follow-up to #14465 / #14467. Keep the landed extract and reorganize the
flat worktree-list dump into drag/, headers/, reveal/, rows/, scroll/,
and viewport/. Fold tiny modules into their owners, move leftover
sidebar-root files into the module, and retarget imports and source-path
tests. Layout-only; no behavior change.

* fix(sidebar): merge duplicate virtual-rows imports

Inlining virtual-row-dom-attributes left a second import from the same
module, which fails audit:code-quality:native --deny-warnings.

* refactor(sidebar): condense indentation comments

Shorten explanations to focus on the essential why, removing redundant
detail and improving readability without changing functionality.

* refactor: organize worktree-list into lifecycle dest folders

* fix react doctor

* fix: update reliability-gates path after worktree-list reorg

host-filtering.test.ts moved from viewport/ to listing/; keep the
runtime-routing.active-server-preference gate pointing at the real file.

* Extract workspace status colors to design tokens

Define theme-aware color tokens for workspace PR-state indicators (done, in-review, in-progress) to ensure consistent identity across theme switches. Update references to use the new tokens and refactor EmptyState button to use the Button component.

* fix(sidebar): stop mutating refs during worktree-list render

React Doctor fails static analysis when refs are written in render.
Commit reused array identity and the Smart live-signal latch after
paint, and return the attention map from the sort memo instead of
stashing it on a render-time ref.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ablyai#14465)

WorktreeList.tsx was 6.8k lines behind an `eslint-disable max-lines`. Break it
into `sidebar/worktree-list/`: the container keeps store wiring and composition,
the virtualized viewport keeps layout, and the drag, reveal, virtualization,
row-model, and row-render concerns each get their own file. Every file now fits
the oxlint budget, so the suppression and its baseline entry are gone.

Behaviour-preserving. The only deliberate cleanups are duplicate branches folded
into shared helpers (drop-preview state updates, status-hover fallback, the two
identical scroll-to-index reveal branches) and a dead sticky-header-index ref.

Tests that asserted on WorktreeList.tsx source text or imported its named
helpers now point at the module that owns them.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* refactor(sidebar): group worktree-list files by domain

Follow-up to stablyai#14465 / stablyai#14467. Keep the landed extract and reorganize the
flat worktree-list dump into drag/, headers/, reveal/, rows/, scroll/,
and viewport/. Fold tiny modules into their owners, move leftover
sidebar-root files into the module, and retarget imports and source-path
tests. Layout-only; no behavior change.

* fix(sidebar): merge duplicate virtual-rows imports

Inlining virtual-row-dom-attributes left a second import from the same
module, which fails audit:code-quality:native --deny-warnings.

* refactor(sidebar): condense indentation comments

Shorten explanations to focus on the essential why, removing redundant
detail and improving readability without changing functionality.

* refactor: organize worktree-list into lifecycle dest folders

* fix react doctor

* fix: update reliability-gates path after worktree-list reorg

host-filtering.test.ts moved from viewport/ to listing/; keep the
runtime-routing.active-server-preference gate pointing at the real file.

* Extract workspace status colors to design tokens

Define theme-aware color tokens for workspace PR-state indicators (done, in-review, in-progress) to ensure consistent identity across theme switches. Update references to use the new tokens and refactor EmptyState button to use the Button component.

* fix(sidebar): stop mutating refs during worktree-list render

React Doctor fails static analysis when refs are written in render.
Commit reused array identity and the Smart live-signal latch after
paint, and return the attention map from the sort memo instead of
stashing it on a render-time ref.
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