[Due for payment 2026-11-24] [$175] [Sentry: APP-NZR] TypeError: Cannot read properties of undefined (reading 'toLowerCase')
Summary
Editing the receipt requirement amount can throw an unhandled TypeError when a keyboard event has no nativeEvent.key.
Sentry: https://expensify.sentry.io/issues/APP-NZR
Reported impact: 1 user, 2 events; first seen November 8, 2026 at 19:36 UTC.
Platform: Web, Chrome Mobile on Android, standalone.
Release: 9.5.33
Route: /workspaces/:policyID/rules/require-receipts
Mechanism: Unhandled (onerror), level error.
Error and first-party frames
TypeError: Cannot read properties of undefined (reading 'toLowerCase')
src/components/AmountEditingController/utils.ts:26 — isForwardDeleteKeyPress
const key = event.nativeEvent.key.toLowerCase();
src/components/AmountEditingController/hooks/useAmountSelection.ts:75
forwardDeletePressedRef.current = isForwardDeleteKeyPress(event);
AmountFormFieldInput.tsx:39 — handleInputKeyPress
handleKeyPress(event);
react-native-web TextInput handleKeyDown → onKeyPress(e)
Root cause
AmountEditingController/utils.ts:25–39 calls event.nativeEvent.key.toLowerCase() without checking that key is a string. The amount input forwards keyboard events into this helper, so an undefined key throws instead of being treated as a non-forward-delete event.
Mobile Chrome/IME behavior is a suspected trigger, not confirmed. Exact UI reproduction steps have not been established.
Expected behavior
Receipt-threshold editing should not throw when a keyboard event has a missing or non-string key.
Suggested fix
- Return
falsefor missing/non-string keys before callingtoLowerCase(). - Add regression coverage for missing/non-string keys and existing forward-delete shortcuts.
Parent tracker: [Tracking] Top Sentry crashes monthly check-in
Slack thread: https://expensify.slack.com/archives/C027V2LD9D1/p1794236798557059
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022119865281675410521
- Upwork Job ID: 2119865281675410521
- Last Price Increase: 2026-11-09
Issue Owner
Current Issue Owner: @mallenexpensify
Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (External)
Job added to Upwork: https://www.upwork.com/jobs/~022119865281675410521
Proposal
Please re-state the problem that we are trying to solve in this issue.
Typing in the receipt requirement amount field (/workspaces/:policyID/rules/require-receipts) can crash with TypeError: Cannot read properties of undefined (reading 'toLowerCase') when the keyboard event reaching the amount editor has no nativeEvent.key, which Sentry shows on Chrome for Android.
What is the root cause of that problem?
Some keyboard events on Android Chrome (likely IME or autofill, as the issue notes) arrive without a key. react-native-web's TextInput passes those events on to onKeyPress unchanged. The amount editor then assumes key is always a string:
isForwardDeleteKeyPressinsrc/components/AmountEditingController/utils.tscallsevent.nativeEvent.key.toLowerCase()with no check (line 26). It's called fromhandleKeyPressinhooks/useAmountSelection.ts, which is the stack in Sentry.handleKeyPressinsrc/components/AmountEditingController/hooks/useDetachedSignEditingController.ts(line 78) does the sameevent.nativeEvent.key.toLowerCase()before delegating to the controller. Any input that uses the detached sign controller would hit the same crash one frame earlier.
AmountEditingKeyPressEvent in types.ts types key as a plain string, so TypeScript doesn't flag either call.
What changes do you think we should make in order to solve the problem?
- In
utils.ts, add a small helper, e.g.getNormalizedKey(event), that returnsevent.nativeEvent?.keylowercased when it's a string and''otherwise. Use it inisForwardDeleteKeyPress, so a missing key simply returnsfalse(not a forward delete). - Use the same helper in
useDetachedSignEditingController.ts'shandleKeyPress, so the backspace check is skipped and the event still goes on tocontroller.handleKeyPress. - Change
keyinAmountEditingKeyPressEventtokey?: stringso the types match what the browser actually sends and future callers have to handle it.
Forward-delete (Delete, Ctrl+D on macOS/iOS, the iOS Safari accessibility Ctrl case) and backspace sign deletion keep working as before.
What specific scenarios should we cover in automated tests?
In tests/unit/components/AmountEditingControllerUtilsTest.ts:
isForwardDeleteKeyPressreturnsfalseand doesn't throw whennativeEvent.keyisundefined, a non-string, or'Unidentified'.- The existing
Deleteand macOS Ctrl+D cases still returntrue.
In tests/unit/components/useDetachedSignEditingControllerTest.tsx:
handleKeyPresswith a missing key doesn't throw, doesn't delete the sign, and still forwards the event to the base controller.
What alternative solutions did you explore? (Optional)
Using optional chaining at each call site (event.nativeEvent.key?.toLowerCase()). That fixes the crash too, but one shared helper plus the optional type is safer, because both call sites behave the same and the compiler catches new ones.
Proposal
What is the root cause of that problem?
There are two affected call sites in the amount editing controller pipeline where event.nativeEvent.key.toLowerCase() is called without verifying that key is a valid string:
1. Forward-delete keypress detector (src/components/AmountEditingController/utils.ts:25-27)
function isForwardDeleteKeyPress(event: AmountEditingKeyPressEvent): boolean {
const key = event.nativeEvent.key.toLowerCase();
In React Native Web's TextInput keyboard pipeline, Android Chrome virtual keyboards, composition/IME events, and autofill often emit synthetic key events where nativeEvent.key is undefined (or empty/non-string). Calling .toLowerCase() directly on undefined throws TypeError: Cannot read properties of undefined (reading 'toLowerCase').
2. Detached-sign controller handler (src/components/AmountEditingController/hooks/useDetachedSignEditingController.ts:77-85)
const handleKeyPress = (event: AmountEditingKeyPressEvent) => {
const key = event.nativeEvent.key.toLowerCase();
if (key === 'backspace') {
deleteSignBeforeCaret();
}
controller.handleKeyPress(event);
};
useDetachedSignEditingController performs the exact same unsafe .toLowerCase() operation. Any amount screen utilizing detached signs (such as negative expenses or detached currency sign controllers) crashes with the identical unhandled TypeError when an IME or autofill key event arrives.
3. Strict typing masks optionality (src/components/AmountEditingController/types.ts:7-12)
type AmountEditingKeyPressEvent = {
nativeEvent: {
key: string;
ctrlKey?: boolean;
};
};
Because key is typed as a required string, TypeScript does not warn developers that browser/native synthetic events can dispatch with key omitted or undefined.
What changes do you think we should make in order to solve the problem?
1. Guard rawKey in isForwardDeleteKeyPress (src/components/AmountEditingController/utils.ts:25-37)
Safely check that rawKey is a string before calling .toLowerCase(). If missing or non-string, return false early:
function isForwardDeleteKeyPress(event: AmountEditingKeyPressEvent): boolean {
const rawKey = event.nativeEvent.key;
if (typeof rawKey !== 'string') {
return false;
}
const key = rawKey.toLowerCase();
if (isMobileSafari() && key === CONST.PLATFORM_SPECIFIC_KEYS.CTRL.DEFAULT) {
// ...
}
}
2. Guard useDetachedSignEditingController with unconditional delegation (src/components/AmountEditingController/hooks/useDetachedSignEditingController.ts:77-85)
const handleKeyPress = (event: AmountEditingKeyPressEvent) => {
const key = event.nativeEvent.key;
if (typeof key === 'string' && key.toLowerCase() === 'backspace') {
deleteSignBeforeCaret();
}
controller.handleKeyPress(event);
};
Critical Architectural Invariant:
controller.handleKeyPress(event)must always be called unconditionally, even whenkeyis missing or malformed. InuseAmountSelection.ts:74-76,handleKeyPressupdatesforwardDeletePressedRef.current = isForwardDeleteKeyPress(event). If a malformed key event were dropped without delegating, any previous forward-delete flag would remain stale and incorrectly offset the caret on subsequent edits! Unconditional delegation resets the flag safely.
3. Update type definition in types.ts (src/components/AmountEditingController/types.ts:7-12)
type AmountEditingKeyPressEvent = {
nativeEvent: {
key?: string;
ctrlKey?: boolean;
};
};
What alternative solutions did you explore? (Optional)
- Only guarding
isForwardDeleteKeyPress(competitor approach): LeavesuseDetachedSignEditingControllercompletely exposed to the exact same production crash. - Optional chaining without type check (
event?.nativeEvent?.key?.toLowerCase()): While safe againstundefined, it still throws ifkeyis passed as a non-string object/number from unexpected native bridge event structures. Usingtypeof rawKey !== 'string'is standard in Expensify core libraries.
What automated tests can you add to prevent this from re-occurring?
-
In
tests/unit/components/AmountEditingControllerUtilsTest.ts: Add tests underdescribe('isForwardDeleteKeyPress'):it('returns false without throwing when key is undefined, null, or missing', () => { expect(isForwardDeleteKeyPress({nativeEvent: {}} as AmountEditingKeyPressEvent)).toBe(false); expect(isForwardDeleteKeyPress({nativeEvent: {key: undefined}} as unknown as AmountEditingKeyPressEvent)).toBe(false); expect(isForwardDeleteKeyPress({nativeEvent: {key: null}} as unknown as AmountEditingKeyPressEvent)).toBe(false); }); -
In
tests/unit/components/useDetachedSignEditingControllerTest.tsx: Add a test verifying thathandleKeyPressgracefully handles keyless events and still delegates to the underlying controller without throwing:it('handles malformed keypress events without throwing and clears forward-delete state', () => { const {result} = renderController({value: '10'}); expect(() => { act(() => result.current.handleKeyPress({nativeEvent: {}} as AmountEditingKeyPressEvent)); }).not.toThrow(); });
Contributor details
Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue.
When editing an amount input managed by AmountEditingController (such as workspace receipt requirement rules at /workspaces/:policyID/rules/require-receipts), keyboard events where nativeEvent.key is missing or undefined (common on Mobile Chrome on Android, virtual IME keyboards, and autofill) trigger an unhandled runtime error:
TypeError: Cannot read properties of undefined (reading 'toLowerCase').
What is the root cause of that problem?
- In
src/components/AmountEditingController/utils.ts(line 26),isForwardDeleteKeyPressdirectly callsevent.nativeEvent.key.toLowerCase()without verifying thatkeyis defined or of type string. - In
src/components/AmountEditingController/hooks/useDetachedSignEditingController.ts(line 78),handleKeyPressalso directly callsevent.nativeEvent.key.toLowerCase()to check for'backspace'before delegating to the base controller, causing the same unhandled TypeError whenkeyis undefined. - In
src/components/AmountEditingController/types.ts(line 9),AmountEditingKeyPressEventtypeskeyas a non-optionalstring, which does not reflect the reality of browser/React Native Web synthetic keyboard events on mobile platforms wherekeycan be omitted.
What changes do you think we should make in order to solve the problem?
- In
src/components/AmountEditingController/types.ts: UpdateAmountEditingKeyPressEventto typekey?: stringto reflect optional key data on synthetic keyboard events. - In
src/components/AmountEditingController/utils.ts: InisForwardDeleteKeyPress, guardevent?.nativeEvent?.key: if it is not a valid string, returnfalseearly so the event is safely treated as a non-forward-delete keypress. - In
src/components/AmountEditingController/hooks/useDetachedSignEditingController.ts: InhandleKeyPress, safely check ifevent.nativeEvent.key?.toLowerCase() === 'backspace'before callingdeleteSignBeforeCaret(), and continue delegating tocontroller.handleKeyPress(event). - In
tests/unit/components/AmountEditingControllerUtilsTest.ts: Add test coverage asserting thatisForwardDeleteKeyPressreturnsfalseand does not throw whenkeyis undefined or omitted. - In
tests/unit/components/useDetachedSignEditingControllerTest.tsx: Add test coverage asserting thathandleKeyPresssafely handles events wherekeyis undefined without throwing.
What alternative solutions did you explore? (Optional)
Creating a separate shared getNormalizedKey helper function. However, direct safe type guards at the two consumer sites are cleaner, more idiomatic TypeScript, and avoid adding extra exported utility overhead.
Contributor details
Your Expensify account email: [email protected]
📣 @gorky117-cell! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~013bdd0475abb70c10
⚠️ Invalid email. Please make sure to create an Expensify account with this email first here.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~013bdd0475abb70c10
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue.
Editing the receipt requirement amount (/workspaces/:policyID/rules/require-receipts) can throw an unhandled TypeError: Cannot read properties of undefined (reading 'toLowerCase') when a keyboard event has no nativeEvent.key (seen on mobile Chrome/IME events).
What is the root cause of that problem?
isForwardDeleteKeyPress in src/components/AmountEditingController/utils.ts calls event.nativeEvent.key.toLowerCase() with no guard that key is a string. It is called from useAmountSelection.ts:75 via handleInputKeyPress on every keypress, so any event with a missing or non-string key throws instead of being treated as a non-forward-delete event. Verified against the current source on main.
What changes do you think we should make in order to solve the problem?
Return false early in isForwardDeleteKeyPress when event.nativeEvent.key is not a string, before calling toLowerCase(). No behaviour change for real keys — Delete and Ctrl+D on Mac/iOS still return true as before.
What alternative solutions did you explore? (Optional)
Guarding at the caller in useAmountSelection.ts was considered, but the helper is the single place every keypress flows through, so guarding there covers all current and future callers.
How will you verify the fix?
Add regression tests for a missing key and a non-string key (both must return false without throwing), plus the existing forward-delete cases (Delete, Ctrl+D on Mac/iOS). Then verify on the receipt-threshold page that editing the amount no longer throws on such events, and run the AmountEditingController test suite.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01c5c6bc0e7d162f7b
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue.
Sentry error APP-NZR: TypeError: Cannot read properties of undefined (reading 'toLowerCase').
What is the root cause of that problem?
In src/libs/OptionsListUtils.ts or search filter helpers:
A string search comparator calls .toLowerCase() on an optional field (such as option.text, option.alternateText, or report.reportName) without nullish coalescing or optional chaining (option?.text?.toLowerCase()), leading to an uncaught TypeError when an option item has undefined text or is missing attributes.
What changes do you think we should make in order to solve the problem?
- In
src/libs/OptionsListUtils.ts:- Replace direct
.toLowerCase()calls with optional chaining and fallback empty string:(option.text ?? '').toLowerCase()or(option.alternateText ?? '').toLowerCase().
- Replace direct
- Add defensive guards across all text-matching helper functions handling user-generated option collections.
What alternative solutions did you explore? (Optional)
Ensuring all upstream data sources always populate strings, which is vulnerable to corrupt or partial Onyx records.
@MelvinBot Propose solution here.
Proposal
What is the root cause of that problem?
The amount editor calls event.nativeEvent.key.toLowerCase() without checking whether key is a string. A missing key therefore produces the exact reported exception.
There are two affected handlers: the forward-delete helper in the reported stack and the detached-sign controller, which performs the same unsafe operation before forwarding the event.
Code evidence
- The receipt requirement input uses the amount form.
- AmountFormFieldInput.tsx:39–44 forwards the event to the controller.
- useAmountSelection.ts:73–76 calls the unsafe forward-delete helper.
- The detached-sign handler independently lowercases the key.
This explains the supplied Sentry stack; option-search filtering does not. The exact keyboard/IME trigger remains unconfirmed.
What changes do you think we should make in order to solve the problem?
- Guard both handlers with a string-type check. The forward-delete helper should return
falsefor missing/non-string keys. - In the detached-sign handler, only perform backspace sign deletion for a valid string key. Always forward the event to the base controller, including malformed keys, so its previous forward-delete state is cleared.
- Make
keyoptional in the local event type. Retain runtime type guards to handle unexpected non-string values. - Add regression tests covering:
- Missing, undefined, null, and non-string keys without exceptions.
- No accidental sign deletion.
- Forward-delete state resetting after a malformed event.
- Existing Delete, macOS/iOS Ctrl+D, Safari accessibility Control, and Backspace behavior.
The existing three relevant unit suites passed: 84 tests. No code was changed, and the production keyboard sequence was not reproduced.
What alternative solutions did you explore? (Optional)
Optional chaining alone handles missing keys but still throws for non-string values. Guarding only the forward-delete helper leaves the detached-sign handler vulnerable. Unrelated option-filter changes would not address this stack.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/106409) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Hi @parasharrajat, my proposal from Nov 9 already covers this exact solution—guarding both isForwardDeleteKeyPress and useDetachedSignEditingController, updating the AmountEditingKeyPressEvent type, and adding regression tests for missing/undefined keys.
I have the branch and unit test suite tested and ready to open as a PR immediately if assigned. Thank you!
@gorky117-cell we don't accept proposals like that. Please read contributing guidelines
@MelvinBot What is your suggested code change for your proposal here https://github.com/Expensify/App/issues/106409#issuecomment-6800264016