@@ -279,8 +279,12 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
279279 contentParts ,
280280 optimisticUserID ,
281281 ) ;
282+
283+ const messagesQueryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
284+ await queryClient . cancelQueries ( { queryKey : messagesQueryKey } ) ;
285+
282286 queryClient . setQueryData < MessageListResponse > (
283- [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ,
287+ messagesQueryKey ,
284288 ( old ) => [ ...( old || [ ] ) , userMessage ] ,
285289 ) ;
286290
@@ -348,7 +352,10 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?:
348352
349353 queryClient . setQueryData < MessageListResponse > (
350354 [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ,
351- ( old ) => old ?. filter ( ( msg ) => msg . info . id !== optimisticUserID ) || [ ] ,
355+ ( old ) => {
356+ if ( ! old ) return old ;
357+ return old . filter ( ( msg ) => msg . info . id !== optimisticUserID ) ;
358+ } ,
352359 ) ;
353360
354361 queryClient . invalidateQueries ( {
@@ -511,8 +518,12 @@ export const useSendShell = (opcodeUrl: string | null | undefined, directory?: s
511518 [ { type : "text" as const , content : command } ] ,
512519 optimisticUserID ,
513520 ) ;
521+
522+ const messagesQueryKey = [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ;
523+ await queryClient . cancelQueries ( { queryKey : messagesQueryKey } ) ;
524+
514525 queryClient . setQueryData < MessageListResponse > (
515- [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ,
526+ messagesQueryKey ,
516527 ( old ) => [ ...( old || [ ] ) , userMessage ] ,
517528 ) ;
518529
@@ -528,7 +539,10 @@ export const useSendShell = (opcodeUrl: string | null | undefined, directory?: s
528539 setSessionStatus ( sessionID , { type : "idle" } ) ;
529540 queryClient . setQueryData < MessageListResponse > (
530541 [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ,
531- ( old ) => old ?. filter ( ( msg ) => ! msg . info . id . startsWith ( "optimistic_" ) ) ,
542+ ( old ) => {
543+ if ( ! old ) return old ;
544+ return old . filter ( ( msg ) => ! msg . info . id . startsWith ( "optimistic_" ) ) ;
545+ } ,
532546 ) ;
533547 } ,
534548 onSuccess : ( data , variables ) => {
@@ -537,7 +551,10 @@ export const useSendShell = (opcodeUrl: string | null | undefined, directory?: s
537551
538552 queryClient . setQueryData < MessageListResponse > (
539553 [ "opencode" , "messages" , opcodeUrl , sessionID , directory ] ,
540- ( old ) => old ?. filter ( ( msg ) => msg . info . id !== optimisticUserID ) || [ ] ,
554+ ( old ) => {
555+ if ( ! old ) return old ;
556+ return old . filter ( ( msg ) => msg . info . id !== optimisticUserID ) ;
557+ } ,
541558 ) ;
542559
543560 queryClient . invalidateQueries ( {
0 commit comments