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
{{ message }}
Repository navigation
[$250] Expense -Scan expense appears in the first position in the carousel position after smartscan #91624
Version Number: v9.3.81-1 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack:#91467 Email or phone of affected tester (no customers): n/a Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Mac 15.4.1 Safari/Chrome, iPhone 13 iOS 26.5 App Component: Money Requests
The carousel sorts transactions with RBR (Red Brick Road) violations first, then by created date ascending. While SmartScan is in progress, isReceiptBeingScanned() returns true, which suppresses the hasMissingSmartscanFields() check — so the scan transaction has no RBR during scanning and stays in its original position.
When SmartScan completes, receipt.state becomes SCANCOMPLETE, isReceiptBeingScanned() flips to false, and if any required fields are still missing (amount, merchant, etc.), hasMissingSmartscanFields() now returns true → the transaction gains RBR status. The compareByRBR() function in the carousel sort then pushes it to position 0.
A secondary factor: both same-day transactions share the same created date (yyyy-MM-dd with no time component, set at MoneyRequest.ts:883), making the date tiebreaker unstable. The server may also update created to the receipt date after SmartScan, further disrupting order.
What changes do you think we should make in order to solve the problem?
The carousel sort should preserve the original insertion order when RBR status changes. Instead of only tiebreaking by created date (which is identical for same-day transactions), add a secondary tiebreaker using a stable, creation-order-preserving key — such as transactionID (which is monotonically increasing) — so that RBR status changes don't cause position jumps for transactions created on the same day.
In MoneyRequestReportPreviewContent.tsx, after the localeCompare(getCreated(a), getCreated(b)) tiebreaker, add a final tiebreaker comparing transactionID strings to maintain stable ordering. The same change should be applied to the sort in MoneyRequestReportTransactionList.tsx for consistency.
Additionally, consider whether RBR-first sorting should apply to the carousel preview at all — the carousel is a visual preview, not an action queue, so reordering it based on violation status may be confusing to users regardless.
What alternative solutions did you explore?
Suppress RBR sorting entirely in the carousel — simpler but changes the existing design intent of surfacing violations prominently. Could be the right call if product decides violations shouldn't drive carousel order.
Use created with full timestamp instead of date-only — would help with the date tiebreaker instability but doesn't solve the RBR-driven reorder, which is the primary cause.
SmartScan guard:TransactionUtils/index.ts:1568-1569 — hasMissingSmartscanFields is suppressed while isReceiptBeingScanned() is true, then activates after scan completes.
Created date format:MoneyRequest.ts:883 — format(new Date(), 'yyyy-MM-dd') produces date-only strings, making same-day tiebreakers return 0.
Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.
🚨 Edited by proposal-police: This proposal was edited at 2026-05-25 15:37:36 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a workspace chat has a manual expense and then a scanned expense, the scan slides over to the first position in the report preview carousel as soon as SmartScan finishes — even though nothing else about its order should change.
What is the root cause of that problem?
PR #91467 added a date-based tiebreaker to the carousel sort (oldest first) on top of the RBR comparison. The tiebreaker is localeCompare(getCreated(a), getCreated(b)), and getCreated returns transaction.modifiedCreated || transaction.created. While SmartScan is running, the scan transaction's created is DateUtils.getDBTime() (i.e. "now"), so it sorts after the older manual expense. Once SmartScan completes, the backend populates modifiedCreated with the actual receipt date — which is almost always earlier than the manual expense — so getCreated flips to that older value and the tiebreaker yanks the scan to the front of the carousel.
// Tiebreak by date (ascending — oldest first) so position is stable across RBR state changes
returnlocaleCompare(getCreated(a),getCreated(b));
});
What changes do you think we should make in order to solve the problem?
The tiebreaker needs a key that doesn't mutate when SmartScan completes. transaction.inserted is set once by the backend when the transaction is created and never changes afterward, which is exactly the "stable insertion order" the PR #91467 fix was reaching for. We should update the tiebreaker in carouselTransactions inside MoneyRequestReportPreviewContent.tsx to compare by a.inserted / b.inserted first, and only fall back to getCreated when inserted is missing (purely optimistic transactions that haven't synced yet). That keeps the original PR's intent (stable order across RBR state changes) while no longer reshuffling when SmartScan rewrites modifiedCreated.
The expense carousel in the report preview sorts transactions by RBR status first, then breaks ties with a date comparison. That date tiebreaker was added in PR #91467 precisely to keep positions stable across RBR state changes:
* @param iouRequestType one of manual/scan/distance
Tracing the flow (both expenses created the same day):
Manual expense and scan expense are both created today, so each has the identical created = '2026-05-25'. Neither has an RBR, so compareByRBR returns 0 and the tiebreaker localeCompare('2026-05-25', '2026-05-25') is also 0 — a tie. The scan expense holds 2nd position only because the input array is in insertion order and the sort is stable.
SmartScan completes and the backend overwrites the scan transaction's created/modifiedCreated with the receipt's real date, which is almost always a past date (e.g. 2026-05-22).
Re-sort now sees getCreated(scan) = '2026-05-22' < getCreated(manual) = '2026-05-25', so the oldest-first tiebreaker is no longer a tie and moves the scan expense to the first position.
So the key chosen to make the position stable is both (a) the one value SmartScan is guaranteed to rewrite, and (b) a same-day tie that leaves ordering to fragile array order — exactly defeating its own purpose for scan expenses.
What changes do you think we should make in order to solve the problem?
Tiebreak by the transaction's insertion order (inserted) instead of the mutable expense date. inserted is a full DB timestamp stamped once at creation in buildOptimisticTransaction (L552) and is never touched by SmartScan. It fixes both failure modes above: it doesn't change when the receipt date arrives, and because it carries millisecond precision it is a genuine deterministic tiebreaker even when two same-day expenses share a date-only created. This is the same immutable creation-order key already used as the stable tiebreaker in getAllSortedTransactions (L2712).
- // Tiebreak by date (ascending — oldest first) so position is stable across RBR state changes- return localeCompare(getCreated(a), getCreated(b));+ // Tiebreak by insertion order (ascending — oldest first) so position is stable across both RBR+ // state changes and SmartScan, which overwrites `created`/`modifiedCreated` with the receipt date+ return localeCompare(a.inserted ?? getCreated(a), b.inserted ?? getCreated(b));
getCreated is kept as a fallback for any transaction missing inserted, so the import stays used and no other change is required.
What alternative solutions did you explore? (Optional)
Freeze the order with a memoized index map / ref keyed by transactionID on first render — adds state, doesn't survive remount or reload, and breaks when transactions are added/removed. inserted gives the same stability for free.
Tiebreak by the IOU report action's created timestamp — also stable, but requires plumbing report actions into the sort; inserted already lives on the transaction object and is the established pattern, so it's the smaller, more consistent change.
Please re-state the problem that we are trying to solve in this issue.
In a workspace chat report that contains more than one expense, the expense carousel preview reorders itself when a scan expense finishes SmartScan. After creating a manual expense followed by a scan expense, the scan expense correctly sits in the second position while it is still scanning, but once SmartScan completes it jumps to the first position instead of staying where it was.
What is the root cause of that problem?
The carousel builds its ordered list in MoneyRequestReportPreviewContent. Transactions are sorted first by Red Brick Road status, and ties are broken by date in ascending order:
modifiedCreated holds the displayed/edited date, not the original creation order. When a scan expense is first created it has no modifiedCreated, so the tiebreaker uses its raw created timestamp (which is later than the manual expense created just before it) and the scan expense correctly stays in second place. When SmartScan completes, the date detected from the receipt is written into modifiedCreated. That date is typically older than the day the expense was created, so getCreated now returns the older receipt date, the ascending date tiebreaker moves the scan expense ahead of the manual expense, and it jumps to the first position.
Both expenses are clean after scanning (no violations), so compareByRBR returns 0 and the date tiebreaker is what actually decides the order — which is why the reorder is observable.
This is inconsistent with how the rest of the app orders a report's transactions. getAllSortedTransactions sorts by the immutable raw created field and uses inserted as the tiebreaker, never modifiedCreated:
Because that canonical sort ignores modifiedCreated, the report's transaction list does not reorder after SmartScan — only the carousel does, since the carousel is the only place that ties on the mutable display date.
What changes do you think we should make in order to solve the problem?
Change the carousel tiebreaker in MoneyRequestReportPreviewContent so it no longer ties on the mutable display date. Instead of comparing getCreated(a) and getCreated(b), break ties on the immutable creation order, matching getAllSortedTransactions: compare the raw created field first and fall back to inserted when the raw created values are equal.
The raw created and inserted fields are set once when the transaction is built and are not changed when SmartScan writes the detected receipt date (which lands in modifiedCreated) or when a user edits the date. As a result the carousel position stays stable across SmartScan completion, while still preserving the existing behavior of putting Red Brick Road expenses first and keeping a deterministic, stable order for the original intent of the previous fix (stability across RBR state changes).
The getCreated import that was added solely for this tiebreaker can be removed if it is no longer used elsewhere in the file.
What alternative solutions did you explore? (Optional)
Reusing getAllSortedTransactions directly to produce the carousel list and then applying only the RBR re-ordering on top was considered, but that is a larger refactor than necessary; switching the existing inline tiebreaker to the immutable creation order is the minimal, targeted fix and keeps the RBR-first behavior intact.
carouselTransactions in MoneyRequestReportPreviewContent re-sorts transactions on every change using compareByRBR, which moves transactions with RBR ahead of those without:
Smartscan completes — fields populate, hasMissingSmartscanFields flips to false, scan no longer has RBR.
useMemo re-runs (deps changed because transactions and transactionViolations updated). Both transactions now have RBR = false, so compareByRBR returns 0 for the pair.
Array.prototype.sort is stable in modern V8, so equal-comparing items preserve relative order — but the relative order being preserved is the current[scan, manual] order from step 2, not the original [manual, scan] insertion order. The sort once-promoted the scan, the equality on re-sort holds it in front.
The video confirms this: the scan stays in position 0 after smartscan completes, ahead of the manual expense that was actually created first.
What changes do you think we should make in order to solve the problem?
Make the sort a true partial ordering with a stable tiebreaker on creation time. When neither transaction has RBR (or both do), fall back to created ascending so the natural chronological order is restored:
function compareByRBR(
a: OnyxTypes.Transaction,
b: OnyxTypes.Transaction,
violations: Record<string, OnyxTypes.TransactionViolations | undefined> | undefined,
currentUserEmail: string,
currentUserAccountID: number,
iouReport: OnyxEntry<OnyxTypes.Report>,
policy: OnyxEntry<OnyxTypes.Policy>,
reportActions?: OnyxTypes.ReportActions,
): number {
const aViolations = violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${a.transactionID}`] ?? [];
const bViolations = violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${b.transactionID}`] ?? [];
const aHasRBR = transactionHasRBR(a, aViolations, currentUserEmail, currentUserAccountID, iouReport, policy, reportActions);
const bHasRBR = transactionHasRBR(b, bViolations, currentUserEmail, currentUserAccountID, iouReport, policy, reportActions);
if (aHasRBR === bHasRBR) {
- return 0;+ // Fall back to creation order when both transactions have the same RBR status,+ // so a transient RBR (e.g. mid-smartscan) doesn't permanently reorder the carousel.+ return (a.created ?? '').localeCompare(b.created ?? '');
}
return aHasRBR ? -1 : 1;
}
After the change, step 4 of the repro re-sorts to [manual, scan] because manual's created precedes scan's — the smartscan completion correctly restores the original carousel position.
The created field is the source of truth for transaction creation time and isn't mutated by smartscan completion (smartscan updates modifiedCreated if it parses a different date from the receipt, but created remains the original transaction creation timestamp). Using localeCompare on the ISO string avoids the Date.parse allocation per comparison and gives stable lexicographic order on date strings.
changed the title [-]Expense -Scan expense appears in the first position in the carousel position after smartscan[/-][+][$250] Expense -Scan expense appears in the first position in the carousel position after smartscan[/+]on May 25, 2026
The carousel preview sorts transactions by RBR status, then breaks ties with getCreated(), which returns the mutable expense date (modifiedCreated || created). PR #91467 added this tiebreaker to keep positions stable across RBR transitions, but the key it chose is the one value SmartScan rewrites:
The manual and scan expenses are created the same day. initMoneyRequest sets a date-only created ('yyyy-MM-dd'), so both share the same key, localeCompare returns 0, and the scan holds 2nd place only because Array.prototype.sort is stable.
SmartScan completes and the backend writes the parsed receipt date back to the scan (modifiedCreated, which getCreated() prefers). Receipts are almost always older than "today".
The ascending tiebreaker now sees getCreated(scan) < getCreated(manual) and pushes the scan to position 0.
The transaction list under the carousel shows the same jump, but only on its default Date/ASC view, where it applies the same RBR-first ordering before falling back to the date sort value:
The immutable creation-order key is transaction.inserted, written once in buildOptimisticTransaction and never touched by SmartScan — the same key the canonical getAllSortedTransactions already uses as its tiebreaker (added in PR #52537 for this exact date-only-string problem):
- // Tiebreak by date (ascending — oldest first) so position is stable across RBR state changes- return localeCompare(getCreated(a), getCreated(b));+ // Tiebreak by insertion order (ascending) so position is stable across BOTH RBR state changes+ // and SmartScan, which overwrites `created`/`modifiedCreated` with the receipt date.+ return localeCompare(a.inserted ?? getCreated(a), b.inserted ?? getCreated(b));
2. Transaction list (MoneyRequestReportTransactionList.tsx) — apply the tiebreaker only in the existing default-sort RBR branch, so explicit Date-column sorting is left alone:
if (rbrComparison !== 0) {
return rbrComparison;
}
+ // Equal RBR on the default Date/ASC view: tiebreak by immutable insertion order so a+ // SmartScan-rewritten receipt date can't reorder the list. Falls through to the date+ // comparison below when `inserted` is absent or equal.+ const insertedComparison = localeCompare(a.inserted ?? '', b.inserted ?? '');+ if (insertedComparison !== 0) {+ return insertedComparison;+ }
}
return compareValues(getTransactionSortValue(a, sortBy, report, policy), getTransactionSortValue(b, sortBy, report, policy), sortOrder, sortBy, localeCompare, true);
This keeps PR #91467's intent (stable position across RBR changes) and extends it to SmartScan completion, while preserving displayed-date semantics everywhere a user explicitly sorts.
What alternative solutions did you explore? (Optional)
⚠️@mukhrr Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.
While most proposals are quite similar, I'd like to go with @FitseTLT's proposal since they considered various cases and raised product concern which can cause unexpected behavior we don't want.
Note on displayed date: Both views currently display the expense date (created) to the user. If we sort by inserted but display created, the visual order may not match the displayed dates after SmartScan updates them (e.g. a receipt dated May 15 could appear after a May 25 expense). This could be acceptable since it preserves positional stability, but if the design team prefers consistency between sort order and displayed date, we could also update the displayed date to show inserted (or add a visual indicator distinguishing "date entered" from "receipt date").
@FitseTLT please discuss and confirm the expected behavior with design/product team before proceeding PR.
Ah ok interesting. I really like the proposal from @FitseTLT. I'm leaning towards calling this not a bug, but I'll double check with a product team member. Idk how to auto assign them so I'll ask in Slack internally.
I raised this in Slack internally. I don't think it's a bug so I will close it now, and we will re-open it if enough people think there's a problem here worth fixing.
Activity
applause-bot commentedon May 25, 2026
While Applause doesn't embed attachments for this bug, here are the links for quick view:
https://platform.applause.com/services/links/v1/external/ede0ac8d7903eac7c518727af2af28babddb49ae5226643470cf8ae7c2b9cdba
MelvinBot commentedon May 25, 2026
Proposal
What is the root cause of that problem?
The carousel sorts transactions with RBR (Red Brick Road) violations first, then by created date ascending. While SmartScan is in progress,
isReceiptBeingScanned()returnstrue, which suppresses thehasMissingSmartscanFields()check — so the scan transaction has no RBR during scanning and stays in its original position.When SmartScan completes,
receipt.statebecomesSCANCOMPLETE,isReceiptBeingScanned()flips tofalse, and if any required fields are still missing (amount, merchant, etc.),hasMissingSmartscanFields()now returnstrue→ the transaction gains RBR status. ThecompareByRBR()function in the carousel sort then pushes it to position 0.A secondary factor: both same-day transactions share the same
createddate (yyyy-MM-ddwith no time component, set atMoneyRequest.ts:883), making the date tiebreaker unstable. The server may also updatecreatedto the receipt date after SmartScan, further disrupting order.What changes do you think we should make in order to solve the problem?
The carousel sort should preserve the original insertion order when RBR status changes. Instead of only tiebreaking by
createddate (which is identical for same-day transactions), add a secondary tiebreaker using a stable, creation-order-preserving key — such astransactionID(which is monotonically increasing) — so that RBR status changes don't cause position jumps for transactions created on the same day.In
MoneyRequestReportPreviewContent.tsx, after thelocaleCompare(getCreated(a), getCreated(b))tiebreaker, add a final tiebreaker comparingtransactionIDstrings to maintain stable ordering. The same change should be applied to the sort inMoneyRequestReportTransactionList.tsxfor consistency.Additionally, consider whether RBR-first sorting should apply to the carousel preview at all — the carousel is a visual preview, not an action queue, so reordering it based on violation status may be confusing to users regardless.
What alternative solutions did you explore?
createdwith full timestamp instead of date-only — would help with the date tiebreaker instability but doesn't solve the RBR-driven reorder, which is the primary cause.Investigation details
Sorting logic (carousel):
MoneyRequestReportPreviewContent.tsx:356-368— sorts by RBR first viacompareByRBR, then bygetCreated()ascending.Sorting logic (transaction list):
MoneyRequestReportTransactionList.tsx:296-316— same RBR-first pattern with date tiebreaker.RBR comparison:
TransactionPreviewUtils.ts:543-561— returns -1 for RBR transactions, pushing them to front.SmartScan guard:
TransactionUtils/index.ts:1568-1569—hasMissingSmartscanFieldsis suppressed whileisReceiptBeingScanned()is true, then activates after scan completes.Created date format:
MoneyRequest.ts:883—format(new Date(), 'yyyy-MM-dd')produces date-only strings, making same-day tiebreakers return 0.Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.MobileMage commentedon May 25, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-05-25 15:37:36 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When a workspace chat has a manual expense and then a scanned expense, the scan slides over to the first position in the report preview carousel as soon as SmartScan finishes — even though nothing else about its order should change.
What is the root cause of that problem?
PR #91467 added a date-based tiebreaker to the carousel sort (oldest first) on top of the RBR comparison. The tiebreaker is
localeCompare(getCreated(a), getCreated(b)), andgetCreatedreturnstransaction.modifiedCreated || transaction.created. While SmartScan is running, the scan transaction'screatedisDateUtils.getDBTime()(i.e. "now"), so it sorts after the older manual expense. Once SmartScan completes, the backend populatesmodifiedCreatedwith the actual receipt date — which is almost always earlier than the manual expense — sogetCreatedflips to that older value and the tiebreaker yanks the scan to the front of the carousel.App/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx
Lines 360 to 367 in 668b0df
What changes do you think we should make in order to solve the problem?
The tiebreaker needs a key that doesn't mutate when SmartScan completes.
transaction.insertedis set once by the backend when the transaction is created and never changes afterward, which is exactly the "stable insertion order" the PR #91467 fix was reaching for. We should update the tiebreaker incarouselTransactionsinsideMoneyRequestReportPreviewContent.tsxto compare bya.inserted/b.insertedfirst, and only fall back togetCreatedwheninsertedis missing (purely optimistic transactions that haven't synced yet). That keeps the original PR's intent (stable order across RBR state changes) while no longer reshuffling when SmartScan rewritesmodifiedCreated.App/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx
Lines 365 to 366 in 668b0df
What alternative solutions did you explore? (Optional)
N/A
yusufdeveloper2903 commentedon May 25, 2026
Proposal
What is the root cause of that problem?
The expense carousel in the report preview sorts transactions by RBR status first, then breaks ties with a date comparison. That date tiebreaker was added in PR #91467 precisely to keep positions stable across RBR state changes:
App/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx
Lines 360 to 367 in c3dba01
The tiebreaker key is
getCreated(), which returns the expense date (modifiedCreated || created):App/src/libs/TransactionUtils/index.ts
Lines 1392 to 1394 in c3dba01
The problem is that this key is mutable for scan expenses. The optimistic
createdis a date-only string (yyyy-MM-dd), set ininitMoneyRequest:App/src/libs/actions/IOU/MoneyRequest.ts
Line 883 in c3dba01
Tracing the flow (both expenses created the same day):
created = '2026-05-25'. Neither has an RBR, socompareByRBRreturns0and the tiebreakerlocaleCompare('2026-05-25', '2026-05-25')is also0— a tie. The scan expense holds 2nd position only because the input array is in insertion order and the sort is stable.created/modifiedCreatedwith the receipt's real date, which is almost always a past date (e.g.2026-05-22).getCreated(scan) = '2026-05-22' < getCreated(manual) = '2026-05-25', so the oldest-first tiebreaker is no longer a tie and moves the scan expense to the first position.So the key chosen to make the position stable is both (a) the one value SmartScan is guaranteed to rewrite, and (b) a same-day tie that leaves ordering to fragile array order — exactly defeating its own purpose for scan expenses.
What changes do you think we should make in order to solve the problem?
Tiebreak by the transaction's insertion order (
inserted) instead of the mutable expense date.insertedis a full DB timestamp stamped once at creation inbuildOptimisticTransaction(L552) and is never touched by SmartScan. It fixes both failure modes above: it doesn't change when the receipt date arrives, and because it carries millisecond precision it is a genuine deterministic tiebreaker even when two same-day expenses share a date-onlycreated. This is the same immutable creation-order key already used as the stable tiebreaker ingetAllSortedTransactions(L2712).getCreatedis kept as a fallback for any transaction missinginserted, so the import stays used and no other change is required.What alternative solutions did you explore? (Optional)
transactionIDon first render — adds state, doesn't survive remount or reload, and breaks when transactions are added/removed.insertedgives the same stability for free.createdtimestamp — also stable, but requires plumbing report actions into the sort;insertedalready lives on the transaction object and is the established pattern, so it's the smaller, more consistent change.melvin-bot commentedon May 25, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @aimane-chnaif (
External)wildan-m commentedon May 25, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
In a workspace chat report that contains more than one expense, the expense carousel preview reorders itself when a scan expense finishes SmartScan. After creating a manual expense followed by a scan expense, the scan expense correctly sits in the second position while it is still scanning, but once SmartScan completes it jumps to the first position instead of staying where it was.
What is the root cause of that problem?
The carousel builds its ordered list in
MoneyRequestReportPreviewContent. Transactions are sorted first by Red Brick Road status, and ties are broken by date in ascending order:App/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx
Lines 356 to 369 in 79426b2
The tiebreaker calls
getCreated, which returnsmodifiedCreatedwhenever it is present and only falls back to the rawcreatedfield otherwise:App/src/libs/TransactionUtils/index.ts
Lines 1392 to 1395 in 79426b2
modifiedCreatedholds the displayed/edited date, not the original creation order. When a scan expense is first created it has nomodifiedCreated, so the tiebreaker uses its rawcreatedtimestamp (which is later than the manual expense created just before it) and the scan expense correctly stays in second place. When SmartScan completes, the date detected from the receipt is written intomodifiedCreated. That date is typically older than the day the expense was created, sogetCreatednow returns the older receipt date, the ascending date tiebreaker moves the scan expense ahead of the manual expense, and it jumps to the first position.Both expenses are clean after scanning (no violations), so
compareByRBRreturns 0 and the date tiebreaker is what actually decides the order — which is why the reorder is observable.This is inconsistent with how the rest of the app orders a report's transactions.
getAllSortedTransactionssorts by the immutable rawcreatedfield and usesinsertedas the tiebreaker, nevermodifiedCreated:App/src/libs/TransactionUtils/index.ts
Lines 2702 to 2713 in 79426b2
Because that canonical sort ignores
modifiedCreated, the report's transaction list does not reorder after SmartScan — only the carousel does, since the carousel is the only place that ties on the mutable display date.What changes do you think we should make in order to solve the problem?
Change the carousel tiebreaker in
MoneyRequestReportPreviewContentso it no longer ties on the mutable display date. Instead of comparinggetCreated(a)andgetCreated(b), break ties on the immutable creation order, matchinggetAllSortedTransactions: compare the rawcreatedfield first and fall back toinsertedwhen the rawcreatedvalues are equal.The raw
createdandinsertedfields are set once when the transaction is built and are not changed when SmartScan writes the detected receipt date (which lands inmodifiedCreated) or when a user edits the date. As a result the carousel position stays stable across SmartScan completion, while still preserving the existing behavior of putting Red Brick Road expenses first and keeping a deterministic, stable order for the original intent of the previous fix (stability across RBR state changes).The
getCreatedimport that was added solely for this tiebreaker can be removed if it is no longer used elsewhere in the file.What alternative solutions did you explore? (Optional)
Reusing
getAllSortedTransactionsdirectly to produce the carousel list and then applying only the RBR re-ordering on top was considered, but that is a larger refactor than necessary; switching the existing inline tiebreaker to the immutable creation order is the minimal, targeted fix and keeps the RBR-first behavior intact.David-2002065 commentedon May 25, 2026
Proposal
What is the root cause of that problem?
carouselTransactionsinMoneyRequestReportPreviewContentre-sorts transactions on every change usingcompareByRBR, which moves transactions with RBR ahead of those without:https://github.com/Expensify/App/blob/main/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx#L359-L367
The repro maps directly onto this:
[manual].merchant/amount, sohasMissingSmartscanFields(transaction, iouReport)at https://github.com/Expensify/App/blob/main/src/libs/TransactionPreviewUtils.ts#L516-L518 returns true,transactionHasRBRreturns true, andcompareByRBRreturns-1for the scan. Sort moves it ahead:[scan, manual].hasMissingSmartscanFieldsflips to false, scan no longer has RBR.useMemore-runs (deps changed becausetransactionsandtransactionViolationsupdated). Both transactions now haveRBR = false, socompareByRBRreturns0for the pair.Array.prototype.sortis stable in modern V8, so equal-comparing items preserve relative order — but the relative order being preserved is the current[scan, manual]order from step 2, not the original[manual, scan]insertion order. The sort once-promoted the scan, the equality on re-sort holds it in front.The video confirms this: the scan stays in position 0 after smartscan completes, ahead of the manual expense that was actually created first.
What changes do you think we should make in order to solve the problem?
Make the sort a true partial ordering with a stable tiebreaker on creation time. When neither transaction has RBR (or both do), fall back to
createdascending so the natural chronological order is restored:function compareByRBR( a: OnyxTypes.Transaction, b: OnyxTypes.Transaction, violations: Record<string, OnyxTypes.TransactionViolations | undefined> | undefined, currentUserEmail: string, currentUserAccountID: number, iouReport: OnyxEntry<OnyxTypes.Report>, policy: OnyxEntry<OnyxTypes.Policy>, reportActions?: OnyxTypes.ReportActions, ): number { const aViolations = violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${a.transactionID}`] ?? []; const bViolations = violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${b.transactionID}`] ?? []; const aHasRBR = transactionHasRBR(a, aViolations, currentUserEmail, currentUserAccountID, iouReport, policy, reportActions); const bHasRBR = transactionHasRBR(b, bViolations, currentUserEmail, currentUserAccountID, iouReport, policy, reportActions); if (aHasRBR === bHasRBR) { - return 0; + // Fall back to creation order when both transactions have the same RBR status, + // so a transient RBR (e.g. mid-smartscan) doesn't permanently reorder the carousel. + return (a.created ?? '').localeCompare(b.created ?? ''); } return aHasRBR ? -1 : 1; }After the change, step 4 of the repro re-sorts to
[manual, scan]because manual'screatedprecedes scan's — the smartscan completion correctly restores the original carousel position.The
createdfield is the source of truth for transaction creation time and isn't mutated by smartscan completion (smartscan updatesmodifiedCreatedif it parses a different date from the receipt, butcreatedremains the original transaction creation timestamp). UsinglocaleCompareon the ISO string avoids theDate.parseallocation per comparison and gives stable lexicographic order on date strings.What alternative solutions did you explore?
N/A
aswin-s commentedon May 25, 2026
🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.
[-]Expense -Scan expense appears in the first position in the carousel position after smartscan[/-][+][$250] Expense -Scan expense appears in the first position in the carousel position after smartscan[/+]19 remaining items
mukhrr commentedon May 25, 2026
Proposal
What is the root cause of that problem?
The carousel preview sorts transactions by RBR status, then breaks ties with
getCreated(), which returns the mutable expense date (modifiedCreated || created). PR #91467 added this tiebreaker to keep positions stable across RBR transitions, but the key it chose is the one value SmartScan rewrites:initMoneyRequestsets a date-onlycreated('yyyy-MM-dd'), so both share the same key,localeComparereturns0, and the scan holds 2nd place only becauseArray.prototype.sortis stable.modifiedCreated, whichgetCreated()prefers). Receipts are almost always older than "today".getCreated(scan) < getCreated(manual)and pushes the scan to position 0.Carousel tiebreaker:
App/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx
Lines 360 to 367 in c84d7eb
getCreated():App/src/libs/TransactionUtils/index.ts
Lines 1394 to 1397 in c84d7eb
The transaction list under the carousel shows the same jump, but only on its default Date/ASC view, where it applies the same RBR-first ordering before falling back to the date sort value:
App/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx
Lines 296 to 315 in c84d7eb
The immutable creation-order key is
transaction.inserted, written once inbuildOptimisticTransactionand never touched by SmartScan — the same key the canonicalgetAllSortedTransactionsalready uses as its tiebreaker (added in PR #52537 for this exact date-only-string problem):App/src/libs/TransactionUtils/index.ts
Lines 2684 to 2696 in c84d7eb
What changes do you think we should make in order to solve the problem?
Tiebreak on the immutable
insertedkey instead of the mutable expense date, falling back togetCreatedwheninsertedis absent.1. Carousel (
MoneyRequestReportPreviewContent.tsx):2. Transaction list (
MoneyRequestReportTransactionList.tsx) — apply the tiebreaker only in the existing default-sort RBR branch, so explicit Date-column sorting is left alone:if (rbrComparison !== 0) { return rbrComparison; } + // Equal RBR on the default Date/ASC view: tiebreak by immutable insertion order so a + // SmartScan-rewritten receipt date can't reorder the list. Falls through to the date + // comparison below when `inserted` is absent or equal. + const insertedComparison = localeCompare(a.inserted ?? '', b.inserted ?? ''); + if (insertedComparison !== 0) { + return insertedComparison; + } } return compareValues(getTransactionSortValue(a, sortBy, report, policy), getTransactionSortValue(b, sortBy, report, policy), sortOrder, sortBy, localeCompare, true);This keeps PR #91467's intent (stable position across RBR changes) and extends it to SmartScan completion, while preserving displayed-date semantics everywhere a user explicitly sorts.
What alternative solutions did you explore? (Optional)
N/A
github-actions commentedon May 25, 2026
MussabPro commentedon May 26, 2026
Contributor details
Your Expensify account email: me@mussab.tech
Upwork Profile Link: https://www.upwork.com/freelancers/~012ce398e712ce4b2e
melvin-bot commentedon May 26, 2026
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
melvin-bot commentedon May 28, 2026
@aimane-chnaif Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
aimane-chnaif commentedon Jun 1, 2026
While most proposals are quite similar, I'd like to go with @FitseTLT's proposal since they considered various cases and raised product concern which can cause unexpected behavior we don't want.
@FitseTLT please discuss and confirm the expected behavior with design/product team before proceeding PR.
🎀 👀 🎀 C+ reviewed
melvin-bot commentedon Jun 1, 2026
Triggered auto assignment to @neil-marcellini, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
neil-marcellini commentedon Jun 3, 2026
On my list to review today, but there's 9 other things so not sure I'll get to it
neil-marcellini commentedon Jun 4, 2026
Ah ok interesting. I really like the proposal from @FitseTLT. I'm leaning towards calling this not a bug, but I'll double check with a product team member. Idk how to auto assign them so I'll ask in Slack internally.
neil-marcellini commentedon Jun 4, 2026
I raised this in Slack internally. I don't think it's a bug so I will close it now, and we will re-open it if enough people think there's a problem here worth fixing.