fix(offline): cache sprite artwork once instead of on every sync

Each sync created a new artwork cache and re-fetched every sprite with no-cors. Opaque responses are padded to several MB each for storage quota, so a Living Dex grew to tens of GB, syncs never finished, and the offline copy could fail to save.

Artwork now lives in one cache per user that is topped up with only missing sprites, fetched with CORS so they count at their real size, with a per-fetch timeout. The offline copy is committed before any artwork, legacy per-sync artwork caches are removed first, and sprites shown online are cached on first load. Also requests persistent storage.
This commit is contained in:
Josh Creek
2026-09-14 15:22:05 +01:00
parent f2d8451c34
commit c3a3d43883
2 changed files with 76 additions and 39 deletions
+2
View File
@@ -158,6 +158,8 @@ export function startOfflineSync(getUserId: () => string | null): () => void {
}, 1_000);
};
// Best effort: ask the browser not to evict the offline artwork cache under storage pressure.
void navigator.storage?.persist?.().catch(() => undefined);
window.addEventListener(SYNC_EVENT, schedule);
window.addEventListener('online', schedule);
schedule();