You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 false for missing/non-string keys before calling toLowerCase().
Add regression coverage for missing/non-string keys and existing forward-delete shortcuts.
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:
isForwardDeleteKeyPress in src/components/AmountEditingController/utils.ts calls event.nativeEvent.key.toLowerCase() with no check (line 26). It's called from handleKeyPress in hooks/useAmountSelection.ts, which is the stack in Sentry.
handleKeyPress in src/components/AmountEditingController/hooks/useDetachedSignEditingController.ts (line 78) does the same event.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 returns event.nativeEvent?.key lowercased when it's a string and '' otherwise. Use it in isForwardDeleteKeyPress, so a missing key simply returns false (not a forward delete).
Use the same helper in useDetachedSignEditingController.ts's handleKeyPress, so the backspace check is skipped and the event still goes on to controller.handleKeyPress.
Change key in AmountEditingKeyPressEvent to key?: string so 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:
isForwardDeleteKeyPress returns false and doesn't throw when nativeEvent.key is undefined, a non-string, or 'Unidentified'.
The existing Delete and macOS Ctrl+D cases still return true.
In tests/unit/components/useDetachedSignEditingControllerTest.tsx:
handleKeyPress with 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.
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:
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.
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:
Critical Architectural Invariant:controller.handleKeyPress(event) must always be called unconditionally, even when key is missing or malformed. In useAmountSelection.ts:74-76, handleKeyPress updates forwardDeletePressedRef.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)
What alternative solutions did you explore? (Optional)
Only guarding isForwardDeleteKeyPress (competitor approach): Leaves useDetachedSignEditingController completely exposed to the exact same production crash.
Optional chaining without type check (event?.nativeEvent?.key?.toLowerCase()): While safe against undefined, it still throws if key is passed as a non-string object/number from unexpected native bridge event structures. Using typeof 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 under describe('isForwardDeleteKeyPress'):
it('returns false without throwing when key is undefined, null, or missing',()=>{expect(isForwardDeleteKeyPress({nativeEvent: {}}asAmountEditingKeyPressEvent)).toBe(false);expect(isForwardDeleteKeyPress({nativeEvent: {key: undefined}}asunknownasAmountEditingKeyPressEvent)).toBe(false);expect(isForwardDeleteKeyPress({nativeEvent: {key: null}}asunknownasAmountEditingKeyPressEvent)).toBe(false);});
In tests/unit/components/useDetachedSignEditingControllerTest.tsx:
Add a test verifying that handleKeyPress gracefully 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: {}}asAmountEditingKeyPressEvent));}).not.toThrow();});
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.
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 false for 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 key optional 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!
The optional type captures missing keys; the runtime typeof checks additionally protect against unexpected non-string values.
Regression coverage should verify missing/non-string keys, preserved sign and shortcut behavior, and resetting forward-delete state after a malformed event. These are suggested changes only; I haven’t applied them.
Activity
melvin-bot commentedon Nov 9, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (
External)[-][Sentry: APP-NZR] TypeError: Cannot read properties of undefined (reading 'toLowerCase')[/-][+][$175] [Sentry: APP-NZR] TypeError: Cannot read properties of undefined (reading 'toLowerCase')[/+]melvin-bot commentedon Nov 9, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022119865281675410521
fitzyracing1 commentedon Nov 9, 2026
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 withTypeError: Cannot read properties of undefined (reading 'toLowerCase')when the keyboard event reaching the amount editor has nonativeEvent.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'sTextInputpasses those events on toonKeyPressunchanged. The amount editor then assumeskeyis 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.AmountEditingKeyPressEventintypes.tstypeskeyas a plainstring, so TypeScript doesn't flag either call.What changes do you think we should make in order to solve the problem?
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).useDetachedSignEditingController.ts'shandleKeyPress, so the backspace check is skipped and the event still goes on tocontroller.handleKeyPress.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'.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.kevinjosh10 commentedon Nov 9, 2026
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 thatkeyis a valid string:1. Forward-delete keypress detector (
src/components/AmountEditingController/utils.ts:25-27)In React Native Web's
TextInputkeyboard pipeline, Android Chrome virtual keyboards, composition/IME events, and autofill often emit synthetic key events wherenativeEvent.keyisundefined(or empty/non-string). Calling.toLowerCase()directly onundefinedthrowsTypeError: Cannot read properties of undefined (reading 'toLowerCase').2. Detached-sign controller handler (
src/components/AmountEditingController/hooks/useDetachedSignEditingController.ts:77-85)useDetachedSignEditingControllerperforms 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 unhandledTypeErrorwhen an IME or autofill key event arrives.3. Strict typing masks optionality (
src/components/AmountEditingController/types.ts:7-12)Because
keyis typed as a requiredstring, TypeScript does not warn developers that browser/native synthetic events can dispatch withkeyomitted or undefined.What changes do you think we should make in order to solve the problem?
1. Guard
rawKeyinisForwardDeleteKeyPress(src/components/AmountEditingController/utils.ts:25-37)Safely check that
rawKeyis a string before calling.toLowerCase(). If missing or non-string, returnfalseearly:2. Guard
useDetachedSignEditingControllerwith unconditional delegation (src/components/AmountEditingController/hooks/useDetachedSignEditingController.ts:77-85)3. Update type definition in
types.ts(src/components/AmountEditingController/types.ts:7-12)What alternative solutions did you explore? (Optional)
isForwardDeleteKeyPress(competitor approach): LeavesuseDetachedSignEditingControllercompletely exposed to the exact same production crash.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 under
describe('isForwardDeleteKeyPress'):In
tests/unit/components/useDetachedSignEditingControllerTest.tsx:Add a test verifying that
handleKeyPressgracefully handles keyless events and still delegates to the underlying controller without throwing:Contributor details
Your Expensify account email: lkevinjosh10@gmail.com
Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374
melvin-bot commentedon Nov 9, 2026
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
10 remaining items
parasharrajat commentedon Nov 11, 2026
@MelvinBot Propose solution here.
MelvinBot commentedon Nov 11, 2026
Proposal
What is the root cause of that problem?
The amount editor calls
event.nativeEvent.key.toLowerCase()without checking whetherkeyis 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
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?
falsefor missing/non-string keys.keyoptional in the local event type. Retain runtime type guards to handle unexpected non-string values.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.
view run
gorky117-cell commentedon Nov 11, 2026
Hi @parasharrajat, my proposal from Nov 9 already covers this exact solution—guarding both
isForwardDeleteKeyPressanduseDetachedSignEditingController, updating theAmountEditingKeyPressEventtype, 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!
parasharrajat commentedon Nov 11, 2026
@gorky117-cell we don't accept proposals like that. Please read contributing guidelines
parasharrajat commentedon Nov 11, 2026
@MelvinBot What is your suggested code change for your proposal here #106409 (comment)
MelvinBot commentedon Nov 11, 2026
I suggest these three changes, without introducing a shared helper:
1. In utils.ts:25–37, replace the initial normalization with:
Keep the remaining forward-delete shortcut logic unchanged.
2. In useDetachedSignEditingController.ts:77–85, replace the handler with:
The unconditional delegation matters: malformed keys must still reach the base controller to clear any previous forward-delete flag.
3. In types.ts:7–12, make the key optional:
The optional type captures missing keys; the runtime
typeofchecks additionally protect against unexpected non-string values.Regression coverage should verify missing/non-string keys, preserved sign and shortcut behavior, and resetting forward-delete state after a malformed event. These are suggested changes only; I haven’t applied them.
view run
parasharrajat commentedon Nov 11, 2026
@MelvinBot Implement your proposal #106409 (comment).
🎀 👀 🎀 C+ reviewed
melvin-bot commentedon Nov 11, 2026
Triggered auto assignment to @Julesssss, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
Julesssss commentedon Nov 11, 2026
@parasharrajat please go ahead