File tree Expand file tree Collapse file tree
apps/sim/app/workspace/[workspaceId]/home/hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -926,6 +926,14 @@ export function useChat(
926926 new Set ( ) )
927927 const streamReaderRef = useRef < ReadableStreamDefaultReader < Uint8Array > | null > ( null )
928928 const chatIdRef = useRef < string | undefined > ( initialChatId )
929+ /** Cleared on unmount, so a late rollback cannot hand a pick to a surface the user left. */
930+ const surfaceMountedRef = useRef ( true )
931+ useEffect ( ( ) => {
932+ surfaceMountedRef . current = true
933+ return ( ) => {
934+ surfaceMountedRef . current = false
935+ }
936+ } , [ ] )
929937 const tableViewContextsRef = useRef ( {
930938 scopeId : desktopScopeId ,
931939 views : new Map < string , MothershipTableViewContext > ( ) ,
@@ -3542,8 +3550,15 @@ export function useChat(
35423550 }
35433551
35443552 const rollbackOptimisticSend = ( ) => {
3545- // A withdrawn first send hands its pick back to the new-chat composer for the retry.
3546- if ( ! requestChatId && effortChoice )
3553+ // A withdrawn first send hands its pick back to the new-chat composer for the retry,
3554+ // only while that surface is still open on the new chat.
3555+ if (
3556+ ! requestChatId &&
3557+ effortChoice &&
3558+ surfaceMountedRef . current &&
3559+ ! chatIdRef . current &&
3560+ ! selectedChatIdRef . current
3561+ )
35473562 useMothershipEffortStore . getState ( ) . setNewChatEffort ( effortChoice )
35483563 if ( requestChatId ) {
35493564 upsertChatHistory ( requestChatId , ( current ) => ( {
You can’t perform that action at this time.
0 commit comments