From d8812a67d9fd22236ec56952b33b76eb3493c922 Mon Sep 17 00:00:00 2001 From: abhay-codes07 Date: Fri, 14 Aug 2026 23:31:56 +0530 Subject: [PATCH] fix(web): reset image and PDF preview when the modal switches documents DocumentContent renders ImagePreview and PdfViewer without a key, so React keeps the same instance alive when the open document modal moves to another document. Both components seed internal state from their props on mount and never resync: - ImagePreview stores the source in `activeSrc = useState(url)`, so opening a second image keeps showing the first one (and a prior load error keeps the "Failed to load image" state). - PdfViewer holds `cachedUrl` from the previous document. Its effect revokes the old object URL when documentId changes, but the state still points at the now-revoked blob URL, and fileSource returns it first, so the next PDF fails to render. Key both previews by document id so switching documents mounts a fresh instance with clean state, and the existing unmount cleanup revokes the old object URLs. --- apps/web/components/document-modal/content/index.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/web/components/document-modal/content/index.tsx b/apps/web/components/document-modal/content/index.tsx index 2232d159..7bc57db5 100644 --- a/apps/web/components/document-modal/content/index.tsx +++ b/apps/web/components/document-modal/content/index.tsx @@ -90,6 +90,7 @@ export function DocumentContent({ case "image": return ( case "pdf": - return + return ( + + ) case "notion": return