mapbox / mapbox/mapbox-gl-js

addSource geojson with "null" data renders previous geojson

Open
#13,300 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**: 3.7.0

**browser**: Chrome for Linux: Version 129.0.6668.100 (Official Build) (64-bit)

### Steps to Trigger Behavior

1. Add valid mapbox access token to jsfiddle
2. See the orange polygon which gets initialized with geojson data and is rendered properly. Script will remove and add the source + layer every couple of seconds with geojson data `null`:

https://github.com/user-attachments/assets/3ef19542-3094-4944-8aa8-fdf77701742c

Adding a empty featureCollection instead of `null` is behaving as expected:

```
map.addSource('my-source', {
type: 'geojson',
data: data ?? {
type: 'FeatureCollection',
features: []
}
});
```

https://github.com/user-attachments/assets/418554cc-08b1-4ad7-bf28-149503e2f5c5

Should passing `null` as `data` work?

### Link to Demonstration
https://jsfiddle.net/ogy2xwsc/

### Expected Behavior
It renders nothing, since passed geojson data is `null`.

### Actual Behavior
It renders previous existing geojson.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked JSFiddle and the map.addSource entry point, reproducing the cycle that removes and re-adds a GeoJSON source with null data. Trace the source update and rendering behavior to determine why earlier GeoJSON remains visible; done means null renders no previous geometry while the empty FeatureCollection behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.