Repository navigation
fix(ui): ship the MapLibre worker so vector map layers render - #597
Conversation
MapLibre 6 (bumped in #581) loads its worker from ./maplibre-gl-worker.mjs next to its own module. Vite bundles maplibre-gl into a hashed chunk and never emits that file, so the request falls through to index.html and every worker fails with "Worker failed to load". Raster layers still draw, but vector tiles are never parsed: Topo and Topo Dark show an empty background and the relief styles lose roads, buildings, water and labels. Import the worker with ?url so Vite emits it as an asset, and pass its URL to setWorkerUrl() before any map is created. Both maplibre-gl import sites now go through loadMaplibre().
|
Ratatoskr reviewed this pull request. Approved on Finished 2026-11-04 02:15 UTC. |
Coverage Report for ui
File Coverage
|
||||||||||||||||||||||||||||||||||||||
fank
left a comment
There was a problem hiding this comment.
APPROVE — 0 blocking findings.
Review details
Reviewed head 605f244755e768cab36d68f85277ba051c36b742. The loader configures the same MapLibre module used by the Leaflet bridge before map creation, including the PMTiles-registration failure path and style previews. The production build emits assets/maplibre-gl-worker-CMkqA50c.mjs and references it relative to the importing chunk, preserving subpath deployments.
Checks run in a temporary copy, leaving the review checkout unchanged:
npm ci --ignore-scripts: succeeded.npm test: 116 files passed, 1 skipped; 2306 tests passed, 13 skipped.npx tsc --noEmit: passed.npm run build: passed; worker asset emission and generated URL inspected.npx eslint src/renderers/leaflet/maplibreLoader.ts src/renderers/leaflet/__tests__/maplibreLoader.test.ts src/renderers/leaflet/leafletRenderer.ts: passed.
The new unit tests pin URL configuration and repeated-call behavior; production asset emission was checked separately because those tests mock the asset import. Browser rendering and live vector-tile loading were not independently exercised. Current Go/UI/coverage CI checks passed.
Discussion follow-up: GitHub GraphQL enumerated review threads (no further pages); none exist, so none were resolved, left open, or skipped.
Problem
Since maplibre-gl 6 (#581), maps render without any vector layers. Topo and Topo Dark show an empty background, and Color Relief / Topo Relief show the relief rasters but no roads, buildings, water or labels.
The browser console shows
Error: Worker failed to load. Check that the worker URL is correct.MapLibre 6 loads its worker fromnew URL("./maplibre-gl-worker.mjs", import.meta.url). Vite bundles maplibre-gl into a hashed chunk and does not emit that file, so/assets/maplibre-gl-worker.mjsfalls through to the SPA'sindex.html(200,text/html) and every worker dies. Rasters are drawn without workers; vector tiles are parsed only in them.Fix
ui/src/renderers/leaflet/maplibreLoader.ts: importsmaplibre-gl/dist/maplibre-gl-worker.mjs?url(Vite emits it as an asset and returns its final URL) and callssetWorkerUrl()before returning the module.leafletRenderer.tsusesloadMaplibre()at bothimport("maplibre-gl")sites, and before@maplibre/maplibre-gl-leafletcreates the map (so the URL is set even if PMTiles registration fails).Verification
vite buildnow emitsassets/maplibre-gl-worker-<hash>.mjs, referenced asnew URL("maplibre-gl-worker-<hash>.mjs", import.meta.url).maptool render: no worker errors, all four styles draw roads, buildings, water, contours and labels. Before the fix, the same page on the deployedmain-fullimage showed sixWorker failed to loaderrors and an empty Topo style.vitest run: 2306 passed (two new tests for the loader).tsc --noEmitclean, eslint has no new warnings.