Fix AI chat infinite loading shimmer on empty workspace#17521
Fix AI chat infinite loading shimmer on empty workspace#17521FelixMalfait merged 3 commits intomainfrom
Conversation
When opening the AI chat on a workspace with no conversation history, the loading shimmer would display indefinitely because: 1. `isLoading` in useAgentChat included `!currentAIChatThread` 2. With no threads, `currentAIChatThread` stayed null 3. This made `isLoading` permanently true The fix: - Remove `!currentAIChatThread` from `isLoading` calculation in useAgentChat - Auto-create a chat thread in useAgentChatData when the threads query returns empty, ensuring a valid thread exists for the useChat hook - Add primary font color to empty state title for better visibility Co-authored-by: Cursor <cursoragent@cursor.com>
Greptile OverviewGreptile SummaryFixed infinite loading shimmer in AI chat on empty workspaces by correcting the Key Changes:
How it works: Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant AIChatTab
participant AgentChatProvider
participant useAgentChatData
participant useAgentChat
participant GraphQL
User->>AIChatTab: Opens AI chat
AIChatTab->>AgentChatProvider: Render
AgentChatProvider->>useAgentChatData: Initialize
useAgentChatData->>GraphQL: useGetChatThreadsQuery()
alt No existing threads (empty workspace)
GraphQL-->>useAgentChatData: threads = []
useAgentChatData->>GraphQL: createChatThread()
GraphQL-->>useAgentChatData: newThread { id }
useAgentChatData->>useAgentChatData: setCurrentAIChatThread(newThread.id)
else Existing threads found
GraphQL-->>useAgentChatData: threads = [thread1, ...]
useAgentChatData->>useAgentChatData: setCurrentAIChatThread(threads[0].id)
end
useAgentChatData->>GraphQL: useGetChatMessagesQuery(threadId)
GraphQL-->>useAgentChatData: messages = []
useAgentChatData-->>AgentChatProvider: { uiMessages: [], isLoading: false }
AgentChatProvider->>useAgentChat: Initialize with uiMessages
Note over useAgentChat: isLoading = isStreaming || hasSelectedFiles<br/>(no longer checks !currentAIChatThread)
useAgentChat-->>AgentChatProvider: { isLoading: false }
AgentChatProvider-->>AIChatTab: { isLoading: false, messages: [] }
AIChatTab->>AIChatTab: Render AIChatEmptyState
AIChatTab-->>User: Shows empty state (not infinite shimmer)
|
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:35968 This environment will automatically shut down when the PR is closed or after 5 hours. |
There was a problem hiding this comment.
2 issues found across 3 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/twenty-front/src/modules/ai/hooks/useAgentChatData.ts">
<violation number="1" location="packages/twenty-front/src/modules/ai/hooks/useAgentChatData.ts:65">
P2: Auto-creating the first thread doesn’t clear `agentChatUsageState`, so usage from a previous thread/workspace can persist in the UI. Consider resetting usage before creating the initial thread.</violation>
<violation number="2" location="packages/twenty-front/src/modules/ai/hooks/useAgentChatData.ts:65">
P2: Race condition: `createChatThread()` is called when threads are empty, but `currentAIChatThread` is set asynchronously in the mutation's `onCompleted`. If the component re-renders before the mutation completes, the query may fire again and call `createChatThread()` multiple times, creating duplicate threads. Consider using a ref to track whether thread creation is in progress to prevent duplicate calls.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Add isCreatingChatThreadState Recoil atom to track thread creation - Use state to prevent duplicate createChatThread calls during race conditions - Reset agentChatUsageState when creating initial thread (consistent with useCreateNewAIChatThread) - Add onError handler to reset creation state on failure Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hey @FelixMalfait! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
Summary
Fixes an issue where the AI chat would show loading shimmers indefinitely when opened on a workspace with no conversation history.
Root cause: The
isLoadingstate inuseAgentChatincluded!currentAIChatThread. On workspaces with no chat threads,currentAIChatThreadremainednull, causingisLoadingto be permanentlytrue.Changes:
!currentAIChatThreadfromisLoadingcalculation inuseAgentChat- this state should only reflect streaming/file selection statususeAgentChatDatawhen the threads query returns empty, ensuring a valid thread exists for theuseChathook to initialize properlyTest plan
Made with Cursor