Skip to content

v4.4.2

Latest

Choose a tag to compare

@alekswebnet alekswebnet released this 01 Nov 12:40

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 bare wasm/ and cmaps/. The element now resolves these URLs against the page. (#65, #66, #70)
  • next build --webpack broke the viewer. Next's CSS handling emitted the viewer's two stylesheets as empty files, so the viewer never initialized ("The container must be absolutely positioned"). It also moved their rules into the app's own stylesheets, restyling the page, even with assets-base set. 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' in style-src, the element collapsed to a 150px-high iframe and injectViewerStyles did nothing. The element, the viewer and injectViewerStyles now apply their styles as constructed stylesheets, which a CSP doesn't block. (#70)
  • package.json is exported, so scripts can locate the package with require.resolve('@missing-elements/pdfjs-viewer/package.json') or import.meta.resolve(), for example to copy dist. (#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 dist folder into your public files and point assets-base at it, as the README's Install section now explains. (#65, #66)
  • injectViewerStyles adds 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, read iframe.contentDocument.adoptedStyleSheets instead.
  • theme-css-src without viewer-css-src: the bundled viewer stylesheet now sits in a cascade layer, so your theme overrides it regardless of specificity, while its !important declarations still win. Other combinations cascade as before.
  • Without assets-base, viewer-css-src or theme-css-src, the default stylesheets load as JS chunks with the viewer instead of as .css files. dist still has both .css files for those attributes.

Full changelog: v4.4.1...v4.4.2