Skip to content

Update pdfjs-viewer docs for v4.6.0: the Vite plugin - #108

Merged
alekswebnet merged 1 commit into
mainfrom
docs/pdfjs-viewer-4.6.0
Nov 24, 2026
Merged

alekswebnet merged 1 commit into
mainfrom
docs/pdfjs-viewer-4.6.0

Conversation

@alekswebnet

@alekswebnet alekswebnet commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Docs for @missing-elements/pdfjs-viewer 4.6.0, which adds a Vite plugin that copies the PDF.js data folders into the build (pdfjs-viewer#84).

  • Bump the pinned package to 4.6.0. The CDN examples now show @4.6.0.
  • Hosting splits the old "Bundlers and assets-base" section into three, all in the sidebar:
    • Bundlers: what bundlers copy and what they leave out, and that vite dev hides the problem.
    • Vite plugin: the config, where the data goes, the size, supported Vite versions, the framework configs, and the caching caveat below.
    • Other bundlers and assets-base: the copy route, unchanged. A <span id="bundlers-and-assets-base"> keeps old links landing here.
  • Smaller edits: the assets-base attribute 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 as immutable, so a returning visitor can keep an older version's files after an upgrade. I checked that this breaks something: the openjpeg.wasm published 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 or assets-base.

Validation

  • pnpm build passes.
  • In _site/pdfjs-viewer/index.html, every href="#…" matches an id on the page, the three new headings are in the table of contents, and #bundlers-and-assets-base still exists.
  • Not checked: what each framework's config looks like with the plugin in it. Plain Vite was tested with a client build and an SSR build.

🤖 Generated with Claude Code


Summary by cubic

Documents @missing-elements/pdfjs-viewer 4.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

  • Splits the old "Bundlers and assets-base" section into Bundlers, Vite plugin, and Other bundlers and assets-base; the old anchor still lands on the copy route.
  • The Vite plugin section covers the config, where the data goes, the 286-file / 3.4 MB build output, supported Vite versions, and the framework configs.
  • Notes that the plugin's copy goes unused when assets-base or a resource attribute is set.
  • Warns that the plugin's fixed file names can outlive an upgrade in an immutable cache, since PDF.js can't mix data from different versions; recommends a short cache or the assets-base route.
  • Adds a fourth bullet under Frameworks, a migration note for 4.5.0 and earlier, and updates the assets-base attribute row and the resources section.

Written for commit 4e5608b. Summary will update on new commits.

View guided diff Turn on auto-fix

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>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​missing-elements/​pdfjs-viewer@​4.5.0 ⏵ 4.6.07310096 +591 -170

View full report

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/pdfjs-viewer/index.md

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>
Suggested change
- **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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in #109.

Comment thread src/pdfjs-viewer/index.md

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>
Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in #109.

Comment thread src/pdfjs-viewer/index.md
- 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>
Suggested change
- 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in #109.

Comment thread src/pdfjs-viewer/index.md
- 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>
Suggested change
- 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in #109.

@alekswebnet
alekswebnet merged commit 87b84aa into main Nov 24, 2026
4 checks passed
alekswebnet added a commit that referenced this pull request Nov 24, 2026
…n-review

Fix the Vite plugin notes from the #108 review
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.

1 participant