From 09cd3630a829d8a593c4d3cdb9cf47b4caa40f06 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Thu, 23 Apr 2026 12:42:03 +1000 Subject: [PATCH] fix(staged): prevent duplicate action detection on re-navigation When a user clicks "Detect Actions", navigates away, and returns, the detection button appeared clickable again because the local `detecting` state was lost on unmount. Clicking it again would run a second detection in parallel, creating duplicate actions. Backend: add early-return guard in `detect_repo_actions` that rejects concurrent detection when `detecting_actions` is already true. Frontend: initialize `detecting` from the persisted `detectingActions` flag on context change, and subscribe to `repo-actions-detection` events so the UI stays in sync with in-flight detection across navigations. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/staged/src-tauri/src/actions/commands.rs | 3 ++ .../settings/ActionsSettingsPanel.svelte | 30 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/staged/src-tauri/src/actions/commands.rs b/apps/staged/src-tauri/src/actions/commands.rs index 14509caf9..19d6ab33e 100644 --- a/apps/staged/src-tauri/src/actions/commands.rs +++ b/apps/staged/src-tauri/src/actions/commands.rs @@ -116,6 +116,9 @@ pub async fn detect_repo_actions( let context = store .get_or_create_action_context(&github_repo, subpath.as_deref()) .map_err(|e| format!("Failed to get action context: {e}"))?; + if context.detecting_actions { + return Err("Detection is already in progress for this repository".into()); + } store .set_action_context_detecting(&context.id, true) .map_err(|e| format!("Failed to set detection status: {e}"))?; diff --git a/apps/staged/src/lib/features/settings/ActionsSettingsPanel.svelte b/apps/staged/src/lib/features/settings/ActionsSettingsPanel.svelte index 2f1d7b223..72f22812d 100644 --- a/apps/staged/src/lib/features/settings/ActionsSettingsPanel.svelte +++ b/apps/staged/src/lib/features/settings/ActionsSettingsPanel.svelte @@ -1,5 +1,5 @@