Fix async save flow in firestore upload and download (closes #38)#47
Open
Prachi01Yadav wants to merge 1 commit intoseetadev:mainfrom
Open
Fix async save flow in firestore upload and download (closes #38)#47Prachi01Yadav wants to merge 1 commit intoseetadev:mainfrom
Prachi01Yadav wants to merge 1 commit intoseetadev:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Async save flow bugs in firestore.ts (Issue #38)
What was wrong
Bug 1: Double save in uploadFileToCloud:
When a file with a duplicate name was detected, the code correctly
prompted for a new name and saved the renamed file. But there was no
return` statement after that save. So the function kept running and
saved the file a second time under the original duplicate name,
creating two copies in Firestore.
Bug 2 : Missing
awaitin downloadFileFromFirebase:local._saveFile() is an async function but was called without
awaitin two places. This means the file save was started but not finished
before the success callback fired : causing silent save failures where
the user sees "File Downloaded" but the file was not actually saved.
Bonus fix : Variable redeclaration:
The variable
prevFilewas declared twice usingconstin the samescope inside
uploadFileToCloud, which is a JavaScript error.Renamed the inner one to
prevFileWithNewNameto fix this.What I changed
src/firebase/firestore.ts: 3 fixes in this one fileHow to test
→ Before fix: two copies saved. After fix: only the renamed copy saved.
→ Before fix: "Downloaded" shown but file not saved. After fix: file
properly saved before callback fires.
Fix: Async bugs in Firebase cloud save operations (firestore.ts)
Related to the async reliability theme of #38, but fixes separate
bugs specifically in the Firebase cloud save layer:
uploadFileToCloud— missing return afterrename caused file to be saved twice
downloadFileFromFirebase— _saveFile() calledwithout await, causing silent failures
Note: The local save flow bugs in Menu.tsx and NewFile.tsx are
being addressed separately in PR #39.