fix: preserve offline workflows across activation (Closes #977)
CI / lint (pull_request) Successful in 2m3s
CI / build-release (pull_request) Successful in 6s
CI / browser-journey (pull_request) Failing after 1m43s
CI / release-candidate (pull_request) Has been skipped

This commit is contained in:
timmy committed 2026-08-16 17:25:48 +00:00
1 parent 5217f6a86f
commit d80091d244
11 files changed
+84 -30

No files matched your search

+19 -5
View File
@@ -1,7 +1,7 @@
const BASE = new URL('./', self.location.href).pathname;
importScripts(BASE + 'static/private-data-registry.js');
importScripts(BASE + 'static/background-issue-sync.js');
const CACHE = 'stackchain-dashboard-shell-v113';
const CACHE = 'stackchain-dashboard-shell-v114';
const OFFLINE_LEASE_URL = new URL(BASE + '__offline-session-lease', self.location.origin).href;
const OUTAGE_STATUSES = new Set([500, 502, 503, 504]);
const NAVIGATION_TIMEOUT_MS = self.__STACKCHAIN_NAVIGATION_TIMEOUT_MS || 4000;
@@ -366,15 +366,29 @@ self.addEventListener('install', event => {
event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(SHELL)).then(() => self.skipWaiting()));
});
async function warmOptionalFeature(cache, staleCacheNames, asset) {
for (const cacheName of staleCacheNames) {
const staleCache = await caches.open(cacheName);
const cached = await staleCache.match(asset);
if (cached) {
await cache.put(asset, cached);
return;
}
}
await cache.add(asset);
}
self.addEventListener('activate', event => {
event.waitUntil((async () => {
const keys = await caches.keys();
await Promise.all(
keys.filter(key => key.startsWith('stackchain-dashboard-') && key !== CACHE)
.map(key => caches.delete(key))
const staleCacheNames = keys.filter(
key => key.startsWith('stackchain-dashboard-') && key !== CACHE
);
const cache = await caches.open(CACHE);
await Promise.allSettled(OPTIONAL_FEATURES.map(asset => cache.add(asset)));
await Promise.allSettled(
OPTIONAL_FEATURES.map(asset => warmOptionalFeature(cache, staleCacheNames, asset))
);
await Promise.all(staleCacheNames.map(key => caches.delete(key)));
await self.clients.claim();
})());
});