Skip to content

Commit 81f221b

Browse files
fix(copilot): fix new task error
1 parent 94f5411 commit 81f221b

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,30 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
362362
})
363363
.then((res) => (res.ok ? res.json() : Promise.reject(new Error('create chat failed'))))
364364
.then((data: { id?: string }) => {
365-
if (data?.id) {
366-
setCopilotChatId(data.id)
367-
loadCopilotChats()
368-
}
365+
if (!data?.id) return
366+
// Seed the new chat into the list cache before selecting it. Without this, the
367+
// auto-select effect sees a selected id that isn't in the (still-stale) list and
368+
// deselects it, which leaves the panel detached from the freshly created row.
369+
queryClient.setQueryData<CopilotChatListItem[]>(
370+
copilotChatsKeys.list(activeWorkflowId),
371+
(prev) => [
372+
{
373+
id: data.id!,
374+
title: null,
375+
workflowId: activeWorkflowId,
376+
updatedAt: new Date().toISOString(),
377+
activeStreamId: null,
378+
},
379+
...(prev ?? []),
380+
]
381+
)
382+
setCopilotChatId(data.id)
383+
loadCopilotChats()
369384
})
370385
.catch((err) => {
371386
logger.error('Failed to create copilot chat', err)
372387
})
373-
}, [activeWorkflowId, workspaceId, loadCopilotChats, setCopilotChatId])
388+
}, [activeWorkflowId, workspaceId, loadCopilotChats, setCopilotChatId, queryClient])
374389

375390
const prevResolvedRef = useRef<string | undefined>(undefined)
376391
useEffect(() => {

0 commit comments

Comments
 (0)