Skip to content

Commit 9e23300

Browse files
mournergithub-actions[bot]
authored andcommitted
Remove redundant WebP check
GitOrigin-RevId: e074307d8117804409e0cc5d9e93dd141d375095
1 parent 694c72e commit 9e23300

8 files changed

Lines changed: 20 additions & 120 deletions

File tree

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@
231231
"dist/esm/*.js"
232232
]
233233
},
234-
{
235-
"limit": "50 kb",
236-
"name": "Debug Module (brotli)",
237-
"path": "dist/esm/debug.js"
238-
},
239234
{
240235
"gzip": true,
241236
"limit": "600 kb",

src/ui/map.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {RGBAImage} from '../util/image';
3434
import {Event, ErrorEvent} from '../util/evented';
3535
import {MapMouseEvent} from './events';
3636
import TaskQueue from '../util/task_queue';
37-
import webpSupported from '../util/webp_supported';
3837
import {PerformanceUtils, PerformanceMarkers} from '../util/performance';
3938
import {LivePerformanceMarkers, LivePerformanceUtils} from '../util/live_performance';
4039
import EasedVariable from '../util/eased_variable';
@@ -4395,8 +4394,6 @@ export class Map extends Camera {
43954394
this.painter.setTileLoadedFlag(true);
43964395
}
43974396
});
4398-
4399-
webpSupported.testSupport(gl);
44004397
}
44014398

44024399
// eslint-disable-next-line @typescript-eslint/no-explicit-any

src/util/ajax.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import config from './config';
22
import assert from '../style-spec/util/assert';
3-
import webpSupported from './webp_supported';
43
import {warnOnce, isWorker} from './util';
54
import {cacheGet, cachePut} from './tile_request_cache';
65
import {isMapboxHTTPURL, hasCacheDefeatingSku} from './mapbox_url';
@@ -383,12 +382,10 @@ function acquireImageRequest(signal?: AbortSignal): Promise<() => void> {
383382
}
384383

385384
export async function getImage(requestParameters: RequestParameters, signal?: AbortSignal): Promise<RequestResponse<ImageBitmap>> {
386-
if (webpSupported.supported) {
387-
if (!requestParameters.headers) {
388-
requestParameters.headers = {};
389-
}
390-
requestParameters.headers['accept'] = 'image/webp,*/*';
385+
if (!requestParameters.headers) {
386+
requestParameters.headers = {};
391387
}
388+
requestParameters.headers['accept'] = 'image/webp,*/*';
392389

393390
const release = await acquireImageRequest(signal);
394391
try {

src/util/mapbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import assert from '../style-spec/util/assert';
1515
import config from './config';
16-
import webpSupported from './webp_supported';
1716
import {isMapboxHTTPURL, isMapboxURL} from './mapbox_url';
1817
import {createSkuToken, SKU_ID} from './sku_token';
1918
import {version as sdkVersion} from '../../package.json';
@@ -147,7 +146,8 @@ export class RequestManager {
147146
if (tileURL && !isMapboxURL(tileURL)) return tileURL;
148147

149148
const urlObject = parseUrl(tileURL);
150-
const extension = webpSupported.supported ? '.webp' : '$1';
149+
// WebP is supported in all browsers that can run GL JS (which requires WebGL2)
150+
const extension = '.webp';
151151

152152
// The v4 mapbox tile API supports 512x512 image tiles but they must be requested as '@2x' tiles.
153153
const use2xAs512 = rasterTileSize && urlObject.authority !== 'raster' && rasterTileSize === 512;

src/util/webp_supported.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

test/unit/source/vector_tile_source.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ describe('VectorTileSource', () => {
634634
source.loadTile(tile, () => {});
635635
expect(transformSpy).toHaveBeenCalledTimes(1);
636636
expect(transformSpy.mock.calls[0][0]).toEqual(
637-
`https://api.mapbox.com/v4/user.map/10/5/5.png?sku=${source.map._requestManager._skuToken}&access_token=key`
637+
`https://api.mapbox.com/v4/user.map/10/5/5.webp?sku=${source.map._requestManager._skuToken}&access_token=key`
638638
);
639639
expect(transformSpy.mock.calls[0][1]).toEqual('Tile');
640640
}

test/unit/util/ajax.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
resetImageRequestQueue
1313
} from '../../../src/util/ajax';
1414
import config from '../../../src/util/config';
15-
import webpSupported from '../../../src/util/webp_supported';
1615

1716
describe('ajax', () => {
1817
test('getArrayBuffer, 404', async () => {
@@ -313,7 +312,7 @@ describe('ajax', () => {
313312
expect(onReject.mock.calls[0][0]).toMatchObject({name: 'AbortError'});
314313
});
315314

316-
test('getImage sends accept/webp when supported', async () => {
315+
test('getImage sends accept/webp', async () => {
317316
resetImageRequestQueue();
318317

319318
await new Promise<void>(resolve => {
@@ -324,8 +323,6 @@ describe('ajax', () => {
324323
return new Promise<Response>(() => {});
325324
});
326325

327-
webpSupported.supported = true;
328-
329326
getImage({url: ''}).catch(() => {});
330327
});
331328
});

test/unit/util/mapbox.test.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {describe, test, beforeEach, afterEach, expect, vi, equalWithPrecision} f
44
import {getRequestBody} from '../../util/network';
55
import * as mapbox from '../../../src/util/mapbox';
66
import config from '../../../src/util/config';
7-
import webpSupported from '../../../src/util/webp_supported';
87
import {uuid} from '../../../src/util/util';
98
import {SKU_ID} from '../../../src/util/sku_token';
109
import {version} from '../../../package.json';
@@ -131,8 +130,6 @@ describe("mapbox", () => {
131130
});
132131
});
133132

134-
webpSupported.supported = false;
135-
136133
describe('.normalizeStyleURL', () => {
137134
test(
138135
'returns an API URL with access_token parameter when no query string',
@@ -421,44 +418,33 @@ describe("mapbox", () => {
421418
});
422419

423420
describe('.normalizeTileURL', () => {
424-
test('.normalizeTileURL does nothing on 1x devices', () => {
425-
config.API_URL = 'http://path.png';
426-
config.REQUIRE_ACCESS_TOKEN = false;
427-
webpSupported.supported = false;
428-
expect(manager.normalizeTileURL('mapbox://path.png/tile.png')).toEqual(`http://path.png/v4/tile.png`);
429-
expect(manager.normalizeTileURL('mapbox://path.png/tile.png32')).toEqual(`http://path.png/v4/tile.png32`);
430-
expect(manager.normalizeTileURL('mapbox://path.png/tile.jpg70')).toEqual(`http://path.png/v4/tile.jpg70`);
431-
});
432-
433421
test('.normalizeTileURL inserts @2x if source requests it', () => {
434422
config.API_URL = 'http://path.png';
435423
config.REQUIRE_ACCESS_TOKEN = false;
436-
expect(manager.normalizeTileURL('mapbox://path.png/tile.png', true)).toEqual(`http://path.png/v4/tile@2x.png`);
437-
expect(manager.normalizeTileURL('mapbox://path.png/tile.png32', true)).toEqual(`http://path.png/v4/tile@2x.png32`);
438-
expect(manager.normalizeTileURL('mapbox://path.png/tile.jpg70', true)).toEqual(`http://path.png/v4/tile@2x.jpg70`);
424+
expect(manager.normalizeTileURL('mapbox://path.png/tile.png', true)).toEqual(`http://path.png/v4/tile@2x.webp`);
425+
expect(manager.normalizeTileURL('mapbox://path.png/tile.png32', true)).toEqual(`http://path.png/v4/tile@2x.webp`);
426+
expect(manager.normalizeTileURL('mapbox://path.png/tile.jpg70', true)).toEqual(`http://path.png/v4/tile@2x.webp`);
439427
expect(
440428
manager.normalizeTileURL('mapbox://path.png/tile.png?access_token=foo', true)
441-
).toEqual(`http://path.png/v4/tile@2x.png?access_token=foo`);
429+
).toEqual(`http://path.png/v4/tile@2x.webp?access_token=foo`);
442430
});
443431

444432
test('.normalizeTileURL inserts @2x for 512 raster tiles on v4 of the api', () => {
445433
config.API_URL = 'http://path.png';
446434
config.REQUIRE_ACCESS_TOKEN = false;
447-
expect(manager.normalizeTileURL('mapbox://path.png/tile.png', false, 256)).toEqual(`http://path.png/v4/tile.png`);
448-
expect(manager.normalizeTileURL('mapbox://path.png/tile.png', false, 512)).toEqual(`http://path.png/v4/tile@2x.png`);
449-
expect(manager.normalizeTileURL("mapbox://raster/a.b/0/0/0.png", false, 256)).toEqual(`http://path.png/raster/v1/a.b/0/0/0.png`);
450-
expect(manager.normalizeTileURL("mapbox://raster/a.b/0/0/0.png", false, 512)).toEqual(`http://path.png/raster/v1/a.b/0/0/0.png`);
435+
expect(manager.normalizeTileURL('mapbox://path.png/tile.png', false, 256)).toEqual(`http://path.png/v4/tile.webp`);
436+
expect(manager.normalizeTileURL('mapbox://path.png/tile.png', false, 512)).toEqual(`http://path.png/v4/tile@2x.webp`);
437+
expect(manager.normalizeTileURL("mapbox://raster/a.b/0/0/0.png", false, 256)).toEqual(`http://path.png/raster/v1/a.b/0/0/0.webp`);
438+
expect(manager.normalizeTileURL("mapbox://raster/a.b/0/0/0.png", false, 512)).toEqual(`http://path.png/raster/v1/a.b/0/0/0.webp`);
451439
});
452440

453-
test('.normalizeTileURL replaces img extension with webp on supporting devices', () => {
454-
webpSupported.supported = true;
441+
test('.normalizeTileURL replaces img extension with webp', () => {
455442
config.API_URL = 'http://path.png';
456443
config.REQUIRE_ACCESS_TOKEN = false;
457444
expect(manager.normalizeTileURL('mapbox://path.png/tile.png')).toEqual(`http://path.png/v4/tile.webp`);
458445
expect(manager.normalizeTileURL('mapbox://path.png/tile.png32')).toEqual(`http://path.png/v4/tile.webp`);
459446
expect(manager.normalizeTileURL('mapbox://path.png/tile.jpg70')).toEqual(`http://path.png/v4/tile.webp`);
460447
expect(manager.normalizeTileURL('mapbox://path.png/tile.png?access_token=foo')).toEqual(`http://path.png/v4/tile.webp?access_token=foo`);
461-
webpSupported.supported = false;
462448
});
463449

464450
test('.normalizeTileURL ignores non-mapbox:// sources', () => {
@@ -506,16 +492,16 @@ describe("mapbox", () => {
506492
`https://api.mapbox.com/v4/a.b/0/0/0.pbf?sku=${manager._skuToken}&access_token=key`
507493
);
508494
expect(manager.normalizeTileURL("mapbox://tiles/a.b/0/0/0.png")).toEqual(
509-
`https://api.mapbox.com/v4/a.b/0/0/0.png?sku=${manager._skuToken}&access_token=key`
495+
`https://api.mapbox.com/v4/a.b/0/0/0.webp?sku=${manager._skuToken}&access_token=key`
510496
);
511497
expect(manager.normalizeTileURL("mapbox://tiles/a.b/0/0/0@2x.png")).toEqual(
512-
`https://api.mapbox.com/v4/a.b/0/0/0@2x.png?sku=${manager._skuToken}&access_token=key`
498+
`https://api.mapbox.com/v4/a.b/0/0/0@2x.webp?sku=${manager._skuToken}&access_token=key`
513499
);
514500
expect(manager.normalizeTileURL("mapbox://tiles/a.b,c.d/0/0/0.pbf")).toEqual(
515501
`https://api.mapbox.com/v4/a.b,c.d/0/0/0.pbf?sku=${manager._skuToken}&access_token=key`
516502
);
517503
expect(manager.normalizeTileURL("mapbox://raster/a.b/0/0/0.png")).toEqual(
518-
`https://api.mapbox.com/raster/v1/a.b/0/0/0.png?sku=${manager._skuToken}&access_token=key`
504+
`https://api.mapbox.com/raster/v1/a.b/0/0/0.webp?sku=${manager._skuToken}&access_token=key`
519505
);
520506
expect(manager.normalizeTileURL("mapbox://rasterarrays/a.b/0/0/0.mrt")).toEqual(
521507
`https://api.mapbox.com/rasterarrays/v1/a.b/0/0/0.mrt?sku=${manager._skuToken}&access_token=key`
@@ -526,13 +512,11 @@ describe("mapbox", () => {
526512

527513
config.API_URL = 'https://api.example.com/';
528514
expect(manager.normalizeTileURL("mapbox://tiles/a.b/0/0/0.png")).toEqual(
529-
`https://api.example.com/v4/a.b/0/0/0.png?sku=${manager._skuToken}&access_token=key`
515+
`https://api.example.com/v4/a.b/0/0/0.webp?sku=${manager._skuToken}&access_token=key`
530516
);
531517
expect(manager.normalizeTileURL("http://path")).toEqual("http://path");
532518
});
533519
});
534-
535-
webpSupported.supported = true;
536520
});
537521

538522
describe('TelemetryEvent', () => {

0 commit comments

Comments
 (0)