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.
This commit is contained in:
abhay-codes07 2026-08-14 23:31:56 +05:30
parent 2e85722cf4
commit d8812a67d9
No known key found for this signature in database

View file

@ -90,6 +90,7 @@ export function DocumentContent({
case "image":
return (
<ImagePreview
key={document.id}
url={document.url ?? ""}
title={document.title}
documentId={document.id}
@ -109,7 +110,13 @@ export function DocumentContent({
return <TextEditorContent {...textEditorProps} />
case "pdf":
return <PdfViewer url={document.url} documentId={document.id} />
return (
<PdfViewer
key={document.id}
url={document.url}
documentId={document.id}
/>
)
case "notion":
return <NotionDoc content={document.content ?? ""} />