-
Notifications
You must be signed in to change notification settings - Fork 55
[WC-3050] allow self hosted pdfjs worker file #1899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR allows users to configure a custom URL for the PDF.js worker file in the Document Viewer widget, enabling self-hosted deployments instead of relying on external CDNs.
Key changes:
- Added a new "PDF.js worker URL" configuration property in the Advanced settings
- Modified the PDF viewer to use the custom worker URL when provided, with fallback to unpkg CDN
- Version bumped to 1.1.1 with appropriate changelog entry
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
package.xml | Version bump to 1.1.1 |
DocumentViewer.xml | Added new pdfjsWorkerUrl property in Advanced propertyGroup |
package.json | Version bump to 1.1.1 |
PDFViewer.tsx | Implemented dynamic worker URL configuration with useMemo hook |
CHANGELOG.md | Added entry for the new self-hosted worker configuration feature |
8ebaa0d
to
2efb3a0
Compare
const { file, setDocumentStatus, pdfjsWorkerUrl } = props; | ||
pdfjs.GlobalWorkerOptions.workerSrc = useMemo(() => { | ||
if (pdfjsWorkerUrl?.status === "available" && pdfjsWorkerUrl?.value) { | ||
return pdfjsWorkerUrl.value; | ||
} | ||
return `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`; | ||
}, [pdfjsWorkerUrl]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be on the safe side, we probably should delay the rendering until this value if correctly resolved, we don't what to process with loading from cdn while it is being loaded. Also if this URL is unavailable we probably should not render at all. Unexpected loading from CDN can be seen as security issues.
So I guess we should load from cdn only if the value is available and is explicitly empty string. Other than that - wait for it. If value goes to unavailable - show an error message.
Pull request type
Description