fix(ihm_client): double fallback IndexedDB si service worker.ready échoue
All checks were successful
Build and Push Docker image (ext) / docker (push) Successful in 52s

This commit is contained in:
4NK CI Bot 2025-09-18 16:16:48 +00:00
parent c21eb9170a
commit a40416a248

View File

@ -308,8 +308,28 @@ export class Database {
// Check if the service worker is active
if (!this.serviceWorkerRegistration) {
try {
// console.warn('Service worker registration is not ready. Waiting...');
this.serviceWorkerRegistration = await navigator.serviceWorker.ready;
} catch (error) {
// Si le service worker n'est pas disponible, fallback vers IndexedDB direct
console.warn('Service worker not available, falling back to direct IndexedDB');
try {
const db = await this.getDb();
const tx = (db as any).transaction(payload.storeName, 'readwrite');
const store = tx.objectStore(payload.storeName);
if (payload.key) {
await store.put(payload.object, payload.key);
} else {
await store.put(payload.object);
}
resolve();
return;
} catch (dbError: any) {
reject(new Error(dbError?.message || 'IndexedDB write failed'));
return;
}
}
}
const activeWorker = await this.waitForServiceWorkerActivation(this.serviceWorkerRegistration);