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
- Skip project refetch on focus if data was loaded recently (TTL check)
- Track focused option in a ref and restore it after options update (react-select internal API needed)
- Replace react-select with custom list (like Sessions tab) for full control
- Debounce/batch state updates to reduce re-renders during focus
🤖 On behalf of @grimmerk — generated with Claude Code
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
onFocusWindowtriggersfetchRecentProjectRecord()which callssetPathInfoArray()with a new array reference. react-select treats this as new options and resetsfocusedOptionto the first item.Sessions tab doesn't have this issue because it uses a custom
selectedSessionIndexstate 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)
useMemoforpathArray— not enough, upstreamsetPathInfoArraystill creates new referencesetStatewith path comparison — didn't take effect (possibly webpack cache, or react-select tracks options by reference internally)Possible Approaches
🤖 On behalf of @grimmerk — generated with Claude Code