@@ -70,6 +70,7 @@ import { soundNotificationsEnabledAtom } from "../../../lib/atoms"
7070import { appStore } from "../../../lib/jotai-store"
7171import { api } from "../../../lib/mock-api"
7272import { trpc , trpcClient } from "../../../lib/trpc"
73+ import { getQueryClient } from "../../../contexts/TRPCProvider"
7374import { cn } from "../../../lib/utils"
7475import { getShortcutKey , isDesktopApp } from "../../../lib/utils/platform"
7576import { terminalSidebarOpenAtom } from "../../terminal/atoms"
@@ -1727,6 +1728,32 @@ function ChatViewInner({
17271728 } )
17281729 }
17291730
1731+ // Desktop app: Optimistic update for chats.list to update sidebar immediately
1732+ const queryClient = getQueryClient ( )
1733+ if ( queryClient ) {
1734+ const now = new Date ( )
1735+ const queries = queryClient . getQueryCache ( ) . getAll ( )
1736+ const chatsListQuery = queries . find ( q =>
1737+ Array . isArray ( q . queryKey ) &&
1738+ Array . isArray ( q . queryKey [ 0 ] ) &&
1739+ q . queryKey [ 0 ] [ 0 ] === 'chats' &&
1740+ q . queryKey [ 0 ] [ 1 ] === 'list'
1741+ )
1742+ if ( chatsListQuery ) {
1743+ queryClient . setQueryData ( chatsListQuery . queryKey , ( old : any [ ] | undefined ) => {
1744+ if ( ! old ) return old
1745+ // Update the timestamp and sort by updatedAt descending
1746+ const updated = old . map ( ( c : any ) =>
1747+ c . id === parentChatId ? { ...c , updatedAt : now } : c ,
1748+ )
1749+ return updated . sort (
1750+ ( a : any , b : any ) =>
1751+ new Date ( b . updatedAt ) . getTime ( ) - new Date ( a . updatedAt ) . getTime ( ) ,
1752+ )
1753+ } )
1754+ }
1755+ }
1756+
17301757 // Optimistically update sub-chat timestamp to move it to top
17311758 useAgentSubChatStore . getState ( ) . updateSubChatTimestamp ( subChatId )
17321759
@@ -3852,6 +3879,9 @@ export function ChatView({
38523879
38533880 // Refresh diff stats after agent finishes making changes
38543881 fetchDiffStatsRef . current ( )
3882+
3883+ // Note: sidebar timestamp update is handled via optimistic update in handleSend
3884+ // No need to refetch here as it would overwrite the optimistic update with stale data
38553885 } ,
38563886 } )
38573887
@@ -3971,6 +4001,9 @@ export function ChatView({
39714001
39724002 // Refresh diff stats after agent finishes making changes
39734003 fetchDiffStatsRef . current ( )
4004+
4005+ // Note: sidebar timestamp update is handled via optimistic update in handleSend
4006+ // No need to refetch here as it would overwrite the optimistic update with stale data
39744007 } ,
39754008 } )
39764009 agentChatStore . set ( newId , newChat , chatId )
0 commit comments