Skip to content

Commit

Permalink
Prevent calling filter on an undefined property when service worker…
Browse files Browse the repository at this point in the history
… cache is empty
  • Loading branch information
p5nbTgip0r committed Sep 8, 2020
1 parent c0cfbd2 commit 108764b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion views/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@ self.addEventListener('fetch', function(evt) {
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((cacheNames) => {
if (!cacheNames) {
// Fallback to an empty array if cache is empty.
// This can occur if the prefetch fails.
return [];
}

return cacheNames.filter((cacheName) => CACHE !== cacheName);
}).then((unusedCaches) => {
//console.log('DESTROYING CACHE', unusedCaches.join(','));
// console.log('DESTROYING CACHE', unusedCaches.join(','));
return Promise.all(unusedCaches.map((unusedCache) => {
return caches.delete(unusedCache);
}));
Expand Down

0 comments on commit 108764b

Please sign in to comment.