diff --git a/frontend/src/components/viewer/EmbedPdfViewer.tsx b/frontend/src/components/viewer/EmbedPdfViewer.tsx index 99979155b..a8609c0f3 100644 --- a/frontend/src/components/viewer/EmbedPdfViewer.tsx +++ b/frontend/src/components/viewer/EmbedPdfViewer.tsx @@ -335,6 +335,7 @@ const EmbedPdfViewerContent = ({ {/* Navigation Warning Modal */} diff --git a/frontend/src/components/viewer/ThumbnailSidebar.tsx b/frontend/src/components/viewer/ThumbnailSidebar.tsx index 6c3422d36..e6c515941 100644 --- a/frontend/src/components/viewer/ThumbnailSidebar.tsx +++ b/frontend/src/components/viewer/ThumbnailSidebar.tsx @@ -5,15 +5,27 @@ import { useViewer } from '../../contexts/ViewerContext'; interface ThumbnailSidebarProps { visible: boolean; onToggle: () => void; + activeFileIndex?: number; } -export function ThumbnailSidebar({ visible, onToggle: _onToggle }: ThumbnailSidebarProps) { +export function ThumbnailSidebar({ visible, onToggle: _onToggle, activeFileIndex }: ThumbnailSidebarProps) { const { getScrollState, scrollActions, getThumbnailAPI } = useViewer(); const [thumbnails, setThumbnails] = useState<{ [key: number]: string }>({}); const scrollState = getScrollState(); const thumbnailAPI = getThumbnailAPI(); + // Clear thumbnails when active file changes + useEffect(() => { + // Revoke old blob URLs to prevent memory leaks + Object.values(thumbnails).forEach((thumbUrl) => { + if (typeof thumbUrl === 'string' && thumbUrl.startsWith('blob:')) { + URL.revokeObjectURL(thumbUrl); + } + }); + setThumbnails({}); + }, [activeFileIndex]); + // Clear thumbnails when sidebar closes and revoke blob URLs to prevent memory leaks useEffect(() => { if (!visible) {