Skip to content

refactor(desktop): simplify state management with derived state pattern#55

Merged
oxwen11 merged 1 commit intomainfrom
changsha
Feb 3, 2026
Merged

refactor(desktop): simplify state management with derived state pattern#55
oxwen11 merged 1 commit intomainfrom
changsha

Conversation

@iamdin
Copy link
Collaborator

@iamdin iamdin commented Feb 1, 2026

Summary

  • Rename selected* to current* (currentRepositoryId, currentTaskId)
  • Remove selectedWorktreeId (derive from task instead)
  • Rename openedWorktreeIds to worktreeTerminalIds
  • Use useMemo to derive currentRepository instead of syncing with useEffect
  • Remove unused use-selected-worktree hook
  • Add state management best practices to CLAUDE.md

Key Principle

Don't Sync State. Derive It! - Never use useEffect to synchronize state between different sources. Instead, derive values at render time using useMemo.

Test plan

  • Verify repository selection works correctly
  • Verify task selection works correctly
  • Verify terminal sessions persist when switching tasks
  • Verify fallback to first repository when stored ID is invalid

- Rename selected* to current* (currentRepositoryId, currentTaskId)
- Remove selectedWorktreeId (derive from task)
- Rename openedWorktreeIds to worktreeTerminalIds
- Use useMemo to derive currentRepository instead of syncing with useEffect
- Remove unused use-selected-worktree hook
- Add state management best practices to CLAUDE.md ("Don't Sync State. Derive It!")
@oxwen11 oxwen11 merged commit 2a9fcae into main Feb 3, 2026
1 check failed
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.

2 participants