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
[Due for payment 2025-11-12] [$250] API - Duplicate ReadNewestAction API call for new messages #72774
Each useEffect serves a different purpose. One calls readNewestAction whenever there are unread messages, while the other triggers it when the ReportScreen is re-focused or when the app returns from the background to the foreground.
// This effect logic to `mark as read` will only run when the report focused has new messages and the App visibility
// is changed to visible(meaning user switched to app/web, while user was previously using different tab or application).
// We will mark the report as read in the above case which marks the LHN report item as read while showing the new message
// marker for the chat messages received while the user wasn't focused on the report or on another browser tab for web.
What changes do you think we should make in order to solve the problem?
There are two solutions:
Solution 1:
We can merge the two useEffect blocks by adding preIsVisible and preIsFocused to ensure the second effect’s behavior is preserved.
Solution 2:
We can create a ref to store the state that determines whether readNewestAction should be called in the second useEffect.
If readNewestAction has already been triggered in the first useEffect, the state will be set to false.
Then, it can be reset to true in the second useEffect.
Or more simply, we could use useDebounce for readNewestAction with a reasonable delay.
changed the title [-]API - Duplicate ReadNewestAction API call for new messages[/-][+][$250] API - Duplicate ReadNewestAction API call for new messages[/+]on Oct 16, 2025
@dmkt9 I don't think your RCA is correct, that's fine to trigger readNewestAction many times, but in readNewestAction because we already used writeWithNoDuplicatesConflictAction which prevents the duplication. Can you please check again?
@dukenv0307 Yes. I just double-checked. We indeed used writeWithNoDuplicatesConflictAction, but because readNewestAction is inside callbacks of two different useEffects, and those callbacks are triggered separately and asynchronously, usually after the first callback, the whole request queue gets resolved successfully, so when the second callback gets triggered, the queue is already empty.
Please re-state the problem that we are trying to solve in this issue.
Opening a chat report that just received a new message fires the /ReadNewestAction API twice, which shows up as duplicate network calls and adds unnecessary traffic.
What is the root cause of that problem?
When the report gains focus, the visibility effect in ReportActionsList calls readNewestAction even if the earlier logic already handled the unread state. There is no guard that checks whether the read was previously skipped, so the second effect retriggers the write request every time the report becomes visible.
What changes do you think we should make in order to solve the problem?
Add a guard that only lets the visibility effect call readNewestAction when readActionSkipped is true, and reset the flag after the call so the API runs once per unread batch.
📣 @dmkt9 You have been assigned to this job!
Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑💻
Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
Keep in mind: Code of Conduct | Contributing 📖
Activity
melvin-bot commentedon Oct 16, 2025
Triggered auto assignment to @garrettmknight (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.dmkt9 commentedon Oct 16, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
Duplicate instances of the /ReadNewestAction API call are initiated for the chat report
What is the root cause of that problem?
readNewestActionis called sequentially in twouseEffectblocks here:App/src/pages/home/report/ReportActionsList.tsx
Lines 392 to 412 in 27845f8
App/src/pages/home/report/ReportActionsList.tsx
Lines 610 to 648 in 27845f8
Each
useEffectserves a different purpose. One callsreadNewestActionwhenever there are unread messages, while the other triggers it when theReportScreenis re-focused or when the app returns from the background to the foreground.App/src/pages/home/report/ReportActionsList.tsx
Lines 643 to 646 in 27845f8
What changes do you think we should make in order to solve the problem?
There are two solutions:
Solution 1:
We can merge the two
useEffectblocks by addingpreIsVisibleandpreIsFocusedto ensure the second effect’s behavior is preserved.Solution 2:
We can create a
refto store the state that determines whetherreadNewestActionshould be called in the seconduseEffect.If
readNewestActionhas already been triggered in the firstuseEffect, the state will be set tofalse.Then, it can be reset to
truein the seconduseEffect.Or more simply, we could use
useDebounceforreadNewestActionwith a reasonable delay.[-]API - Duplicate ReadNewestAction API call for new messages[/-][+][$250] API - Duplicate ReadNewestAction API call for new messages[/+]melvin-bot commentedon Oct 16, 2025
Job added to Upwork: https://www.upwork.com/jobs/~021978915596703523565
melvin-bot commentedon Oct 16, 2025
Triggered auto assignment to Contributor-plus team member for initial proposal review - @dukenv0307 (
External)dukenv0307 commentedon Oct 18, 2025
@dmkt9 I don't think your RCA is correct, that's fine to trigger
readNewestActionmany times, but inreadNewestActionbecause we already usedwriteWithNoDuplicatesConflictActionwhich prevents the duplication. Can you please check again?dmkt9 commentedon Oct 19, 2025
@dukenv0307 Yes. I just double-checked. We indeed used
writeWithNoDuplicatesConflictAction, but becausereadNewestActionis inside callbacks of two differentuseEffects, and those callbacks are triggered separately and asynchronously, usually after the first callback, the whole request queue gets resolved successfully, so when the second callback gets triggered, the queue is already empty.ShridharGoel commentedon Oct 19, 2025
Proposal
Please re-state the problem that we are trying to solve in this issue.
Opening a chat report that just received a new message fires the
/ReadNewestActionAPI twice, which shows up as duplicate network calls and adds unnecessary traffic.What is the root cause of that problem?
When the report gains focus, the visibility effect in
ReportActionsListcallsreadNewestActioneven if the earlier logic already handled the unread state. There is no guard that checks whether the read was previously skipped, so the second effect retriggers the write request every time the report becomes visible.App/src/pages/home/report/ReportActionsList.tsx
Lines 610 to 641 in 7165a14
What changes do you think we should make in order to solve the problem?
Add a guard that only lets the visibility effect call
readNewestActionwhenreadActionSkippedis true, and reset the flag after the call so the API runs once per unread batch.65 remaining items
melvin-bot commentedon Nov 17, 2025
Job added to Upwork: https://www.upwork.com/jobs/~021990497809920039578
melvin-bot commentedon Nov 17, 2025
Current assignee @dukenv0307 is eligible for the External assigner, not assigning anyone new.
melvin-bot commentedon Nov 17, 2025
📣 @dmkt9 You have been assigned to this job!
Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑💻
Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
Keep in mind: Code of Conduct | Contributing 📖
garrettmknight commentedon Nov 17, 2025
@dmkt9 please apply to the new upwork job for payment.
@dukenv0307 request when you're ready.
dmkt9 commentedon Nov 18, 2025
@garrettmknight Thanks. I just applied for this job.
garrettmknight commentedon Nov 18, 2025
@dmkt9 offer out to you.
dmkt9 commentedon Nov 18, 2025
@garrettmknight Thanks. I've just requested payment.
garrettmknight commentedon Nov 19, 2025
All paid up!
quinthar commentedon Dec 19, 2025
Approved $250 to @dukenv0307