diff --git a/invokeai/frontend/web/src/features/gallery/hooks/useNextPrevImage.ts b/invokeai/frontend/web/src/features/gallery/hooks/useNextPrevImage.ts index 1dc0e2c10d..7b4b8bed7b 100644 --- a/invokeai/frontend/web/src/features/gallery/hooks/useNextPrevImage.ts +++ b/invokeai/frontend/web/src/features/gallery/hooks/useNextPrevImage.ts @@ -52,8 +52,8 @@ export const nextPrevImageButtonsSelector = createSelector( const prevImageIndex = clamp(currentImageIndex - 1, 0, images.length - 1); - const nextImageId = images[nextImageIndex].image_name; - const prevImageId = images[prevImageIndex].image_name; + const nextImageId = images[nextImageIndex]?.image_name; + const prevImageId = images[prevImageIndex]?.image_name; const nextImage = selectors.selectById(data, nextImageId); const prevImage = selectors.selectById(data, prevImageId);