Repository navigation
perf(hotkeys): Keep defineAppHotkeys fast to edit in large declarations - #327
Merged
Merged
Conversation
defineAppHotkeys inferred declarations against a constraint holding the chord union, and the language service walked that union for every literal in the call on every keystroke. It now infers against AppHotkeyDeclaration, which names no hotkey union, and checks each hotkey after inference. Also fixes TS2590 for generic lookups over spread-in app hotkeys.
🦋 Changeset detectedLatest commit: 8d233d4 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 |
|
Caution Review failedThe pull request is closed.
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. |
Contributor
🚀 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: |
It timed out at 60 seconds on CI, about ten times slower than locally. Take the best of two interleaved runs, allow 3 minutes, and fail above 4x the satisfies baseline (main measures 8.4x).
Contributor
|
🎉 This PR has been released! Thank you for your contribution! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🎯 Changes
Typing a hotkey string inside a large
defineAppHotkeyscall made editors lag: up to 0.6 seconds per keystroke in Supabase Studio'sappHotkeys.ts, and up to 2 seconds in a 300-entry call.tscbarely shows it, because the cost is in work the language service repeats on every edit.While TypeScript infers the declarations, it checks every literal in the call against contextual types built from the generic's constraint, and each check walks any union it finds (
isConstTypeVariable,mapType). The constraint wasRecord<string, AppHotkeyInput>, whosehotkeyholds the 6,720-member chord union, so every chord string and sequence step walked it on every keystroke.defineAppHotkeysinfers againstAppHotkeyDeclaration, a new exported shape whosehotkeynames no hotkey union. It includes a privateUncheckedHotkeymarker, so the unresolved constraint can be told apart from any value someone writes.ValidatedAppHotkeyInputschecks each hotkey after inference. A string is checked against the chord union and a sequence step by step. While inference runs, the unresolved constraint counts as valid, so the error branch and itsHotkey | nullare never built for a contextual type. Invalid entries are still reported againstHotkey | nullwith TypeScript's "Did you mean" suggestion, and options are checked against the kind on both branches.hotkey,meta,scope, oroptionsstill shows their documentation.UseAppHotkeyOptions<RegisteredAppHotkeys[TId]>failed with "Expression produces a union type that is too complex to represent", which breaks Supabase Studio's<Shortcut>component on 0.40.1. The spread-in kind check readTInput['hotkey']inside theAppHotkeybranch, where TypeScript intersects it withHotkey | null; it now reads the hotkey withinfer.app-hotkeys-editor-latency.test.tstypes a hotkey through the language service and fails ifdefineAppHotkeysis more than 4× slower than the same 300 declarations checked withas const satisfies(main: 8.4×, this branch: 0.7–0.8×). It takes about 6 seconds locally and allows 3 minutes for slow CI runners. It also asserts the call was checked. New type tests cover the generic lookup, conditional and??hotkeys, nullable replacements of spread-in hotkeys, and values that are not hotkeys.Worst keystroke while typing
'Mod+Shift+K'into one entry (language service, TypeScript 6.0.3):appHotkeys.ts(~300, 36 files spread in)The same 300 declarations checked with
as const satisfiestake 251 ms. With this build, Supabase Studio type-checks (it fails on 0.40.1) and its 1,196 shortcut, UI, grid, and preferences tests pass.Types only: the emitted JavaScript of
app-hotkeys.tsis identical to main, so there is no bundle size change.Notes
These type behaviors change, and they are worth a look before this merges:
defineAppHotkeys(flag ? a : {}), no longer type-checks; calldefineAppHotkeysin each branch. A generic function that passes its argument todefineAppHotkeysnow type-checks, where main rejected it.'M'or'Mod+S', completions at that position list only the current text; main listed every chord.hotkeythat is not a string, array, ornull, such as5, is reported againststring | readonly string[] | UncheckedHotkey | nullinstead ofHotkey | null.DefinedAppHotkeys<T>used on its own no longer rejects invalid hotkeys;defineAppHotkeysdoes.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.🚀 Release Impact