Skip to content

Commit 3d11d59

Browse files
committed
fix(drafts): guard save effect against first-render race that wipes file-only drafts
On mount the save effect fired before the restore effect's setState calls propagated, so fileAttachments and contexts were still empty. For a draft with files but no text this caused isEmpty() to return true and setDraft to delete the entry. Added isFirstSaveRef to skip the initial run; the restore triggers a re-render that fires the save with the full, correct payload.
1 parent c6f0195 commit 3d11d59

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/home/components/user-input

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,14 @@ export const UserInput = forwardRef<UserInputHandle, UserInputProps>(function Us
205205
}
206206
}, []) // eslint-disable-line react-hooks/exhaustive-deps -- intentional mount-only restore
207207

208+
// Skip the initial save — restore's setState calls haven't propagated yet, so
209+
// files/contexts are still empty and would transiently wipe a file-only draft.
210+
const isFirstSaveRef = useRef(true)
208211
useEffect(() => {
212+
if (isFirstSaveRef.current) {
213+
isFirstSaveRef.current = false
214+
return
215+
}
209216
if (!draftScopeKeyRef.current) return
210217
const fileAttachments = files.attachedFiles
211218
.filter((f) => !f.uploading && f.key)

0 commit comments

Comments
 (0)