Repository navigation
fix: remember last active sidebar tab per agent session - #24631
Conversation
|
/coder-agents-review |
There was a problem hiding this comment.
Solid, focused fix. The localStorage persistence follows the existing agents.draft-input.<chatID> pattern exactly, the lifecycle is complete (create on click, restore on mount, clear on archive), and the test strategy splits correctly between vitest for pure helpers and Storybook for integration. The getEffectiveTabId fallback handles stale/unavailable tabs gracefully without clobbering the stored value. Tests pass (46/46).
Two P3s, five nits. The P3s are a naming inconsistency that makes the archive call site look like a bug, and a missing story for the PR description's claimed "tab survives unavailability" behavior.
"A developer reading that line has to chase the function signature, see
agentID, wonder if the wrong ID type was passed, then trace through to learn thatagentIdandchatIdare the same value in this codebase." (Leorio)
🤖 This review was automatically generated with Coder Agents.
2ef3f53 to
f23f22b
Compare
f23f22b to
7550b73
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7550b73bf6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Add localStorage-backed helpers to save, restore, and clear the active right-panel tab per agent session (keyed by agent ID). - AgentChatPage.tsx: new exported helpers getPersistedSidebarTabId, savePersistedSidebarTabId, clearPersistedSidebarTabId, and the lastActiveSidebarTabStorageKeyPrefix constant. - AgentChatPageView.tsx: initialize sidebarTabId from localStorage via getPersistedSidebarTabId; wrap setter in useCallback that persists on every tab change via savePersistedSidebarTabId. - AgentsPage.tsx: call clearPersistedSidebarTabId in both archiveAgentMutation and archiveAndDeleteMutation onSuccess handlers to clean up stale entries. - AgentChatPage.test.ts: 15 unit tests covering get/save/clear helpers including edge cases (undefined, empty string, no-op, round-trip, cross-agent isolation).
… persistence Add two play-function stories to AgentChatPageView.stories.tsx: - RestoresPersistedSidebarTab: Seeds localStorage with a persisted 'terminal' tab ID before mount and verifies the Terminal tab is selected instead of the default Git tab on render. - PersistsSidebarTabClick: Starts with empty localStorage, clicks the Terminal tab, and asserts both the aria-selected attribute and the localStorage value are updated. Both stories use beforeEach/cleanup to manage localStorage state and provide workspace + workspaceAgent props so the Terminal tab is available in the sidebar. Archive cleanup story was intentionally skipped because the archive flow in AgentsPage.tsx requires substantial mock infrastructure, and the clearPersistedSidebarTabId helper is already covered by unit tests.
- Rename agentID parameter to chatID across the three new helpers to match the sibling getPersistedDraftInputValue and the clearPersistedSidebarTabId(chatId) archive call site. (DEREM-1) - Replace useCallback wrapper around setSidebarTabId with a plain arrow function. babel-plugin-react-compiler auto-memoizes closures under site/src/pages/AgentsPage. (DEREM-3) - Add @internal annotation and correct the wording on lastActiveSidebarTabStorageKeyPrefix (right-panel -> sidebar, per-session -> per-chat). (DEREM-4, DEREM-5) - Add JSDoc to the three new helpers to match the sibling getPersistedDraftInputValue. (DEREM-6) - Drop the redundant localStorage.getItem assertion that was testing the test harness rather than the helper. (DEREM-7) - Add PreservesUnavailableSidebarTab story that locks down the contract that a stored tab ID survives when its tab is not currently available, so getEffectiveTabId's read-only fallback cannot silently regress. (DEREM-2)
After archiving a chat, archiveAgentMutation.onSuccess calls clearPersistedSidebarTabId(chatId) so a subsequent unarchive starts from the default tab. The plain archive flow (via the chat menu) does not navigate away, so the user remains on the now-read-only chat. If the user clicks a sidebar tab in that state, savePersistedSidebarTabId would silently recreate the entry, defeating the archive cleanup. Gate savePersistedSidebarTabId on !isArchived. React local state still switches for immediate visual feedback; only the persistence step is skipped. Add DoesNotPersistForArchivedChat storybook story that seeds an empty localStorage, renders with isArchived=true, clicks the Terminal tab, and asserts the entry stays null. Addresses the codex P2 comment on #24631.
7550b73 to
5e7363e
Compare
closes CODAGT-142
The Agents right-panel tabs (Git, Terminal, Desktop) reset to the
default tab (Git) every time the user switches between agent sessions.
This happens because
KeyedAgentChatPageforces a full remount onagentIdchange, discarding theuseStatethat holds the active tab.Persist the active tab per agent session in
localStorage, followingthe existing
agents.draft-input.<chatID>pattern. When the userreturns to a session, the last tab they selected is restored. If the
stored tab is temporarily unavailable (e.g. Desktop while the workspace
is stopped),
SidebarTabView's existing fallback to the firstavailable tab applies, and the stored value survives so it can be
honoured once that tab reappears.
Archiving a chat clears its stored tab entry so unarchiving starts
fresh with the default tab.