fix(web): ignore keyboard events with a missing key - #2785
Open
tyler-dane wants to merge 3 commits into
Open
Conversation
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
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>
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.
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 fireKeyboardEvents withkeyunset; 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.keyas""in a shared helper, and use it fromisBareLetterKeyplus the other shortcut/onboarding listeners so they no-op instead of throwing.The same events also crash
@tanstack/hotkeys(normalizeKeyName→key.toUpperCase()), which backsuseAppShortcut. That library is patched to return""whenkeyis 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
KeyboardEventno longer throws from Compass listeners or TanStack hotkeys.Independent review
Not run for this change.
Test plan
41 pass, 0 fail.
bun lintreports only pre-existing warnings.Error signatures addressed
TypeError: Cannot read properties of undefined (reading 'length')TypeError: Cannot read properties of undefined (reading 'toLowerCase')@tanstack/hotkeyskey.toUpperCase()on the same events