From b102f6da4a1da7312cb7f68cd9058028702e7d19 Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Thu, 11 Jan 2024 17:09:05 -0500 Subject: [PATCH] fix app crashign when document is undefined --- .../src/features/gallery/hooks/useGalleryNavigation.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/invokeai/frontend/web/src/features/gallery/hooks/useGalleryNavigation.ts b/invokeai/frontend/web/src/features/gallery/hooks/useGalleryNavigation.ts index a0d6d208a4..79921ba9b0 100644 --- a/invokeai/frontend/web/src/features/gallery/hooks/useGalleryNavigation.ts +++ b/invokeai/frontend/web/src/features/gallery/hooks/useGalleryNavigation.ts @@ -29,13 +29,11 @@ import { imagesSelectors } from 'services/api/util'; */ const getImagesPerRow = (): number => { const widthOfGalleryImage = - document - .querySelector(`[data-testid="${imageItemContainerTestId}"]`) + document?.querySelector(`[data-testid="${imageItemContainerTestId}"]`) ?.getBoundingClientRect().width ?? 1; const widthOfGalleryGrid = - document - .querySelector(`[data-testid="${imageListContainerTestId}"]`) + document?.querySelector(`[data-testid="${imageListContainerTestId}"]`) ?.getBoundingClientRect().width ?? 0; const imagesPerRow = Math.round(widthOfGalleryGrid / widthOfGalleryImage); @@ -59,7 +57,7 @@ const scrollToImage = (imageName: string, index: number) => { return; } - const imageElement = document.querySelector( + const imageElement = document?.querySelector( `[data-testid="${getGalleryImageDataTestId(imageName)}"]` ); const itemRect = imageElement?.getBoundingClientRect();