From 6547393586dcfabd9a07047e03c1797c1240c6cc Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Thu, 19 Oct 2023 22:37:34 -0400 Subject: [PATCH] fix: check if all refs loaded in --- .../PhotoViewer/ImageEditorOverlay/index.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx index c9eb59003..419943e3b 100644 --- a/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx +++ b/apps/photos/src/components/PhotoViewer/ImageEditorOverlay/index.tsx @@ -142,13 +142,21 @@ const ImageEditorOverlay = (props: IProps) => { }; const loadCanvas = async () => { + if ( + !canvasRef.current || + !parentRef.current || + !originalSizeCanvasRef.current + ) { + return; + } + setCanvasLoading(true); setTransformationPerformed(false); resetFilters(); setCurrentRotationAngle(0); const img = new Image(); - const ctx = canvasRef.current?.getContext('2d'); + const ctx = canvasRef.current.getContext('2d'); ctx.imageSmoothingEnabled = false; if (!fileURL) { const stream = await downloadManager.downloadFile(props.file); @@ -165,8 +173,8 @@ const ImageEditorOverlay = (props: IProps) => { img.onload = () => { const scale = Math.min( - parentRef.current?.clientWidth / img.width, - parentRef.current?.clientHeight / img.height + parentRef.current.clientWidth / img.width, + parentRef.current.clientHeight / img.height ); const width = img.width * scale;