From 9b666cfe0893cd250ae27dfec6d9a8da81e3d3e4 Mon Sep 17 00:00:00 2001 From: ryzmae Date: Sun, 1 Mar 2026 22:14:59 +0100 Subject: [PATCH 1/6] refactor: Remove state reset in HotkeyRecorder destroy method Because it already does this in the stop function itself --- packages/hotkeys/src/recorder.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/hotkeys/src/recorder.ts b/packages/hotkeys/src/recorder.ts index 048ad1c..408878e 100644 --- a/packages/hotkeys/src/recorder.ts +++ b/packages/hotkeys/src/recorder.ts @@ -258,9 +258,5 @@ export class HotkeyRecorder { */ destroy(): void { this.stop() - this.store.setState(() => ({ - isRecording: false, - recordedHotkey: null, - })) } } From 81415aebbf74397fe0cb973f95fe1f0efdba5b15 Mon Sep 17 00:00:00 2001 From: ryzmae Date: Sun, 1 Mar 2026 22:20:24 +0100 Subject: [PATCH 2/6] refactor: Use IDLE_STATE for initial store state in HotkeyRecorder --- packages/hotkeys/src/recorder.ts | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/packages/hotkeys/src/recorder.ts b/packages/hotkeys/src/recorder.ts index 408878e..8e62ed0 100644 --- a/packages/hotkeys/src/recorder.ts +++ b/packages/hotkeys/src/recorder.ts @@ -18,6 +18,11 @@ export interface HotkeyRecorderState { recordedHotkey: Hotkey | null } +/** + * Initial idle state for the recorder, used when not recording. + */ +const IDLE_STATE: HotkeyRecorderState = { isRecording: false, recordedHotkey: null } + /** * Options for configuring a HotkeyRecorder instance. */ @@ -74,10 +79,7 @@ export class HotkeyRecorder { * The TanStack Store instance containing the recorder state. * Use this to subscribe to state changes or access current state. */ - readonly store: Store = new Store({ - isRecording: false, - recordedHotkey: null, - }) + readonly store: Store = new Store(IDLE_STATE) #keydownHandler: ((event: KeyboardEvent) => void) | null = null #options: HotkeyRecorderOptions @@ -113,10 +115,7 @@ export class HotkeyRecorder { } // Update store state - this.store.setState(() => ({ - isRecording: true, - recordedHotkey: null, - })) + this.store.setState(() => (IDLE_STATE)) // Create keydown handler const handler = (event: KeyboardEvent) => { @@ -172,10 +171,7 @@ export class HotkeyRecorder { } // Update store state immediately - this.store.setState(() => ({ - isRecording: false, - recordedHotkey: finalHotkey, - })) + this.store.setState(() => (IDLE_STATE)) // Call callback AFTER listener is removed and state is set this.#options.onRecord(finalHotkey) @@ -199,10 +195,7 @@ export class HotkeyRecorder { } // Update store state - this.store.setState(() => ({ - isRecording: false, - recordedHotkey: null, - })) + this.store.setState(() => (IDLE_STATE)) } /** @@ -219,10 +212,7 @@ export class HotkeyRecorder { } // Update store state - this.store.setState(() => ({ - isRecording: false, - recordedHotkey: null, - })) + this.store.setState(() => (IDLE_STATE)) // Call cancel callback this.#options.onCancel?.() From c7a5b836456462322795c2f3ed70d93f2cb4a6e3 Mon Sep 17 00:00:00 2001 From: ryzmae Date: Sun, 1 Mar 2026 22:25:35 +0100 Subject: [PATCH 3/6] chore: add changeset --- .changeset/wild-snails-retire.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wild-snails-retire.md diff --git a/.changeset/wild-snails-retire.md b/.changeset/wild-snails-retire.md new file mode 100644 index 0000000..ce75b6e --- /dev/null +++ b/.changeset/wild-snails-retire.md @@ -0,0 +1,5 @@ +--- +'@tanstack/hotkeys': patch +--- + +Remove redundant `setState` in `destroy()` and share a single `IDLE_STATE` constant across `stop()` and `cancel()` From 4d1f3150b4a7ae0492d39a08581497fc987706bd Mon Sep 17 00:00:00 2001 From: ryzmae Date: Sun, 1 Mar 2026 22:32:31 +0100 Subject: [PATCH 4/6] refactor: update store state to set isRecording to true in HotkeyRecorder --- packages/hotkeys/src/recorder.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/hotkeys/src/recorder.ts b/packages/hotkeys/src/recorder.ts index 8e62ed0..4644b52 100644 --- a/packages/hotkeys/src/recorder.ts +++ b/packages/hotkeys/src/recorder.ts @@ -115,7 +115,10 @@ export class HotkeyRecorder { } // Update store state - this.store.setState(() => (IDLE_STATE)) + this.store.setState(() => ({ + isRecording: true, + recordedHotkey: null, + })) // Create keydown handler const handler = (event: KeyboardEvent) => { From 48da959720cb3326411fdb345de2dd60af2dc0ea Mon Sep 17 00:00:00 2001 From: ryzmae Date: Sun, 1 Mar 2026 22:32:57 +0100 Subject: [PATCH 5/6] refactor: update store state to set recordedHotkey in HotkeyRecorder --- packages/hotkeys/src/recorder.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/hotkeys/src/recorder.ts b/packages/hotkeys/src/recorder.ts index 4644b52..086e77b 100644 --- a/packages/hotkeys/src/recorder.ts +++ b/packages/hotkeys/src/recorder.ts @@ -174,7 +174,10 @@ export class HotkeyRecorder { } // Update store state immediately - this.store.setState(() => (IDLE_STATE)) + this.store.setState(() => ({ + isRecording: false, + recordedHotkey: finalHotkey, + })) // Call callback AFTER listener is removed and state is set this.#options.onRecord(finalHotkey) From bfd855f8e9d7b06b3a79a406d8d09b0c8a6ffe74 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 6 Mar 2026 18:19:00 +0000 Subject: [PATCH 6/6] ci: apply automated fixes --- docs/reference/classes/HotkeyRecorder.md | 16 ++++++++-------- .../interfaces/HotkeyRecorderOptions.md | 8 ++++---- packages/hotkeys/src/recorder.ts | 13 +++++++++---- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/docs/reference/classes/HotkeyRecorder.md b/docs/reference/classes/HotkeyRecorder.md index d3c8bab..8d9237d 100644 --- a/docs/reference/classes/HotkeyRecorder.md +++ b/docs/reference/classes/HotkeyRecorder.md @@ -5,7 +5,7 @@ title: HotkeyRecorder # Class: HotkeyRecorder -Defined in: [recorder.ts:72](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L72) +Defined in: [recorder.ts:80](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L80) Framework-agnostic class for recording keyboard shortcuts. @@ -54,7 +54,7 @@ unsubscribe() new HotkeyRecorder(options): HotkeyRecorder; ``` -Defined in: [recorder.ts:86](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L86) +Defined in: [recorder.ts:93](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L93) #### Parameters @@ -74,7 +74,7 @@ Defined in: [recorder.ts:86](https://github.com/TanStack/hotkeys/blob/main/packa readonly store: Store; ``` -Defined in: [recorder.ts:77](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L77) +Defined in: [recorder.ts:85](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L85) The TanStack Store instance containing the recorder state. Use this to subscribe to state changes or access current state. @@ -87,7 +87,7 @@ Use this to subscribe to state changes or access current state. cancel(): void; ``` -Defined in: [recorder.ts:214](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L214) +Defined in: [recorder.ts:218](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L218) Cancel recording without saving. @@ -106,7 +106,7 @@ the onCancel callback if provided. destroy(): void; ``` -Defined in: [recorder.ts:259](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L259) +Defined in: [recorder.ts:260](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L260) Clean up event listeners and reset state. @@ -125,7 +125,7 @@ all event listeners are properly removed. setOptions(options): void; ``` -Defined in: [recorder.ts:95](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L95) +Defined in: [recorder.ts:102](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L102) Updates the recorder options, including callbacks. This allows framework adapters to sync callback changes without recreating the recorder. @@ -148,7 +148,7 @@ This allows framework adapters to sync callback changes without recreating the r start(): void; ``` -Defined in: [recorder.ts:109](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L109) +Defined in: [recorder.ts:116](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L116) Start recording a new hotkey. @@ -168,7 +168,7 @@ a valid hotkey is recorded, Escape is pressed, or stop/cancel is called. stop(): void; ``` -Defined in: [recorder.ts:194](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L194) +Defined in: [recorder.ts:201](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L201) Stop recording (same as cancel, but doesn't call onCancel). diff --git a/docs/reference/interfaces/HotkeyRecorderOptions.md b/docs/reference/interfaces/HotkeyRecorderOptions.md index 24e67df..fce18ff 100644 --- a/docs/reference/interfaces/HotkeyRecorderOptions.md +++ b/docs/reference/interfaces/HotkeyRecorderOptions.md @@ -5,7 +5,7 @@ title: HotkeyRecorderOptions # Interface: HotkeyRecorderOptions -Defined in: [recorder.ts:24](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L24) +Defined in: [recorder.ts:32](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L32) Options for configuring a HotkeyRecorder instance. @@ -17,7 +17,7 @@ Options for configuring a HotkeyRecorder instance. optional onCancel: () => void; ``` -Defined in: [recorder.ts:28](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L28) +Defined in: [recorder.ts:36](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L36) Optional callback when recording is cancelled (Escape pressed) @@ -33,7 +33,7 @@ Optional callback when recording is cancelled (Escape pressed) optional onClear: () => void; ``` -Defined in: [recorder.ts:30](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L30) +Defined in: [recorder.ts:38](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L38) Optional callback when shortcut is cleared (Backspace/Delete pressed) @@ -49,7 +49,7 @@ Optional callback when shortcut is cleared (Backspace/Delete pressed) onRecord: (hotkey) => void; ``` -Defined in: [recorder.ts:26](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L26) +Defined in: [recorder.ts:34](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/recorder.ts#L34) Callback when a hotkey is successfully recorded diff --git a/packages/hotkeys/src/recorder.ts b/packages/hotkeys/src/recorder.ts index 086e77b..109796f 100644 --- a/packages/hotkeys/src/recorder.ts +++ b/packages/hotkeys/src/recorder.ts @@ -21,7 +21,10 @@ export interface HotkeyRecorderState { /** * Initial idle state for the recorder, used when not recording. */ -const IDLE_STATE: HotkeyRecorderState = { isRecording: false, recordedHotkey: null } +const IDLE_STATE: HotkeyRecorderState = { + isRecording: false, + recordedHotkey: null, +} /** * Options for configuring a HotkeyRecorder instance. @@ -79,7 +82,9 @@ export class HotkeyRecorder { * The TanStack Store instance containing the recorder state. * Use this to subscribe to state changes or access current state. */ - readonly store: Store = new Store(IDLE_STATE) + readonly store: Store = new Store( + IDLE_STATE, + ) #keydownHandler: ((event: KeyboardEvent) => void) | null = null #options: HotkeyRecorderOptions @@ -201,7 +206,7 @@ export class HotkeyRecorder { } // Update store state - this.store.setState(() => (IDLE_STATE)) + this.store.setState(() => IDLE_STATE) } /** @@ -218,7 +223,7 @@ export class HotkeyRecorder { } // Update store state - this.store.setState(() => (IDLE_STATE)) + this.store.setState(() => IDLE_STATE) // Call cancel callback this.#options.onCancel?.()