-
-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save draft on chat change #4144
base: main
Are you sure you want to change the base?
Conversation
maxphilippov
commented
Sep 23, 2024
- resolves Message draft discarded when switching to different chat quickly #3733
OUTDATED: This is a thing we discussed a long time ago, we had a 1 second debounce for saving draft, so if you're in any way fast at switching between different chats you just lose what you were typing right before switching. We were talking about testing something around 200-300ms, I went for 100. |
c9e78c0
to
2896590
Compare
I did keep the original 1 second delay between autosave |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do you suggest to save the draft on every key press? Because this is what's happening in this MR, and it doesn't seem intentional.
packages/frontend/src/components/composer/ComposerMessageInput.tsx
Outdated
Show resolved
Hide resolved
packages/frontend/src/components/composer/ComposerMessageInput.tsx
Outdated
Show resolved
Hide resolved
dd5b26b
to
3a10e62
Compare
Oops, my bad, rushed that a bit. Didn't notice we have a setState above. I'll draft it for now. Reverted back to 200ms, removed saveDraft from onChange then. Gonna look for a way to maybe flush via ref to messageInputComposer. I don't agree with throttle, since I don't see the point in saving first character immediately and thus pushing next save further in time. Next save is what's more likely to happen on chat change. |
I don't think that's how throttle works. Throttle is never less frequent than debounce. |
Oh, my bad again, for some reason I got memorized that debounce is just throttle but without the inital call (so it calls at the end of time interval while throttle in the beginning). Yeah, makes sense then. |
3a10e62
to
b0a8ac8
Compare
As discussed with @nicodh, I've added a simple throttle implementation and made saveDraft use this one instead of debounce. |
- add throttle to packages/shared/utils.ts - use throttle in saveDraft for messages - remove explicit call to saveDraft when setting state with new text - fixes #3733
b0a8ac8
to
72b4452
Compare