Skip to content

Commit 2e86d2d

Browse files
committed
fix(chat): re-chipify a restored draft once skills load
1 parent c42b027 commit 2e86d2d

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,35 @@ it('keeps text typed into the server-rendered textarea before hydration', () =>
494494
container.remove()
495495
}
496496
})
497+
498+
it('re-chipifies a seeded draft once skills load', () => {
499+
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
500+
const skill = {
501+
id: 'review',
502+
workspaceId: 'ws-1',
503+
userId: null,
504+
name: 'Review',
505+
description: '',
506+
content: '',
507+
canEdit: false,
508+
createdAt: '',
509+
updatedAt: '',
510+
}
511+
let latest: ReturnType<typeof usePromptEditor> | undefined
512+
function Editor({ skills }: { skills: (typeof skill)[] }) {
513+
latest = usePromptEditor({ workspaceId: 'ws-1', availableSkills: skills })
514+
return null
515+
}
516+
const container = document.createElement('div')
517+
const root = createRoot(container)
518+
try {
519+
act(() => root.render(<Editor skills={[]} />))
520+
act(() => latest?.setValue('/Review the draft', { seed: true }))
521+
act(() => root.render(<Editor skills={[skill]} />))
522+
expect(latest?.getActiveContexts()).toEqual([
523+
{ kind: 'skill', skillId: 'review', label: 'Review' },
524+
])
525+
} finally {
526+
act(() => root.unmount())
527+
}
528+
})

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,12 @@ export function usePromptEditor({
335335
* Programmatically replaces the editor text. Chipifies by default so any
336336
* seeded prose (template, transcript, queued message) registers its
337337
* integration / skill chips; pass `{ chipify: false }` for verbatim text.
338+
* `{ seed: true }` treats the text like `initialValue`, re-chipified once
339+
* the skill list loads while it stays untouched.
338340
*/
339-
const setValue = useCallback((text: string, options?: { chipify?: boolean }) => {
341+
const setValue = useCallback((text: string, options?: { chipify?: boolean; seed?: boolean }) => {
340342
const next = options?.chipify === false ? text : applyAutoMentionsRef.current(text)
343+
if (options?.seed) seedRef.current = next
341344
atInsertPosRef.current = null
342345
pendingCursorRef.current = null
343346
mentionRangeRef.current = null

‎apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ const UserInputImpl = forwardRef<UserInputHandle, UserInputProps>(function UserI
204204
if (restoredContexts) editor.setContexts(restoredContexts)
205205
if (restoredFiles) files.restoreAttachedFiles(restoredFiles)
206206
if (caretText !== null) {
207-
if (editor.getValue() === '') editor.setValue(caretText)
207+
if (editor.getValue() === '') editor.setValue(caretText, { seed: true })
208208
const textarea = textareaRef.current
209209
if (textarea) {
210210
if (!isMobileViewport()) textarea.focus()

0 commit comments

Comments
 (0)