Skip to content

Commit 4328701

Browse files
committed
fix(scheduled-tasks): preserve @-mention contexts on edit; sync editor valueRef on input
1 parent 45eaa05 commit 4328701

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/use-prompt-editor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ export function usePromptEditor({
563563
}
564564

565565
const caret = e.target.selectionStart ?? finalValue.length
566+
// Keep the ref in lockstep with state so synchronous readers (getValue /
567+
// getPlainValue) never see pre-keystroke text before the next render.
568+
valueRef.current = finalValue
566569
setValueState(finalValue)
567570
syncMentionState(e.target, finalValue, caret)
568571
syncSlashState(e.target, finalValue, caret)

apps/sim/app/workspace/[workspaceId]/scheduled-tasks/components/task-modal/task-modal.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useState } from 'react'
3+
import { useEffect, useState } from 'react'
44
import { format } from 'date-fns'
55
import { useParams } from 'next/navigation'
66
import {
@@ -49,6 +49,8 @@ export interface TaskDraft {
4949
export interface TaskEditSeed {
5050
scheduleId: string
5151
prompt: string
52+
/** Stored `@`-mention contexts, re-registered so editing preserves them. */
53+
contexts?: ChatContext[]
5254
launchDate: string
5355
launchTime: string
5456
recurrence: Recurrence
@@ -114,6 +116,15 @@ function TaskModalContent({
114116
}: Omit<TaskModalProps, 'open'>) {
115117
const { workspaceId } = useParams<{ workspaceId: string }>()
116118
const editor = usePromptEditor({ workspaceId, initialValue: edit?.prompt })
119+
120+
// Re-register the stored mentions once on open so saving an edit preserves
121+
// them — the editor seeds from `initialValue` text only, not its contexts.
122+
const setContexts = editor.setContexts
123+
useEffect(() => {
124+
if (edit?.contexts && edit.contexts.length > 0) setContexts(edit.contexts)
125+
// Runs once per open; content remounts each time the dialog opens.
126+
// eslint-disable-next-line react-hooks/exhaustive-deps
127+
}, [])
117128
const [launchDate, setLaunchDate] = useState(
118129
() => edit?.launchDate ?? format(slot?.date ?? new Date(), 'yyyy-MM-dd')
119130
)

apps/sim/app/workspace/[workspaceId]/scheduled-tasks/hooks/use-scheduled-tasks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export function useScheduledTasks({
139139
return {
140140
scheduleId: schedule.id,
141141
prompt: schedule.prompt ?? '',
142+
contexts: task.contexts,
142143
launchDate: format(task.runAt, 'yyyy-MM-dd'),
143144
launchTime,
144145
recurrence,

0 commit comments

Comments
 (0)