Skip to content

fix: Projects tab resets focused item on window focus return #108

@grimmerk

Description

@grimmerk

Problem

When returning to CodeV from background, the Projects tab (react-select) resets the focused/selected item to the first one. Sessions tab preserves position correctly.

Root Cause

onFocusWindow triggers fetchRecentProjectRecord() which calls setPathInfoArray() with a new array reference. react-select treats this as new options and resets focusedOption to the first item.

Sessions tab doesn't have this issue because it uses a custom selectedSessionIndex state that survives data refresh.

Related

Arrow key navigation in Projects tab may also occasionally jump back — likely the same root cause (async data refresh mid-navigation).

Attempted Fixes (didn't work)

  • useMemo for pathArray — not enough, upstream setPathInfoArray still creates new reference
  • Functional setState with path comparison — didn't take effect (possibly webpack cache, or react-select tracks options by reference internally)

Possible Approaches

  1. Skip project refetch on focus if data was loaded recently (TTL check)
  2. Track focused option in a ref and restore it after options update (react-select internal API needed)
  3. Replace react-select with custom list (like Sessions tab) for full control
  4. Debounce/batch state updates to reduce re-renders during focus

🤖 On behalf of @grimmerk — generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions