Skip to content

Fix excessive re-renders causing UI lag - #26

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennankbenson/perf-issue
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennankbenson/perf-issue

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: Broad Zustand store subscriptions caused cascading re-renders on every UI interaction. A single worktree click triggered App → Terminal → TabBar → all TerminalPanes to re-render unnecessarily.
  • Remove worktreesByRepo subscription from Terminal.tsx — tracked mounted worktrees in local state instead of subscribing to the full worktree map that changes on any worktree update
  • Wrap Terminal, TabBar, TerminalPane in React.memo — prevents cascade re-renders when parent components re-render with unchanged props
  • Fix inline onPtyExit callback — was creating new function references per tab per render, defeating React.memo. Now uses stable per-tab handlers via a ref-backed Map
  • Consolidate 4 keydown listeners into 1 in TerminalPane — reduced event handler overhead
  • Attach sidebar resize listeners only during drag — previously always active on document, firing on every mouse move
  • Extract session/UI persistence into useSessionPersistence hook — removed 7 store subscriptions from App.tsx that were only needed for IPC persistence, so changes to sidebarWidth, groupBy, etc. no longer re-render the entire component tree

Test plan

  • Run pnpm dev and click around between worktrees — should feel responsive
  • Switch between terminal tabs — no lag
  • Drag sidebar to resize — smooth, no jank
  • Split terminal panes (Cmd+D) and verify shortcuts still work (Cmd+[, Cmd+], Cmd+W, Ctrl+Backspace, Alt+Backspace, Shift+Enter)
  • Verify session state persists across restarts (active worktree, tabs, sidebar width)
  • Run pnpm typecheck — passes clean

🤖 Generated with Claude Code

Root cause: broad Zustand store subscriptions in the component tree caused
cascading re-renders on every interaction. A single worktree click triggered
App → Terminal → TabBar → all TerminalPanes to re-render unnecessarily.

Key fixes:
- Remove worktreesByRepo subscription from Terminal.tsx; track mounted
  worktrees in local state instead of subscribing to the full map
- Wrap Terminal, TabBar, TerminalPane in React.memo to prevent cascade
  re-renders from parent updates
- Fix inline onPtyExit callback that defeated React.memo by creating
  stable per-tab handlers via a ref-backed Map
- Consolidate 4 separate keydown listeners into 1 in TerminalPane
- Attach sidebar resize listeners only during drag instead of always
- Extract session/UI persistence effects into useSessionPersistence hook
  so that persisted-value changes (sidebarWidth, activeTabId, etc.)
  trigger IPC calls without re-rendering the App component tree

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Found to be not the issue

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