From 7b536189210ffaf91d73849b61363394d4427584 Mon Sep 17 00:00:00 2001 From: Ferdinand Urban Date: Wed, 3 Jun 2026 12:21:23 +0000 Subject: [PATCH] fix(state): surface localStorage save failures instead of silent loss (#4) saveState now logs a console.warn on failure and alerts the user once per session (storage full/unavailable) so they can export their data and avoid silent data loss. Co-Authored-By: Claude Opus 4.8 --- js/app.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/app.js b/js/app.js index 6e9bc26..3c10656 100644 --- a/js/app.js +++ b/js/app.js @@ -31,6 +31,7 @@ try { } // Call after any state mutation to persist automatically +let storageWarned = false; export function saveState() { try { localStorage.setItem(STORAGE_KEY, JSON.stringify({ @@ -39,8 +40,15 @@ export function saveState() { history: state.history, settings: state.settings })); - } catch { - // Storage full or unavailable — silently ignore + } catch (e) { + // Storage full or unavailable — warn once so the user can react (export data) + console.warn('Speichern in localStorage fehlgeschlagen:', e); + if (!storageWarned) { + storageWarned = true; + alert('Achtung: Änderungen konnten nicht gespeichert werden ' + + '(Speicher voll oder nicht verfügbar). Bitte exportiere deine Daten ' + + 'als JSON, um Datenverlust zu vermeiden.'); + } } }