[Due for payment 2026-12-08] [$175] [Sentry: APP-PGS] TypeError: undefined is not a function in DynamicReviewDescriptionPage
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
- Upwork Job URL: https://www.upwork.com/jobs/~022124948500638620318
- Upwork Job ID: 2124948500638620318
- Last Price Increase: 2026-11-23
Issue Owner
Current Issue Owner: @linhvovan29546
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:
- Unnormalized
change.description(src/libs/TransactionUtils/duplicates.ts:285-299, 341): Unlikemerchant, which already delegates togetMerchant(item)insidegetDifferentValues(lines 291-293),description(keys = ['comment']) collects rawCommentobjects intonew Set(...). As a result:change.descriptioncontains rawCommentobjects whose.commentproperty may still be a non-string (e.g. number12345or0).new Set(...)deduplicates byCommentobject reference rather than normalized text, so distinct transactions with equivalent descriptions (e.g.123vs'123', or two{comment: 'Lunch'}objects) are not deduplicated.
- Unnormalized
keep.description(src/libs/TransactionUtils/duplicates.ts:339): When all descriptions are equal,keep[fieldName] = firstTransaction?.comment?.comment ?? firstTransaction?.commentbypassesgetDescription(firstTransaction). If the description is numeric (12345or0),keep.descriptionstores a raw number instead of a string; ifcommentis{}, it leaks{}intokeep.description(typed asstringinReviewDuplicates). - Unnormalized parse & truthiness check in
DynamicReviewDescriptionPage(src/pages/TransactionDuplicate/DynamicReviewDescriptionPage.tsx:51-58): The screen maps each rawCommentobject fromcompareResult.change.description, checks!description?.comment, and passesdescription.commentstraight intoParser.htmlToText(description.comment)andvalue: description.comment:- For a truthy non-string (e.g.
12345),Parser.htmlToTextpasses it toExpensiMark.replaceTextWithExtras, which callstext.replace(...)and throwsTypeError: undefined is not a function. - For numeric
0,!description?.commentevaluates totrue, silently discarding"0"and renderingtranslate('violations.none')withvalue: ''.
- For a truthy non-string (e.g.
- Related raw access on the preceding duplicate-list item (
src/pages/TransactionDuplicate/DuplicateTransactionItem.tsx:105):accessibilityLabel={transaction.comment?.comment ?? ''}also bypassesgetDescription(transaction)and would pass a raw number to React Native's stringaccessibilityLabelprop.
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:
src/libs/TransactionUtils/duplicates.ts:- Update
FieldsToChange['description'](line 33) fromArray<Comment | undefined>tostring[](consistent with every other field inFieldsToChange, all of which are primitive arrays; verified via repo-wide search thatchange.descriptionis only read insrc/libs/TransactionPreviewUtils.ts:89,src/pages/TransactionDuplicate/DynamicReviewDescriptionPage.tsx:51, andtests/unit/TransactionUtilsTest.ts). - In
getDifferentValues(lines 285-299), add a branch alongside the existingmerchantbranch: whenkeys.includes('comment'), returngetDescription(item). This normalizes every entry (including12345 -> '12345',0 -> '0', andundefined/null/''->'') and ensuresnew Set(...)deduplicates by normalized string value. - In the
descriptionkeepbranch (line 339), replacefirstTransaction?.comment?.comment ?? firstTransaction?.commentwithgetDescription(firstTransaction)sokeep.descriptionis always a normalizedstring(matchingkeep[fieldName] = getMerchant(firstTransaction)right below it on line 345).
- Update
src/pages/TransactionDuplicate/DynamicReviewDescriptionPage.tsx(lines 51-58):- Map directly over the normalized
stringarray incompareResult.change.description. - Check
!description(since0is 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))andvalue: description, ensuring both rendered labels and the value stored viasetReviewDuplicatesKey({description: data.value})(and compared againstselectedValue={reviewDuplicates?.description}inReviewFields) are always strings.
- Map directly over the normalized
src/pages/TransactionDuplicate/DuplicateTransactionItem.tsx(line 105):- Replace
transaction.comment?.comment ?? ''withgetDescription(transaction)foraccessibilityLabel.
- Replace
- Regression tests:
- Add unit tests in
tests/unit/TransactionUtilsTest.ts(compareDuplicateTransactionFields->description field comparison) covering:- numeric descriptions (
12345and0) normalized to'12345'and'0'inchange.description, - equal numeric/mixed descriptions (e.g.
0&0, or12345&'12345') kept as normalized strings inkeep.descriptionwithchange.descriptionundefined, - empty/undefined/
{}comments normalized and deduplicated to''.
- numeric descriptions (
- Add a component regression test for
DynamicReviewDescriptionPageverifying that numeric descriptions (12345and0) 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''.
- Add unit tests in
What alternative solutions did you explore? (Optional)
- Normalizing only inside
DynamicReviewDescriptionPage.tsx(e.g. callinggetDescription({comment: description})ordescription?.comment?.toString() ?? ''on the rawCommentobject):- This would prevent the immediate crash in
DynamicReviewDescriptionPage, but would leavecompareDuplicateTransactionFieldsreturning raw unnormalized values inkeep.description(storing numbers or{}intoReviewDuplicates.description) and rawCommentobjects inchange.description(failing to deduplicate123vs'123'or two transactions with identical comment text). Normalizing once insidecompareDuplicateTransactionFieldsviagetDescriptionsolves all three issues cleanly and mirrorsgetMerchant.
- This would prevent the immediate crash in
- Coercing non-strings inside
Parser.htmlToText:- Defensively coercing in
Parserwould mask type bugs elsewhere without fixing thevalue: description.commentnumeric leak intoReviewDuplicates, the!description?.commentmisclassification of0as"None", or the broken deduplication incompareDuplicateTransactionFields.
- Defensively coercing in
@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 Thank you for the heads-up! Apologies for jumping the gun — I will strictly wait for the \Help Wanted\ label going forward.
@MelvinBot Please analyze the issue and provide a proposal.
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
- duplicates.ts:285–303: equality uses
getDescription(), while differing choices retain raw comment objects. - duplicates.ts:328–342: matching descriptions also bypass normalization.
- DynamicReviewDescriptionPage.tsx:51–63: truthiness determines emptiness, and the raw value is parsed and selected.
- fields.ts:137–144: existing
getDescription()converts numbers to strings, preserves zero as'0', and converts missing values to''.
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:
- Return unique normalized strings in
change.description, updating its type tostring[]. Normalize before deduplication. - Populate
keep.descriptionthroughgetDescription()too; matching descriptions bypass the review screen. - 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. - Leave
keep.commentuntouched 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.
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
Current assignee @mountiny is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.
Go ahead please @linhvovan29546
@MelvinBot implement this
🤖 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.
| 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.![]() |
❌ |
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
@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]