ui: request persistent storage on startup (#31299)

Ask the browser to keep IndexedDB and localStorage data under storage
pressure, so conversations and settings are less likely to be evicted.

Assisted-by: Claude (Opus 5.5 Medium)
This commit is contained in:
Aleksander Grygier authored and GitHub committed 2026-10-29 10:14:53 +02:00
1 parent 3dd0f60bb4
commit b7cde589e4
1 file changed
+13
+13
View File
@@ -11,12 +11,25 @@ import { validateApiKey } from '$lib/utils/api-key-validation';
let startup: Promise<void> | null = null;
/** Ask the browser not to evict conversations and settings under storage pressure, best effort. */
async function requestPersistentStorage(): Promise<void> {
try {
if (!navigator.storage?.persist || (await navigator.storage.persisted())) return;
await navigator.storage.persist();
} catch {
// unsupported or denied, storage stays best-effort
}
}
export function initStores(): Promise<void> {
if (!browser) return Promise.resolve();
startup ??= (async () => {
await MigrationService.runAllMigrations();
void requestPersistentStorage();
settingsStore.initialize();
permissionsStore.initialize();
toolsStore.initialize();