Skip to content

fix(hotkeys): Let the active scope decide before the match score - #306

Merged
KevinVandy merged 1 commit into
mainfrom
fix/scope-before-score
Nov 25, 2026
Merged

KevinVandy merged 1 commit into
mainfrom
fix/scope-before-score

Conversation

@KevinVandy

@KevinVandy KevinVandy commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

🎯 Changes

  • Chord dispatch used to keep the best match score first and apply scope precedence only among those matches. That made scope precedence depend on the keyboard layout. With a non-exclusive dialog scope holding Mod+S and a global Mod+[KeyS], the dialog won on a US layout (both score 3) but lost on Russian, where Mod+S matches through the key's position (score 1) and the physical binding scores 3.
  • #processChords now picks the highest scope with any match, then the best score within that scope, then the existing physical-over-logical rule. This is what the scopes guides and the defaults guide already describe.
  • One consequence: a scope's fallback match now beats an outer exact match. With a global Mod+Ы and a dialog Mod+S, a Russian Ctrl+ы fires the dialog hotkey.
  • Tests cover US, Russian keydown and Russian keyup across scopes, plus score still deciding within one scope. The defaults guide's priority bullet now states the order, and the changeset names the behavior change.

Bundle size

Brotli, from size-limit. Base is main at 5cbaccf4.

Entry Base PR Change
everything 13,630 B 13,622 B -8 B (-0.1%)
HotkeyManager 8,111 B 8,116 B +5 B (+0.1%)
React useHotkey 9,045 B 9,054 B +9 B (+0.1%)
React useHotkey + HotkeysProvider 9,597 B 9,601 B +4 B (+0.0%)
React useHotkey + AppHotkeysProvider 10,884 B 10,891 B +7 B (+0.1%)
Preact useHotkey 9,184 B 9,177 B -7 B (-0.1%)
Vue useHotkey 9,182 B 9,184 B +2 B (+0.0%)
Solid createHotkey 9,062 B 9,079 B +17 B (+0.2%)
Svelte createHotkey 9,025 B 9,035 B +10 B (+0.1%)
Angular injectHotkey 9,238 B 9,242 B +4 B (+0.0%)
Lit hotkey decorator 9,222 B 9,231 B +9 B (+0.1%)
Alpine createHotkeysScope + hotkeysPlugin 11,545 B 11,526 B -19 B (-0.2%)
Octane useHotkey 9,249 B 9,263 B +14 B (+0.2%)

The other 13 entries are unchanged.

Notes

Sequences still rank by match score alone and have no scope precedence yet; that's a separate dispatch change.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Hotkey matching now prioritizes the active scope over binding specificity across scopes. Within the selected scope, exact matches still take precedence over compatibility fallbacks.
    • This behavior applies to keyboard layouts including US and Russian, for both key press and release events. Sequence ranking remains based on match score.

Chord dispatch chose the best match score first and the scope only among
those, so scope precedence depended on the keyboard layout. A dialog
Mod+S beat a global Mod+[KeyS] on US layouts but lost on Russian, where
Mod+S matches through the key's position. Dispatch now picks the highest
scope with a match, then the best score within it, then physical over
logical, as the scopes docs describe.
@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 660bcb4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
@tanstack/hotkeys Patch
@tanstack/alpine-hotkeys Patch
@tanstack/angular-hotkeys Patch
@tanstack/ember-hotkeys Patch
@tanstack/hotkeys-devtools Patch
@tanstack/lit-hotkeys Patch
@tanstack/octane-hotkeys Patch
@tanstack/preact-hotkeys Patch
@tanstack/react-hotkeys Patch
@tanstack/solid-hotkeys Patch
@tanstack/svelte-hotkeys Patch
@tanstack/vue-hotkeys Patch
@tanstack/angular-hotkeys-devtools Patch
@tanstack/preact-hotkeys-devtools Patch
@tanstack/react-hotkeys-devtools Patch
@tanstack/solid-hotkeys-devtools Patch
@tanstack/svelte-hotkeys-devtools Patch
@tanstack/vue-hotkeys-devtools Patch

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

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

9 package(s) bumped directly, 9 bumped as dependents.

🟨 Minor bumps

Package Version Reason
@tanstack/hotkeys 0.33.1 → 0.34.0 Changeset

🟩 Patch bumps

Package Version Reason
@tanstack/angular-hotkeys-devtools 0.5.15 → 0.5.16 Changeset
@tanstack/hotkeys-devtools 1.12.0 → 1.12.1 Changeset
@tanstack/preact-hotkeys-devtools 0.13.15 → 0.13.16 Changeset
@tanstack/react-hotkeys-devtools 0.14.15 → 0.14.16 Changeset
@tanstack/solid-hotkeys 0.26.0 → 0.26.1 Changeset
@tanstack/solid-hotkeys-devtools 0.14.0 → 0.14.1 Changeset
@tanstack/svelte-hotkeys-devtools 0.5.15 → 0.5.16 Changeset
@tanstack/vue-hotkeys-devtools 0.13.15 → 0.13.16 Changeset
@tanstack/alpine-hotkeys 0.15.3 → 0.15.4 Dependent
@tanstack/angular-hotkeys 0.25.3 → 0.25.4 Dependent
@tanstack/ember-hotkeys 0.14.3 → 0.14.4 Dependent
@tanstack/lit-hotkeys 0.27.3 → 0.27.4 Dependent
@tanstack/octane-hotkeys 0.15.3 → 0.15.4 Dependent
@tanstack/preact-hotkeys 0.24.3 → 0.24.4 Dependent
@tanstack/react-hotkeys 0.27.2 → 0.27.3 Dependent
@tanstack/svelte-hotkeys 0.25.3 → 0.25.4 Dependent
@tanstack/vue-hotkeys 0.25.3 → 0.25.4 Dependent

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/alpine-hotkeys

npm i https://pkg.pr.new/@tanstack/alpine-hotkeys@306

@tanstack/angular-hotkeys

npm i https://pkg.pr.new/@tanstack/angular-hotkeys@306

@tanstack/angular-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/angular-hotkeys-devtools@306

@tanstack/ember-hotkeys

npm i https://pkg.pr.new/@tanstack/ember-hotkeys@306

@tanstack/hotkeys

npm i https://pkg.pr.new/@tanstack/hotkeys@306

@tanstack/hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/hotkeys-devtools@306

@tanstack/lit-hotkeys

npm i https://pkg.pr.new/@tanstack/lit-hotkeys@306

@tanstack/octane-hotkeys

npm i https://pkg.pr.new/@tanstack/octane-hotkeys@306

@tanstack/preact-hotkeys

npm i https://pkg.pr.new/@tanstack/preact-hotkeys@306

@tanstack/preact-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/preact-hotkeys-devtools@306

@tanstack/react-hotkeys

npm i https://pkg.pr.new/@tanstack/react-hotkeys@306

@tanstack/react-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/react-hotkeys-devtools@306

@tanstack/solid-hotkeys

npm i https://pkg.pr.new/@tanstack/solid-hotkeys@306

@tanstack/solid-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/solid-hotkeys-devtools@306

@tanstack/svelte-hotkeys

npm i https://pkg.pr.new/@tanstack/svelte-hotkeys@306

@tanstack/svelte-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/svelte-hotkeys-devtools@306

@tanstack/vue-hotkeys

npm i https://pkg.pr.new/@tanstack/vue-hotkeys@306

@tanstack/vue-hotkeys-devtools

npm i https://pkg.pr.new/@tanstack/vue-hotkeys-devtools@306

commit: 660bcb4

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Chord matching now selects the highest-ranked matching scope before comparing match scores. Exact matches still outrank fallbacks within that scope. Tests cover US and Russian layouts across keydown and keyup events.

Changes: Chord ranking

Layer / File(s) Summary
Scope-first selection
docs/guides/sensible-defaults.md, packages/hotkeys/src/hotkey-manager.ts
The manager selects the highest-ranked scope with a match, then chooses the best-scoring match within that scope. The guide documents scope priority and within-scope matching rules.
Layout coverage and release records
packages/hotkeys/tests/hotkey-manager.test.ts, .changeset/scope-before-match-score.md, .intent/review-state.json
Tests verify scope precedence on US and Russian layouts for keydown and keyup, and physical-over-logical priority within one scope. The changeset and review records are updated.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • TanStack/hotkeys#210: Changes which logical-binding fallback matches are available before this PR ranks matches.
  • TanStack/hotkeys#232: Changes candidate matching and physical-over-logical priority used by the dispatch selection.

Suggested reviewers: alemtuzlak, schiller-manuel

Merge Risk: Minimal · up to 660bc · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: chord dispatch now lets the active scope decide before the match score. It uses the fix prefix and matches the hotkey-manager change and its objectives. It is concise,…
Description check Passed The description follows the template sections: Changes, Checklist, and Release Impact. The Changes section explains the motivation, the new dispatch order, the layout-dependent bug, and a behavior con…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: chord dispatch now lets the active scope decide before the match score. It uses the fix prefix and matches the hotkey-manager change and its objectives. It is concise, specific, and contains no noise.

Full details: Description check

Explanation

The description follows the template sections: Changes, Checklist, and Release Impact. The Changes section explains the motivation, the new dispatch order, the layout-dependent bug, and a behavior consequence. It also adds bundle-size data and a note on sequences. The unchecked 'pnpm run test:pr' box is left unticked, which the template allows when it is not run. The author does not state whether that command was run, so reviewers should confirm it.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit taps a key, then waits,
The nested scope determines its fate.
Exact matches lead within their space,
While scores compare in second place.
US and Russian layouts join the dance,
Keydown and keyup get their chance.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5cbaccf and 660bcb4.

Files ignored due to path filters: 2

  • docs/reference/classes/HotkeyManager.md is excluded by !docs/**/reference/**
  • docs/reference/functions/getHotkeyManager.md is excluded by !docs/**/reference/**
Files selected for processing: 5

  • .changeset/scope-before-match-score.md
  • .intent/review-state.json
  • docs/guides/sensible-defaults.md
  • packages/hotkeys/src/hotkey-manager.ts
  • packages/hotkeys/tests/hotkey-manager.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@KevinVandy
KevinVandy merged commit be758b3 into main Nov 25, 2026
16 checks passed
@KevinVandy
KevinVandy deleted the fix/scope-before-score branch November 25, 2026 23:17
@github-actions github-actions Bot mentioned this pull request Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR has been released!

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant