-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Adjust new task button to create new task #4063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
5c741f1
ff6bfad
2913b67
f4dd51a
7780dc7
2ba89a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { useCallback, useEffect, useMemo, useRef, useState } from 'react' | ||
| import { createLogger } from '@sim/logger' | ||
| import { useQueryClient } from '@tanstack/react-query' | ||
| import { usePathname } from 'next/navigation' | ||
| import { useRouter } from 'next/navigation' | ||
| import { | ||
| cancelRunToolExecution, | ||
| executeRunToolOnClient, | ||
|
|
@@ -65,6 +65,7 @@ import type { WorkflowMetadata } from '@/stores/workflows/registry/types' | |
|
|
||
| export interface UseChatReturn { | ||
| messages: ChatMessage[] | ||
| isHistoryReady: boolean | ||
| isSending: boolean | ||
| isReconnecting: boolean | ||
| error: string | null | ||
|
|
@@ -410,7 +411,7 @@ export function useChat( | |
| initialChatId?: string, | ||
| options?: UseChatOptions | ||
| ): UseChatReturn { | ||
| const pathname = usePathname() | ||
| const router = useRouter() | ||
| const queryClient = useQueryClient() | ||
| const [messages, setMessages] = useState<ChatMessage[]>([]) | ||
| const [isSending, setIsSending] = useState(false) | ||
|
|
@@ -506,7 +507,6 @@ export function useChat( | |
| const streamingBlocksRef = useRef<ContentBlock[]>([]) | ||
| const clientExecutionStartedRef = useRef<Set<string>>(new Set()) | ||
| const executionStream = useExecutionStream() | ||
| const isHomePage = pathname.endsWith('/home') | ||
|
|
||
| const { data: chatHistory } = useChatHistory(initialChatId) | ||
|
|
||
|
|
@@ -595,32 +595,6 @@ export function useChat( | |
| setPendingRecoveryMessage(null) | ||
| }, [initialChatId, queryClient]) | ||
|
|
||
| useEffect(() => { | ||
| if (workflowIdRef.current) return | ||
| if (!isHomePage || !chatIdRef.current) return | ||
| streamGenRef.current++ | ||
| chatIdRef.current = undefined | ||
| setResolvedChatId(undefined) | ||
| appliedChatIdRef.current = undefined | ||
| abortControllerRef.current = null | ||
| sendingRef.current = false | ||
| setMessages([]) | ||
| setError(null) | ||
| setIsSending(false) | ||
| setIsReconnecting(false) | ||
| setResources([]) | ||
| setActiveResourceId(null) | ||
| setStreamingFile(null) | ||
| streamingFileRef.current = null | ||
| genericResourceDataRef.current = { entries: [] } | ||
| setGenericResourceData({ entries: [] }) | ||
| setMessageQueue([]) | ||
| lastEventIdRef.current = 0 | ||
| clientExecutionStartedRef.current.clear() | ||
| pendingRecoveryMessageRef.current = null | ||
| setPendingRecoveryMessage(null) | ||
| }, [isHomePage]) | ||
|
|
||
| const fetchStreamBatch = useCallback( | ||
| async ( | ||
| streamId: string, | ||
|
|
@@ -895,7 +869,10 @@ export function useChat( | |
|
|
||
| if (isNewChat) { | ||
| applyChatHistorySnapshot(chatHistory, { preserveActiveStreamingMessage: true }) | ||
| } else if (!activeStreamId || sendingRef.current) { | ||
| } else if (sendingRef.current) { | ||
| return | ||
| } else if (!activeStreamId) { | ||
| applyChatHistorySnapshot(chatHistory) | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -1119,11 +1096,9 @@ export function useChat( | |
| }) | ||
| } | ||
| if (!workflowIdRef.current) { | ||
| window.history.replaceState( | ||
| null, | ||
| '', | ||
| `/workspace/${workspaceId}/task/${parsed.chatId}` | ||
| ) | ||
| router.replace(`/workspace/${workspaceId}/task/${parsed.chatId}`) | ||
| abortControllerRef.current?.abort() | ||
| streamGenRef.current++ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Router navigation aborts active SSE message streamMedium Severity Replacing Reviewed by Cursor Bugbot for commit 2ba89a7. Configure here. |
||
| } | ||
| } | ||
| } | ||
|
|
@@ -2106,6 +2081,7 @@ export function useChat( | |
| [ | ||
| workspaceId, | ||
| queryClient, | ||
| router, | ||
| processSSEStream, | ||
| finalize, | ||
| resumeOrFinalize, | ||
|
|
@@ -2282,8 +2258,11 @@ export function useChat( | |
| } | ||
| }, []) | ||
|
|
||
| const isHistoryReady = !initialChatId || chatHistory !== undefined | ||
|
|
||
| return { | ||
| messages, | ||
| isHistoryReady, | ||
| isSending, | ||
| isReconnecting, | ||
| error, | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greeting screen flashes on task page navigation
Medium Severity
The condition changed from
!hasMessages && !chatIdto!hasMessages && isHistoryReady. Themessagesstate is initialized as[]viauseStateand only populated fromchatHistoryvia auseEffectthat runs after the render. When navigating to a task page with existing messages,isHistoryReadybecomestrue(cache hit) before the effect populatesmessages, so for at least one render frame!hasMessages && isHistoryReadyevaluates totrue, causing the "What should we get done?" greeting to flash. The old!chatIdguard prevented this becausechatIdis always set on the task page.Additional Locations (1)
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts#L2260-L2261Reviewed by Cursor Bugbot for commit 2ba89a7. Configure here.