Repository navigation
Fixes
- Next.js ran PDF.js on the main thread. Next.js, with webpack and Turbopack, turns the element's default file URLs into root-relative paths such as
/_next/static/media/pdf.worker.min.<hash>.mjs. Inside the viewer's iframe, PDF.js couldn't resolve the worker URL and silently fell back to the main thread, and the data folder defaults degraded to barewasm/andcmaps/. The element now resolves these URLs against the page. (#65, #66, #70) next build --webpackbroke the viewer. Next's CSS handling emitted the viewer's two stylesheets as empty files, so the viewer never initialized ("Thecontainermust be absolutely positioned"). It also moved their rules into the app's own stylesheets, restyling the page, even withassets-baseset. The default stylesheets now ship as JS modules and are applied as constructed stylesheets inside the viewer. (#66, #70)- Page CSPs that block inline styles. Without
'unsafe-inline'instyle-src, the element collapsed to a 150px-high iframe andinjectViewerStylesdid nothing. The element, the viewer andinjectViewerStylesnow apply their styles as constructed stylesheets, which a CSP doesn't block. (#70) package.jsonis exported, so scripts can locate the package withrequire.resolve('@missing-elements/pdfjs-viewer/package.json')orimport.meta.resolve(), for example to copydist. (#66, #70)
Upgrading
- Bundled apps and the PDF.js data folders. Bundlers still don't copy the folders PDF.js loads data from by name. Without them, scans compressed with JBIG2, CCITT or JPEG 2000 render blank or black, CJK text in fonts the PDF doesn't embed goes missing, and JavaScript in PDFs doesn't run. To support every PDF, copy the package's
distfolder into your public files and pointassets-baseat it, as the README's Install section now explains. (#65, #66) injectViewerStylesadds constructed stylesheets instead of<style data-pdfjs-viewer-runtime-style>elements. They still come after the viewer and theme styles. If your code looked for those elements, readiframe.contentDocument.adoptedStyleSheetsinstead.theme-css-srcwithoutviewer-css-src: the bundled viewer stylesheet now sits in a cascade layer, so your theme overrides it regardless of specificity, while its!importantdeclarations still win. Other combinations cascade as before.- Without
assets-base,viewer-css-srcortheme-css-src, the default stylesheets load as JS chunks with the viewer instead of as.cssfiles.diststill has both.cssfiles for those attributes.
Full changelog: v4.4.1...v4.4.2