Skip to content

Self-hosted AI workspace.

Python

Fix duplicate compare modal on repeated clicks (#491)

Cosmin Enache5b6f0ca31bc7
diff --git a/static/js/compare/index.js b/static/js/compare/index.js
index c6ed0f124..cd1d580b2 100644
--- a/static/js/compare/index.js
+++ b/static/js/compare/index.js
@@ -92,7 +92,9 @@ async function toggleMode() {
deactivate(true);
return false;
}
+ if (state._openingSelector) return false;
+ state._openingSelector = true;
try {
const confirmed = await showModelSelector();
if (!confirmed) return false;
@@ -104,6 +106,8 @@ async function toggleMode() {
} catch (err) {
console.error('Compare toggleMode error:', err);
return false;
+ } finally {
+ state._openingSelector = false;
}
}
diff --git a/static/js/compare/state.js b/static/js/compare/state.js
index 91d6807ed..7db77a89d 100644
--- a/static/js/compare/state.js
+++ b/static/js/compare/state.js
@@ -2,6 +2,7 @@
const state = {
API_BASE: '',
isActive: false,
+ _openingSelector: false, // prevents duplicate compare modals on rapid re-clicks
_streaming: false,
_blindMode: true,
_saveOnClose: false,
@@ -36,6 +37,7 @@ const state = {
/** Reset transient state to defaults — useful for clean restarts. */
export function reset() {
+ state._openingSelector = false;
state._streaming = false;
state._finishOrder = 0;
state._paneElapsed = [];
diff --git a/tests/test_compare_js.py b/tests/test_compare_js.py
index 3660ec526..61d397f89 100644
--- a/tests/test_compare_js.py
+++ b/tests/test_compare_js.py
@@ -59,6 +59,7 @@ def test_state_reset_preserves_config(node_available):
state.API_BASE = 'http://x';
state._blindMode = true;
state._parallel = false;
+ state._openingSelector = true;
state._streaming = true;
state._finishOrder = 7;
state._paneSessionIds = ['a','b'];
@@ -71,6 +72,7 @@ def test_state_reset_preserves_config(node_available):
api_base_sticky: state.API_BASE,
blind_sticky: state._blindMode,
parallel_sticky: state._parallel,
+ opening_cleared: state._openingSelector,
streaming_cleared: state._streaming,
finish_order_cleared: state._finishOrder,
session_ids_cleared: state._paneSessionIds.length,
@@ -85,6 +87,7 @@ def test_state_reset_preserves_config(node_available):
"api_base_sticky": "http://x",
"blind_sticky": True,
"parallel_sticky": False,
+ "opening_cleared": False,
"streaming_cleared": False,
"finish_order_cleared": 0,
"session_ids_cleared": 0,