Repository navigation
fix(hotkeys): Validate adapter hotkeys only in register - #322
Conversation
createHotkeyBindings repeated checks that HotkeyManager.register already
does: option defaults, rejecting empty, nullish, null-target, and invalid
hotkeys with a dev warning, and dropping options for the other kind.
Adapters now pass hotkeys through and register is the one place that
validates.
- String hotkeys register as written from every entry point. Adapters
used to normalize them first, so useHotkey('Control+S') listed Mod+S
on Windows while register listed Control+S.
- Chord objects register in normalized form everywhere, as the framework
docs promise for context.hotkey, and createHotkeyChordHandler reports
them the same way.
- A bracketed key that isn't a code, such as 'Control+[1]', no longer
throws in adapters.
- register warns about each invalid hotkey once per manager, so adapters
that register again after a remount or target change don't repeat it.
🦋 Changeset detectedLatest commit: 7c0ab0b The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
🚀 Changeset Version Preview1 package(s) bumped directly, 17 bumped as dependents. 🟩 Patch bumps
|
@tanstack/alpine-hotkeys
@tanstack/angular-hotkeys
@tanstack/angular-hotkeys-devtools
@tanstack/ember-hotkeys
@tanstack/hotkeys
@tanstack/hotkeys-devtools
@tanstack/lit-hotkeys
@tanstack/octane-hotkeys
@tanstack/preact-hotkeys
@tanstack/preact-hotkeys-devtools
@tanstack/react-hotkeys
@tanstack/react-hotkeys-devtools
@tanstack/solid-hotkeys
@tanstack/solid-hotkeys-devtools
@tanstack/svelte-hotkeys
@tanstack/svelte-hotkeys-devtools
@tanstack/vue-hotkeys
@tanstack/vue-hotkeys-devtools
commit: |
zizmor failed because the pinned commit no longer matched the main branch named in each pin's version comment. The actions under .github are unchanged between the two commits.
|
🎉 This PR has been released! Thank you for your contribution! |
🎯 Changes
createHotkeyBindingsrepeated work thatHotkeyManager.registeralready does. It merged default options, skipped nullish, empty, and null-target hotkeys, parsed each hotkey to reject steps without a key (with its own dev warning), and droppedtimeoutfrom chords andrequireResetfrom sequences. Now it only merges option layers and reconciles registrations, andregisteris the one place that validates.registration.hotkey. A string hotkey registers as written from every entry point. Adapters used to normalize first, souseHotkey('Control+S')on Windows listedMod+Swhileregister('Control+S')listedControl+S. A chord object registers in normalized form everywhere ({ key: 'K', mod: true }becomesMod+K), as the framework guides promise forcontext.hotkey. Before, core storedMeta+Kon macOS.createHotkeyChordHandlerreports chord objects the same way. A parsed chord keeps its formatted form.'Control+[1]'no longer throws in adapters. The adapter re-parsed its own parse result, which throws for a bracketed key that isn't a code.registeralways accepted it.registerkeeps a dev-only set of hotkeys it has warned about. Adapters retry an unregistered definition on each update, so a remount, a target change, or Lit'sdestroy()and reconnect doesn't repeat the warning. Retrying also means a definition skipped while there was nodocumentregisters on a later update.sensible-defaults.mdno longer saysctrl+sis stored asMod+S. The generated reference pages pick up the newcreateHotkeyBindingsdoc comment and shifted line numbers.TanStack/configaction pins move toade00ae6, the currentmaintheir version comments name, so zizmor passes. Nothing under.githubchanged in that repository between the two commits.The adapter no longer parses every hotkey on every update.
Notes
The adapter keys each registration by the hotkey as written, so switching a call site between equivalent spellings re-registers instead of updating in place, and a sequence in progress resets. Examples are
'mod+s'and'Mod+S', chord object keys in another order, or an omitted target andtarget: document. A source literal keeps one spelling, so this only matters for hotkeys built from data.HotkeyManageris now at 8,941 of its 9,000 B budget.Bundle size
Brotli, from
size-limit. Base ismainat54a14ddc. The other 13 entries are unchanged, including all devtools entries.everythingHotkeyManageruseHotkeyuseHotkey+HotkeysProvideruseHotkey+AppHotkeysProvideruseHotkeyuseHotkeycreateHotkeycreateHotkeyinjectHotkeycreateHotkeysScope+hotkeysPluginhotkeyDirectiveuseHotkeyuseHotkeyHotkeyManagerand Alpine's directive grew becauseregisternow importsnormalizeHotkeyinstead offormatHotkey. The directive calls the manager directly, so it doesn't get the adapter savings.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Summary by CodeRabbit