From 7c334a2e99da82c4369649682569d0245d6eca36 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Fri, 5 Jun 2026 12:13:21 -0500 Subject: [PATCH] fix(desktop): capture context name before awaits in handleDelete The reactive `context` prop is derived from the contexts store. After refreshContexts() removes the deleted context, the derived prop becomes undefined and reading context.name on the success line throws, showing a false "Failed to delete context" toast even though deletion succeeded. Hoist the name into a local before the awaits. --- .../src/lib/components/context/ContextSheet.svelte | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/desktop/src/renderer/src/lib/components/context/ContextSheet.svelte b/desktop/src/renderer/src/lib/components/context/ContextSheet.svelte index d0faef533..795d66f30 100644 --- a/desktop/src/renderer/src/lib/components/context/ContextSheet.svelte +++ b/desktop/src/renderer/src/lib/components/context/ContextSheet.svelte @@ -89,10 +89,13 @@ let confirmDeleteOpen = $state(false) async function handleDelete() { deleting = true + // Capture before awaits: refreshContexts() can null out the reactive + // `context` prop once this context is removed from the store. + const name = context.name try { - await contextDelete(context.name) + await contextDelete(name) await refreshContexts() - toasts.success(`Context "${context.name}" deleted`) + toasts.success(`Context "${name}" deleted`) open = false } catch (err) { toasts.error(`Failed to delete context: ${extractErrorMessage(err)}`)