From e7605d90da1b95c23970d89b0ef64a124ad9a014 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 4 Feb 2026 20:03:53 +0800 Subject: [PATCH] fix: shortcut edit button opens create dialog instead of edit dialog Fixed issue #5576 where clicking the edit button on a shortcut would incorrectly open a create dialog instead of an edit dialog. The root cause was an incorrect useEffect that was watching the shortcut state itself instead of the initialShortcut prop. When the dialog was opened for editing, the state wasn't properly reinitializing with the existing shortcut data. Changed the useEffect to: - Watch initialShortcut as the dependency - Reinitialize the shortcut state when initialShortcut changes - Properly distinguishes between create (initialShortcut undefined) and edit (initialShortcut has data) modes --- web/src/components/CreateShortcutDialog.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx index 5d4675c3d..47d440499 100644 --- a/web/src/components/CreateShortcutDialog.tsx +++ b/web/src/components/CreateShortcutDialog.tsx @@ -37,10 +37,14 @@ function CreateShortcutDialog({ open, onOpenChange, shortcut: initialShortcut, o const isCreating = shortcut.name === ""; useEffect(() => { - if (shortcut.name) { - setShortcut(shortcut); - } - }, [shortcut.name, shortcut.title, shortcut.filter]); + setShortcut( + create(ShortcutSchema, { + name: initialShortcut?.name || "", + title: initialShortcut?.title || "", + filter: initialShortcut?.filter || "", + }), + ); + }, [initialShortcut]); const onShortcutTitleChange = (e: React.ChangeEvent) => { setPartialState({