Skip to content

A local-first personal finance app

[AI] Request persistent storage so browsers do not evict local budget data (#8667)

Matiss Janis Aboltins4dedf88e58a5
diff --git a/packages/desktop-client/src/browser-preload.js b/packages/desktop-client/src/browser-preload.js
index 0b44f70326..66905da0c7 100644
--- a/packages/desktop-client/src/browser-preload.js
+++ b/packages/desktop-client/src/browser-preload.js
@@ -58,6 +58,25 @@ const worker = startBrowserBackend({
isOpenIdCallback,
});
+// Ask the browser to exclude this origin's storage (the local budget database
+// in IndexedDB) from automatic eviction under storage pressure. Without this,
+// the browser is allowed to silently delete all local data, forcing a full
+// re-download of the budget and losing any changes not yet synced.
+if (navigator.storage?.persist) {
+ void navigator.storage
+ .persist()
+ .then(persisted => {
+ if (!persisted) {
+ console.warn(
+ 'Persistent storage was not granted; the browser may evict local budget data under storage pressure.',
+ );
+ }
+ })
+ .catch(error => {
+ console.warn('Persistent storage request failed:', error);
+ });
+}
+
let isUpdateReadyForDownload = false;
let markUpdateReadyForDownload;
const isUpdateReadyForDownloadPromise = new Promise(resolve => {
diff --git a/upcoming-release-notes/request-persistent-storage.md b/upcoming-release-notes/request-persistent-storage.md
new file mode 100644
index 0000000000..69bf501189
--- /dev/null
+++ b/upcoming-release-notes/request-persistent-storage.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [MatissJanis]
+---
+
+Ask the browser to protect local budget data from being automatically deleted when disk space runs low