π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix crash when accessing itemData during slide transitions
Anand Baburajan136b80f675c0
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex 9292cd2327..89c82f33b2 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -1012,14 +1012,16 @@ export const FileViewer: React.FC<FileViewerProps> = ({// Not memoized since it uses the frequently changing `activeAnnotatedFile`.const handleCopyImage = useCallback(() => {handleMoreMenuCloseIfNeeded();- const imageURL = activeAnnotatedFile?.itemData.imageURL;+ if (!activeAnnotatedFile) return;+ const { imageURL } = activeAnnotatedFile.itemData;+ if (!imageURL) return;// Safari does not copy if we do not call `navigator.clipboard.write`// synchronously within the click event handler, but it does supports// passing a promise in lieu of the blob.void window.navigator.clipboard.write([new ClipboardItem({- "image/png": createImagePNGBlob(imageURL!),+ "image/png": createImagePNGBlob(imageURL),}),]).catch(onGenericError);@@ -1345,7 +1347,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({const canCopyImage = useCallback(() =>activeAnnotatedFile?.annotation.showCopyImage &&- activeAnnotatedFile.itemData.imageURL,+ !!activeAnnotatedFile.itemData.imageURL,[activeAnnotatedFile],);diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.tsindex 4c7f31d035..28e9ac2e34 100644--- a/web/packages/gallery/components/viewer/photoswipe.ts+++ b/web/packages/gallery/components/viewer/photoswipe.ts@@ -321,7 +321,7 @@ export class FileViewerPhotoSwipe {const currentFile = () => delegate.getFiles()[pswp.currIndex]!;- const currentAnnotatedFile = () => {+ const currentAnnotatedFile = (): FileViewerAnnotatedFile => {const file = currentFile();let annotatedFile = _currentAnnotatedFile;if (@@ -329,10 +329,17 @@ export class FileViewerPhotoSwipe {annotatedFile.file.id != file.id ||annotatedFile.file.updationTime != file.updationTime) {- annotatedFile = onAnnotate(file, currSlideData());- _currentAnnotatedFile = annotatedFile;+ // Guard: slide data can be unavailable during state transitions.+ // If unavailable, we keep using the cached annotatedFile.+ const slideData = pswp.currSlide?.data as ItemData | undefined;+ if (slideData) {+ annotatedFile = onAnnotate(file, slideData);+ _currentAnnotatedFile = annotatedFile;+ }}- return annotatedFile;+ // By design, this should never be undefined after the initial slide+ // is shown. Use non-null assertion to maintain API contract.+ return annotatedFile!;};const currentFileAnnotation = () => currentAnnotatedFile().annotation;