Repository navigation
Description
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Version Number: 9.3.67-11
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from BrowserStack:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @shawnborton
Slack conversation (hyperlinked to channel name): #Expensify Bugs
Action Performed:
- Trigger an email notification with multiple messages (e.g., chat thread or report activity)
- Open the email
- Observe the order of messages
Expected Result:
Messages should be displayed in chronological order with the latest message at the bottom
Actual Result:
Messages are displayed in reverse order
Workaround:
Unknown
Platforms:
Select the officially supported platforms where the issue was reproduced:
- Android: App
- Android: mWeb Chrome
- iOS: App
- iOS: mWeb Safari
- iOS: mWeb Chrome
- Windows: Chrome
- MacOS: Chrome / Safari
MelvinBot investigation:
I investigated the email notification comment ordering code. Here's what I found:
The array_reverse() on email comments has been in the code since at least Oct 2024 (and likely since Jan 2023 when getCommentBlock() was first created). This means email notifications have shown newest-on-top for a long time — this is not a recent regression.
The data flow is:
1. Auth returns comments in ASC order (oldest first) via getHistory() with ACTION_ORDER_ASC
2. Comment.php:686 calls array_reverse() → flips to newest-first
3. The for loop renders them top-to-bottom → newest comment appears at top of email
Recent changes reviewed:
• App PR #85114 (FlashList migration) — purely frontend, zero impact on email notifications
• Commit 47b5d98640 (Apr 21, 2026) — added usort() + system message filtering in ReportUtils.php:3190. The usort sorts by created ASC which is the same order the data was already in, so this shouldn't have changed display order.
Bottom line: I could not find a recent commit that changed the ordering. The newest-on-top behavior appears to be long-standing. If the ordering truly needs to be oldest-on-top (newest-on-bottom), the fix would be to remove the array_reverse() call on line 686 of Comment.php. But I'd recommend first confirming with the reporter whether this is actually a recent change vs. something that was always this way and is only now being noticed.
Screenshots/Videos
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
m-natarajan commentedon May 6, 2026
@MelvinBot Don't replace Internal label
MelvinBot commentedon May 6, 2026
Proposal
What is the root cause of that problem?
Email notifications show messages newest-first (reverse chronological) because
Comment.php:686callsarray_reverse()on comments that Auth already returns in ASC order (oldest first). The rendering loop then iterates top-to-bottom, placing the newest message at the top of the email.This is not a recent regression — the
array_reverse()has been present sincegetCommentBlock()was first created (~Jan 2023). The recentusort()change inReportUtils.php:3190(commit47b5d98640, Apr 2026) sorts bycreated ASCwhich matches the pre-existing order and had no effect on display order.What changes do you think we should make in order to solve the problem?
Remove the
array_reverse()call on Comment.php:686. Without the reversal, comments will remain in their original ASC order (oldest first) and render chronologically in the email — newest message at the bottom, matching the expected behavior.Before applying the fix, confirm via
git blamewhether thearray_reverse()was intentional (e.g., a deliberate design choice for email digest format) and verify no other callers ofgetCommentBlock()depend on the reversed order.What alternative solutions did you explore? (Optional)
Instead of removing
array_reverse(), the rendering loop could be modified to iterate in reverse. However, this adds unnecessary complexity — removing the reversal is the simplest and most direct fix.Data flow summary
Auth/getHistory()returns comments inACTION_ORDER_ASC(oldest first)Comment.php:686callsarray_reverse()→ flips to newest-firstforloop ingetCommentBlock()renders top-to-bottom → newest appears at email topNext 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.Beamanator commentedon May 6, 2026
I do believe https://github.com/Expensify/Web-Expensify/pull/52233 may have caused this, as it looks like the order flipped the day that PR went to prod 😅