@@ -34,6 +34,7 @@ import {
3434 useAgentSubChatStore ,
3535 type SubChatMeta ,
3636} from "../agents/stores/sub-chat-store"
37+ import { useShallow } from "zustand/react/shallow"
3738import {
3839 PlusIcon ,
3940 ArchiveIcon ,
@@ -103,15 +104,16 @@ export function AgentsSubChatsSidebar({
103104 isLoading = false ,
104105 agentName,
105106} : AgentsSubChatsSidebarProps ) {
106- const activeSubChatId = useAgentSubChatStore ( ( state ) => state . activeSubChatId )
107- const openSubChatIds = useAgentSubChatStore ( ( state ) => state . openSubChatIds )
108- const pinnedSubChatIds = useAgentSubChatStore (
109- ( state ) => state . pinnedSubChatIds ,
110- )
111- const allSubChats = useAgentSubChatStore ( ( state ) => state . allSubChats )
112- const parentChatId = useAgentSubChatStore ( ( state ) => state . chatId )
113- const togglePinSubChat = useAgentSubChatStore (
114- ( state ) => state . togglePinSubChat ,
107+ // Use shallow comparison to prevent re-renders when arrays have same content
108+ const { activeSubChatId, openSubChatIds, pinnedSubChatIds, allSubChats, parentChatId, togglePinSubChat } = useAgentSubChatStore (
109+ useShallow ( ( state ) => ( {
110+ activeSubChatId : state . activeSubChatId ,
111+ openSubChatIds : state . openSubChatIds ,
112+ pinnedSubChatIds : state . pinnedSubChatIds ,
113+ allSubChats : state . allSubChats ,
114+ parentChatId : state . chatId ,
115+ togglePinSubChat : state . togglePinSubChat ,
116+ } ) )
115117 )
116118 const [ loadingSubChats ] = useAtom ( loadingSubChatsAtom )
117119 const subChatFiles = useAtomValue ( subChatFilesAtom )
@@ -154,7 +156,7 @@ export function AgentsSubChatsSidebar({
154156 // Pending plan approvals from DB - only for open sub-chats
155157 const { data : pendingPlanApprovalsData } = trpc . chats . getPendingPlanApprovals . useQuery (
156158 { openSubChatIds } ,
157- { refetchInterval : 5000 , enabled : openSubChatIds . length > 0 }
159+ { refetchInterval : 5000 , enabled : openSubChatIds . length > 0 , placeholderData : ( prev ) => prev }
158160 )
159161 const pendingPlanApprovals = useMemo ( ( ) => {
160162 const set = new Set < string > ( )
@@ -1092,7 +1094,7 @@ export function AgentsSubChatsSidebar({
10921094 { /* Loading state - centered spinner */ }
10931095 { isLoading ? (
10941096 < div className = "flex items-center justify-center h-full" >
1095- < IconSpinner className = "w-5 h-5 text-muted-foreground" />
1097+ < IconSpinner className = "w-4 h-4 text-muted-foreground" />
10961098 </ div >
10971099 ) : (
10981100 < >
0 commit comments