Fix imported PDFs not rendering in the Docker image #3

Merged
reudy merged 1 commit from fix-pdf-worker into main 2026-09-27 12:00:37 +02:00
Member

Problem

In the Docker image, every imported PDF page showed "Source PDF … is not available", even for a PDF imported seconds earlier.

nginx's MIME table has no entry for .mjs, so the pdf.js worker (pdf.worker.min.mjs) was served as application/octet-stream. Browsers refuse to run module scripts with that type, and pdf.js's fallback loads the same file, so it failed too. The dev server serves .mjs correctly, which is why this only showed up in Docker. No data was missing: source PDFs are embedded in each synced canvas and restored on pull.

Fix

  • docker/nginx.conf: serve .mjs as text/javascript. The file is included at http level, so this adds to nginx's MIME table instead of replacing it.
  • PdfBackground.svelte / render.ts: tell the two failures apart instead of showing one misleading message:
    • "Source PDF “…” is not stored on this device" when the source bytes are really missing,
    • "Could not display “…” (see the browser console)" when pdf.js fails, with the error logged.

Testing

  • curl: the worker is now text/javascript and keeps its long-term cache header. HTML, JS and the manifest types are unchanged, and nginx -t passes.
  • Firefox (Playwright) against the rebuilt container:
    • normal import: both pages render the PDF content (checked for drawn pixels),
    • source deleted from IndexedDB: shows "not stored on this device",
    • worker forced to application/octet-stream: shows "Could not display".
  • The same test against the current main image reproduces the bug: "is not available" and nothing drawn.
  • npm run check and all 24 unit tests pass.

After merging, rebuild on the server with git pull && docker compose up -d --build, then reload the page (the new service worker takes over on reload).

🤖 Generated with Claude Code

https://claude.ai/code/session_01VsorPV3JeJRoZ1mD1pdvtL

## Problem In the Docker image, every imported PDF page showed "Source PDF … is not available", even for a PDF imported seconds earlier. nginx's MIME table has no entry for `.mjs`, so the pdf.js worker (`pdf.worker.min.mjs`) was served as `application/octet-stream`. Browsers refuse to run module scripts with that type, and pdf.js's fallback loads the same file, so it failed too. The dev server serves `.mjs` correctly, which is why this only showed up in Docker. No data was missing: source PDFs are embedded in each synced canvas and restored on pull. ## Fix - `docker/nginx.conf`: serve `.mjs` as `text/javascript`. The file is included at http level, so this adds to nginx's MIME table instead of replacing it. - `PdfBackground.svelte` / `render.ts`: tell the two failures apart instead of showing one misleading message: - "Source PDF “…” is not stored on this device" when the source bytes are really missing, - "Could not display “…” (see the browser console)" when pdf.js fails, with the error logged. ## Testing - `curl`: the worker is now `text/javascript` and keeps its long-term cache header. HTML, JS and the manifest types are unchanged, and `nginx -t` passes. - Firefox (Playwright) against the rebuilt container: - normal import: both pages render the PDF content (checked for drawn pixels), - source deleted from IndexedDB: shows "not stored on this device", - worker forced to `application/octet-stream`: shows "Could not display". - The same test against the current `main` image reproduces the bug: "is not available" and nothing drawn. - `npm run check` and all 24 unit tests pass. After merging, rebuild on the server with `git pull && docker compose up -d --build`, then reload the page (the new service worker takes over on reload). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VsorPV3JeJRoZ1mD1pdvtL
agent added 1 commit 2026-09-27 11:37:28 +02:00
nginx has no MIME type for .mjs, so the pdf.js worker was served as
application/octet-stream and browsers refused to load it. Every imported
PDF page then showed "Source PDF ... is not available", which looked like
missing files. Serve .mjs as text/javascript.

The page background now also tells the two failures apart: "not stored on
this device" when the source bytes are missing, and "could not display"
(with the error logged) when pdf.js fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VsorPV3JeJRoZ1mD1pdvtL
reudy merged commit df1f3c27f7 into main 2026-09-27 12:00:37 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/Papure#3
No description provided.