Missing messages edge case#86735
Conversation
|
@jayeshmangwani Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
@luacmartins I think @suneox should review this PR as he has more context |
| if (!isBackfillingRef.current) { | ||
| const hasIOUActions = reportActions.some((action) => isMoneyRequestAction(action)); | ||
| if (!hasIOUActions || reportActions.length < 50 || !reportMetadata?.newestFetchedReportActionID) { | ||
| return; |
There was a problem hiding this comment.
❌ CONSISTENCY-2 (docs)
The magic number 50 is used as a threshold to determine whether to trigger the backfill loop, but its meaning is not self-evident. If this value represents the backend page size or a similar server-side constant, it should be extracted into a named constant so future readers understand its origin and can update it in one place if the backend changes.
Extract the threshold into a named constant:
const BACKFILL_MIN_ACTIONS_THRESHOLD = 50;
// ...
if (!hasIOUActions || reportActions.length < BACKFILL_MIN_ACTIONS_THRESHOLD || !reportMetadata?.newestFetchedReportActionID) {Alternatively, if this corresponds to an existing constant (e.g., a page size in CONST), reference that instead.
Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
| prevBackfillCursorRef.current = cursor; | ||
| // eslint-disable-next-line @typescript-eslint/no-deprecated | ||
| InteractionManager.runAfterInteractions(() => requestAnimationFrame(() => getOlderActions(reportID, cursor))); | ||
| }, [ |
There was a problem hiding this comment.
❌ PERF-15 (docs)
The useEffect schedules async work via InteractionManager.runAfterInteractions and requestAnimationFrame, but provides no cleanup function. If the effect re-fires (e.g., because reportActions changed or the user navigated away), the previously scheduled callback will still execute, calling getOlderActions with a potentially stale reportID and cursor. This creates a race condition where multiple in-flight backfill requests could overlap.
Return a cleanup function that cancels the pending interaction and animation frame:
useEffect(() => {
// ... guards ...
isBackfillingRef.current = true;
prevBackfillCursorRef.current = cursor;
let rafId: number;
// eslint-disable-next-line @typescript-eslint/no-deprecated
const handle = InteractionManager.runAfterInteractions(() => {
rafId = requestAnimationFrame(() => getOlderActions(reportID, cursor));
});
return () => {
handle.cancel();
if (rafId) {
cancelAnimationFrame(rafId);
}
};
}, [/* deps */]);Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
| prevBackfillCursorRef.current = cursor; | ||
| // eslint-disable-next-line @typescript-eslint/no-deprecated | ||
| InteractionManager.runAfterInteractions(() => requestAnimationFrame(() => getOlderActions(reportID, cursor))); | ||
| }, [ |
There was a problem hiding this comment.
❌ CONSISTENCY-5 (docs)
The eslint-disable-next-line @typescript-eslint/no-deprecated comment lacks a justification explaining why the deprecated InteractionManager.runAfterInteractions API is being used. Even though the same pattern exists elsewhere in the file, each suppression should include a brief explanation so reviewers and future maintainers understand the exception.
Add a justification comment:
// InteractionManager.runAfterInteractions is deprecated but still the best way to defer
// work until after animations complete on React Native; no replacement API exists yet.
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => requestAnimationFrame(() => getOlderActions(reportID, cursor)));Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5f8427fd23
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const cursor = isBackfillingRef.current ? reportMetadata?.oldestFetchedReportActionID : reportMetadata?.newestFetchedReportActionID; | ||
| if (!cursor) { |
There was a problem hiding this comment.
Reset backfill refs on report switch
When reportID changes but this component instance is reused, isBackfillingRef.current and prevBackfillCursorRef.current keep values from the previous report. In that state, this effect immediately switches to oldestFetchedReportActionID for the new report; if that cursor is not set yet (common on first load), it returns early and never starts backfilling from newestFetchedReportActionID. This reintroduces the missing-messages gap for the next money request report opened in the same session.
Useful? React with 👍 / 👎.
|
@suneox reviewed the original PR, so I'm assigning them as reviewer here too |
|
I will take a look on this one soon |
|
I’ll take a look at this one after an hour. |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppCleanShot.2026-04-02.at.01.01.55.4.mp4Android: mWeb ChromeCleanShot.2026-04-02.at.01.01.55.mp4iOS: HybridAppCleanShot.2026-04-02.at.01.13.58.mp4iOS: mWeb SafariCleanShot.2026-04-02.at.01.04.59.mp4MacOS: Chrome / SafariCleanShot.2026-04-02.at.00.57.11.3.mp4 |
suneox
left a comment
There was a problem hiding this comment.
Currently, the solution of continuously backfilling messages using a cursor within a short period can fully resolve loading messages in the report. However, rendering becomes slow with around 170 messages but I think we can handle large list performance issue as a separate issue for further optimization.
|
🚧 @luacmartins has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/luacmartins in version: 9.3.52-0 🚀
Bundle Size Analysis (Sentry): |
|
No help site changes are required for this PR. This PR fixes an internal edge case in report action pagination (loading messages in reports with 50+ actions or messages interleaved with IOUs). The changes are confined to:
No user-facing features, settings, UI labels, or workflows were added or modified — this is a bug fix for data loading behavior that was already documented/expected to work. The help site articles under |

Explanation of Change
Fixing the edge case for the reports with more than 50 messages or messages sent between IOUs. More infoo here: #86114 (comment)
Fixed Issues
$ #85647
PROPOSAL: -
Tests
Prerequisites: at least one workspace
Offline tests
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, 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.ScrollViewcomponent to make it scrollable when more elements are added to the page.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
Screen.Recording.2026-03-31.at.14.12.40.mp4
Android: mWeb Chrome
Screen.Recording.2026-03-31.at.14.17.37.mp4
iOS: Native
Screen.Recording.2026-03-31.at.14.00.05.mp4
iOS: mWeb Safari
Screen.Recording.2026-03-31.at.14.01.27.mp4
MacOS: Chrome / Safari
Screen.Recording.2026-03-31.at.15.11.08.mp4