From 65ba70085c038d9571c682030afb23dab1d796df Mon Sep 17 00:00:00 2001 From: Vader Yang Date: Wed, 20 May 2026 11:11:19 +0800 Subject: [PATCH] fix(console/agent-sessions): keep prior data during refetch (no flash) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The three Agent Session list hooks (`useAgentSessions`, `useAgentSessionDetail`, `useSessionTurns`) were missing the `placeholderData: (prev) => prev` setting that every other list hook in the app uses (`useAgentTurns`, `useLlmCalls`, `useHttpExchanges`, `useMetrics`, etc.). Without it, every auto-refresh tick / toolbar key change wipes the query cache to undefined before the new response lands — react-query renders the loading skeleton, then the new data — and the user sees a full-page flash on every refresh while other list pages do a frame-perfect swap. Setting `placeholderData: (prev) => prev` keeps the last-known data visible while a background refetch is in flight. New data drops in when the response arrives; no skeleton, no blanked-out list. Caught by user: "Agent Session 界面每次刷新都会重刷整个页面, 而不是像其他页面一样看上去重刷幅度很小". Co-Authored-By: Claude Opus 4.7 (1M context) --- console/src/hooks/use-agent-sessions.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/console/src/hooks/use-agent-sessions.ts b/console/src/hooks/use-agent-sessions.ts index 7582ce5..6c81a52 100644 --- a/console/src/hooks/use-agent-sessions.ts +++ b/console/src/hooks/use-agent-sessions.ts @@ -31,6 +31,12 @@ export function useAgentSessions({ agentKind, pageSize = DEFAULT_PAGE_SIZE }: Us cursor: pageParam || undefined, }), getNextPageParam: (last) => last.next_cursor ?? undefined, + // Keep the previously-loaded pages visible while a background + // refetch (auto-refresh, window-focus, query-key churn) is in + // flight. Every other list hook in the app does this — without + // it the Sessions page blanks out and re-renders the whole list + // each refresh tick, while other pages do a frame-perfect swap. + placeholderData: (prev) => prev, }) } @@ -42,6 +48,7 @@ export function useAgentSessionDetail(sourceId: string | null, sessionId: string `/api/agent-sessions/${encodeURIComponent(sourceId!)}/${encodeURIComponent(sessionId!)}`, ), enabled: sourceId != null && sessionId != null, + placeholderData: (prev) => prev, }) } @@ -63,5 +70,6 @@ export function useSessionTurns( }, ), getNextPageParam: (last) => last.next_cursor ?? undefined, + placeholderData: (prev) => prev, }) }