Skip to content

Conversation

@bvenceslas
Copy link
Contributor

@bvenceslas bvenceslas commented Nov 14, 2025

Description

Issue #10983

Link this pull request to the GitHub issue (and optionally name the branch ocrvs-<issue #>)

Checklist

  • I have linked the correct Github issue under "Development"
  • I have tested the changes locally, and written appropriate tests
  • I have tested beyond the happy path (e.g. edge cases, failure paths)
  • I have updated the changelog with this change (if applicable)
  • I have updated the GitHub issue status accordingly

Note

Adds PDF support to the review document viewer (opens PDFs in a new tab) and updates document URL validation to allow PDF files.

  • Frontend
    • Document Viewer (PanViewer.tsx): Detects .pdf images; opens fetched PDF in a new tab; shows placeholder text instead of inline image.
  • Backend/Commons
    • Document URL Validation (packages/commons/src/documents.ts): Extends MINIO_REGEX to include pdf.
  • Docs
    • Changelog: Notes review page PDF support.

Written by Cursor Bugbot for commit 332cafb. This will update automatically on new commits. Configure here.

@github-actions

This comment has been minimized.

@rikukissa rikukissa mentioned this pull request Nov 14, 2025
2 tasks
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

const [dx] = useState(0)
const [dy] = useState(0)

const isPdf = image.toLowerCase().endsWith('.pdf')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: PDFs Hidden by URL Query Strings

The PDF detection using image.toLowerCase().endsWith('.pdf') fails when the URL contains query parameters. Based on the MINIO_REGEX pattern in documents.ts and actual usage in the codebase, URLs can include query strings like ?X-Amz-Algorithm=..., which would cause endsWith('.pdf') to return false even for valid PDF URLs, preventing PDFs from being opened.

Fix in Cursor Fix in Web

window.open(blobUrl, '_blank')
})
}
}, [image, isPdf])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unrevoked Blob URLs Cause Memory Leaks

The blob URL created by URL.createObjectURL(blob) is never revoked with URL.revokeObjectURL(), causing a memory leak. Each time a PDF is viewed, a new blob URL is created and retained in memory until the page is closed, which can accumulate if users view multiple PDFs in a session.

Fix in Cursor Fix in Web

window.open(blobUrl, '_blank')
})
}
}, [image, isPdf])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Duplicate Tabs: PDF Re-opens Unnecessarily

The useEffect runs every time the image prop changes without tracking whether the PDF has already been opened. This causes the same PDF to be fetched and opened in a new tab multiple times if the component re-renders with the same image URL, creating duplicate tabs and unnecessary network requests.

Fix in Cursor Fix in Web

const [dx] = useState(0)
const [dy] = useState(0)

const isPdf = image.toLowerCase().endsWith('.pdf')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Encoded PDFs Undetected, Feature Malfunctions

Base64-encoded PDFs in the format data:application/pdf;base64,... are not detected by the endsWith('.pdf') check. These PDFs will be rendered as images instead of being opened in a new tab, which browsers may not handle correctly, causing the feature to fail for base64 PDF data.

Fix in Cursor Fix in Web

type="positive"
onClick={handleOpenPdf}
>
Open PDF in a new tab
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs translation keya

{!isPdf ? (
<img
src={image}
alt="Supporting Document"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs translation key

- `RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES`
- `PROFILE_UPDATE`

- Review page now supports PDF rendering when a PDF link is clicked allowing to verify the uploaded PDF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test case for this?

Comment on lines +49 to +59
const handleOpenPdf = async () => {
try {
const res = await fetch(image, { cache: 'default' })
const blob = await res.blob()
const blobUrl = URL.createObjectURL(blob)
window.open(blobUrl, '_blank')
} catch (err) {
console.error('Failed to open PDF', err)
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the name of the component "pan viewer" it makes me think this might not be the right place for this logic. Pan viewer, if I'm not mistaken, is the component that makes it possible to zoom / pan the image that is previewed. Should this be one level up? @pankaj-pant @bvenceslas

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rikukissa you are right. It should be moved a level up. Although we have discovered internally that the PDF upload scope got accidentally introduced, and we are reverting back to image uploads for a cert that has been printed + signed + stamped (so a image taken with a phone/tablet). With that in mind, if this PR helps @tareq89 in the scope of this ticket #3613, please use the general gist of the fix. I think @euanmillar already updated in the issue 3613 the status of @bvenceslas's availability

@github-actions
Copy link

This PR has been marked with label stale Since it has been inactive for 20 days. It will automatically be closed in 10 days if no further activity occurs.

@github-actions github-actions bot added the Stale The pr is inactive label Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stale The pr is inactive

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants