fix(notes): dedupe quota failure toasts during autosave

Debounced draft flushes can hit QuotaExceededError repeatedly; rate-limit
the error toast so users are not spammed every 300ms.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
This commit is contained in:
Cursor Agentand陈大猫 committed 2026-08-07 09:55:30 +00:00
1 parent f03c9f4e49
commit 3c81e42167
2 files changed
+12 -4

No files matched your search

+10 -4
View File
@@ -288,6 +288,7 @@ export const useVaultState = () => {
const hostsRef = useRef<Host[]>([]);
const notesRef = useRef<VaultNote[]>([]);
const noteGroupsRef = useRef<string[]>([]);
const notesPersistFailureNotifiedAtRef = useRef(0);
customGroupsRef.current = customGroups;
managedSourcesRef.current = managedSources;
hostsRef.current = hosts;
@@ -611,10 +612,15 @@ export const useVaultState = () => {
setNotes(cleaned);
publishNotesSnapshot({ notes: cleaned, noteGroups: noteGroupsRef.current });
if (!persisted) {
notify.error(
"Notes could not be saved. Free some local storage space and try again.",
"Notes",
);
const now = Date.now();
// Debounced autosave can hit quota repeatedly; avoid toast spam.
if (now - notesPersistFailureNotifiedAtRef.current > 10_000) {
notesPersistFailureNotifiedAtRef.current = now;
notify.error(
"Notes could not be saved. Free some local storage space and try again.",
"Notes",
);
}
return false;
}
return true;
@@ -50,4 +50,6 @@ test("useVaultState updateNotes surfaces storage write failures", () => {
assert.match(source, /notify\.error/);
assert.match(source, /!persisted|persisted === false/);
assert.match(source, /return false/);
assert.match(source, /notesPersistFailureNotifiedAtRef/);
assert.match(source, /10_000/);
});