Avoid restoring stale History snapshots

The History mutation handlers already wait for backend success before changing visible list state, so failure recovery does not need to write back the request-time snapshot. Removing that restoration avoids overwriting a newer refresh result, and delete success now updates from the latest list state instead of the closure captured before the IPC call.

Constraint: PR #343 review identified stale snapshot writes during overlapping refresh and mutation requests.\nRejected: Add action-wide locking | more UI state than needed once failed mutations stop writing stale snapshots.\nConfidence: high\nScope-risk: narrow\nTested: cd openless-all/app && git diff --check && npm run build\nNot-tested: Manual overlapping refresh/delete in the Tauri app.
This commit is contained in:
H-Chris233 committed 2026-05-08 08:50:47 +08:00
1 parent 1676557a75
commit f79a8dc089
1 file changed
+4 -12
+4 -12
View File
@@ -77,8 +77,6 @@ export function History() {
const onClear = async () => {
if (items.length === 0) return;
if (!confirm(t('history.confirmClear', { count: items.length }))) return;
const previousItems = items;
const previousSelectedId = selectedId;
setActionError(null);
try {
await clearHistory();
@@ -86,26 +84,20 @@ export function History() {
setSelectedId(null);
} catch (error) {
console.error('[history] failed to clear history', error);
setItems(previousItems);
setSelectedId(previousSelectedId);
setActionError(t('history.clearFailed', { err: errorMessage(error) }));
}
};
const onDelete = async () => {
if (!item) return;
const previousItems = items;
const previousSelectedId = selectedId;
const deletedId = item.id;
setActionError(null);
try {
await deleteHistoryEntry(item.id);
const nextItems = items.filter(s => s.id !== item.id);
setItems(nextItems);
setSelectedId(prev => (prev === item.id ? nextItems[0]?.id ?? null : prev));
await deleteHistoryEntry(deletedId);
setItems(prev => prev.filter(s => s.id !== deletedId));
setSelectedId(current => (current === deletedId ? null : current));
} catch (error) {
console.error('[history] failed to delete history entry', error);
setItems(previousItems);
setSelectedId(previousSelectedId);
setActionError(t('history.deleteFailed', { err: errorMessage(error) }));
}
};