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 <noreply@anthropic.com>
This commit is contained in:
1 parent
065876ced4
commit
7b53618921
1 file changed
+10
-2
@@ -31,6 +31,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call after any state mutation to persist automatically
|
// Call after any state mutation to persist automatically
|
||||||
|
let storageWarned = false;
|
||||||
export function saveState() {
|
export function saveState() {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
||||||
@@ -39,8 +40,15 @@ export function saveState() {
|
|||||||
history: state.history,
|
history: state.history,
|
||||||
settings: state.settings
|
settings: state.settings
|
||||||
}));
|
}));
|
||||||
} catch {
|
} catch (e) {
|
||||||
// Storage full or unavailable — silently ignore
|
// 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.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user