fix: set MapLibre CSP worker URL to prevent Vite production build errors - #8
Merged
Conversation
Call maplibregl.setWorkerUrl() with the pre-built CSP worker at module load time in useMap.js. This prevents Vite's production minifier from mangling variable names that MapLibre serialises into inline worker blobs, which caused 'mo is not defined' ReferenceErrors at runtime. Consuming apps no longer need to apply this workaround themselves. Closes #7 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
Consuming apps using
@ogis/navigatorwith Vite hit a runtimeReferenceErrorin production builds (mo is not defined). Vite's minifier mangles variable names, but MapLibre serialises function bodies into inline worker blobs at runtime — the worker still references the original (pre-minified) names, causing a crash on first tile load.This only affects production builds; dev mode works fine.
Fix
Call
maplibregl.setWorkerUrl()with MapLibre's pre-built CSP worker at module load time inuseMap.js. The CSP worker is a standalone, self-contained file — Vite emits it as a separate asset with proper URL handling, so minification no longer affects it.This is applied once at module initialisation, before any map instance is created. Consuming apps no longer need to apply this workaround themselves.
Testing
All 171 unit tests pass.
Closes #7