Repository navigation
Update pdfjs-viewer docs for v4.6.0: the Vite plugin - #108
Conversation
Hosting splits into Bundlers, Vite plugin, and Other bundlers and `assets-base`. The old #bundlers-and-assets-base anchor still lands on the copy route. The Vite plugin section says where the data goes, which frameworks take it, and that its fixed file names can outlive an upgrade in an immutable cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
4 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/pdfjs-viewer/index.md">
<violation number="1" location="src/pdfjs-viewer/index.md:250">
P2: An individual resource attribute overrides only its own resource; it does not make the plugin copy unused. Clarify that only `assets-base` bypasses the entire plugin copy.</violation>
<violation number="2" location="src/pdfjs-viewer/index.md:362">
P3: This summary covers only some Vite-based frameworks. Say that any Vite app should add the plugin, so React or Vue users on plain Vite don't skip it.</violation>
<violation number="3" location="src/pdfjs-viewer/index.md:362">
P3: The framework checklist omits React Router even though this page lists it as a supported Vite-plugin framework. Include React Router so its production builds do not miss PDF.js data.</violation>
<violation number="4" location="src/pdfjs-viewer/index.md:538">
P2: This step doesn't say to remove `assets-base`. As written, keeping `assets-base` makes the plugin's copy unused, so the migration gives no benefit. Add that `assets-base` (and any resource attributes pointing at the copy) must be removed.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
|
||
| If you're coming from an older version: | ||
|
|
||
| - **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` for the data. |
There was a problem hiding this comment.
P2: This step doesn't say to remove assets-base. As written, keeping assets-base makes the plugin's copy unused, so the migration gives no benefit. Add that assets-base (and any resource attributes pointing at the copy) must be removed.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/pdfjs-viewer/index.md, line 538:
<comment>This step doesn't say to remove `assets-base`. As written, keeping `assets-base` makes the plugin's copy unused, so the migration gives no benefit. Add that `assets-base` (and any resource attributes pointing at the copy) must be removed.</comment>
<file context>
@@ -505,6 +535,7 @@ import '@missing-elements/pdfjs-viewer' // was: import 'pdfjs-viewer-element'
If you're coming from an older version:
+- **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` for the data.
- **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.
</file context>
| - **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` for the data. | |
| - **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`. Remove the `assets-base` attribute, because it makes the plugin's copy unused. |
|
|
||
| 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. | ||
|
|
||
| With `assets-base` or a resource attribute set, the element loads the data from there, and the plugin's copy goes unused. |
There was a problem hiding this comment.
P2: An individual resource attribute overrides only its own resource; it does not make the plugin copy unused. Clarify that only assets-base bypasses the entire plugin copy.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/pdfjs-viewer/index.md, line 250:
<comment>An individual resource attribute overrides only its own resource; it does not make the plugin copy unused. Clarify that only `assets-base` bypasses the entire plugin copy.</comment>
<file context>
@@ -222,9 +222,38 @@ They don't copy the PDF.js [data folders](#cmaps-fonts-and-other-resources), tho
+
+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.
+
+With `assets-base` or a resource attribute set, the element loads the data from there, and the plugin's copy goes unused.
+
+[demo/vite-plugin](https://github.com/missing-elements/pdfjs-viewer/tree/master/demo/vite-plugin) in the repository is a minimal app that uses the plugin.
</file context>
| With `assets-base` or a resource attribute set, the element loads the data from there, and the plugin's copy goes unused. | |
| With `assets-base` set, the element loads the data from there, and the plugin's copy goes unused. Individual resource attributes override only their corresponding resource. |
| - Import the package once, on the client. It needs `window`, so in server-rendered apps (Next.js, Nuxt, SvelteKit, Astro) import it in a client-only hook or component. | ||
| - Give the element a height. | ||
| - Attributes are strings. Call methods (`setViewerOptions`, `injectViewerStyles`) through a ref. | ||
| - Bundlers don't copy the data some PDFs need. Add the [Vite plugin](#vite-plugin) in SvelteKit, Nuxt and Astro, or [copy `dist` and set `assets-base`](#other-bundlers-and-assets-base) in Next.js. |
There was a problem hiding this comment.
P3: This summary covers only some Vite-based frameworks. Say that any Vite app should add the plugin, so React or Vue users on plain Vite don't skip it.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/pdfjs-viewer/index.md, line 362:
<comment>This summary covers only some Vite-based frameworks. Say that any Vite app should add the plugin, so React or Vue users on plain Vite don't skip it.</comment>
<file context>
@@ -325,11 +354,12 @@ If your page has a Content Security Policy, the WASM decoders and the scripting
- Import the package once, on the client. It needs `window`, so in server-rendered apps (Next.js, Nuxt, SvelteKit, Astro) import it in a client-only hook or component.
- Give the element a height.
- Attributes are strings. Call methods (`setViewerOptions`, `injectViewerStyles`) through a ref.
+- Bundlers don't copy the data some PDFs need. Add the [Vite plugin](#vite-plugin) in SvelteKit, Nuxt and Astro, or [copy `dist` and set `assets-base`](#other-bundlers-and-assets-base) in Next.js.
### React
</file context>
| - Bundlers don't copy the data some PDFs need. Add the [Vite plugin](#vite-plugin) in SvelteKit, Nuxt and Astro, or [copy `dist` and set `assets-base`](#other-bundlers-and-assets-base) in Next.js. | |
| - Bundlers don't copy the data some PDFs need. In a Vite app, add the [Vite plugin](#vite-plugin), or [copy `dist` and set `assets-base`](#other-bundlers-and-assets-base) in Next.js and other bundlers. |
| - Import the package once, on the client. It needs `window`, so in server-rendered apps (Next.js, Nuxt, SvelteKit, Astro) import it in a client-only hook or component. | ||
| - Give the element a height. | ||
| - Attributes are strings. Call methods (`setViewerOptions`, `injectViewerStyles`) through a ref. | ||
| - Bundlers don't copy the data some PDFs need. Add the [Vite plugin](#vite-plugin) in SvelteKit, Nuxt and Astro, or [copy `dist` and set `assets-base`](#other-bundlers-and-assets-base) in Next.js. |
There was a problem hiding this comment.
P3: The framework checklist omits React Router even though this page lists it as a supported Vite-plugin framework. Include React Router so its production builds do not miss PDF.js data.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/pdfjs-viewer/index.md, line 362:
<comment>The framework checklist omits React Router even though this page lists it as a supported Vite-plugin framework. Include React Router so its production builds do not miss PDF.js data.</comment>
<file context>
@@ -325,11 +354,12 @@ If your page has a Content Security Policy, the WASM decoders and the scripting
- Import the package once, on the client. It needs `window`, so in server-rendered apps (Next.js, Nuxt, SvelteKit, Astro) import it in a client-only hook or component.
- Give the element a height.
- Attributes are strings. Call methods (`setViewerOptions`, `injectViewerStyles`) through a ref.
+- Bundlers don't copy the data some PDFs need. Add the [Vite plugin](#vite-plugin) in SvelteKit, Nuxt and Astro, or [copy `dist` and set `assets-base`](#other-bundlers-and-assets-base) in Next.js.
### React
</file context>
| - Bundlers don't copy the data some PDFs need. Add the [Vite plugin](#vite-plugin) in SvelteKit, Nuxt and Astro, or [copy `dist` and set `assets-base`](#other-bundlers-and-assets-base) in Next.js. | |
| - Bundlers don't copy the data some PDFs need. Add the [Vite plugin](#vite-plugin) in React Router, SvelteKit, Nuxt and Astro, or [copy `dist` and set `assets-base`](#other-bundlers-and-assets-base) in Next.js. |
…n-review Fix the Vite plugin notes from the #108 review
Summary
Docs for
@missing-elements/pdfjs-viewer4.6.0, which adds a Vite plugin that copies the PDF.js data folders into the build (pdfjs-viewer#84).@4.6.0.assets-base" section into three, all in the sidebar:vite devhides the problem.assets-base: the copy route, unchanged. A<span id="bundlers-and-assets-base">keeps old links landing here.assets-baseattribute row, the resources section, a fourth "things to remember" bullet under Frameworks, and a "From 4.5.0 or earlier" bullet under Migrating.The caching caveat
The plugin's data files keep fixed names. SvelteKit (
_app/immutable/), Nuxt (_nuxt/) and Astro (_astro/) serve their asset folders asimmutable, so a returning visitor can keep an older version's files after an upgrade. I checked that this breaks something: theopenjpeg.wasmpublished in 4.4.2 needs 17 imports, and the 4.6.0 worker provides 8, so it can't load. The section says so and points to a short cache orassets-base.Validation
pnpm buildpasses._site/pdfjs-viewer/index.html, everyhref="#…"matches an id on the page, the three new headings are in the table of contents, and#bundlers-and-assets-basestill exists.🤖 Generated with Claude Code
Summary by cubic
Documents
@missing-elements/pdfjs-viewer4.6.0, which adds a Vite plugin that copies the PDF.js data folders into the build. The pinned package bumps to 4.6.0, so the CDN examples now show@4.6.0.Docs
assets-base" section into Bundlers, Vite plugin, and Other bundlers andassets-base; the old anchor still lands on the copy route.assets-baseor a resource attribute is set.assets-baseroute.assets-baseattribute row and the resources section.Written for commit 4e5608b. Summary will update on new commits.