fix(console-data): discard superseded load responses

Only the latest request may update a list, its error or loading state. Invalidate pending group loads after a save so an older response cannot restore stale configuration during persistent-console navigation.
This commit is contained in:
翅膀 committed 2026-10-17 14:31:12 +08:00
1 parent de84155e09
commit 05d025ef9c
4 files changed
+34 -11

No files matched your search

+8 -3
View File
@@ -5,19 +5,24 @@ export function useMetrics() {
const metrics = ref<DeliveryMetrics | null>(null);
const loading = ref(false);
const error = ref("");
// Bumped by every load, so only the latest request may land: Overview
// (all groups) and Stats (maybe one group) share this state.
let request = 0;
async function load(groupId?: string): Promise<void> {
const mine = ++request;
loading.value = true;
error.value = "";
needLogin.value = false;
try {
const qs = groupId ? `?groupId=${encodeURIComponent(groupId)}` : "";
const data = await apiFetch<{ metrics?: DeliveryMetrics }>(`/admin/api/metrics${qs}`);
metrics.value = data.metrics ?? null;
if (mine === request) metrics.value = data.metrics ?? null;
} catch (err) {
if (!needLogin.value) error.value = err instanceof Error ? err.message : String(err);
if (mine === request && !needLogin.value)
error.value = err instanceof Error ? err.message : String(err);
} finally {
loading.value = false;
if (mine === request) loading.value = false;
}
}