Repository navigation
Open
Labels
Description
The cacheGet method calls back to validateOrFetch with a null error if window.caches is not available. From what I can tell, this could happen when the Cache API is not available at all or if a page is served over http and the Cache API is not usable.
mapbox-gl-js/src/util/tile_request_cache.js
Lines 72 to 81 in dd5dcd0
| export function cacheGet(request: Request, callback: (error: ?any, response: ?Response, fresh: ?boolean) => void) { | |
| if (!window.caches) return callback(null); | |
| window.caches.open(CACHE_NAME) | |
| .catch(callback) | |
| .then(cache => { | |
| cache.match(request, { ignoreSearch: true }) | |
| .catch(callback) | |
| .then(response => { |
In this case validateOrFetch still calls clones the response and attempts to place it in the cache.
Lines 127 to 131 in dd5dcd0
| window.fetch(request).then(response => { | |
| if (response.ok) { | |
| const cacheableResponse = cacheIgnoringSearch ? response.clone() : null; | |
| return finishRequest(response, cacheableResponse, requestTime); |
If it is known that window.caches is no available or usable, there is not need to clone the response or to load its contents:
Lines 144 to 152 in dd5dcd0
| const finishRequest = (response, cacheableResponse, requestTime) => { | |
| ( | |
| requestParameters.type === 'arrayBuffer' ? response.arrayBuffer() : | |
| requestParameters.type === 'json' ? response.json() : | |
| response.text() | |
| ).then(result => { | |
| if (cacheableResponse && requestTime) { | |
| // The response needs to be inserted into the cache after it has completely loaded. |
Activity
ahk commentedon Jul 8, 2019
Didn't a fix for this get merged into our most recent release as a late patch, or do I misunderstand the extent of the bug?
asheemmamoowala commentedon Dec 11, 2019
@ahk This was not addressed. I can still reproduce this in the latest
master.