Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore style.loadURL abort error when style is removed #4425

Merged
merged 8 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### 🐞 Bug fixes

- Fix lag on fast map zoom ([#4366](https://github.com/maplibre/maplibre-gl-js/pull/4366))
- Fix `style.loadURL` abort error being logged when removing style ([#4425](https://github.com/maplibre/maplibre-gl-js/pull/4425))
- _...Add new stuff here..._

## 4.5.0
Expand Down
12 changes: 12 additions & 0 deletions src/style/style.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ describe('Style#loadURL', () => {
style._remove();
expect((server.lastRequest as any).aborted).toBe(true);
});

test('does not fire an error if removed', async () => {
const style = new Style(getStubMap());
const spy = jest.fn();

style.on('error', spy);
HarelM marked this conversation as resolved.
Show resolved Hide resolved
style.loadURL('style.json');
style._remove();
await sleep(0);

expect(spy).toHaveBeenCalledTimes(0);
});
});

describe('Style#loadJSON', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/style/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,13 @@ export class Style extends Evented {

const request = this.map._requestManager.transformRequest(url, ResourceType.Style);
this._loadStyleRequest = new AbortController();
const abortController = this._loadStyleRequest;
HarelM marked this conversation as resolved.
Show resolved Hide resolved
getJSON<StyleSpecification>(request, this._loadStyleRequest).then((response) => {
this._loadStyleRequest = null;
this._load(response.data, options, previousStyle);
}).catch((error) => {
this._loadStyleRequest = null;
if (error) {
if (error && !abortController.signal.aborted) { // ignore abort
this.fire(new ErrorEvent(error));
}
});
Expand Down