Skip to content

Fix async save flow in firestore upload and download (closes #38)#47

Open
Prachi01Yadav wants to merge 1 commit intoseetadev:mainfrom
Prachi01Yadav:prachi/fix-async-save-issue-38
Open

Fix async save flow in firestore upload and download (closes #38)#47
Prachi01Yadav wants to merge 1 commit intoseetadev:mainfrom
Prachi01Yadav:prachi/fix-async-save-issue-38

Conversation

@Prachi01Yadav
Copy link
Copy Markdown

@Prachi01Yadav Prachi01Yadav commented May 8, 2026

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 await in downloadFileFromFirebase:
local._saveFile() is an async function but was called without await
in 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 prevFile was declared twice using const in the same
scope inside uploadFileToCloud, which is a JavaScript error.
Renamed the inner one to prevFileWithNewName to fix this.

What I changed

  • src/firebase/firestore.ts : 3 fixes in this one file

How to test

  1. Upload a file, then upload another file with the same name
    → Before fix: two copies saved. After fix: only the renamed copy saved.
  2. Download a file from Firebase
    → 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:

  1. Double-save bug in uploadFileToCloud — missing return after
    rename caused file to be saved twice
  2. Missing await in downloadFileFromFirebase — _saveFile() called
    without await, causing silent failures
  3. Variable redeclaration error (const prevFile declared twice)

Note: The local save flow bugs in Menu.tsx and NewFile.tsx are
being addressed separately in PR #39.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants