setStyle(URL) is a race condition - subsequent addLayer() and addSource() possibly lost
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
mapbox-gl-js version: 1.13.0
Steps to Trigger Behavior
// first initialise map with say 5 layers
map.setStyle('mystyle.json'); // style containing 10 layers)
console.log(map.loaded(), map.isStyleLoaded(), map.getStyle().layers.length);
map.addLayer({ type: 'background', id: 'background' });
setTimeout(()=> console.log(map.getLayer('background')), 5000);
Expected Behavior
false, false, 10 (maybe - unclear what isStyleLoaded should do exactly)
Then print out the background layer we added
Actual Behavior
true, true, 5
undefined
Super frustrating, like #8691, #9779, #2268.
After calling setStyle() (with a JSON) it's difficult/impossible to know when the new style has actually taken effect. If you immediately add new layers, there is no error, but they apparently happen before the actual style change takes place, so they get removed.
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 reproducing the issue with the provided setStyle(), addLayer(), and addSource() sequence, then trace the style-loading lifecycle and the loaded() and isStyleLoaded() entry points. Done means additions made after setStyle() are retained and the loading state accurately reflects when the new style is ready.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100