Skip to content

The agent that grows with you

fix(dashboard): pause session refresh off chat route

debadityad81d4ac33f6a
diff --git a/web/src/components/ChatSessionList.test.tsx b/web/src/components/ChatSessionList.test.tsx
index 95cd2bb9aa4..da0d358d992 100644
--- a/web/src/components/ChatSessionList.test.tsx
+++ b/web/src/components/ChatSessionList.test.tsx
@@ -158,4 +158,41 @@ describe('ChatSessionList', () => {
expect(getSessions).toHaveBeenCalledTimes(2)
expect(container.textContent).toContain('Newly created session')
})
+
+ it('waits for the Chat tab to become active before loading or polling', async () => {
+ getSessions
+ .mockResolvedValueOnce(response('first', 'First session'))
+ .mockResolvedValueOnce(response('second', 'Newly created session'))
+
+ await act(async () => {
+ root.render(
+ <MemoryRouter>
+ <ChatSessionList activeSessionId={null} isActive={false} />
+ </MemoryRouter>
+ )
+ })
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(20_000)
+ })
+ expect(getSessions).not.toHaveBeenCalled()
+
+ await act(async () => {
+ root.render(
+ <MemoryRouter>
+ <ChatSessionList activeSessionId={null} isActive />
+ </MemoryRouter>
+ )
+ })
+
+ expect(getSessions).toHaveBeenCalledTimes(1)
+ expect(container.textContent).toContain('First session')
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(20_000)
+ })
+
+ expect(getSessions).toHaveBeenCalledTimes(2)
+ expect(container.textContent).toContain('Newly created session')
+ })
})
diff --git a/web/src/components/ChatSessionList.tsx b/web/src/components/ChatSessionList.tsx
index 01f9fdd7daa..b286b98bb11 100644
--- a/web/src/components/ChatSessionList.tsx
+++ b/web/src/components/ChatSessionList.tsx
@@ -35,6 +35,8 @@ const SESSION_REFRESH_MS = 20_000;
interface ChatSessionListProps {
/** Active resume target (the session currently shown in the terminal). */
activeSessionId: string | null;
+ /** Whether the Chat route is visible and should refresh its session list. */
+ isActive?: boolean;
/** Management profile from the dashboard switcher — scopes the listing. */
profile?: string;
className?: string;
@@ -67,6 +69,7 @@ function rowLabel(session: SessionInfo, untitled: string): string {
export function ChatSessionList({
activeSessionId,
+ isActive = true,
profile,
className,
onPicked,
@@ -114,15 +117,17 @@ export function ChatSessionList({
const reload = useCallback(() => setReloadNonce((n) => n + 1), []);
useEffect(() => {
+ if (!isActive) return;
// Dashboard data surfaces fetch from an effect on mount + scope change;
// keep this local and explicit until the shared lint profile is updated
// for async loaders (matches FilesPage).
// eslint-disable-next-line react-hooks/set-state-in-effect
load();
// `reloadNonce` is a manual refetch trigger (Refresh button / row pick).
- }, [load, reloadNonce]);
+ }, [isActive, load, reloadNonce]);
useEffect(() => {
+ if (!isActive) return;
const interval = window.setInterval(reload, SESSION_REFRESH_MS);
const onVisibilityChange = () => {
if (document.visibilityState === "visible") reload();
@@ -132,7 +137,7 @@ export function ChatSessionList({
window.clearInterval(interval);
document.removeEventListener("visibilitychange", onVisibilityChange);
};
- }, [reload]);
+ }, [isActive, reload]);
// Picking a row sets `/chat?resume=<id>`. Re-picking the row already in
// the terminal is a no-op (avoids a needless PTY teardown).
diff --git a/web/src/pages/ChatPage.tsx b/web/src/pages/ChatPage.tsx
index f876c366d1a..7a0f69c6b49 100644
--- a/web/src/pages/ChatPage.tsx
+++ b/web/src/pages/ChatPage.tsx
@@ -1854,6 +1854,7 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
</div>
<ChatSessionList
activeSessionId={resumeParam}
+ isActive={isActive}
profile={scopedProfile}
onPicked={closeMobilePanel}
onNewChat={startFreshDashboardChat}
@@ -2068,6 +2069,7 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
<div className="min-h-0 flex-1 overflow-hidden">
<ChatSessionList
activeSessionId={resumeParam}
+ isActive={isActive}
profile={scopedProfile}
onNewChat={startFreshDashboardChat}
workspaceCwd={workspaceCwd}