fix(sidebar): remove menu-deleted sessions optimistically

This commit is contained in:
Frank Song 2026-06-30 10:56:48 +08:00
parent ae8f42ec13
commit bb6487a70a
2 changed files with 14 additions and 2 deletions

View file

@ -3899,7 +3899,11 @@ function _openSessionActionMenu(session, anchorEl){
ICONS.trash,
async()=>{
closeSessionActionMenu();
await deleteSession(session.session_id);
// Menu Delete has no swipe/removal animation to wait for. Pass an
// immediate beforeDelete hook so deleteSession() removes the sidebar row
// optimistically while slow backend cleanup (/api/session/delete,
// state.db/FTS/journal cleanup) continues.
await deleteSession(session.session_id,()=>Promise.resolve());
},
'danger'
));

View file

@ -36,7 +36,7 @@ class TestSidebarCancelAction:
assert "cancelSessionStream(session)" in body, (
"running sidebar sessions must expose a stop action that cancels that session"
)
assert body.find("cancelSessionStream(session)") < body.find("deleteSession(session.session_id)"), (
assert body.find("cancelSessionStream(session)") < body.find("deleteSession(session.session_id"), (
"stop action should appear before destructive delete action"
)
@ -91,3 +91,11 @@ class TestSidebarCancelAction:
second = body.find("t('session_delete')")
assert first > 0 and second > 0, "menu actions should still include duplicate/delete nodes"
assert first < second, "duplicate action should render before delete action"
def test_menu_delete_optimistically_removes_sidebar_row_before_backend_cleanup(self):
"""Context-menu Delete should not keep the row visible while slow DELETE cleanup runs."""
body = _function_body(SESSIONS_JS, "_openSessionActionMenu", 8400)
assert "await deleteSession(session.session_id,()=>Promise.resolve());" in body, (
"menu Delete must pass an immediate beforeDelete hook so deleteSession() "
"optimistically removes the sidebar row before awaiting /api/session/delete"
)