Skip to content

refactor(cloud-chat): lift sidebar sessions query out of CloudChatContainer#764

Merged
eshurakov merged 3 commits intomainfrom
session/agent_41d55dbe-0fad-4d9f-81bf-c03f24962213
Mar 3, 2026
Merged

refactor(cloud-chat): lift sidebar sessions query out of CloudChatContainer#764
eshurakov merged 3 commits intomainfrom
session/agent_41d55dbe-0fad-4d9f-81bf-c03f24962213

Conversation

@kilo-code-bot
Copy link
Contributor

@kilo-code-bot kilo-code-bot bot commented Mar 3, 2026

Problem

useSidebarSessions (which calls useQuery for unifiedSessions.list) was called inside CloudChatContainer. That component re-renders ~6 times during its session-loading lifecycle due to cascading state updates from useState / useAtomValue, and React Strict Mode doubles that to ~12.

tRPC's batching layer collects all useQuery calls within a React tick and sends them as one HTTP request. React Query deduplicates concurrent requests with the same key, but here it sees a single in-flight batched request with 12 sub-operations — so deduplication never fires. The server processes the same query 12 times per page load (6 in production without Strict Mode).

Fix

Lifted useSidebarSessions one level up into CloudChatPage, which is a stateless pass-through component that never re-renders during the session-loading lifecycle. sessions and refetchSessions are passed down as props to CloudChatContainer.

  • cloud-agent/CloudChatPage.tsx — call useSidebarSessions here, pass results as props
  • cloud-agent/CloudChatContainer.tsx — accept sessions / refetchSessions as props, remove hook call
  • cloud-agent-next/CloudChatPage.tsx — same
  • cloud-agent-next/CloudChatContainer.tsx — same

All downstream consumers (handleStreamComplete, useSessionDeletion, CloudChatPresentation) are unchanged — they consume the same values, now via props instead of a local hook call.

Expected outcome

Scenario Before After
Dev (Strict Mode) ~12 sub-operations per batch ~2
Production ~6 sub-operations per batch ~1

kilo-code-bot bot added 2 commits March 3, 2026 12:44
…as props

Move logic:
- move useSidebarSessions call from CloudChatContainer to CloudChatPage for both packages
- CloudChatContainer now accepts sessions: StoredSession[] and refetchSessions: () => void; remove internal fetch
- CloudChatPage now uses useSidebarSessions and passes sessions and refetchSessions to container
- update type imports to include StoredSession

BREAKING CHANGE: CloudChatContainer API changed to require sessions and refetchSessions props; CloudChatPage wires loading to avoid re-renders
@eshurakov eshurakov self-assigned this Mar 3, 2026
@kilo-code-bot
Copy link
Contributor Author

kilo-code-bot bot commented Mar 3, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

Clean refactor that lifts the useSidebarSessions hook from CloudChatContainer up to CloudChatPage in both cloud-agent and cloud-agent-next directories. This correctly prevents redundant unifiedSessions.list tRPC invocations that were being triggered by frequent internal state changes in CloudChatContainer.

Key observations:

  • StoredSession type is properly imported and used in the new props
  • isLoading from useSidebarSessions was never used in CloudChatContainer, so omitting it from props is correct
  • CloudChatContainer is only consumed by CloudChatPage in both directories — no other callers need updating
  • refetchSessions is wrapped in useCallback and sessions in useMemo inside the hook, so referential stability is maintained
  • Both cloud-agent and cloud-agent-next are updated consistently in parallel
Files Reviewed (4 files)
  • src/components/cloud-agent-next/CloudChatContainer.tsx - no issues
  • src/components/cloud-agent-next/CloudChatPage.tsx - no issues
  • src/components/cloud-agent/CloudChatContainer.tsx - no issues
  • src/components/cloud-agent/CloudChatPage.tsx - no issues

@eshurakov eshurakov requested a review from a team March 3, 2026 16:36
@eshurakov eshurakov merged commit 7e781cd into main Mar 3, 2026
12 checks passed
@eshurakov eshurakov deleted the session/agent_41d55dbe-0fad-4d9f-81bf-c03f24962213 branch March 3, 2026 20:57
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.

2 participants