Skip to content

fix(ui): ship the MapLibre worker so vector map layers render - #597

Merged
smitt14ua merged 1 commit into
mainfrom
fix/maplibre-worker-url
Nov 4, 2026
Merged

smitt14ua merged 1 commit into
mainfrom
fix/maplibre-worker-url

Conversation

@smitt14ua

Copy link
Copy Markdown
Contributor

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 from new 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.mjs falls through to the SPA's index.html (200, text/html) and every worker dies. Rasters are drawn without workers; vector tiles are parsed only in them.

Fix

  • New ui/src/renderers/leaflet/maplibreLoader.ts: imports maplibre-gl/dist/maplibre-gl-worker.mjs?url (Vite emits it as an asset and returns its final URL) and calls setWorkerUrl() before returning the module.
  • leafletRenderer.ts uses loadMaplibre() at both import("maplibre-gl") sites, and before @maplibre/maplibre-gl-leaflet creates the map (so the URL is set even if PMTiles registration fails).

Verification

  • vite build now emits assets/maplibre-gl-worker-<hash>.mjs, referenced as new URL("maplibre-gl-worker-<hash>.mjs", import.meta.url).
  • Ran the built server locally with a production recording (farabad) and maps rendered by maptool render: no worker errors, all four styles draw roads, buildings, water, contours and labels. Before the fix, the same page on the deployed main-full image showed six Worker failed to load errors and an empty Topo style.
  • vitest run: 2306 passed (two new tests for the loader). tsc --noEmit clean, eslint has no new warnings.

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().
@smitt14ua
smitt14ua marked this pull request as ready for review November 4, 2026 02:09
@smitt14ua
smitt14ua requested a review from fank November 4, 2026 02:10
@fank

fank commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Ratatoskr reviewed this pull request.

Approved on 605f2447. See the review.

Finished 2026-11-04 02:15 UTC.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Coverage Report for ui

Status Category Percentage Covered / Total
🔵 Lines 97.3%
🟰 ±0 pp
10069 / 10348
🔵 Statements 95.61%
🟰 ±0 pp
14078 / 14724
🔵 Functions 95.45%
⬆️ +0.01 pp
3986 / 4176
🔵 Branches 85.02%
🟰 ±0 pp
5303 / 6237
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
ui/src/renderers/leaflet/maplibreLoader.ts 100% 100% 100% 100%
Generated in workflow #265 for commit 605f244 by the Vitest Coverage Report Action

@fank fank left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@smitt14ua
smitt14ua merged commit 078ea60 into main Nov 4, 2026
6 checks passed
@smitt14ua
smitt14ua deleted the fix/maplibre-worker-url branch November 4, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants