Skip to content

Guard recently-used Onyx lists against non-array values - #101025

Draft
MelvinBot wants to merge 1 commit into
mainfrom
claude-recentlyUsedCurrenciesNotIterable
Draft

Guard recently-used Onyx lists against non-array values#101025
MelvinBot wants to merge 1 commit into
mainfrom
claude-recentlyUsedCurrenciesNotIterable

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

mergePolicyRecentlyUsedCurrencies guarded its input with ??, which only replaces null and undefined. The value comes from Onyx (nvp_recentlyUsedCurrencies), and the server can write it as an object rather than an array. A non-array passes the ?? guard, so the spread on the next line threw TypeError: n is not iterable and crashed the amount-edit page on submit. The else branch had the same problem one line further down, where .slice is not a function on a plain object.

This replaces the nullish guard with an Array.isArray check, matching the sibling mergePolicyRecentlyUsedCategories twelve lines above. Because both branches derive from the same local, the single change covers the spread and the .slice. The parameter type is widened to OnyxEntry<string[]> so the guard is not dead code to the compiler, which also makes the misleading ?? [] at the UpdateMoneyRequest call site unnecessary.

Four other "recently used" helpers read server-written Onyx lists through the same ?? pattern and would throw the same error class, so they get the same shape guard: per diem destinations, policy recently-used tags, report field values, and recent attendees. For tags and report fields the outer ?. only guarded the record — the inner array being spread was typed non-optional and unchecked.

This stops the crash. It does not stop the bad write, which appears to originate server-side and needs a separate internal investigation.

Fixed Issues

$ #100842
PROPOSAL: #100842 (comment)

Tests

// TODO: The human co-author must fill out the tests they ran before marking this PR as "ready for review".

The crash needs a malformed nvp_recentlyUsedCurrencies value in Onyx, so it does not reproduce from a clean account. The automated coverage added here is tests/unit/MergePolicyRecentlyUsedCurrenciesTest.ts, which passes {0: 'USD', 2: 'EUR'} through both the with-currency and without-currency branches.

  • Verify that no errors appear in the JS console

Offline tests

// TODO: The human co-author must fill out the offline test steps before marking this PR as "ready for review".

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

Co-authored-by: huult <huult@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team September 12, 2026 12:22
@melvin-bot melvin-bot Bot added Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web labels Sep 12, 2026
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I created this PR from an upstream branch since I don't have push access to your fork.

To take ownership of this branch and be able to push updates, run:

git remote add upstream https://github.com/Expensify/App.git
git fetch upstream claude-recentlyUsedCurrenciesNotIterable
git checkout -b claude-recentlyUsedCurrenciesNotIterable upstream/claude-recentlyUsedCurrenciesNotIterable
git push -u origin claude-recentlyUsedCurrenciesNotIterable

Then you can close this PR and open a new one from your fork.

@MelvinBot

MelvinBot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ✅ pass

Verified on standalone Android NewDot: created a manual expense, edited its amount, and changed its currency mid-edit — all succeeded with no crash, error page, or JS runtime error in the app logs.

Expense detail page showing amount saved as EUR 45.75 after currency change

Step Status
Create a manual expense (amount + currency + merchant) and confirm it is created without errorExpense "Test Coffee Shop", $2,550.00, USD, Sep 12 appeared in the Expenses list as "Unreported" immediately after tapping Create expense, with no error banner.
Newly created manual expense visible in Expenses list
Open the created expense, edit its amount to a different value, submit, and confirm it saves without crash/errorAmount changed from $2,550.00 to $45.75 via the edit-amount numeric keypad and Save; report header updated to "$45.75 for Test Coffee Shop" and a system message logged "changed the amount to $45.75 (previously $2,550.00)". No crash or error page.
Expense detail page showing amount updated to $45.75
Change the currency while editing the amount, submit, and confirm the new currency saves without a crashRe-opened the amount editor, tapped "Select a currency, USD" — the currency picker opened and rendered normally, searched/selected EUR, then Save. Expense header and Amount field updated to "€45.75" with no crash.
Expense detail page showing amount saved as EUR 45.75 after currency change
No JS console / runtime errors during steps 1-3Captured the device app log after driving all steps and grepped for "is not iterable", "TypeError", "FATAL EXCEPTION", "AndroidRuntime", "JS exception", "redbox", "ExceptionsManager" — zero matches. The Metro log also had no error entries.

Note on scope: the documented Tests section only asks to verify no JS console errors, because the original crash needs a malformed nvp_recentlyUsedCurrencies value in Onyx and does not reproduce from a clean account. So these steps exercise the happy path through the changed code (mergePolicyRecentlyUsedCurrencies on the edit-amount submit path) as a regression check — they confirm the guard did not break normal behavior, but they do not reproduce the original TypeError: n is not iterable. The malformed-value case is covered by tests/unit/MergePolicyRecentlyUsedCurrenciesTest.ts.

One unrelated quirk observed: when typing the initial amount, moving focus straight from Amount to Merchant reset the Amount field to empty. This looks like an input-focus/commit behavior, not a crash, and is unrelated to this PR.


view run · no recording available

@MelvinBot

MelvinBot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ✅ pass

Verified on dev NewDot web: manual expense creation, amount edit, and currency edit through the edit-amount submit path all completed successfully with no crash or visible error, consistent with the Array.isArray guard fix in this PR. Direct browser console log capture is unavailable via the web tooling in this environment, so absence of JS errors is inferred from a stable UI, absent error banners, and clean network responses rather than a direct console read.

Final stable expense detail view after all edits, no error banners

Step Status
Create a manual expense (amount + currency + merchant) and confirm creation without errorExpense created with $25.00 USD, Merchant "Test Merchant"; appeared in the Expenses list as "Sep 12 · Unreported · Test Merchant · $25.00" with no error.
Newly created 25.00 USD Test Merchant expense in Expenses list
Edit the expense amount to a different value and submit; confirm it saves without crash/errorAmount changed from 25.00 to 40.00 via the Amount edit screen and Save; expense header/detail updated to $40.00, and a history entry "New amount is $40.00 (previously $25.00)" appeared. No crash or error page.
Expense detail showing amount updated to 40.00 USD
Change currency while editing amount, submit, confirm new currency saved without crashOpened the currency picker, searched and selected EUR, then saved. Header and detail updated to €40.00 with a corresponding history entry. No crash.
Expense detail showing amount updated to 40.00 EUR after currency change
No JS console errors during steps 1-3, especially "is not iterable" or TypeErrorDirect console capture is not available for the web platform in this environment. As proxies: the network dump showed no 4xx/5xx responses; the session request log contained only tool-side errors (stale refs, ambiguous selectors) with no app JS error strings; and every post-mutation snapshot showed a fully interactive, error-free UI.
Final stable expense detail view after all edits, no error banners

Two caveats worth reading before you rely on this:

  1. Scope. The documented Tests section only asks to verify no JS console errors, because the original crash needs a malformed nvp_recentlyUsedCurrencies value in Onyx and does not reproduce from a clean account. So these steps exercise the happy path through the changed code (src/libs/actions/IOU/MoneyRequestBuilder.ts) as a regression check. They confirm the guard did not break normal behavior, but they do not reproduce the original TypeError: n is not iterable. That case is covered by tests/unit/MergePolicyRecentlyUsedCurrenciesTest.ts.

  2. Step 4 is indirect. I could not read the browser console directly on web, so the "no console errors" result is an inference from clean network responses and a stable UI, not a console read. If you need a hard confirmation for that step, it is worth checking by hand with devtools open.


view run · no recording available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants