Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
fix: cancel raster tile requests when deck.gl aborts the tile (#3715)
Javier Andrés García34921e2d43d1
diff --git a/src/layers/src/raster-tile/gpu-utils.ts b/src/layers/src/raster-tile/gpu-utils.tsindex 3169f7477..0d8db3fde 100644--- a/src/layers/src/raster-tile/gpu-utils.ts+++ b/src/layers/src/raster-tile/gpu-utils.ts@@ -305,7 +305,9 @@ export async function loadNpyArray(const response = (await load(request.url, NPYLoader as Loader<NPYLoaderResponse>, {npy: npyOptions,- fetch: options?.fetch+ // Without the signal the browser keeps downloading a tile deck.gl has+ // already abandoned, and it queues ahead of the tiles still in view.+ fetch: options?.fetch ?? {signal: request.options?.signal}})) as NPYLoaderResponse;if (!response || !response.data || request.options.signal?.aborted) {diff --git a/test/browser/layer-tests/raster-tile-layer-specs.js b/test/browser/layer-tests/raster-tile-layer-specs.jsindex fa5e62a7f..20ae981b9 100644--- a/test/browser/layer-tests/raster-tile-layer-specs.js+++ b/test/browser/layer-tests/raster-tile-layer-specs.js@@ -14,6 +14,7 @@ import {import {RasterWebGL} from '@kepler.gl/deckgl-layers';import {parseRasterMetadata} from '@kepler.gl/table';import {testCreateCases} from 'test/helpers/layer-utils';+import {loadNpyArray} from '../../../src/layers/src/raster-tile/gpu-utils';const {RasterTileLayer} = KeplerGlLayers;@@ -75,6 +76,49 @@ const createRenderOpts = (dataset, mapState = {dragRotate: false, bearing: 0, piinteractionConfig: {tooltip: {enabled: true}}});+test('#RasterTileLayer -> tile requests carry the abort signal', async t => {+ // deck.gl aborts a tile that scrolls out of view by firing the AbortSignal it+ // puts in the request. The signal has to reach the fetch, or the browser keeps+ // downloading tiles nobody will draw and they queue ahead of the ones in view.+ const controller = new AbortController();+ const requests = [];+ const originalFetch = globalThis.fetch;++ globalThis.fetch = (url, init) => {+ requests.push(init);+ return Promise.resolve({+ ok: true,+ status: 200,+ url: String(url),+ headers: new Map(),+ arrayBuffer: async () => new ArrayBuffer(8)+ });+ };++ try {+ await loadNpyArray(+ {+ url: 'https://example.com/tile.npy',+ rasterServerUrl: 'https://example.com',+ options: {signal: controller.signal},+ rasterServerMaxRetries: 0+ },+ true+ );+ } finally {+ globalThis.fetch = originalFetch;+ }++ t.equal(requests.length, 1, 'should issue one tile request');+ t.equal(+ requests[0]?.signal,+ controller.signal,+ 'the tile request should carry the abort signal deck.gl provided'+ );++ t.end();+});+test('#RasterTileLayer -> constructor and basic properties', t => {const TEST_CASES = {CREATE: [