From bb6487a70afc7fc002a776a1a4fd1f35e25e27fa Mon Sep 17 00:00:00 2001 From: Frank Song Date: Tue, 30 Jun 2026 10:56:48 +0800 Subject: [PATCH] fix(sidebar): remove menu-deleted sessions optimistically --- static/sessions.js | 6 +++++- tests/test_1466_sidebar_cancel_clarify.py | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/static/sessions.js b/static/sessions.js index c5ef9467..8763fbf2 100644 --- a/static/sessions.js +++ b/static/sessions.js @@ -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' )); diff --git a/tests/test_1466_sidebar_cancel_clarify.py b/tests/test_1466_sidebar_cancel_clarify.py index 2bac9203..d48cc302 100644 --- a/tests/test_1466_sidebar_cancel_clarify.py +++ b/tests/test_1466_sidebar_cancel_clarify.py @@ -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" + )