Skip to content

fix(android): emit onMapLoadingError; add the SDK error type to its payload - #4322

Merged
mfazekas merged 2 commits into
rnmapbox:mainfrom
arminzaugg:fix/android-map-loading-error
Oct 11, 2026
Merged

mfazekas merged 2 commits into
rnmapbox:mainfrom
arminzaugg:fix/android-map-loading-error

Conversation

@arminzaugg

Copy link
Copy Markdown
Contributor

Description

Fixes onMapLoadingError never firing on Android, and adds the Mapbox SDK's error type to its payload on both platforms.

Android never emits onMapLoadingError. RNMBXMapView.onMapReady subscribes with map.subscribe(observer, listOf(MapEvents.MAP_LOADING_ERROR)). Under Mapbox v11 that call goes to the compat shim in android/src/main/mapbox-v11-compat/v11/.../Event.kt, whose body is a // TODO, so the observer is never registered. This PR subscribes through the v11 API, MapboxMap.subscribeMapLoadingError. It keeps the returned Cancelable and cancels it in onDropViewInstance. The payload now matches iOS: { error, tileId?, sourceId? }.

type on both platforms. Both SDKs classify each error (MapLoadingError.type: STYLE | SPRITE | SOURCE | GLYPHS | TILE on Android, MapLoadingErrorType on iOS), but neither platform forwarded it. Without it, JS can't tell a style that failed to load from a missing sprite: the map still works in the second case, yet the payload looks the same (no tile, no source). The payload gains type: 'style' | 'sprite' | 'source' | 'glyphs' | 'tile', and onMapLoadingError in MapView.tsx is typed with it (MapLoadingErrorPayload).

We carry this change as a pnpm patch on 10.3.2 in our app.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder — not run; docs/MapView.md and docs/docs.json still show () => void for onMapLoadingError. Happy to push the regenerated files if you prefer them in this PR.
  • I have tested the new feature on /example app — not on /example; tested in our own app (below), on 10.3.2 with the same hunks.
    • In V11 mode/ios (our app)
    • In New Architecture mode/ios (our app)
    • In V11 mode/android (our app)
    • In New Architecture mode/android (our app)
  • I added/updated a sample - if a new feature was implemented (/example)

Screenshot OR Video

Measured in our app (Mapbox 11.23.1, rnmapbox 10.3.2, RN 0.85 New Architecture, Android emulator and iOS simulator):

  • Android, before: no onMapLoadingError for a 404 style, nor for failing tiles.
  • Android, after: one { type: "style" } event for a 404 style. For a style whose sprite URL fails: { type: "sprite" } before onDidFinishLoadingStyle, then retried sprite events.
  • iOS, after: the same type values for the same styles.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WadDsndRftrfMGcCF1iLea

arminzaugg and others added 2 commits October 11, 2026 12:27
…ayload

On Mapbox v11, `MapboxMap.subscribe(observer, events)` is an empty shim in
the compat layer, so Android never emitted `onMapLoadingError`. Subscribe
through `subscribeMapLoadingError` instead, keep the returned Cancelable and
cancel it in `onDropViewInstance`. The payload matches iOS:
`{ error, tileId?, sourceId? }`.

Both platforms now also forward the SDK's error kind as `type`
(`style | sprite | source | glyphs | tile`), so JS can tell a style that
failed to load from a missing sprite, which leaves a usable map.
`onMapLoadingError` is typed with the new `MapLoadingErrorPayload`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WadDsndRftrfMGcCF1iLea
@mfazekas

Copy link
Copy Markdown
Contributor

Thanks @arminzaugg. I rebased this onto current main and pushed it to your branch, keeping your commit, plus a small yarn generate commit for the docs. The one conflict was in RNMBXMapView.kt: #4327 meanwhile added its own subscribeMapLoadingError subscription (for the Mapbox.setLanguage rejection warning), so both subscriptions are kept and both are cancelled in onDropViewInstance. On the Android emulator onMapLoadingError now fires once for a missing style with type: "style", and CI is green.

@mfazekas
mfazekas merged commit 9876980 into rnmapbox:main Oct 11, 2026
9 checks passed

This branch was successfully deployed

1 active deployment
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