Repository navigation
fix: resolve MuPDF wasm correctly in desktop dev - #126
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes MuPDF WebAssembly loading in the desktop app during local Vite dev by forcing the worker to fetch the real mupdf-wasm.wasm via Vite’s /@fs/ filesystem-serving path, avoiding the index.html fallback that breaks WASM instantiation. Production/packaged behavior is kept unchanged by applying the override only when import.meta.env.DEV is true.
Changes:
- Inject an absolute filesystem path for
mupdf-wasm.wasminto the Vite bundle viadefine. - Configure the MuPDF worker to override Emscripten’s
locateFilein dev to return a/@fs/...URL for the WASM binary. - Add global TypeScript typings for the injected constant.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/desktop/vite.config.ts | Computes the MuPDF .wasm absolute path and injects it as __MUPDF_WASM_FS_PATH__ for Vite builds. |
| apps/desktop/src/vite-env.d.ts | Declares the injected __MUPDF_WASM_FS_PATH__ constant for TypeScript. |
| apps/desktop/src/lib/mupdf/mupdf-worker.ts | Sets $libmupdf_wasm_Module.locateFile in dev to resolve the WASM via /@fs/, then dynamically imports mupdf. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/@fs/path during desktop dev so the worker fetches the real.wasmbinaryimport.meta.env.DEVWhy
In local desktop dev, the MuPDF worker can request
mupdf-wasm.wasmthrough a path that falls back toindex.html, which then crashes WebAssembly instantiation with an invalid magic word. Resolving the wasm through Vite's filesystem serving path keeps the dev worker on the actual binary while leaving release builds untouched.Validation
pnpm --filter @claude-prism/desktop build200,Content-Type: application/wasm, and the expected00 61 73 6dheaderNotes
/@fs/dev serving behavior, the dev-only path override should remain compatible with macOS as long as the local filesystem path is allowed by the dev server