Describe the bug
The default theme-provider.tsx generated by the shadcn preset contains a ThemeHotkey component that attaches a global keydown listener via window.addEventListener. During browser autofill/autocomplete on Chrome and Edge, the browser fires a synthetic keydown event where event.key is undefined. The listener calls event.key.toLowerCase() without a null-check, causing an uncaught TypeError.
Affected component/components
Input
How to reproduce
- Create a new Next.js project using the shadcn preset (npx shadcn@latest init)
- Use the default generated theme-provider.tsx (no modifications)
- Add a plain to any page
- Save an autofill entry in Chrome or Edge for that field
- Focus the input and select a suggestion from the browser autocomplete dropdown
Current Behavior:
Uncaught TypeError: Cannot read properties of undefined (reading 'toLowerCase')
at onKeyDown (theme-provider.tsx)
Expected Behavior:
No error. The autofill completes normally and the theme hotkey listener safely ignores events with an undefined key.
Root Cause:
In theme-provider.tsx
// Crashes when event.key is undefined (browser autofill synthetic event)
if (event.key.toLowerCase() !== 'd') {
return;
}
Codesandbox/StackBlitz link
No response
Logs
System Info
Next.js: 16.2.3
Node.js: 20x
pnpm: 9.15.9
OS: Windows 10
Browser: Chrome / Edge (Firefox working without any error)
Repro: Plain <input type="email" /> with no custom hooks
Before submitting
Describe the bug
The default theme-provider.tsx generated by the shadcn preset contains a ThemeHotkey component that attaches a global keydown listener via window.addEventListener. During browser autofill/autocomplete on Chrome and Edge, the browser fires a synthetic keydown event where event.key is undefined. The listener calls event.key.toLowerCase() without a null-check, causing an uncaught TypeError.
Affected component/components
Input
How to reproduce
Current Behavior:
Expected Behavior:
No error. The autofill completes normally and the theme hotkey listener safely ignores events with an undefined key.
Root Cause:
In theme-provider.tsx
Codesandbox/StackBlitz link
No response
Logs
System Info
Before submitting