mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
📝 fix: Prevent Deletion of User Input During AI Generation (#9719)
* bug: updating so text doesn't delete * fix: preserve user input when typing during AI response Previously, form.reset() would clear any text the user started typing while waiting for AI response. Now checks if textarea has new content before resetting, preventing text loss and improving UX. * chore: revert useSubmitMessage changes * fix: reduce debounce time for input handling in auto-save * fix: improve debounce handling for auto-save input to enhance user experience --------- Co-authored-by: Megan Greenberg <mgreenberg@networkninja.com>
This commit is contained in:
parent
99135a3dc1
commit
8b2e1c6088
1 changed files with 26 additions and 3 deletions
|
|
@ -105,11 +105,33 @@ export const useAutoSave = ({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleInput = debounce((value: string) => setDraft({ id: conversationId, value }), 750);
|
/** Use shorter debounce for saving text (65ms) to capture rapid typing */
|
||||||
|
const handleInputFast = debounce(
|
||||||
|
(value: string) => setDraft({ id: conversationId, value }),
|
||||||
|
65,
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Use longer debounce for clearing empty values (850ms) to prevent accidental draft loss */
|
||||||
|
const handleInputSlow = debounce(
|
||||||
|
(value: string) => setDraft({ id: conversationId, value }),
|
||||||
|
850,
|
||||||
|
);
|
||||||
|
|
||||||
const eventListener = (e: Event) => {
|
const eventListener = (e: Event) => {
|
||||||
const target = e.target as HTMLTextAreaElement;
|
const target = e.target as HTMLTextAreaElement;
|
||||||
handleInput(target.value);
|
const value = target.value;
|
||||||
|
|
||||||
|
/** Cancel any pending operations to avoid conflicts */
|
||||||
|
handleInputFast.cancel();
|
||||||
|
handleInputSlow.cancel();
|
||||||
|
|
||||||
|
/** If empty, use long delay to prevent accidental clearing
|
||||||
|
* Otherwise use short delay to capture rapid typing */
|
||||||
|
if (value === '') {
|
||||||
|
handleInputSlow(value);
|
||||||
|
} else {
|
||||||
|
handleInputFast(value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const textArea = textAreaRef?.current;
|
const textArea = textAreaRef?.current;
|
||||||
|
|
@ -121,7 +143,8 @@ export const useAutoSave = ({
|
||||||
if (textArea) {
|
if (textArea) {
|
||||||
textArea.removeEventListener('input', eventListener);
|
textArea.removeEventListener('input', eventListener);
|
||||||
}
|
}
|
||||||
handleInput.cancel();
|
handleInputFast.cancel();
|
||||||
|
handleInputSlow.cancel();
|
||||||
};
|
};
|
||||||
}, [conversationId, saveDrafts, textAreaRef]);
|
}, [conversationId, saveDrafts, textAreaRef]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue