Repository navigation
perf: Shrink bundles by dropping @tanstack/store and the key-name tables - #211
Conversation
…in development - Core and every adapter subscribe with a small built-in store instead of @tanstack/store and the framework store adapters. Stores keep the same state, get, setState, and subscribe API, typed with TanStack Store's own types, and still work with TanStack Store's framework adapters. - Providers load app hotkey support only when the app uses defineAppHotkeys. - Console warnings and errors are logged only outside production builds. - Devtools adapters list their TanStack Devtools host as an optional peer at the current release.
🦋 Changeset detectedLatest commit: d3195a5 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 |
|
Important Review skippedToo many files! This PR contains 256 files, which is 106 over the limit of 150. To get a review, reduce the PR to 150 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.
|
🚀 Changeset Version Preview18 package(s) bumped directly, 0 bumped as dependents. 🟨 Minor 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: |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
…ables Typed hotkeys and browser events don't need key aliases or case folding, so those tables no longer ship in every bundle: - normalizeKeyName uppercases letters and maps ' ' to Space; other names stay as written. Modifier aliases (Ctrl, Cmd, Option) still work. - validateHotkey warns about keys not written like a known key, using a small pattern instead of ALL_KEYS. In development, registering such a hotkey warns that it may never fire. - The recorder rejects whitespace keys directly instead of running validateHotkey. - formatForDisplay accepts hotkeys only; formatKeyForDisplay formats single keys such as held keys. - Key sets are built compactly and are dropped by bundles that don't import them. - Lookups by untrusted names use own properties only, so saved custom hotkeys and display labels ignore names such as toString. typed-behavior.test.ts fingerprints parsing, normalization, validation, display, matching, recording, and firing for every typed hotkey and a wide range of real events; the fingerprints match the previous implementation.
…/devtools-peer-deps
…egistration to devtools
- Remove formatKeyForDisplay. formatForDisplay accepts typed hotkeys, which
include single keys, plus modifiers on their own such as 'Shift'. Keys from
a KeyboardEvent, such as held keys, are passed as { key }, which displays
them exactly as before.
- Move HotkeyManager.triggerRegistration into the devtools package, built on
the manager's public API. It was only used by the devtools Trigger button,
and saves about 100 bytes (brotli) in every app.
Cuts bundle size in core and every adapter. A React app with
useHotkeyandHotkeysProvidergoes from 12.0 kB to 7.8 kB (brotli). Typed hotkeys behave as before; the behavior changes only affect input the types don't allow.Size vs. the latest release
@tanstack/hotkeys0.19.0 and@tanstack/react-hotkeys0.18.0 vs. this PR. Each import is bundled with esbuild, minified, in production mode, and compressed with brotli; React is external.@tanstack/hotkeyseverythinggetHotkeyManagerHotkeyRecordergetKeyStateTrackerformatForDisplay@tanstack/react-hotkeyseverythinguseHotkeyuseHotkey+HotkeysProviderdefineAppHotkeysuseHotkeyRecorderuseKeyHold+useHeldKeysuseHotkeyRegistrationsCore size-limit budgets are unchanged, leaving room for upcoming fixes. New entries cover React
useHotkeywith and without the provider, and a provider without app hotkeys.Changes
@tanstack/storeat runtime. Core uses a small built-in store with the samestate,get,setState, andsubscribeAPI, typed by picking from TanStack Store's types.@tanstack/storeis a devDependency, and its types are inlined intodist/vendor. Adapters subscribe with small helpers instead of the@tanstack/*-storepackages, and React uses its built-inuseSyncExternalStore. The stores still work with TanStack Store's framework adapters.defineAppHotkeysregisters, so apps without app hotkeys don't bundle it.normalizeKeyNameuppercases letters and maps' 'toSpace; other names stay as written, and key aliases such asEscare no longer resolved. Validation uses a short pattern instead of a list of keys, and the recorder checks for whitespace keys instead of running full validation. The exported key sets keep their values but are dropped by bundles that don't import them.formatForDisplayaccepts typed input only. It takes hotkeys, which include single keys, plus modifiers on their own such as'Shift', instead of any string. Keys from aKeyboardEvent, such as held keys, are passed as{ key }; the held-key examples and devtools do this.triggerRegistrationmoves to devtools. It was only used by the devtools Trigger button. It's now part of the devtools package, built on the manager's public API.process.env.NODE_ENVis'production'. In development, registering a hotkey with a key name likeescapewarns that it may never fire.toStringor__proto__from saved data are ignored instead of read fromObject.prototype.{ key }form, and the core skill notes that key names are case-sensitive.Every package gets a minor bump.
Behavior changes
escape,Esc,f1,Plus, andpgdn, stay as written and no longer match. Letters still match in any case, and modifier aliases such asCtrl,Cmd, andOptionstill work. Hotkeys saved by the recorder are canonical and keep working.validateHotkeyandcheckHotkeywarn about keys not written like a known key ('escape'), instead of keys missing from a list.formatForDisplayno longer accepts arbitrary strings; pass held keys as{ key }.HotkeyManager.triggerRegistrationis removed from core.Storeinstances, soinstanceof Storeandactionsdon't apply.Testing
pnpm test:cipasses, including example type checks and builds, as do Ember's browser suite and the Playwright e2e suite (150 tests in Chromium, Firefox, and WebKit).typed-behavior.test.tsfingerprints parsing, normalization, validation, display, held-key display, event matching, recorded chords, and recorder and manager runs with dispatched events, for every typed chord, raw chord, and sequence, and for realistic events across all modifiers and every character up to U+2FFF. The fingerprints were captured before the refactor and still match.@tanstack/react-store'suseSelector, the app hotkeys factory, production logging, single-key display, whitespace recording, the registration warning, and prototype-named input.