mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-07 08:26:15 +00:00
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:
parent
2e85722cf4
commit
d8812a67d9
1 changed files with 8 additions and 1 deletions
|
|
@ -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 ?? ""} />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue