fix: keep the sign-in page from creating the offline database again #523

This commit is contained in:
Linus Rath
2026-11-01 12:22:35 +01:00
parent 308956d37f
commit 2ff2e713ec
2 changed files with 19 additions and 1 deletions
+12
View File
@@ -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');
});
});
+7 -1
View File
@@ -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<void> {
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<void> {
}
export async function refreshUsage(): Promise<void> {
if (!offlineSupported()) return;
if (!offlineSupported() || useOfflineStore.getState().enabled.length === 0) return;
try {
useOfflineStore.setState({ usageBytes: (await cacheUsage()).total });
} catch {