Uncaught error during setFeatureState during initial set of value
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
Hey MapboxGL team,
I've hit a bug recently when using setFeatureState for the first time on a feautre.
````
Uncaught TypeError: Cannot read properties of undefined (reading 'some-feature-id')
at of.updateState (source_state.js:46:47)
at If.setFeatureState (source_cache.js:928:21)
at $t.setFeatureState (style.js:1158:25)
at Map.setFeatureState (map.js:2600:20)
````
From what I can tell it relates to this line
https://github.com/mapbox/mapbox-gl-js/blob/b1c54af599c865025b26ce5b73bd6ca78934ad2c/src/source/source_state.js#L46
Putting a break point in on the code `this.state[sourceLayer]` doesn't exist yet.
The error is only triggered once, subsequent calls to setFeatureState for the same feature work.
**mapbox-gl-js version**: 2.8.2
**browser**: Chromium 102
### Steps to Trigger Behavior
In my use case I'm creating a linestring following `click` and `mousemove` events. It's during the mouse move that I'm then setting the state on a feature when something happens. I'm wondering if there is some sort of race condition going on with updating the geojson source and what happens with the feature state?
I haven't had much luck with a minimal repro sorry, but I'll have another go in the next day or two 😢
Thanks,
Rowan
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the reported stack from src/source/source_state.js line 46 through source_cache.js, style.js, and map.js. Reproduce the first setFeatureState call while a GeoJSON source is being updated, then verify that the initial call no longer throws and that subsequent calls still work. The issue does not name a minimal reproduction or test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100