From 2ff2e713ecb50729a537c80004b08ccc3259416d Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Sun, 1 Nov 2026 12:22:35 +0100 Subject: [PATCH] fix: keep the sign-in page from creating the offline database again #523 --- lib/offline/__tests__/outbox.test.ts | 12 ++++++++++++ lib/offline/offline-mode.ts | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/offline/__tests__/outbox.test.ts b/lib/offline/__tests__/outbox.test.ts index 23fa53efd..4a00ee069 100644 --- a/lib/offline/__tests__/outbox.test.ts +++ b/lib/offline/__tests__/outbox.test.ts @@ -220,3 +220,15 @@ describe('signing out with unsent mail', () => { expect(await passSignOutGates('all')).toBe(true); }); }); + +describe('after a sign-out', () => { + it('starting offline mode on the sign-in page doesn\'t create the database again', async () => { + const stop = startOfflineMode(); + await new Promise((r) => setTimeout(r, 50)); + const { refreshQueueState, refreshUsage } = await import('../offline-mode'); + await refreshQueueState(); + await refreshUsage(); + stop(); + expect((await indexedDB.databases()).map((d) => d.name)).not.toContain('bulwark-offline'); + }); +}); diff --git a/lib/offline/offline-mode.ts b/lib/offline/offline-mode.ts index f438e87d1..548e0e56a 100644 --- a/lib/offline/offline-mode.ts +++ b/lib/offline/offline-mode.ts @@ -403,6 +403,12 @@ function decodeMimeWords(value: string): string { /** Reads the queue into the store, for the outbox view and the banner. */ export async function refreshQueueState(): Promise { if (!offlineSupported()) return; + // Nothing is kept for an account that hasn't it on; and opening the + // database would create it (on the sign-in page, after a sign-out). + if (useOfflineStore.getState().enabled.length === 0) { + useOfflineStore.setState({ outbox: [], pendingChanges: 0 }); + return; + } try { const { patches, outbox: entries } = await readQueue(); const rows: OutboxRow[] = entries.map((entry) => ({ @@ -421,7 +427,7 @@ export async function refreshQueueState(): Promise { } export async function refreshUsage(): Promise { - if (!offlineSupported()) return; + if (!offlineSupported() || useOfflineStore.getState().enabled.length === 0) return; try { useOfflineStore.setState({ usageBytes: (await cacheUsage()).total }); } catch {