Skip to content

Commit c99d7b1

Browse files
committed
fix recursive download of pdf resource
1 parent b06696e commit c99d7b1

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

app/[locale]/(user)/components/PdfPreview.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ export default function PdfPreview({ url }: PdfPreviewProps) {
1010
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
1111

1212
useEffect(() => {
13+
let objectUrl: string | null = null;
14+
1315
const fetchPdf = async () => {
1416
try {
1517
const response = await fetch(url);
1618
const blobData = await response.blob();
1719

1820
// Manually set MIME type to PDF (in case it's sent as octet-stream)
1921
const pdfBlob = new Blob([blobData], { type: 'application/pdf' });
20-
const objectUrl = URL.createObjectURL(pdfBlob);
22+
objectUrl = URL.createObjectURL(pdfBlob);
2123
setPreviewUrl(objectUrl);
2224
} catch (error) {
2325
console.error('Failed to load PDF:', error);
@@ -27,11 +29,11 @@ export default function PdfPreview({ url }: PdfPreviewProps) {
2729
fetchPdf();
2830

2931
return () => {
30-
if (previewUrl) {
31-
URL.revokeObjectURL(previewUrl);
32+
if (objectUrl) {
33+
URL.revokeObjectURL(objectUrl);
3234
}
3335
};
34-
}, [previewUrl, url]);
36+
}, [url]);
3537

3638
if (!previewUrl) return <p>Loading PDF preview...</p>;
3739

0 commit comments

Comments
 (0)