Repository navigation
Fix: settle sortEpoch in store to prevent React update depth exceeded - #25313
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)📝 WalkthroughWalkthroughThe store now tracks a settled sort epoch, and the sidebar sorting hook uses it to recompute worktree order. Drops and reorders that change ordering use a shared function to switch to Manual sorting and show a toast with an optional restore action. Tests cover epoch settling, sort behavior, toast dismissal, and reorder cases. English locale strings were added for the toast. Priority: ⬇️ Low Merge Risk: 🔵 Low · up to A newly hydrated worktree may appear at the end of the sidebar for up to three seconds instead of moving immediately to its sorted position. This is a bounded visual delay, but the structural-change handling should be corrected. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The inspected changes remain focused on sidebar ordering and reuse existing worktree mutation operations. No introduced security issue was established, but incomplete lifecycle and downstream coverage prevents a stronger assurance. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 13 files. (1 skipped: 1 unsupported.)
✨ 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: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
09e9b2ee-c328-461c-88a1-59c3f8e468c7
📥 Commits
Reviewing files that changed from the base of the PR and between 6c07570 and 5a92914746e18e94b1d049043bcbd18ca10bd821.
📒 Files selected for processing (15)
src/renderer/src/components/sidebar/WorkspaceKanbanDrawer.tsxsrc/renderer/src/components/sidebar/WorktreeList.tsxsrc/renderer/src/components/sidebar/manual-sort-switch-toast.test.tssrc/renderer/src/components/sidebar/manual-sort-switch-toast.tssrc/renderer/src/components/sidebar/use-workspace-kanban-worktree-actions.tssrc/renderer/src/components/sidebar/worktree-list/drag/use-status-mutations.tssrc/renderer/src/components/sidebar/worktree-list/listing/use-sort-order.test.tsxsrc/renderer/src/components/sidebar/worktree-list/listing/use-sort-order.tssrc/renderer/src/components/sidebar/worktree-manual-order-store-write.test.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/store/index.tssrc/renderer/src/store/settled-sort-epoch.test.tssrc/renderer/src/store/settled-sort-epoch.tssrc/renderer/src/store/slices/worktree-helpers.tssrc/renderer/src/store/slices/worktrees/session/worktree-slice-initial-state.ts
💤 Files with no reviewable changes (1)
- src/renderer/src/components/sidebar/WorkspaceKanbanDrawer.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
Important
The PR's own CI is red: anti-slop/no-reflect-get rejects Reflect.get in the new use-sort-order.test.tsx, and the verify job cascades off that preflight failure. One-line fix below.
Reviewed changes
- Store-level settle (
settled-sort-epoch.ts) — new listener installed in the store creator coalescessortEpochbursts intosettledSortEpoch(3s debounce for time-decaying modes; immediate for Manual, structural add/remove, and mode switches). - Sidebar reads the settled epoch —
use-sort-order.tsdrops theuseDebouncedSortEpochReact effect and theallWorktreesarg; the memo is now triggered bysettledSortEpoch.WorktreeList.tsxcall site updated. - Manual-sort toast —
switchSortToManualAfterDrop()replaces directsetSortBy('manual')at the three drop sites and offers a "Back to " action; i18n keys added. - State + tests —
settledSortEpochfield/initial state; new settle, toast, and hook tests plus updated manual-order-write test.
The settle rules read correctly: the early settledSortEpoch === sortEpoch return retires the pending timer on settle()/reset, and mode switches settle before hook subscribers re-read. pnpm tc passes and the touched suites I ran (settled-sort-epoch, use-sort-order, manual-order-write, toast, WorktreeList mock tests, and the epoch-sensitive store slice tests) are green.
ℹ️ Nitpicks
WorktreeList.card-memo-stability.test.tsx's mock state never providessettledSortEpoch, souseSidebarWorktreeSortOrdernow readsundefinedthere and the "does not re-render cards on an order-preserving sortEpoch bump" case no longer triggers a recompute — it passes vacuously. AddingsettledSortEpochto the mock and bumping that field (alongsidesortEpoch) would restore what the test claims to pin.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
In Manual mode the sort hook copied every sortEpoch bump into state from an effect, adding a nested React update per bump. A burst of store bumps at startup stacked those into 'Maximum update depth exceeded' (React #185). Manual now reads the live epoch directly; debounced modes are unchanged.
Reordering by drag still switches the sidebar to Manual so the drop sticks, but it used to happen silently. Show a toast with a 'Back to <previous sort>' action; it retires itself on any later sort change so it can't override a newer choice. Drops while already in Manual stay silent.
Add settledSortEpoch plus a 3 s settle timer owned by a store listener installed in the state creator. Every write path (slice actions, the web session sync patch) goes through it, so the settled value stays correct with no sidebar mounted. Manual, a sort-mode switch, and a bump that changes the non-archived row count settle in the same notify; other bumps restart the window. A reset that lands settled clears the timer, and the disposer runs on HMR teardown.
…o state The sort hook no longer copies sortEpoch into React state from an effect in any mode; it reads the store's settledSortEpoch directly. That pattern added a nested update per bump and stacked into "Maximum update depth exceeded" (React #185) under flushSync bursts. Tests cover Manual, add/remove, burst reset, no-bump row changes, mode switch, and 80 flushSync bumps in Recent while worktrees are added.
Detect structural changes on worktreesByRepo updates in addition to sort epoch changes. When a row arrives without its own bump during a pending settlement window, the changed composition must still trigger settlement.
883c8b1 to
dc6bb39
Compare

Problem
When workspaces are reordered via drag-and-drop, the app triggers many rapid
sortEpochbumps. The sidebar component was mirroring this into React state with an effect, creating nested updates that exceeded React's maximum update depth and crashed with "Maximum update depth exceeded" (issue #185).Solution
Move the sortEpoch settling logic from a React effect in the sidebar component to a store listener that runs once per state change. The store now tracks
settledSortEpoch— the epoch value the sidebar sort actually reads.Settling rules:
User-facing change:
What Changed
useDebouncedSortEpochlogic from sidebar hook tosettled-sort-epoch.tsstore listenersettledSortEpochstate field; sidebar sort reads this instead ofsortEpochsetSortBy('manual')calls withswitchSortToManualAfterDrop()function that shows a toastallWorktreesparameter fromuseSidebarWorktreeSortOrder(no longer needs local worktree count)Testing
settled-sort-epoch.test.ts,manual-sort-switch-toast.test.ts,use-sort-order.test.tsx, and existingworktree-manual-order-store-write.test.tsupdatedChecklist
pnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)