From 4f343fdb8f384e06ec019b183ce1060031dd3e78 Mon Sep 17 00:00:00 2001 From: Louis Knight-Webb Date: Thu, 25 Sep 2025 19:53:32 +0100 Subject: [PATCH] fix multi-shortcut issue (#856) --- frontend/src/keyboard/useSemanticKey.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/keyboard/useSemanticKey.ts b/frontend/src/keyboard/useSemanticKey.ts index 2e5ca0e6..b21dc0c8 100644 --- a/frontend/src/keyboard/useSemanticKey.ts +++ b/frontend/src/keyboard/useSemanticKey.ts @@ -1,3 +1,4 @@ +import { useMemo } from 'react'; import { useKeyboardShortcut, type KeyboardShortcutOptions, @@ -33,8 +34,13 @@ export function createSemanticHook(action: A) { // Use 'when' as alias for 'enabled' if provided const isEnabled = when !== undefined ? when : enabled; - const keys = getKeysFor(action, scope); - const binding = getBindingFor(action, scope); + // Memoize to get stable array references and prevent unnecessary re-registrations + const keys = useMemo(() => getKeysFor(action, scope), [action, scope]); + + const binding = useMemo( + () => getBindingFor(action, scope), + [action, scope] + ); const keyboardShortcutOptions: KeyboardShortcutOptions = {}; if (enableOnContentEditable !== undefined)