Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix error on unarchiving last archived item

Manav Rathifc7b8c18cb0a
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index 076cee8b6c..357c3d2e6b 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -818,10 +818,18 @@ export const FileViewer: React.FC<FileViewerProps> = ({
}, [handleClose, files]);
useEffect(() => {
- if (open) {
+ // This effect might get triggered when the none of the files that were
+ // being shown are eligible to be shown anymore. e.g. suppose we are the
+ // archiveItems pseudo-collection, and the only archived file there is
+ // marked as unarchived by the user within the file viewer.
+ //
+ // In such cases, don't attempt to refresh since that causes various
+ // invariants (like the existence of a "currentFile") to get broken
+ // inside the `FileViewerPhotoSwipe` implementation.
+ if (open && files.length) {
psRef.current?.refreshCurrentSlideFavoriteButtonIfNeeded();
}
- }, [favoriteFileIDs, pendingFavoriteUpdates, open]);
+ }, [favoriteFileIDs, pendingFavoriteUpdates, files, open]);
useEffect(() => {
if (open) {