Fix: useFirebase error uploading into empty folder
ConlynPattison opened this issue · comments
Conlyn Pattison commented
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
- Open a functioning Firebase drive
- Create a new drive folder (either on Firebase or Firefiles)
- Open the new, empty folder
- 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]);
tosetFiles((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
fayd commented
Ah good catch, would you like to make a PR for this?