Skip to content

fix(console/agent-sessions): keep prior data during refetch (no flash)#24

Merged
vaderyang merged 1 commit into
mainfrom
feat/agent-sessions-no-flash
May 21, 2026
Merged

fix(console/agent-sessions): keep prior data during refetch (no flash)#24
vaderyang merged 1 commit into
mainfrom
feat/agent-sessions-no-flash

Conversation

@vaderyang
Copy link
Copy Markdown
Collaborator

Summary

Add placeholderData: (prev) => prev to the three Agent Session list hooks so the Sessions page does an in-place swap on refetch — same behavior as Agent Turns / LLM Calls / Metrics / every other list page.

Why

User report: "Agent Session 界面每次刷新都会重刷整个页面,而不是像其他页面一样看上去重刷幅度很小".

Every other list hook in the app sets placeholderData: (prev) => prev. The Agent Session hooks didn't — so every auto-refresh tick / toolbar key change wiped the cache to undefined, the page rendered its loading skeleton, then the new data dropped in. The user saw a full-page flash where every other page did a smooth swap.

Files

  • console/src/hooks/use-agent-sessions.ts — three hooks (useAgentSessions, useAgentSessionDetail, useSessionTurns) each get the same one-liner.

Test plan

  • bun test — 111 pass
  • bun run build — clean

🤖 Generated with Claude Code

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) <noreply@anthropic.com>
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Agent run failed (exit 1). See workflow logs.


🤖 Reviewed by viviworkflow run

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR adds placeholderData: (prev) => prev to three Agent Session hooks (useAgentSessions, useAgentSessionDetail, useSessionTurns) to eliminate a UI flash during auto-refresh. The fix matches the pattern used in all other list hooks (useAgentTurns, useLlmCalls, useHttpExchanges, useMetrics) and correctly addresses the reported issue. The implementation is correct and follows established patterns. APPROVE

Verified

  • Pattern consistency: Confirmed that useAgentTurns:44, useLlmCalls:57, useHttpExchanges:72, useMetrics:15 all use placeholderData: (prev) => prev — the three hooks in this PR now match this pattern
  • Infinite query behavior: For useAgentSessions and useSessionTurns, the queryKey includes start/end from toolbar store. When auto-refresh updates the preset (via useAutoRefreshsetPreset), these values change, causing a key transition. Without placeholderData, this would clear cached pages → render loading skeleton → flash; with it, prior pages stay visible until new data arrives
  • Detail hook appropriateness: useAgentSessionDetail doesn't subscribe to start/end, but navigation between sessions (same source, different session_id) would benefit from showing the prior session until the new one loads
  • Caller compatibility: Checked agent-sessions.tsx:54 and agent-session-detail.tsx:11,19 — the hooks are consumed correctly, and the loading-state predicates (isLoading && items.length === 0, loadingDetail && !detail) already handle the placeholderData case properly (they check for data presence, not just loading state)
  • No other hooks missed: Grepped for all useQuery/useInfiniteQuery hooks — all list/timeseries queries now have placeholderData, detail queries (useAgentTurnDetail, useAgentTurnCalls, useLlmCallDetail, useHttpExchange) correctly omit it as they lack time-range dependencies

🤖 Reviewed by viviworkflow run

@vaderyang vaderyang merged commit 9c9cb8e into main May 21, 2026
1 check passed
@vaderyang vaderyang deleted the feat/agent-sessions-no-flash branch May 21, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant