🔄 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:
Danny Avila 2025-05-06 22:49:12 -04:00 committed by GitHub
parent 20c9f1a783
commit 7c4c3a8796
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 675 additions and 16 deletions

View file

@ -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);
}