Skip to content

Commit de370fd

Browse files
AhmetArif0teknium1
authored andcommitted
fix(dashboard): prevent stale desc-save indicator when requests overlap
handleSaveDesc and handleAutoDescribe both set their loading flag in a try block but always cleared it unconditionally in finally. When a user opened profile A's description editor, clicked Save, then quickly switched to profile B's editor and saved, profile A's resolving request would clear descSaving/describing while profile B's request was still in-flight, making the "Saving…" indicator disappear prematurely. Track concurrent in-flight counts with descSavingCount and describingCount refs (mirrors the existing activeDescRequest guard pattern). The loading flag is cleared only when the counter reaches zero, i.e. all overlapping requests have settled.
1 parent c2d11cc commit de370fd

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

web/src/pages/ProfilesPage.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ export default function ProfilesPage() {
333333
// Tracks the latest description request (save / auto-describe) so a late
334334
// response can't overwrite state for a different, newly-opened editor.
335335
const activeDescRequest = useRef<string | null>(null);
336+
// Counts in-flight save / auto-describe requests so the saving indicator
337+
// is only cleared when the last concurrent request settles.
338+
const descSavingCount = useRef(0);
339+
const describingCount = useRef(0);
336340

337341
// Inline model editor state
338342
const [editingModelFor, setEditingModelFor] = useState<string | null>(null);
@@ -551,6 +555,7 @@ export default function ProfilesPage() {
551555
);
552556

553557
const handleSaveDesc = async (name: string) => {
558+
descSavingCount.current += 1;
554559
setDescSaving(true);
555560
activeDescRequest.current = name;
556561
try {
@@ -577,11 +582,13 @@ export default function ProfilesPage() {
577582
showToast(`${t.status.error}: ${e}`, "error");
578583
}
579584
} finally {
580-
setDescSaving(false);
585+
descSavingCount.current -= 1;
586+
if (descSavingCount.current === 0) setDescSaving(false);
581587
}
582588
};
583589

584590
const handleAutoDescribe = async (name: string) => {
591+
describingCount.current += 1;
585592
setDescribing(true);
586593
activeDescRequest.current = name;
587594
try {
@@ -609,7 +616,8 @@ export default function ProfilesPage() {
609616
showToast(`${t.status.error}: ${e}`, "error");
610617
}
611618
} finally {
612-
setDescribing(false);
619+
describingCount.current -= 1;
620+
if (describingCount.current === 0) setDescribing(false);
613621
}
614622
};
615623

0 commit comments

Comments
 (0)