File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -671,8 +671,14 @@ describe("WorkspaceStore", () => {
671671
672672 const live = store . getBashToolLiveOutput ( workspaceId , "call-1" ) ;
673673 expect ( live ) . not . toBeNull ( ) ;
674- expect ( live ?. stdout ) . toContain ( "out" ) ;
675- expect ( live ?. stderr ) . toContain ( "err" ) ;
674+ if ( ! live ) throw new Error ( "Expected live output" ) ;
675+
676+ // getSnapshot in useSyncExternalStore requires referential stability when unchanged.
677+ const liveAgain = store . getBashToolLiveOutput ( workspaceId , "call-1" ) ;
678+ expect ( liveAgain ) . toBe ( live ) ;
679+
680+ expect ( live . stdout ) . toContain ( "out" ) ;
681+ expect ( live . stderr ) . toContain ( "err" ) ;
676682 } ) ;
677683
678684 it ( "clears live output when bash tool result includes output" , async ( ) => {
Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ import type { LanguageModelV2Usage } from "@ai-sdk/provider";
3434import { createFreshRetryState } from "@/browser/utils/messages/retryState" ;
3535import {
3636 appendLiveBashOutputChunk ,
37- toLiveBashOutputView ,
3837 type LiveBashOutputInternal ,
3938 type LiveBashOutputView ,
4039} from "@/browser/utils/messages/liveBashOutputBuffer" ;
@@ -704,7 +703,10 @@ export class WorkspaceStore {
704703 getBashToolLiveOutput ( workspaceId : string , toolCallId : string ) : LiveBashOutputView | null {
705704 const perWorkspace = this . liveBashOutput . get ( workspaceId ) ;
706705 const state = perWorkspace ?. get ( toolCallId ) ;
707- return state ? toLiveBashOutputView ( state ) : null ;
706+
707+ // Important: return the stored object reference so useSyncExternalStore sees a stable snapshot.
708+ // (Returning a fresh object every call can trigger an infinite re-render loop.)
709+ return state ?? null ;
708710 }
709711
710712 /**
You can’t perform that action at this time.
0 commit comments