From fdd7f625b880b49a0f00d035ee4341799dbd6c99 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Tue, 24 Nov 2026 22:22:11 +0200 Subject: [PATCH 1/2] Bump pdfjs-viewer to 4.6.1: the Vite plugin's hashed data folder The Vite plugin section now says the plugin puts the viewer files and their data in a folder named after a hash of their content, so caching the build's assets as immutable is safe. Migrating gets a 4.6.0 step: the cache rule the 4.6.0 docs suggested can go. Co-Authored-By: Claude Opus 5.5 --- package.json | 2 +- pnpm-lock.yaml | 10 +++++----- src/pdfjs-viewer/index.md | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index d6762a5..96bcd80 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@missing-elements/h5p-libraries": "1.1.1", "@missing-elements/h5p-offline-player": "1.7.0", "@missing-elements/h5p-runtime": "1.0.2", - "@missing-elements/pdfjs-viewer": "4.6.0", + "@missing-elements/pdfjs-viewer": "4.6.1", "@zip.js/zip.js": "2.25.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5246887..94f9caa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,8 +45,8 @@ importers: specifier: 1.0.2 version: 1.0.2 '@missing-elements/pdfjs-viewer': - specifier: 4.6.0 - version: 4.6.0 + specifier: 4.6.1 + version: 4.6.1 '@zip.js/zip.js': specifier: 2.25.0 version: 2.25.0 @@ -191,8 +191,8 @@ packages: resolution: {integrity: sha512-Z97zWfBZW2jRQQoacGZmyO0coMHM8KlbjK/UAXZFVFvqSuV3lznuNONFdxz34sXUED2asAVW/tS58rDY23xtqA==} engines: {node: '>=20'} - '@missing-elements/pdfjs-viewer@4.6.0': - resolution: {integrity: sha512-3j2hsG6JDdQCJDq2Clf2tgS5JdHozLolRNlcVgZ3/9iL5W0YeSCFM8855gYuau/IQBQQTMYszLL8BHSr8rJXkQ==} + '@missing-elements/pdfjs-viewer@4.6.1': + resolution: {integrity: sha512-sG1tCjxFNguNzzE5ANpP8oXEpcLid9I+Ro0/T4rtYKSDkdd3yo5L/uRKfCYbTxXgfe27DjQjUAtBfOqOskcwGQ==} '@napi-rs/canvas-android-arm64@1.0.13': resolution: {integrity: sha512-trn7AaDzQ+yeeA0ezhkC7cB1ZDPtp4UYk0EvB5F8qtYL9jEVWtVrU30WOpI52DszoTxaTsCgf5PP4ZVaOlOIHQ==} @@ -1302,7 +1302,7 @@ snapshots: '@missing-elements/h5p-runtime@1.0.2': {} - '@missing-elements/pdfjs-viewer@4.6.0': + '@missing-elements/pdfjs-viewer@4.6.1': dependencies: pdfjs-dist: 6.5.438 diff --git a/src/pdfjs-viewer/index.md b/src/pdfjs-viewer/index.md index 1cedf9c..5c169d6 100644 --- a/src/pdfjs-viewer/index.md +++ b/src/pdfjs-viewer/index.md @@ -245,7 +245,7 @@ It finds `viewer.mjs` and `pdf.mjs` in the build output under whatever names Vit Frameworks built on Vite take it in their Vite config: `vite.config.js` in SvelteKit and React Router, and `vite.plugins` in `nuxt.config.ts` and `astro.config.mjs`. -The copied files keep the names PDF.js asks for, so their URLs stay the same across upgrades. SvelteKit, Nuxt and Astro serve the build's asset folder as `immutable`, and many hosts do the same for Vite's `assets/`. A browser that visited before an upgrade can then keep the old files for as long as its cache lasts, often a year. PDF.js can't use data from another PDF.js version: the `openjpeg.wasm` that shipped with 4.4, for example, doesn't load in 4.6. If your host lets you, serve the data folders with a short cache. Otherwise, [copy `dist` and set `assets-base`](#other-bundlers-and-assets-base) instead. +The plugin puts `viewer.mjs`, `pdf.mjs` and their data in a folder named after a hash of their content, such as `assets/pdfjs-viewer-84204294/`. An app's own `assetFileNames` still decides where the two files go, and the plugin adds the folder in front of their names. An upgrade that changes any of these files gets a new folder, so caching the build's assets as `immutable`, as SvelteKit, Nuxt and Astro do, is safe. With `assets-base` set, the element loads all the data from there, and the plugin's copy goes unused. Without `assets-base`, a [resource attribute](#pdf-js-resources) such as `c-map-url` replaces only its own folder, and the element still loads the rest from the plugin's copy. @@ -535,6 +535,7 @@ import '@missing-elements/pdfjs-viewer' // was: import 'pdfjs-viewer-element' If you're coming from an older version: +- **From 4.6.0:** the Vite plugin's output moves into a folder such as `assets/pdfjs-viewer-84204294/`, so that an upgrade changes its URLs. If you excluded the data folders from an `immutable` cache rule, as the 4.6.0 docs suggested, you can remove that rule. - **From 4.5.0 or earlier:** nothing needs to change. In a Vite app, the new [Vite plugin](#vite-plugin) can replace a copy of `dist` that you serve with `assets-base`. Add the plugin, then remove `assets-base`, any resource attributes that point at the copy, and the copy step. While `assets-base` is set, the element ignores the plugin's copy. - **From 4.4.2 or earlier:** version 4.5 moved from PDF.js 6.4 to 6.5. If you set `worker-src`, point it at `pdfjs-dist@{{ pdfjsViewer.pdfjsVersion }}`. TypeScript now rejects a bare `Uint8Array` in `viewerApp.open()`, which already failed at runtime. Pass `{ data }`, as in [Open a PDF from bytes](#open-a-pdf-from-bytes). - **From 4.4.0 or earlier:** if your Content Security Policy allows `blob:` in `connect-src` only for locales, you can remove it. From 49ef52ecaa9af384532de1bb4222e1505228330b Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Tue, 24 Nov 2026 22:24:33 +0200 Subject: [PATCH 2/2] Name the rule the 4.6.0 docs suggested: a short cache Co-Authored-By: Claude Opus 5.5 --- src/pdfjs-viewer/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pdfjs-viewer/index.md b/src/pdfjs-viewer/index.md index 5c169d6..5f0681d 100644 --- a/src/pdfjs-viewer/index.md +++ b/src/pdfjs-viewer/index.md @@ -535,7 +535,7 @@ import '@missing-elements/pdfjs-viewer' // was: import 'pdfjs-viewer-element' If you're coming from an older version: -- **From 4.6.0:** the Vite plugin's output moves into a folder such as `assets/pdfjs-viewer-84204294/`, so that an upgrade changes its URLs. If you excluded the data folders from an `immutable` cache rule, as the 4.6.0 docs suggested, you can remove that rule. +- **From 4.6.0:** the Vite plugin's output moves into a folder such as `assets/pdfjs-viewer-84204294/`, so that an upgrade changes its URLs. If you gave the data folders a short cache, as the 4.6.0 docs suggested, that rule no longer matches them, and you can remove it. - **From 4.5.0 or earlier:** nothing needs to change. In a Vite app, the new [Vite plugin](#vite-plugin) can replace a copy of `dist` that you serve with `assets-base`. Add the plugin, then remove `assets-base`, any resource attributes that point at the copy, and the copy step. While `assets-base` is set, the element ignores the plugin's copy. - **From 4.4.2 or earlier:** version 4.5 moved from PDF.js 6.4 to 6.5. If you set `worker-src`, point it at `pdfjs-dist@{{ pdfjsViewer.pdfjsVersion }}`. TypeScript now rejects a bare `Uint8Array` in `viewerApp.open()`, which already failed at runtime. Pass `{ data }`, as in [Open a PDF from bytes](#open-a-pdf-from-bytes). - **From 4.4.0 or earlier:** if your Content Security Policy allows `blob:` in `connect-src` only for locales, you can remove it.