mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-11 04:58:51 +01:00
🔄 fix: URL Param Race Condition and File Draft Persistence (#7257)
* chore(useAutoSave): linting * fix: files attached during streaming disappear when stream finishes * fix(useQueryParams): query parameter processing race condition with submission handling, add JSDocs to all functions/hooks * test(useQueryParams): add comprehensive tests for query parameter handling and submission logic
This commit is contained in:
parent
20c9f1a783
commit
7c4c3a8796
3 changed files with 675 additions and 16 deletions
|
|
@ -75,9 +75,9 @@ export const useAutoSave = ({
|
|||
const { fileToRecover, fileIdToRecover } = fileData
|
||||
? { fileToRecover: fileData, fileIdToRecover: fileId }
|
||||
: {
|
||||
fileToRecover: tempFileData,
|
||||
fileIdToRecover: (tempFileData?.temp_file_id ?? '') || fileId,
|
||||
};
|
||||
fileToRecover: tempFileData,
|
||||
fileIdToRecover: (tempFileData?.temp_file_id ?? '') || fileId,
|
||||
};
|
||||
|
||||
if (fileToRecover) {
|
||||
setFiles((currentFiles) => {
|
||||
|
|
@ -188,7 +188,7 @@ export const useAutoSave = ({
|
|||
`${LocalStorageKeys.TEXT_DRAFT}${Constants.PENDING_CONVO}`,
|
||||
);
|
||||
|
||||
// Clear the pending draft, if it exists, and save the current draft to the new conversationId;
|
||||
// Clear the pending text draft, if it exists, and save the current draft to the new conversationId;
|
||||
// otherwise, save the current text area value to the new conversationId
|
||||
localStorage.removeItem(`${LocalStorageKeys.TEXT_DRAFT}${Constants.PENDING_CONVO}`);
|
||||
if (pendingDraft) {
|
||||
|
|
@ -199,6 +199,21 @@ export const useAutoSave = ({
|
|||
encodeBase64(textAreaRef.current.value),
|
||||
);
|
||||
}
|
||||
const pendingFileDraft = localStorage.getItem(
|
||||
`${LocalStorageKeys.FILES_DRAFT}${Constants.PENDING_CONVO}`,
|
||||
);
|
||||
|
||||
if (pendingFileDraft) {
|
||||
localStorage.setItem(
|
||||
`${LocalStorageKeys.FILES_DRAFT}${conversationId}`,
|
||||
pendingFileDraft,
|
||||
);
|
||||
localStorage.removeItem(`${LocalStorageKeys.FILES_DRAFT}${Constants.PENDING_CONVO}`);
|
||||
const filesDraft = JSON.parse(pendingFileDraft || '[]') as string[];
|
||||
if (filesDraft.length > 0) {
|
||||
restoreFiles(conversationId);
|
||||
}
|
||||
}
|
||||
} else if (currentConversationId != null && currentConversationId) {
|
||||
saveText(currentConversationId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue