fix(chat): guard undefined event.key in type-to-focus handler - #639
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(chat): guard undefined event.key in type-to-focus handler#639posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The document-level keydown handler read `event.key.length` without checking that `event.key` exists. On some keydown events — notably Android Chrome soft keyboards, which fire keydown with keyCode 229 and no `key` during IME composition — `event.key` is undefined, throwing an uncaught `TypeError: Cannot read properties of undefined (reading 'length')`. Add a nullish guard before the length check. The existing `event.isComposing` guard does not cover all Android cases where `key` comes through undefined. Generated-By: PostHog Code Task-Id: f9a1223a-c963-4b1c-bca6-a47a81c3c8b2
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
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
The document-level type-to-focus keydown handler read
event.key.lengthwithout checking thatevent.keyexists (shouldRouteTypingToTextInputinsrc/hooks/use-type-to-focus-text-input.ts). On some keydown events — notably Android Chrome soft keyboards, which firekeydownwithkeyCode 229and nokeyduring IME composition —event.keyisundefined, so reading.lengththrew an uncaughtTypeError: Cannot read properties of undefined (reading 'length').This adds a nullish guard (
if (!event.key || event.key.length !== 1) return false;) before the length check. The existingevent.isComposingguard doesn't cover all the Android cases wherekeycomes through undefined. Also adds a regression test for the predicate.Why
Users typing into the AI chat composer were hitting a recurring uncaught production
TypeErroron Android soft keyboards. It's low volume but confirmed firing in the live code (resurfaced ~2.5 months after an earlier occurrence in the pre-snapshot code). The core flow still worked (users can tap to focus), so this is a low-risk, contained fix.Created with PostHog Code from an inbox report.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.