faisalsayed10 / firefiles

The open‑source alternative to Dropbox. ⚡️

Home Page:https://firefiles.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix: useFirebase error uploading into empty folder

ConlynPattison opened this issue · comments

Bug Description

  • Using a Firebase drive, creating an empty folder (either through Firefiles or Firebase) then uploading a file to that empty folder will throw an error to the screen regarding the attempted iteration over an object currently set to a state of null (the initial state of the files array. The upload will succeed, but the user will need to refresh the screen to see this.

Recreation

  1. Open a functioning Firebase drive
  2. Create a new drive folder (either on Firebase or Firefiles)
  3. Open the new, empty folder
  4. Upload any file to this folder from Firefiles

Presumed Behavior

  • As it functions in the useS3 hook, uploading a file into an empty folder should not throw an error, but should instead send a toast that the file has been successfully uploaded and the file should then appear on the screen and be fully interactable.

Suggested Solution

  • Implement a similar check for the current state/definition of the files state as is used in the useS3 hook:
  • From setFiles((files) => [...files, newFile]); to setFiles((files) => (files ? [...files, newFile] : [newFile]));
  • Alternative solution could involve changing how S3 and Firebase handle the initialization of the files state

Additional Context

  • Error thrown in file apps\web\hooks\useFirebase.tsx line 191 in addFile
  • Proposed solution similar to that of apps\web\hooks\useS3.tsx line 235 in addFile
commented

Ah good catch, would you like to make a PR for this?