Skip to content

removeSource() throws TypeError via _updateTerrain() when terrain renderer holds stale source reference #13703

Description

@tibotiber

mapbox-gl-js version

v3.12.0

Browser and version

Chrome Version 152.0.7939.3 (Official Build) dev (arm64)

Expected behavior

removeSource() completes without throwing, or throws before the source is removed (so callers can handle a true failure)

Actual behavior

Source is removed successfully, then _updateTerrain() throws — leaving callers unable to distinguish a real removal failure from this internal bookkeeping error

Calling map.removeSource(sourceId) throws a TypeError: Cannot read properties of undefined (reading 'get') in certain conditions. The throw originates from the internal _updateTerrain() call that runs after this.style.removeSource(e) inside removeSource. By the time the error throws, the source has already been removed from the style, so the error is benign — but it disrupts any code running in the same call stack after removeSource.

Link to the demonstration

No response

Steps to trigger the unexpected behavior

  1. Add a GeoJSON source
  2. Add a terrain to the map
  3. Remove the source — map.removeSource(sourceId) throws

Relevant log output

TypeError: Cannot read properties of undefined (reading 'get')
  at sn.update (mapbox-gl.js)
  at Map._updateTerrain (mapbox-gl.js)
  at Map.removeSource (mapbox-gl.js)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions