App icon indicating copy to clipboard operation
App copied to clipboard

[Due for payment 2026-12-08] [$175] [Sentry: APP-PGS] TypeError: undefined is not a function in DynamicReviewDescriptionPage

Open mountiny opened this issue 1 week ago • 13 comments

Sentry

https://expensify.sentry.io/issues/APP-PGS

Impact

  • 1 user, 1 event since first seen: November 22, 2026, 16:07 UTC.
  • Platform: iOS HybridApp.
  • Release: [email protected].
  • Screen: Dynamic_Transaction_Duplicate_Review.
  • Unhandled React render error; fatal, app_blocking: true.

Stack

DynamicReviewDescriptionPage.tsx:50
  compareResult.change.description?.map(...)
DynamicReviewDescriptionPage.tsx:54
  Parser.htmlToText(description.comment)
src/libs/Parser.ts:47
  super.htmlToText(htmlString, ...)
expensify-common/ExpensiMark.js — replaceTextWithExtras
  text.replace(regexp, replacement)

Suspected root cause

The description-review screen passes raw description.comment into the parser after checking only truthiness. A truthy non-string value lacks .replace() and crashes rendering.

Our getDescription() helper already normalizes numeric API descriptions to strings, but this screen bypasses it. Numeric-only descriptions returning as numbers were documented in an earlier investigation.

The event’s exact description value is unavailable, so the numeric trigger is inferred, not confirmed. No matching tracker was found in Expensify/App or Expensify/Expensify.

Suggested fix

Normalize description values before parsing and selecting them, reusing the existing description-normalization behavior. Add regression coverage for numeric descriptions, including zero, and empty values.

Expected behavior

Reviewing duplicate-expense descriptions never crashes the screen.

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @linhvovan29546

mountiny avatar Nov 23 '26 19:11 mountiny

Triggered auto assignment to Contributor-plus team member for initial proposal review - @linhvovan29546 (External)

Job added to Upwork: https://www.upwork.com/jobs/~022124948500638620318

Proposal

Please re-state the problem that we are trying to solve in this issue.

Opening DynamicReviewDescriptionPage during duplicate expense review crashes with TypeError: undefined is not a function inside Parser.htmlToText -> ExpensiMark.replaceTextWithExtras when a duplicate transaction's comment.comment arrives as a non-string value (such as a number from the API, e.g. 12345). Additionally, a numeric 0 description is falsy under !description?.comment, causing it to be misclassified as "None" (value: '') instead of "0".

What is the root cause of that problem?

In src/libs/TransactionUtils/duplicates.ts, compareDuplicateTransactionFields already imports and uses getDescription (src/libs/TransactionUtils/fields.ts:154, which normalizes via transaction?.comment?.comment?.toString() ?? '') inside areAllCommentsEqual (line 303) and allCommentsAreEmpty (line 337), but bypasses getDescription in both its return paths:

  1. Unnormalized change.description (src/libs/TransactionUtils/duplicates.ts:285-299, 341): Unlike merchant, which already delegates to getMerchant(item) inside getDifferentValues (lines 291-293), description (keys = ['comment']) collects raw Comment objects into new Set(...). As a result:
    • change.description contains raw Comment objects whose .comment property may still be a non-string (e.g. number 12345 or 0).
    • new Set(...) deduplicates by Comment object reference rather than normalized text, so distinct transactions with equivalent descriptions (e.g. 123 vs '123', or two {comment: 'Lunch'} objects) are not deduplicated.
  2. Unnormalized keep.description (src/libs/TransactionUtils/duplicates.ts:339): When all descriptions are equal, keep[fieldName] = firstTransaction?.comment?.comment ?? firstTransaction?.comment bypasses getDescription(firstTransaction). If the description is numeric (12345 or 0), keep.description stores a raw number instead of a string; if comment is {}, it leaks {} into keep.description (typed as string in ReviewDuplicates).
  3. Unnormalized parse & truthiness check in DynamicReviewDescriptionPage (src/pages/TransactionDuplicate/DynamicReviewDescriptionPage.tsx:51-58): The screen maps each raw Comment object from compareResult.change.description, checks !description?.comment, and passes description.comment straight into Parser.htmlToText(description.comment) and value: description.comment:
    • For a truthy non-string (e.g. 12345), Parser.htmlToText passes it to ExpensiMark.replaceTextWithExtras, which calls text.replace(...) and throws TypeError: undefined is not a function.
    • For numeric 0, !description?.comment evaluates to true, silently discarding "0" and rendering translate('violations.none') with value: ''.
  4. Related raw access on the preceding duplicate-list item (src/pages/TransactionDuplicate/DuplicateTransactionItem.tsx:105): accessibilityLabel={transaction.comment?.comment ?? ''} also bypasses getDescription(transaction) and would pass a raw number to React Native's string accessibilityLabel prop.

What changes do you think we should make in order to solve the problem?

Reuse the existing getDescription normalization consistently across the duplicate-comparison boundary (matching how merchant already reuses getMerchant), then consume normalized strings in DynamicReviewDescriptionPage:

  1. src/libs/TransactionUtils/duplicates.ts:
    • Update FieldsToChange['description'] (line 33) from Array<Comment | undefined> to string[] (consistent with every other field in FieldsToChange, all of which are primitive arrays; verified via repo-wide search that change.description is only read in src/libs/TransactionPreviewUtils.ts:89, src/pages/TransactionDuplicate/DynamicReviewDescriptionPage.tsx:51, and tests/unit/TransactionUtilsTest.ts).
    • In getDifferentValues (lines 285-299), add a branch alongside the existing merchant branch: when keys.includes('comment'), return getDescription(item). This normalizes every entry (including 12345 -> '12345', 0 -> '0', and undefined/null/'' -> '') and ensures new Set(...) deduplicates by normalized string value.
    • In the description keep branch (line 339), replace firstTransaction?.comment?.comment ?? firstTransaction?.comment with getDescription(firstTransaction) so keep.description is always a normalized string (matching keep[fieldName] = getMerchant(firstTransaction) right below it on line 345).
  2. src/pages/TransactionDuplicate/DynamicReviewDescriptionPage.tsx (lines 51-58):
    • Map directly over the normalized string array in compareResult.change.description.
    • Check !description (since 0 is already normalized to '0', only truly empty/missing descriptions map to '' -> {text: translate('violations.none'), value: ''}).
    • For non-empty strings, compute text: StringUtils.lineBreaksToSpaces(Parser.htmlToText(description)) and value: description, ensuring both rendered labels and the value stored via setReviewDuplicatesKey({description: data.value}) (and compared against selectedValue={reviewDuplicates?.description} in ReviewFields) are always strings.
  3. src/pages/TransactionDuplicate/DuplicateTransactionItem.tsx (line 105):
    • Replace transaction.comment?.comment ?? '' with getDescription(transaction) for accessibilityLabel.
  4. Regression tests:
    • Add unit tests in tests/unit/TransactionUtilsTest.ts (compareDuplicateTransactionFields -> description field comparison) covering:
      • numeric descriptions (12345 and 0) normalized to '12345' and '0' in change.description,
      • equal numeric/mixed descriptions (e.g. 0 & 0, or 12345 & '12345') kept as normalized strings in keep.description with change.description undefined,
      • empty/undefined/{} comments normalized and deduplicated to ''.
    • Add a component regression test for DynamicReviewDescriptionPage verifying that numeric descriptions (12345 and 0) and empty/undefined descriptions render without throwing, '0' renders as '0' (not "None") and selects '0', '12345' selects '12345', and empty/missing descriptions render "None" and select ''.

What alternative solutions did you explore? (Optional)

  1. Normalizing only inside DynamicReviewDescriptionPage.tsx (e.g. calling getDescription({comment: description}) or description?.comment?.toString() ?? '' on the raw Comment object):
    • This would prevent the immediate crash in DynamicReviewDescriptionPage, but would leave compareDuplicateTransactionFields returning raw unnormalized values in keep.description (storing numbers or {} into ReviewDuplicates.description) and raw Comment objects in change.description (failing to deduplicate 123 vs '123' or two transactions with identical comment text). Normalizing once inside compareDuplicateTransactionFields via getDescription solves all three issues cleanly and mirrors getMerchant.
  2. Coercing non-strings inside Parser.htmlToText:
    • Defensively coercing in Parser would mask type bugs elsewhere without fixing the value: description.comment numeric leak into ReviewDuplicates, the !description?.comment misclassification of 0 as "None", or the broken deduplication in compareDuplicateTransactionFields.

danlopes18-ctrl avatar Nov 23 '26 19:11 danlopes18-ctrl

@danlopes18-ctrl Thanks for your interest in contributing to Expensify! Please only post proposal if Help Wanted label has been applied. Also, take a look at CONTRIBUTING.md to get familiar with the guidelines.

samranahm avatar Nov 23 '26 19:11 samranahm

@samranahm Thank you for the heads-up! Apologies for jumping the gun — I will strictly wait for the \Help Wanted\ label going forward.

danlopes18-ctrl avatar Nov 23 '26 19:11 danlopes18-ctrl

@MelvinBot Please analyze the issue and provide a proposal.

linhvovan29546 avatar Nov 24 '26 06:11 linhvovan29546

Proposal

What is the root cause of that problem?

Duplicate-description comparison uses normalized strings to decide whether descriptions match, but returns raw comment values for both matching and differing descriptions.

The description-review screen then passes a truthy raw value directly to the HTML parser. A nonzero numeric description can therefore cause the reported .replace() failure. Numeric 0 follows a different incorrect path: it is treated as empty and displayed as “None.”

Confidence: medium. The code supports this failure mechanism, but the exact value behind the Sentry event is unavailable, so a numeric production trigger remains unconfirmed.

Code evidence

What changes do you think we should make in order to solve the problem?

Normalize descriptions at the duplicate-comparison boundary, consistent with the existing proposal:

  1. Return unique normalized strings in change.description, updating its type to string[]. Normalize before deduplication.
  2. Populate keep.description through getDescription() too; matching descriptions bypass the review screen.
  3. Update the screen to consume strings directly. Only '' should represent “None.” Parse text for display, but preserve the original normalized string as the selected value.
  4. Leave keep.comment untouched so transaction metadata remains preserved.

Regression coverage:

  • Nonzero numbers and numeric zero produce string choices without crashing.
  • Equal number/string descriptions produce a normalized keep.description.
  • Missing, null and empty descriptions normalize consistently.
  • Repeated equivalent descriptions produce one choice when another description differs.
  • Selecting '0' or “None” preserves '0' or '' through confirmation and merge parameters.
  • HTML descriptions retain their original value while displaying plain text.
Compatibility and verification

The review-state contract already declares description as a string: ReviewDuplicates.ts:31–35. Metadata and description are handled separately during confirmation: duplicates.ts:436–475.

This was a source-level investigation; no automated tests or browser reproduction were run.

What alternative solutions did you explore? (Optional)

Screen-only normalization prevents the immediate crash but leaves matching-description values unnormalized. Parser-wide coercion similarly misses zero handling and selected-value consistency.

Related issue: Selected empty description is replaced after merging duplicates concerns a different post-merge symptom; this proposal does not establish a fix for it.


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/107766) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Nov 24 '26 06:11 MelvinBot

MelvinBot's solution fixes the crash. LGTM! I reproduced it on iOS with a numeric description (comment: {comment: 12345}), and normalizing it with getDescription() fixes it. We should do the same in a few other places that parse the raw comment.comment: DynamicIOURequestStepDescription, ReportUtils.getTransactionSortValue, and ReportUtils.getTransactionCommentObject.

I'm just not sure why the BE can return comment as a number. When I save 12345 normally, it comes back as a string.

🎀 👀 🎀 C+ reviewed

linhvovan29546 avatar Nov 24 '26 10:11 linhvovan29546

Current assignee @mountiny is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

Go ahead please @linhvovan29546

mountiny avatar Nov 24 '26 23:11 mountiny

@MelvinBot implement this

linhvovan29546 avatar Nov 25 '26 06:11 linhvovan29546

🤖 Web test steps verification results: ⚠️ partial

Browser verification was blocked because the available dev session was suspended and exposed no UI nodes. The requested flows remain manually unverified.

Browser state when verification was blocked
Step Status
Verify numeric/zero rendering, zero/None selection, HTML preservation, and numeric-description editingBlocked before reaching the expense flows—not a demonstrated product failure.
Browser state when verification was blocked
❌

Implemented in draft PR: Normalize expense descriptions before parsing and duplicate review, assigned to linhvovan29546, with PullerBear review requested.

Includes the approved fix, the three additional parsing sites, and regression coverage. 43,238 tests passed, plus lint, TypeScript, formatting, spelling, and Storybook smoke checks. Direct React Compiler checks passed; its changed-files wrapper was blocked by an empty base-ref setting. Independent code review found no violations.


view run · no recording available

MelvinBot avatar Nov 25 '26 07:11 MelvinBot

@linhvovan29546

The solution for this issue has been :rocket: deployed to production :rocket: in version 9.5.55-6 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:

  • https://github.com/Expensify/App/pull/107925

If no regressions arise, payment will be issued on 2026-12-08. :confetti_ball:

The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]. If no checklist is needed for this issue, you can click: [no checklist button]

melvin-bot[bot] avatar Dec 01 '26 03:12 melvin-bot[bot]