Skip to content

perf: isolate hotkey registry updates from binding consumers - #6

Merged
K-Mistele merged 2 commits into
mainfrom
perf/isolate-hotkey-registry
Sep 12, 2026
Merged

K-Mistele merged 2 commits into
mainfrom
perf/isolate-hotkey-registry

Conversation

@K-Mistele

Copy link
Copy Markdown

Summary

Registering or unregistering one shortcut currently broadcasts through both the public hotkeys context and the bound-registration context. Every unrelated useHotkeys consumer rerenders, even when active scopes have not changed.

  • Add useHotkeysScopeContext and its HotkeysScopeContextType export for scope-only consumers; make useHotkeys subscribe to this separate context.
  • Memoize scope, public registry, and bound-registration context values. Keep useHotkeysContext backward-compatible and reactive to registry changes.
  • Preserve active-scope identity for semantic enable/disable no-ops, including existing wildcard replacement behavior.
  • Document the two subscription surfaces and add 13 source-level regression cases.

This is a library-source fix. No dependency patches, application changes, listener ordering changes, registry-removal redesign, or dependency updates are included. Parent renders and genuine scope transitions can still rerender consumers. No application latency improvement is claimed by this PR.

Validation

  • bun --bun run --cwd packages/react-hotkeys-hook test: 162 passed, 4 skipped across 6 files.
  • Red/green in a disposable baseline checkout: 5 regression cases fail behaviorally against 05a2780; all 13 new cases pass with the implementation. No mocked contexts or export aliases.
  • Targeted Biome lint and formatting pass, including TSX via a temporary configuration. One pre-existing unused-suppression warning remains in useHotkeys.ts.
  • React Doctor changed-file scan, including the new test: no issues found.
  • Independent read-only review: no findings.
  • git diff --check: passed.

Existing validation limitations

bun --bun run --cwd packages/react-hotkeys-hook build emits the bundle/declarations and exits 0, but vite:dts reports TS2503: Cannot find namespace 'NodeJS' for the existing sequence timer type. Reproduced the same diagnostic on unchanged 05a2780; this is not a diagnostic-free build claim.

The existing Bun lockfile still identifies the old unscoped package name/version, so a frozen install fails before this change. Used bun install --ignore-scripts --no-save for local validation; neither manifest nor lockfile was changed. Documentation-site build and application integration remain unverified.

@github-actions

Copy link
Copy Markdown

Committed and pushed successfully. The package-lock.json change (from npm version running install) and the pre-existing untracked CLAUDE_OUTPUT.md were left out of the commit, as instructed to only touch the two package.json files.

Version Bump Summary

Package: @humanlayer/react-hotkeys-hook
Action: bumped to 5.4.0
Reasoning: The user had not yet bumped the version (root and package both still at 5.3.1, matching main). The PR adds a new backwards-compatible public API — the useHotkeysScopeContext() hook and its exported HotkeysScopeContextType type — alongside internal performance work (memoized context values, reference-preserving no-ops for enableScope/disableScope) that doesn't change existing behavior or signatures. Since useHotkeysContext() and all other exports remain fully intact and functionally unchanged, this is a MINOR bump (5.3.1 → 5.4.0), not a PATCH (new export) or MAJOR (nothing breaking).

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ K-Mistele
❌ github-actions[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@K-Mistele
K-Mistele merged commit b23799e into main Sep 12, 2026
1 check was pending
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.

2 participants