Skip to content

Fix the browser build failing to load without import.meta.url - #1874

Open
ravitejas-tech wants to merge 1 commit into
foliojs:masterfrom
ravitejas-tech:fix/browser-icc-profile-import-meta
Open

ravitejas-tech wants to merge 1 commit into
foliojs:masterfrom
ravitejas-tech:fix/browser-icc-profile-import-meta

Conversation

@ravitejas-tech

Copy link
Copy Markdown

Fixes #1873

What kind of change does this PR introduce?

Bug fix. The browser build registered its embedded sRGB ICC profile at import time, under the path getIccProfilePath() resolves from import.meta.url. Bundles for runtimes such as Cloudflare Workers leave import.meta.url undefined, so importing pdfkit threw.

The browser build now registers the profile under a fixed name (sRGB_IEC61966_2_1.icc) and points the PDF/A output at it, so it never reads import.meta.url. The Node build is unchanged and still resolves the file on first use.

The new test bundles the browser entry the way the release build does, with import.meta.url resolved to undefined. It checks that the bundle loads and that PDF/A-1 output still contains the ICC output intent.

Checklist:

  • Unit Tests
  • Documentation N/A
  • Update CHANGELOG.md
  • Ready to be merged

The browser build registered its embedded sRGB ICC profile under the
path getIccProfilePath() resolves from import.meta.url, at import time.
Bundles for runtimes such as Cloudflare Workers leave import.meta.url
undefined, so importing pdfkit threw.

The profile is embedded, so register it under a fixed name and point
the PDF/A output at that name instead.

Fixes foliojs#1873
Comment thread lib/mixins/pdfa.js
// document that never produces PDF/A output has no reason to fail over it.
export const getIccProfilePath = () => {
if (iccProfilePath === undefined) {
if (import.meta.url == null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This check is still relevant?

In which situation it will be triggered?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, it is still relevant, but only for the Node build.

The browser build no longer reaches it: it calls setIccProfilePath() at import time, so getIccProfilePath() returns the fixed name before this check.

The Node build still resolves the path on first use. If an application bundles the Node build into a CommonJS output, import.meta.url is undefined there, and a document with a PDF/A subset hits this check. Without it the user would get a bare Invalid URL from new URL(). The existing spec "explains a missing import.meta.url when PDF/A needs the profile" in tests/unit/bundling.spec.js covers that case.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

browser build still reads import.meta.url at module load: registerFile(getIccProfilePath(), ...) runs at top level

2 participants