-
-
Notifications
You must be signed in to change notification settings - Fork 38
fix: Add guard to normalizeKeyName() #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KevinVandy
merged 5 commits into
TanStack:main
from
ryck:feat-add-guard-normalizeKeyName
Mar 31, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/hotkeys': patch | ||
| --- | ||
|
|
||
| fix: normalizeKeyName null check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π§© Analysis chain
π Script executed:
Repository: TanStack/hotkeys
Length of output: 5912
π Script executed:
Repository: TanStack/hotkeys
Length of output: 2317
π Script executed:
Repository: TanStack/hotkeys
Length of output: 1669
π Script executed:
Repository: TanStack/hotkeys
Length of output: 1037
Line 460: Avoid returning
''for invalid keys; usenulland require callers to short-circuit.The guard prevents a crash but lets invalid events (with
undefinedevent.key) flow as empty-string sentinels into downstream stateful paths. For example, inkey-state-tracker.ts:113β116, the empty string gets added directly to#heldKeysSetand#heldCodesMapwith no validation. Returningnullinstead makes the invalid state explicit and forces callers to handle it.π€ Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used '' so the return type stays
string, but happy to be corrected...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π§© Analysis chain
Good question β let me look at the actual downstream call sites to give you a concrete recommendation.
π Script executed:
Length of output: 15632
@ryckKeepingstringis the right call here β changing tostring | nullwould cascade through 7+ call sites across the codebase. The''sentinel is actually fine for most of them:''match.ts:66eventKey.length === 1is false β safely skippedhotkey-manager.ts:638''won't match any registered key β harmlessparse.ts:267ParsedHotkeywithkey: ''β no hotkey will match itsequence-manager.ts:442,recorder-chord.ts:17isModifierKey('')β false, minor but non-criticalThe one concrete problem is
key-state-tracker.tslines 113β116, where no guard exists and''would be stored directly into#heldKeysSetand#heldCodesMap:The fix is simple β a single guard at that call site, keeping your
stringreturn type intact:So: your
normalizeKeyNameguard is correct, and''is the right sentinel value. The remaining gap is just this one guard inkey-state-tracker.ts.