Skip to content

Commit f12acb9

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(copilot): persist workflow drafts across navigation
1 parent edc25aa commit f12acb9

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/mothership-chat/mothership-chat.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ export function MothershipChat({
764764
onCancelEdit={onCancelQueueEdit}
765765
/>
766766
<UserInput
767+
key={draftScopeKey}
767768
ref={userInputRef}
768769
onSubmit={onSubmit}
769770
isSending={isStreamActive}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const Panel = memo(function Panel() {
117117
const router = useRouter()
118118
const params = useParams()
119119
const workspaceId = params.workspaceId as string
120+
const routeWorkflowId = params.workflowId as string
120121

121122
const posthog = usePostHog()
122123
const posthogRef = useRef(posthog)
@@ -396,6 +397,7 @@ export const Panel = memo(function Panel() {
396397
},
397398
})
398399
)
400+
const copilotDraftScopeKey = `${workspaceId}:workflow-copilot:${routeWorkflowId}`
399401

400402
const handleCopilotNewChat = useCallback(() => {
401403
if (!activeWorkflowId || !workspaceId) return
@@ -482,7 +484,7 @@ export const Panel = memo(function Panel() {
482484
* skip the caller's own fallback.
483485
*/
484486
useEffect(() => {
485-
if (!isCopilotTabAvailable) return
487+
if (!isCopilotTabAvailable || activeWorkflowId !== routeWorkflowId) return
486488

487489
const handler = (e: Event) => {
488490
const detail = (e as CustomEvent<MothershipSendMessageDetail>).detail
@@ -495,7 +497,7 @@ export const Panel = memo(function Panel() {
495497
}
496498
window.addEventListener(MOTHERSHIP_SEND_MESSAGE_EVENT, handler)
497499
return () => window.removeEventListener(MOTHERSHIP_SEND_MESSAGE_EVENT, handler)
498-
}, [isCopilotTabAvailable, setActiveTab, copilotSendMessage])
500+
}, [isCopilotTabAvailable, activeWorkflowId, routeWorkflowId, setActiveTab, copilotSendMessage])
499501

500502
useEffect(() => {
501503
if (activeTab !== 'copilot') return
@@ -847,7 +849,7 @@ export const Panel = memo(function Panel() {
847849

848850
{/* Tab Content - Keep all tabs mounted but hidden to preserve state */}
849851
<div className='flex-1 overflow-hidden pt-3'>
850-
{isCopilotTabAvailable && (
852+
{isCopilotTabAvailable && activeWorkflowId === routeWorkflowId && (
851853
<div
852854
className={
853855
_hasHydrated && activeTab === 'copilot'
@@ -943,6 +945,7 @@ export const Panel = memo(function Panel() {
943945
onCancelQueueEdit={copilotCancelQueueEdit}
944946
userId={session?.user?.id}
945947
chatId={copilotResolvedChatId}
948+
draftScopeKey={copilotDraftScopeKey}
946949
layout='copilot-view'
947950
/>
948951
</div>

0 commit comments

Comments
 (0)