Skip to content

fix(web): ignore keyboard events with a missing key - #2785

Open
tyler-dane wants to merge 3 commits into
mainfrom
cursor/fix-undefined-keyboard-key-a133
Open

fix(web): ignore keyboard events with a missing key#2785
tyler-dane wants to merge 3 commits into
mainfrom
cursor/fix-undefined-keyboard-key-a133

Conversation

@tyler-dane

@tyler-dane tyler-dane commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Discord/PostHog reported production TypeErrors:

  • Cannot read properties of undefined (reading 'length') (4)
  • Cannot read properties of undefined (reading 'toLowerCase') (1)

Those match the document-level shortcut listeners added with event jump, Hardcore mode, edit sequences, and the Shortcut Showcase. They call event.key.length / event.key.toLowerCase() on every keydown/keyup. Some browsers, extensions, IME, and autofill paths fire KeyboardEvents with key unset; Chrome then throws exactly those messages. One such event hits several capture listeners, which matches a burst of the same TypeError.

Fix: treat a non-string event.key as "" in a shared helper, and use it from isBareLetterKey plus the other shortcut/onboarding listeners so they no-op instead of throwing.

The same events also crash @tanstack/hotkeys (normalizeKeyNamekey.toUpperCase()), which backs useAppShortcut. That library is patched to return "" when key is not a string.

PostHog MCP was unavailable during this run, so this is from the Discord signatures plus the call sites that produce them. After deploy, confirm the issues stop receiving events and resolve them.

Simplicity

One helper (keyboardKey / normalizedKeyboardKey) and a one-line guard in the existing TanStack hotkeys patch pattern. No new shortcut behavior.

Automated validation

Focused web tests for the helper and the document-level listeners that previously threw. Dispatching a keyless KeyboardEvent no longer throws from Compass listeners or TanStack hotkeys.

Independent review

Not run for this change.

Test plan

cd packages/web && TZ=UTC NODE_ENV=test bun test ./src/shortcuts/is-bare-letter-key.test.ts ./src/shortcuts/useEditSequenceShortcut.test.tsx ./src/shortcuts/shift-hint/useShiftHoldEventHints.test.tsx ./src/shortcuts/keyboard-only/useKeyboardOnlyMode.test.tsx
bun lint

41 pass, 0 fail. bun lint reports only pre-existing warnings.

Error signatures addressed

  • TypeError: Cannot read properties of undefined (reading 'length')
  • TypeError: Cannot read properties of undefined (reading 'toLowerCase')
  • Related: @tanstack/hotkeys key.toUpperCase() on the same events
Open in Web Open in Cursor 

cursoragent and others added 2 commits August 14, 2026 23:06
Chrome reports TypeError when shortcut listeners call .length or
.toLowerCase on KeyboardEvent.key that some browsers/extensions leave
unset. Treat a missing key as empty so those listeners no-op.

Co-authored-by: Tyler Dane <tyler-dane@users.noreply.github.com>
@tanstack/hotkeys normalizeKeyName calls key.toUpperCase() on every
keydown. The same unset-key events that crashed Compass listeners also
throw there. Return empty string when key is not a string.

Co-authored-by: Tyler Dane <tyler-dane@users.noreply.github.com>
@tyler-dane
tyler-dane marked this pull request as ready for review August 14, 2026 23:11
Round out dispatchMissingKey coverage for the three call sites left
untested (useChecklistDetection, ShortcutShowcase, WelcomeModal) and
add a first test file for useShortcutTipTrigger, which had none.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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