1- import { keepPreviousData , useMutation , useQuery , useQueryClient } from '@tanstack/react-query'
1+ import { useMutation , useQuery , useQueryClient } from '@tanstack/react-query'
22import type { PersistedMessage } from '@/lib/copilot/chat/persisted-message'
33import { normalizeMessage } from '@/lib/copilot/chat/persisted-message'
44import {
@@ -254,7 +254,6 @@ export function useTasks(workspaceId?: string) {
254254 queryKey : taskKeys . list ( workspaceId ) ,
255255 queryFn : ( { signal } ) => fetchTasks ( workspaceId as string , signal ) ,
256256 enabled : Boolean ( workspaceId ) ,
257- placeholderData : keepPreviousData ,
258257 staleTime : 60 * 1000 ,
259258 } )
260259}
@@ -535,6 +534,10 @@ async function markTaskUnread(chatId: string): Promise<void> {
535534
536535/**
537536 * Marks a task as read with optimistic update.
537+ *
538+ * The server only updates `lastSeenAt`, never `updatedAt`, so we deliberately
539+ * do not invalidate the list cache — that would trigger a refetch that can
540+ * reorder the sidebar if any unrelated server-side update landed in between.
538541 */
539542export function useMarkTaskRead ( workspaceId ?: string ) {
540543 const queryClient = useQueryClient ( )
@@ -556,14 +559,14 @@ export function useMarkTaskRead(workspaceId?: string) {
556559 queryClient . setQueryData ( taskKeys . list ( workspaceId ) , context . previousTasks )
557560 }
558561 } ,
559- onSettled : ( ) => {
560- queryClient . invalidateQueries ( { queryKey : taskKeys . list ( workspaceId ) } )
561- } ,
562562 } )
563563}
564564
565565/**
566566 * Marks a task as unread with optimistic update.
567+ *
568+ * Same rationale as `useMarkTaskRead` — no list invalidation, since the server
569+ * only flips `lastSeenAt` and the optimistic update fully reflects the change.
567570 */
568571export function useMarkTaskUnread ( workspaceId ?: string ) {
569572 const queryClient = useQueryClient ( )
@@ -585,8 +588,5 @@ export function useMarkTaskUnread(workspaceId?: string) {
585588 queryClient . setQueryData ( taskKeys . list ( workspaceId ) , context . previousTasks )
586589 }
587590 } ,
588- onSettled : ( ) => {
589- queryClient . invalidateQueries ( { queryKey : taskKeys . list ( workspaceId ) } )
590- } ,
591591 } )
592592}
0 commit comments