Skip to content

fix: upgrade maplibre-gl to 5.24.1 to stop WebGL context-restore crash - #286

Merged
Alessandro100 merged 1 commit into
mainfrom
claude/fix-sentry-bug-accd2e
Dec 3, 2026
Merged

Alessandro100 merged 1 commit into
mainfrom
claude/fix-sentry-bug-accd2e

Conversation

@Alessandro100

Copy link
Copy Markdown
Contributor

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 webglcontextrestored handler (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() returns undefined before load), but it does have an image map. On restore, MapLibre skips setStyle() and then runs this.style.imageManager.images = ... with this.style still null.

MapLibre 5.23.0 added a guard (if (this._lostContextStyle.images && this.style)). Our ^5.7.0 range had resolved to 5.16.0.

Our feed map makes the loading window more likely: GtfsVisualizationMap builds a new mapStyle object 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).
  • The new MapLibre no longer pulls in @types/geojson-vt, which was what brought the global GeoJSON type namespace into our build. Map.tsx and MapGeoJSON.tsx now import Feature, Polygon and FeatureCollection from geojson, and @types/geojson is declared as a dev dependency instead of being picked up from MapLibre.

Verification

  • Reproduced on a standalone page: create a map, dispatch webglcontextlost before the style loads, then webglcontextrestored. 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 --noEmit and yarn build:prod all pass.

Not verified

  • The feed map pages were not checked in a running app (the worktree had no env config). Please give the feed map a quick look on the Vercel preview, since this is a 5.16 -> 5.24 minor upgrade.
  • In this edge case 5.24.1 no longer crashes, but the map has no style until it is next set. GtfsVisualizationMap sets it again on the next hover; Map and MapGeoJSON stay 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

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>
@vercel

vercel Bot commented Dec 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
mobilitydatabase-web Ready Ready Preview Dec 3, 2026 1:37pm UTC

Request Review

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/ * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟠 73 🟢 90 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/feeds * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟠 89 🟠 87 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/feeds/gtfs/mdb-2126 * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🔴 48 🟢 95 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/feeds/gtfs_rt/mdb-2585 * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟢 99 🟠 84 🟢 96 🟢 100

*Lighthouse ran on https://mobilitydatabase-1jcqmqx8w-mobility-data.vercel.app/feeds/gbfs/gbfs-flamingo_porirua * (Desktop)
⚡️ HTML Report Lighthouse report for the changes in this PR:

Performance Accessibility Best Practices SEO
🟠 67 🟢 94 🟢 96 🟢 100

@davidgamez davidgamez 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.

LGTM!

@Alessandro100
Alessandro100 merged commit 8379fda into main Dec 3, 2026
5 checks passed

This branch was successfully deployed

1 active deployment
Preview — dc8e14ff Deployed Dec 3, 2026 by vercel[bot]
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