fix(maps): keep a browser without WebGL out of the error screen

The default basemap has been a vector style since 4.1.0, and maplibre-gl builds
its WebGL context inside the Map constructor. A browser that refuses one throws
from there, and VectorBasemap attaches the layer inside an async effect, so the
throw became an unhandled rejection no boundary could see.

What actually took the page down was the teardown. Leaflet registers a layer
before onAdd runs, so the half-built one stayed on the map, and the bridge's
onRemove calls this._glMap.remove() without asking whether there is one. That
TypeError lands in a React cleanup, which is why the error appears on the way
out of a map rather than on the way in, and why it reads as "Something went
wrong" when a tab changes and "TREK could not start" when the route does.

The browser is now asked first, once per page load, with a one-pixel probe that
hands the context straight back. Without WebGL the basemap is OSM raster tiles
instead of an empty map, and the maplibre chunk, about a megabyte, is never
fetched. The teardown path is safe either way: a half-built GL layer gets a
no-op stand-in so the bridge can finish its own cleanup, and detaching never
throws, because unmounting a map must not fail just because its basemap did.

Reproduced against demo.liketrek.com with WebGL switched off, and verified with
the fix: 14 raster tiles drawn, no GL canvas, no error screen.

Closes #2288
This commit is contained in:
Maurice
2026-09-08 16:18:18 +02:00
committed by Maurice
parent 8be594d34c
commit 1761f2bcd5
9 changed files with 497 additions and 42 deletions
+15
View File
@@ -22,6 +22,21 @@ export const SATELLITE_TILE_ATTRIBUTION =
'Imagery &copy; <a href="https://www.esri.com">Esri</a>, Maxar, Earthstar Geographics'
export const SATELLITE_TILE_MAXZOOM = 19
/**
* The basemap for a browser that will not give MapLibre a WebGL context (#2288).
*
* OpenFreeMap serves vector tiles only, so the app default needs a GL canvas, and
* with WebGL off there is nothing to draw it on. Of the keyless raster sources
* TREK already points at, this is the only street map: the ESRI layer above is
* imagery, and the CARTO templates below have carried an "API KEY REQUIRED"
* watermark since 26.08.2026. It is preset one in the Map settings tab, so this
* aims no new traffic at OSM's servers, and the volume is bounded by how few
* browsers refuse a context in the first place. Attribution is required and comes
* from attributionForTile(), which already reads this host as OpenStreetMap.
*/
export const RASTER_FALLBACK_TILE_URL = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
export const RASTER_FALLBACK_MAX_ZOOM = 19
// OpenFreeMap, the default basemap since CARTO began watermarking keyless tiles
// on 26.08.2026 and moved its key behind a request by mail. No key, no
// registration, no request limits, commercial use allowed, attribution required.