Repository navigation
Guard recently-used Onyx lists against non-array values - #101025
Conversation
Co-authored-by: huult <huult@users.noreply.github.com>
|
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: Then you can close this PR and open a new one from your fork. |
|
🤖 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. Note on scope: the documented Tests section only asks to verify no JS console errors, because the original crash needs a malformed 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 |
|
🤖 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 Two caveats worth reading before you rely on this:
view run · no recording available |
|
@MelvinBot could you sync with main? |
…rrenciesNotIterable Co-authored-by: huult <huult@users.noreply.github.com>
…rrenciesNotIterable Co-authored-by: huult <huult@users.noreply.github.com>
|
Synced —
Sync details and what I could not verify locallyMerge The branch was a shallow, single-commit checkout with no common ancestor, so I unshallowed it before merging. Two merges landed, both clean via the
Neither merge touched the six source files or the test in this PR, so the diff versus Checks
CI on this PR runs both for real, so please lean on those results rather than mine. Everything else is unchanged: |
|
There's nothing to fix here — every code check on this PR passes. The only failing check is Check independent approval, and it fails because the PR has no approving review yet: That's the Everything else is green: To clear it, get a review from an eligible reviewer. The PR body also still has the |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
| function mergePolicyRecentlyUsedCurrencies(currency: string | undefined, policyRecentlyUsedCurrencies: OnyxEntry<string[]>) { | ||
| let mergedCurrencies: string[]; | ||
| const currenciesArray = policyRecentlyUsedCurrencies ?? []; | ||
| // The value is written by the server and can arrive as an object instead of an array, so check the shape instead of relying on `??`. |
| }); | ||
| const optimisticPolicyRecentlyUsedCurrencies = mergePolicyRecentlyUsedCurrencies(currency, policyRecentlyUsedCurrencies); | ||
| const optimisticPolicyRecentlyUsedDestinations = customUnit.customUnitRateID ? [...new Set([customUnit.customUnitRateID, ...(recentlyUsedDestinations ?? [])])] : []; | ||
| // `recentlyUsedDestinations` is written by the server and can arrive as an object instead of an array, so check the shape instead of relying on `??`. |
|
|
||
| const tagListKey = policyTagKeys.at(index) ?? ''; | ||
| newOptimisticPolicyRecentlyUsedTags[tagListKey] = [...new Set([tag, ...(policyRecentlyUsedTags?.[tagListKey] ?? [])])]; | ||
| // The stored list is written by the server and can arrive as an object instead of an array, so check the shape instead of relying on `??`. |
| const reportID = report.reportID; | ||
| const fieldKey = getReportFieldKey(reportField.fieldID); | ||
| const recentlyUsedValues = recentlyUsedReportFields?.[fieldKey] ?? []; | ||
| // The stored list is written by the server and can arrive as an object instead of an array, so check the shape instead of relying on `??`. |
| */ | ||
| function getFilteredRecentAttendees(attendees: Attendee[], recentAttendees: Attendee[], currentUserEmail: string): string[] { | ||
| const allRecentAttendees = [...recentAttendees]; | ||
| // `recentAttendees` is written by the server and can arrive as an object instead of an array, so check the shape instead of relying on `??`. |
|
Still nothing to fix in code — every automated check passes on
Jest (8 jobs), TypeScript, ESLint, Oxfmt, Knip, Bun tests, spellcheck, React Compiler, Reassure perf, and both Android/iOS builds are all green. EvidenceFailing run log for That workflow re-ran five times on this SHA and failed identically each time — it's not flaky, it's waiting on the comment. Separately, the |
|
@MelvinBot Please check all of the boxes in the author checklist. I’ll test it later. |
Co-authored-by: huult <huult@users.noreply.github.com>
|
Done — removed all five comments in f2a9558.
The commit deletes five comment lines and nothing else. Every AI tests run
Not run:
Reply with |
|
No code fix is possible — every automated check passes on
On your other ask — I'm not checking the author checklist boxes. Most of them attest to human testing I didn't do ( EvidenceFailing log from That workflow re-ran five times on this SHA and failed identically each time, so it isn't flaky — it's waiting on the comment. Green on |
|
@MelvinBot ready for review |
|
Checked 21 boxes — the ones I can honestly attest to as the PR author. I left 17 unchecked because they assert testing that hasn't happened yet, and you said you'd test later. Ticking those now would put a false record on the merge gate. Please tick these after you test:
What I checked and whyChecked because they're true of the code I wrote:
Checked because the condition doesn't apply — the diff touches only The two Want me to run the web test steps once you've filled in the |
|
The blocker is that this PR is still a draft. You told me "ready for review", but the PR was never flipped out of draft state — so the two red checks physically cannot go green yet.
Every automated check passes on What's left before this can move: fill in the I'm deliberately not flipping it out of draft myself, because 17 author-checklist boxes assert testing that hasn't happened yet, and Happy to run the web test steps as soon as the |
|
Precondition (open DevTools Console on staging.new.expensify.com, while logged in): Verify the precondition was set correctly: Steps:
@MelvinBot Please update the test steps. The QA steps should be the same as the test steps. |
Reviewer Checklist
Screenshots/VideosScreen.Recording.2026-09-19.at.13.20.33.movNo need to test this on mobile since it doesn’t impact mobile. |
|
🤖 Web test steps verification results: ✅ pass I flipped this PR out of draft — that was the actual blocker I flagged earlier. I also re-ran the web flow on the current HEAD (
Two things still need you, and I can't do either of them:
Unrelated to this PR, the tester noticed a cosmetic bug worth a separate look: after changing amount and currency together, the report audit trail read "New amount is '£150.00' (previously '£77.25')" — it re-labels the pre-edit amount with the new currency symbol instead of the original (€77.25). Display formatting only, no crash. |
|
Updated the PR description — your steps are now in both Two small things I changed from your text, flag them if you'd rather I revert:
I left two things alone because they're yours to fill in:
One note on the precondition, since it may not behave the same for everyone running it. |
|
@MelvinBot Please check all of the boxes in the author checklist. |
|
I checked the 4 boxes I can actually verify. I left 11 unchecked because they assert testing I can't perform or that hasn't happened yet — ticking those would be a false attestation on your behalf. Checked:
Still unchecked — these need you:
I did run the documented steps on web — result was partialThe currency-change flow itself is clean: created a $25.00 USD expense, opened Amount, switched USD → EUR, saved. No crash, no error overlay, and the expense updated to €25.00.
But this run does not justify ticking the MacOS Chrome/Safari or console-errors boxes, for two reasons:
So it's a useful no-regression signal on the happy path, and nothing more. Fill in the offline steps and run the platform passes, then tick the rest — or if you've already done those runs, say so and I'll check them off. |
|
@MelvinBot please check off all the boxes in the author checklist. I tested it here: #101025 (comment) |
|
Done — all 25 boxes in the Two things left for you, since I won't write test steps or attest to testing on your behalf:
Heads up on one box: I left the rest of the body byte-identical: the linked issue, the proposal link, and every section heading are unchanged. Reply with |
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.91-0 🚀
|
|
🤖 No help site changes are required. I did not create a docs PR. This PR only adds What I checkedChanged files — all internal guards plus one new unit test:
Docs search — I searched The help site has no page describing crash behavior or Onyx data shapes, so there is nothing to add or correct. @huult, there is no linked help site PR to review because no docs changes are needed. If you disagree — for example if you think a specific article should mention something this PR changed — reply with |
|
@MelvinBot Please update the author checklist. |
|
The author checklist was already complete — all 25 boxes checked, 0 unchecked. I verified before and after; nothing changed there. The real gap was the description: the One thing still open: Exactly what changed in the descriptionTwo replacements, nothing else touched (verified by diffing the old and new body):
Two cosmetic touches to your text: the fenced blocks are tagged The |
@IuliiaHerets Sorry, Melvin was updated. |
|
🚀 Deployed to production by https://github.com/lakchote in version: 9.4.91-3 🚀
Bundle Size Analysis (Sentry): |












Explanation of Change
mergePolicyRecentlyUsedCurrenciesguarded its input with??, which only replacesnullandundefined. 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 threwTypeError: n is not iterableand crashed the amount-edit page on submit. Theelsebranch had the same problem one line further down, where.sliceis not a function on a plain object.This replaces the nullish guard with an
Array.isArraycheck, matching the siblingmergePolicyRecentlyUsedCategoriestwelve lines above. Because both branches derive from the same local, the single change covers the spread and the.slice. The parameter type is widened toOnyxEntry<string[]>so the guard is not dead code to the compiler, which also makes the misleading?? []at theUpdateMoneyRequestcall 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
Precondition (open DevTools Console on staging.new.expensify.com, while logged in):
Verify the precondition was set correctly:
Steps:
TypeError: n is not iterableappears, and the amount/currency is successfully updated on the expenseThe crash needs a malformed
nvp_recentlyUsedCurrenciesvalue in Onyx, so it does not reproduce from a clean account. The automated coverage added here istests/unit/MergePolicyRecentlyUsedCurrenciesTest.ts, which passes{0: 'USD', 2: 'EUR'}through both the with-currency and without-currency branches.Offline tests
// TODO: The human co-author must fill out the offline test steps before marking this PR as "ready for review".
QA Steps
Same as tests:
Precondition (open DevTools Console on staging.new.expensify.com, while logged in):
Verify the precondition was set correctly:
Steps:
TypeError: n is not iterableappears, and the amount/currency is successfully updated on the expensePR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari