Skip to content

Commit dcefe24

Browse files
IM.codesclaude
andcommitted
fix: PDF worker loading — use Vite ?url import for reliable asset resolution
The new URL() pattern failed in production because the worker file URL didn't match the emitted asset path. Using ?url suffix lets Vite emit the worker as a hashed asset and return the correct URL. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bc9eeff commit dcefe24

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

web/src/components/OfficePreview.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ function PdfPreview({ data }: { data: string }) {
2929
(async () => {
3030
try {
3131
const pdfjsLib = await import('pdfjs-dist');
32-
// Use the bundled worker via URL import — Vite handles this
33-
const workerUrl = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url);
34-
pdfjsLib.GlobalWorkerOptions.workerSrc = workerUrl.href;
32+
// Vite ?url suffix emits the worker as a hashed asset and returns its URL
33+
const workerUrl = (await import('pdfjs-dist/build/pdf.worker.min.mjs?url')).default;
34+
pdfjsLib.GlobalWorkerOptions.workerSrc = workerUrl;
3535
const pdf = await pdfjsLib.getDocument({ data: base64ToArrayBuffer(data) }).promise;
3636
if (cancelled || !containerRef.current) return;
3737
containerRef.current.innerHTML = '';

web/src/env.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
declare const __BUILD_TIME__: string;
2+
3+
// Vite ?url suffix — returns the asset URL as a string
4+
declare module '*?url' {
5+
const src: string;
6+
export default src;
7+
}

0 commit comments

Comments
 (0)