Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,6 @@ export function useChat(
const recoveringClientWorkflowToolIdsRef = useRef<Set<string>>(new Set())
const executionStream = useExecutionStream()
const isHomePage = pathname.endsWith('/home')
const wasHomePageRef = useRef(isHomePage)
const pendingHomeResetRef = useRef(false)

const setTransportIdle = useCallback(() => {
sendingRef.current = false
Expand Down Expand Up @@ -1219,33 +1217,10 @@ export function useChat(
])

useEffect(() => {
const wasHomePage = wasHomePageRef.current
wasHomePageRef.current = isHomePage

if (!isHomePage) {
pendingHomeResetRef.current = false
return
}
if (workflowIdRef.current || !chatIdRef.current) return

const shouldHandleHomeReset = pendingHomeResetRef.current || !wasHomePage
if (!shouldHandleHomeReset) return

const hasActiveTransport =
isSending ||
sendingRef.current ||
isReconnecting ||
abortControllerRef.current !== null ||
streamReaderRef.current !== null

if (hasActiveTransport) {
pendingHomeResetRef.current = true
return
}

pendingHomeResetRef.current = false
if (workflowIdRef.current) return
if (!isHomePage || !chatIdRef.current) return
resetHomeChatState()
}, [isHomePage, isReconnecting, isSending, resetHomeChatState])
}, [isHomePage, resetHomeChatState])

useEffect(() => {
if (!chatHistory) return
Expand Down
Loading