Skip to content

fix(frontend): ignore keyless key events and stop composer autocorrect - #480

Merged
chriswritescode-dev merged 3 commits into
mainfrom
fix/shortcut-missing-key
Nov 6, 2026
Merged

chriswritescode-dev merged 3 commits into
mainfrom
fix/shortcut-missing-key

Conversation

@chriswritescode-dev

@chriswritescode-dev chriswritescode-dev commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

User description

Summary

  • A keydown with no key value, such as the one Chrome dispatches when its autofill popup touches a password field, made the shortcut handler throw "Cannot read properties of undefined (reading 'length')".
  • The session composer set no autocomplete, autocorrect, spellcheck or auto-capitalize attributes, so browser defaults applied and iOS replaced shell commands such as ls with "Is" and turned quotes curly.

Change

  • lib/keyboardShortcuts.ts: formatShortcutEvent returns null for an event without a key, next to the existing modifier-only case. Both callers, the global shortcut handler and the Keyboard Shortcuts recorder, already treat null as "not a shortcut".
  • components/message/PromptInput.tsx: the textarea sets autocomplete="off" always, keeps autocorrect, sentence capitalization and spellcheck in normal mode, and turns all three off in bash mode.
  • Tests: a keyless key event formats to null; the existing bash-mode composer test now also asserts the attributes in normal and bash mode.

Validation

  • pnpm test: frontend 320 files / 4096 tests pass
  • pnpm typecheck, pnpm lint: clean (41 pre-existing warnings, 0 errors)
  • Browser, dev server on :5173: opening the API-key dialog and typing in the password field no longer raises a page error, and the composer attributes switch as expected when entering and leaving bash mode

Notes

  • System-level text replacement such as macOS "Correct spelling automatically" or smart quotes is outside these attributes and still applies.
  • The composer attributes mirror OpenCode's own web composer: autocorrect on for prompts, off for shell mode.

PR Type

Bug fix


Description

  • Skip key events that have no key value

  • Disable browser autocorrect, autocapitalize and spellcheck in composer

  • Extend tests for keyless events and composer attributes


Diagram Walkthrough

flowchart LR
  A["keydown event without key"] -- "formatShortcutEvent" --> B["return null"]
  C["PromptInput textarea"] -- "autoComplete / autoCorrect / autoCapitalize off" --> D["spellCheck false"]
  E["tests"] -- "assert new behavior" --> A
  E -- "assert attributes" --> C
Loading

File Walkthrough

Relevant files
Bug fix
keyboardShortcuts.ts
Guard shortcut formatting against keyless events                 

frontend/src/lib/keyboardShortcuts.ts

  • formatShortcutEvent now returns null when the event has no key value
  • Guards against keyless keydown events dispatched by Chrome autofill
  • Reuses the existing modifier-only null path for callers
+1/-1     
Tests
keyboardShortcuts.test.ts
Cover keyless keydown in shortcut tests                                   

frontend/src/lib/keyboardShortcuts.test.ts

  • Adds a test for a keydown event whose key is undefined
  • Asserts formatShortcutEvent returns null for that case
+7/-0     
PromptInput.command.test.tsx
Extend composer tests for text assistance attributes         

frontend/src/components/message/PromptInput.command.test.tsx

  • Asserts autocomplete, autocorrect, autocapitalize and spellcheck in
    normal mode
  • Repeats the attribute assertions after entering bash mode
  • Verifies attributes stay stable when bash mode toggles
+7/-0     
Enhancement
PromptInput.tsx
Disable composer text assistance attributes                           

frontend/src/components/message/PromptInput.tsx

  • Textarea sets autoComplete="off" unconditionally
  • Disables autoCorrect, autoCapitalize and spellCheck in all modes
  • Prevents browsers from rewriting commands and identifiers in prompts
+4/-0     

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The prompt textarea now changes input settings based on bash mode. Keyboard shortcut formatting now returns null for events with an empty key.

Changes: Prompt Textarea Behavior

Layer / File(s) Summary
Prompt attributes by bash mode
frontend/src/components/message/PromptInput.tsx, frontend/src/components/message/PromptInput.command.test.tsx
The textarea disables autocomplete. Bash mode disables autocorrect, autocapitalization, and spellcheck; the mobile keybar test checks the settings in both modes.

Keyboard Shortcut Formatting

Layer / File(s) Summary
Ignore events with an empty key
frontend/src/lib/keyboardShortcuts.ts, frontend/src/lib/keyboardShortcuts.test.ts
formatShortcutEvent now returns null when the event key is empty. A test checks an event with an undefined key.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · up to a1c25

No merge-blocking behavior has been identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title describes both changes. Autocorrect is disabled only in bash mode.
Description check Passed The description covers the changes, bug-fix type, tests, lint, and typecheck. It omits the template checklist and does not confirm style, TypeScript types, or the coverage target.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 4 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 531c6545-52e3-4c41-801e-af493dea4094
Commits

Reviewing files that changed from the base of the PR and between dc02208 and a1c2546.

Files selected for processing: 4

  • frontend/src/components/message/PromptInput.command.test.tsx
  • frontend/src/components/message/PromptInput.tsx
  • frontend/src/lib/keyboardShortcuts.test.ts
  • frontend/src/lib/keyboardShortcuts.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@lil-worker-cstech

lil-worker-cstech Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit bb196cb)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
⚠️ Risk level: Low
✅ Merge recommendation: No concerns found
🔎 Failure modes

What: A keyboard event with no key value could still crash a shortcut path that skips `formatShortcutEvent`, for example a direct matcher that reads `e.key` or calls `eventMainKey`/`isModifierOnlyEvent` itself.
Where: frontend/src/lib/keyboardShortcuts.ts:formatShortcutEvent
Trigger: Chrome autofill sends a keydown with an undefined `key` to a handler that does not go through `formatShortcutEvent`.
Detected by: The new unit test covers only `formatShortcutEvent`. Nothing visible covers other callers.
Covered in this PR: No

What: The composer's autocorrect, auto-capitalize and spellcheck are now off in every mode. This contradicts the PR description, which says normal mode keeps them on. Reviewers or users who expect autocorrect in normal prompts will see different behavior.
Where: frontend/src/components/message/PromptInput.tsx:PromptInput
Trigger: A user types a natural-language prompt on mobile in normal mode.
Detected by: The updated test in PromptInput.command.test.tsx asserts the attributes are off in both modes.
Covered in this PR: Yes

🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@lil-worker-cstech

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

… the composer

Prompts often mention file names, commands and identifiers, which browser text assistance rewrites. Disable autocorrect, auto-capitalization and spellcheck in every composer mode, not only bash mode.
@lil-worker-cstech

Copy link
Copy Markdown

Persistent review updated to latest commit bb196cb

@lil-worker-cstech

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@chriswritescode-dev
chriswritescode-dev merged commit c6c1333 into main Nov 6, 2026
1 check passed
@chriswritescode-dev
chriswritescode-dev deleted the fix/shortcut-missing-key branch November 6, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant