Repository navigation
fix: upgrade maplibre-gl to 5.24.1 to stop WebGL context-restore crash - #286
Conversation
MapLibre 5.16.0 crashes with "Cannot read properties of null (reading 'imageManager')" when the WebGL context is lost while a style is still loading: the lost-context snapshot has no style, so the restore handler skips setStyle() and then dereferences the null style. MapLibre 5.23.0 added a null guard for this. Sentry: MOBILITY-DATABASE-WEB-APP-43. The new MapLibre no longer pulls in the global GeoJSON type namespace, so Map.tsx and MapGeoJSON.tsx now import their types from 'geojson' and @types/geojson is declared as a dev dependency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/ * (Desktop)
*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/feeds * (Desktop)
*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/feeds/gtfs/mdb-2126 * (Desktop)
*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/feeds/gtfs_rt/mdb-2585 * (Desktop)
*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/feeds/gbfs/gbfs-flamingo_porirua * (Desktop)
|
Summary
Fixes Sentry issue MOBILITY-DATABASE-WEB-APP-43:
TypeError: Cannot read properties of null (reading 'imageManager'), about 2.1k events since April 2026, on feed map pages.Root cause
The crash is in MapLibre 5.16.0's
webglcontextrestoredhandler (maplibre-gl/src/ui/map.ts). If the browser loses the WebGL context while a style is still loading, the saved snapshot has no style (Style.serialize()returnsundefinedbefore load), but it does have an image map. On restore, MapLibre skipssetStyle()and then runsthis.style.imageManager.images = ...withthis.stylestillnull.MapLibre 5.23.0 added a guard (
if (this._lostContextStyle.images && this.style)). Our^5.7.0range had resolved to 5.16.0.Our feed map makes the loading window more likely:
GtfsVisualizationMapbuilds a newmapStyleobject on every render, and hover changes the layers, so the style is often being reloaded. The Sentry breadcrumbs show MapLibre's "Style is not done loading" warning for this.Changes
maplibre-gl^5.7.0->^5.24.1(latest 5.x, no major version change).@types/geojson-vt, which was what brought the globalGeoJSONtype namespace into our build.Map.tsxandMapGeoJSON.tsxnow importFeature,PolygonandFeatureCollectionfromgeojson, and@types/geojsonis declared as a dev dependency instead of being picked up from MapLibre.Verification
webglcontextlostbefore the style loads, thenwebglcontextrestored. On 5.16.0 that throws the exact Sentry error; on 5.24.1 it restores without an error.yarn lint(0 errors),yarn test:ci(608 passed),npx tsc --noEmitandyarn build:prodall pass.Not verified
GtfsVisualizationMapsets it again on the next hover;MapandMapGeoJSONstay blank until the page reloads. MapLibre 6 restores the style properly but is a major upgrade, so it is left for a follow-up.🤖 Generated with Claude Code