diff --git a/apps/web/src/components/chat/ExpandedImageDialog.tsx b/apps/web/src/components/chat/ExpandedImageDialog.tsx index b734589e58..75a117b97f 100644 --- a/apps/web/src/components/chat/ExpandedImageDialog.tsx +++ b/apps/web/src/components/chat/ExpandedImageDialog.tsx @@ -60,18 +60,16 @@ function useExpandedImageKeyboardShortcuts(input: { } function ExpandedImageDialogContent({ preview, onClose }: ExpandedImageDialogProps) { - const [currentIndex, setCurrentIndex] = useState(preview.index); + const [indexOffset, setIndexOffset] = useState(0); const images = preview.images; const canNavigate = images.length > 1; + const currentIndex = canNavigate + ? (preview.index + indexOffset + images.length) % images.length + : preview.index; const navigateImage = (direction: -1 | 1) => { - setCurrentIndex((existingIndex) => { - if (!canNavigate) return existingIndex; - const safeExistingIndex = - existingIndex >= 0 && existingIndex < images.length ? existingIndex : preview.index; - const nextIndex = (safeExistingIndex + direction + images.length) % images.length; - return nextIndex === existingIndex ? existingIndex : nextIndex; - }); + if (!canNavigate) return; + setIndexOffset((existingOffset) => existingOffset + direction); }; useExpandedImageKeyboardShortcuts({ diff --git a/docs/perf/expanded-image-dialog-react-scan-after.json b/docs/perf/expanded-image-dialog-react-scan-after.json index b2140c0839..8678e95085 100644 --- a/docs/perf/expanded-image-dialog-react-scan-after.json +++ b/docs/perf/expanded-image-dialog-react-scan-after.json @@ -1,8 +1,8 @@ { "hasReactScan": true, - "summary": "Profiler commits: 3 total (1 mount, 2 update), last 1.30ms", + "summary": "Profiler commits: 3 total (1 mount, 2 update), last 1.20ms", "report": { "reactScanReport": null, "renderEvents": [] } -} +} \ No newline at end of file diff --git a/docs/perf/expanded-image-dialog-react-scan-after.webm b/docs/perf/expanded-image-dialog-react-scan-after.webm index 3b469ee86b..0f04300a52 100644 Binary files a/docs/perf/expanded-image-dialog-react-scan-after.webm and b/docs/perf/expanded-image-dialog-react-scan-after.webm differ