From eff497600c4d75be6c2115f4ac37f8842c669bbd Mon Sep 17 00:00:00 2001 From: Innei Date: Mon, 19 May 2025 20:28:07 +0800 Subject: [PATCH] fix(desktop): use ref for hotkey arguments to maintain state consistency Signed-off-by: Innei --- .../src/modules/command/hooks/use-register-hotkey.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/desktop/layer/renderer/src/modules/command/hooks/use-register-hotkey.ts b/apps/desktop/layer/renderer/src/modules/command/hooks/use-register-hotkey.ts index 86abb77df..89a19a151 100644 --- a/apps/desktop/layer/renderer/src/modules/command/hooks/use-register-hotkey.ts +++ b/apps/desktop/layer/renderer/src/modules/command/hooks/use-register-hotkey.ts @@ -1,3 +1,4 @@ +import { useRefValue } from "@follow/hooks" import { useEffect } from "react" import { tinykeys } from "tinykeys" @@ -27,6 +28,7 @@ export const useCommandHotkey = ({ args, options, }: RegisterHotkeyOptions) => { + const argsRef = useRefValue(args) useEffect(() => { if (!when) { return @@ -57,7 +59,7 @@ export const useCommandHotkey = ({ const command = getCommand(commandId) if (!command) return - + const args = argsRef.current if (Array.isArray(args)) { // It should be safe to spread the args here because we are checking if it is an array // @ts-expect-error - A spread argument must either have a tuple type or be passed to a rest parameter.ts(2556) @@ -76,7 +78,7 @@ export const useCommandHotkey = ({ }) return tinykeys(document.documentElement, keyMap) - }, [shortcut, commandId, when, args]) + }, [shortcut, commandId, when, argsRef, options?.forceInputElement]) } export const useCommandBinding = ({