From 81f221b3128b9cd20800f56a129c31487dd1e293 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Wed, 29 Apr 2026 11:27:16 -0700 Subject: [PATCH 1/2] fix(copilot): fix new task error --- .../w/[workflowId]/components/panel/panel.tsx | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx index 55369c378ca..589f1c7e5fe 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx @@ -362,15 +362,30 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel }) .then((res) => (res.ok ? res.json() : Promise.reject(new Error('create chat failed')))) .then((data: { id?: string }) => { - if (data?.id) { - setCopilotChatId(data.id) - loadCopilotChats() - } + if (!data?.id) return + // Seed the new chat into the list cache before selecting it. Without this, the + // auto-select effect sees a selected id that isn't in the (still-stale) list and + // deselects it, which leaves the panel detached from the freshly created row. + queryClient.setQueryData( + copilotChatsKeys.list(activeWorkflowId), + (prev) => [ + { + id: data.id!, + title: null, + workflowId: activeWorkflowId, + updatedAt: new Date().toISOString(), + activeStreamId: null, + }, + ...(prev ?? []), + ] + ) + setCopilotChatId(data.id) + loadCopilotChats() }) .catch((err) => { logger.error('Failed to create copilot chat', err) }) - }, [activeWorkflowId, workspaceId, loadCopilotChats, setCopilotChatId]) + }, [activeWorkflowId, workspaceId, loadCopilotChats, setCopilotChatId, queryClient]) const prevResolvedRef = useRef(undefined) useEffect(() => { From 07ee8e50f7869f5533fc2b41b886838537a701c6 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Wed, 29 Apr 2026 11:29:00 -0700 Subject: [PATCH 2/2] Keep recent copilot chat open on refresh --- .../[workspaceId]/w/[workflowId]/components/panel/panel.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx index 589f1c7e5fe..a221304126c 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx @@ -265,11 +265,9 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel if (copilotChatId) return if (autoSelectAttemptedForRef.current.has(activeWorkflowId)) return + if (copilotChatList.length === 0) return autoSelectAttemptedForRef.current.add(activeWorkflowId) - - if (copilotChatList.length > 0) { - setCopilotChatId(copilotChatList[0].id) - } + setCopilotChatId(copilotChatList[0].id) }, [copilotChatList, copilotChatId, activeWorkflowId, setCopilotChatId]) useEffect(() => {