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
Notification appears when user A is focused on the report #101235
Version Number: v9.4.78-2 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack:https://github.com/Expensify/Expensify/issues/670283 Email or phone of affected tester (no customers): - Issue reported by: Applause Internal Team Bug source: Regression TC Execution Device used: Windows 10 - Chrome
Action Performed:
Precondition: User A has a one-single expense report
Open the one-single expense report as User A
As User B, open the transaction thread (you can invite the user by mentioning them on the report)
As User B, send a message on the transaction thread
Expected Result:
While the report is open as User A, verify no notification appears
Actual Result:
Notification appears when user A is focused on the report
The code that is supposed to suppress this notification exists, but the value it compares against is unreliable. src/libs/actions/Report/index.ts:5166-5170 suppresses a transaction-thread comment only when reportID === topmostOneTransactionThreadReportID. That right-hand side is wrong in two ways:
It can be the literal string 'FAKE_REPORT_ID'.getTransactionThreadReportIDFromAction returns childReportID ?? CONST.FAKE_REPORT_ID. Transaction threads are not created optimistically, so User A's copy of the IOU action often has no childReportID. The === against a real thread ID can then never match, so the guard falls through.
It is a stale React snapshot. The value reaches the notification code through a ref that is only assigned inside a passive useEffect (AuthScreensInitHandler.tsx:117-121), but it is read synchronously in the microtask right after Onyx.update (User.ts:869-871) — before React re-renders. If the same Pusher batch both creates the thread link and carries the comment, the ref still holds the pre-update value. Note the sibling ref two lines up (:108-109) is assigned during render — the correct pattern.
Everything else in the chain checks out: Navigation.getFocusedReportId() correctly returns the expense report ID, and the first guard (reportID === topmostReportID) cannot help because the comment's reportID is the thread's, not the expense report's.
Fixed only the focused-report resolution for #95711.
No test covers this.tests/unit/showReportActionNotificationTest.ts mocks getFocusedReportId to 'other-report-id' and both isVisible/hasFocus to false, and passes undefined for topmostOneTransactionThreadReportID in all three cases — so neither suppression branch is ever exercised. That is why the July fix could regress silently.
Ruled out: the useOnyx selector in useOneTransactionThreadReportID.tsx being cached/stale (Onyx keys the snapshot cache by selector identity, so a new closure forces a recompute); report.type or a missing chatReport rejecting the expense report; and the hook's omitted 5th reportTransactionIDs argument (it only makes the hook more permissive, never falsely undefined).
What changes do you think we should make in order to solve the problem?
Stop comparing IDs from a snapshot, and derive the relationship from live Onyx at notification time. Inside shouldShowReportActionNotification, look up the notifying report and ask whether it is the one-transaction thread of the currently focused report — compare its parentReportID to Navigation.getFocusedReportId() and confirm with the existing isOneTransactionThread helper. Comparing parent → child instead of child ID → possible sentinel removes both failure modes at once, because the notifying report's own parentReportID is always the real ID and is read after the Onyx update has landed.
Two supporting changes:
Never let CONST.FAKE_REPORT_ID flow into an ID equality check. Either return undefined from getTransactionThreadReportIDFromAction for notification callers, or guard the comparison explicitly.
If the ref is kept for any reason, assign it during render like reportAttributesRef does, not in a useEffect.
Add unit tests that assert a transaction-thread comment is suppressed while the parent one-expense report is focused, for both the childReportID-present and childReportID-absent cases. Also worth fixing in the same pass: the push path still uses Navigation.getTopmostReportId() (shouldShowPushNotification.ts:57) rather than getFocusedReportId(), so native foreground push still has the bug #96891 fixed for web.
What alternative solutions did you explore?
One alternative explanation should be checked before any code is written. Both guards require Visibility.hasFocus(), which on web is a bare document.hasFocus(). If User A's browser window was visible but not the OS-focused window, a notification is correct behaviour. #95711's repro explicitly instructed the tester to click into the app to focus it; these steps drop that note. Two questions for QA would settle it:
In the video, does User B's message appear inline in User A's already-open expense report? If yes, childReportID was present and the stale ref (or focus) is at fault; if no, the 'FAKE_REPORT_ID' path is confirmed.
Does a second message on the same thread also notify? Only the 'FAKE_REPORT_ID' cause predicts that it does.
A secondary, narrower path also exists: isClientTheLeader() picks the most recently initialised tab, not the focused one, so with two NewDot tabs in one profile the leader tab evaluates the guard against its own navigation state and focus. Unlikely in this repro if the testers used separate profiles.
Confidence: medium. The code paths above are verified by reading the source at fc3dcee; which of the two mechanisms fired in this specific recording is not, since I could not reproduce it (the repro needs two accounts) and have no client logs. shouldShowReportActionNotification logs a distinct reason per branch, so a session log would confirm it immediately — the absence of [LocalNotification] No notification because the report is a transaction thread associated with the current one-transaction report alongside [LocalNotification] Creating notification is the signature.
This looks like a recurring, mechanically detectable pattern, so it may be worth a coding-standards rule so the AI reviewer catches the next one. Proposed for Expensify/App:
Rule:PERF-20 Assign latest-value refs during render, not in an Effect
Condition: When a ref exists only so a non-React callback (a Pusher or Onyx subscription, a DOM listener, a module-level getter) can read the latest rendered value, assign ref.current during render. Flag useEffect(() => { xRef.current = x; }, [x]), because the callback can fire before the passive effect flushes and will read a stale value.
Why: In this issue, a notification-suppression check read a ref that had not yet been updated for the Onyx batch being processed, so the notification fired while the user was looking at the report.
Search pattern:grep -rn -A2 'useEffect(() => {' src --include=*.tsx --include=*.ts | grep 'Ref\.current = ' — 117 hits at fc3dcee, so scope review to refs read from non-React callbacks.
No existing rule covers this: PERF-9, PERF-10 and CLEAN-REACT-PATTERNS-4 cover Effect chains and side-effect structure, not latest-value refs. If it's worth adding, a maintainer can open it as a draft PR in App/.claude/skills/app-coding-standards/.
Next Steps for Contributor+ team: To accept:@MelvinBot implement [this](https://github.com/Expensify/App/issues/101235) to create a draft PR. To refine:@MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.
Please re-state the problem that we are trying to solve in this issue.
When User A has a one-single expense report open and focused, and User B sends a message on the associated transaction thread, User A receives a local/push notification instead of suppressing it while focused on the report.
What is the root cause of that problem?
In src/libs/actions/Report/index.ts:5198-5201, suppression for transaction threads relies on:
if(reportID===topmostOneTransactionThreadReportID&&Visibility.isVisible()&&Visibility.hasFocus()){Log.info(`${tag} No notification because the report is a transaction thread associated with the current one-transaction report`);returnfalse;}
topmostOneTransactionThreadReportID fails to match due to two issues:
Stale Ref in AuthScreensInitHandler.tsx:
In src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx:128-132:
Unlike reportAttributesRef (line 118: reportAttributesRef.current = reportAttributes;), topmostOneTransactionThreadReportIDRef is assigned inside a passive useEffect. When a Pusher event arrives with a new transaction thread message, the Onyx update callback executes synchronously in a microtask before React commits and runs passive effects. The ref therefore provides a stale value to triggerNotifications.
CONST.FAKE_REPORT_ID sentinel and missing live parent relationship check:
When the transaction thread is first created or when childReportID is not yet indexed on the parent action, getTransactionThreadReportIDFromAction returns CONST.FAKE_REPORT_ID. If this sentinel flows into shouldShowReportActionNotification, equality checking against the real thread ID fails.
Furthermore, notification suppression relies strictly on a precomputed child ID rather than checking whether the notifying report's parent is the currently focused report.
What changes do you think we should make in order to solve the problem?
Assign topmostOneTransactionThreadReportIDRef synchronously during render in AuthScreensInitHandler.tsx:
Remove the redundant useEffect that delayed updating the ref.
Harden shouldShowReportActionNotification in src/libs/actions/Report/index.ts:
In addition to comparing reportID === topmostOneTransactionThreadReportID, verify the relationship using the notifying report's parent data:
constisViewingParentOneTransactionReport=()=>{if(reportID===topmostOneTransactionThreadReportID&&topmostOneTransactionThreadReportID!==CONST.FAKE_REPORT_ID){returntrue;}constreport=allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];if(report?.parentReportID&&report.parentReportID===topmostReportID){constparentReport=allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`];returnisOneTransactionThread(report,parentReport);}returnfalse;};if(isViewingParentOneTransactionReport()&&Visibility.isVisible()&&Visibility.hasFocus()){Log.info(`${tag} No notification because the report is a transaction thread associated with the current one-transaction report`);returnfalse;}
This guarantees suppression whether the event is evaluated via the cached hook ID or directly derived from the notifying report's parent ID upon arrival.
In shouldShowPushNotification.ts:
Ensure Navigation.getFocusedReportId() is used consistently for the focused report check.
What alternative solutions did you explore? (Optional)
Relying solely on topmostOneTransactionThreadReportIDRef leaves the system vulnerable to cases where childReportID is absent from the parent report actions cache at the exact instant the message is received. Adding the live parent check ensures complete reliability across both local notifications and push notifications.
@Pujan92 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
Activity
MelvinBot commentedon Sep 15, 2026
Proposal
What is the root cause of that problem?
The code that is supposed to suppress this notification exists, but the value it compares against is unreliable.
src/libs/actions/Report/index.ts:5166-5170suppresses a transaction-thread comment only whenreportID === topmostOneTransactionThreadReportID. That right-hand side is wrong in two ways:'FAKE_REPORT_ID'.getTransactionThreadReportIDFromActionreturnschildReportID ?? CONST.FAKE_REPORT_ID. Transaction threads are not created optimistically, so User A's copy of the IOU action often has nochildReportID. The===against a real thread ID can then never match, so the guard falls through.useEffect(AuthScreensInitHandler.tsx:117-121), but it is read synchronously in the microtask right afterOnyx.update(User.ts:869-871) — before React re-renders. If the same Pusher batch both creates the thread link and carries the comment, the ref still holds the pre-update value. Note the sibling ref two lines up (:108-109) is assigned during render — the correct pattern.Everything else in the chain checks out:
Navigation.getFocusedReportId()correctly returns the expense report ID, and the first guard (reportID === topmostReportID) cannot help because the comment's reportID is the thread's, not the expense report's.This is a re-report of [Due for payment 2026-08-08] [$250] Notification appears when user is focused on the report, whose fix (fix: Notification appears when user is focused on the report) only changed
getTopmostReportId→getFocusedReportIdand never touched the one-transaction branch.Evidence chain and history
Execution order in the repro:
getFocusedReportId()= expense report ID ✅useOneTransactionThreadReportIDreturnschildReportID ?? 'FAKE_REPORT_ID'topmostOneTransactionThreadReportIDRefin a passive effectONYX_API_UPDATE→Onyx.update(pushJSON)writesreport_{threadID}andreportActions_{threadID}.then()→triggerNotifications(..., ref.current)— ref holds the pre-update valueReport/index.ts:5167does not match → notification shownHistory:
useRefsnapshot +useOneTransactionThreadReportID. This is the regression surface.No test covers this.
tests/unit/showReportActionNotificationTest.tsmocksgetFocusedReportIdto'other-report-id'and bothisVisible/hasFocustofalse, and passesundefinedfortopmostOneTransactionThreadReportIDin all three cases — so neither suppression branch is ever exercised. That is why the July fix could regress silently.Ruled out: the
useOnyxselector inuseOneTransactionThreadReportID.tsxbeing cached/stale (Onyx keys the snapshot cache by selector identity, so a new closure forces a recompute);report.typeor a missingchatReportrejecting the expense report; and the hook's omitted 5threportTransactionIDsargument (it only makes the hook more permissive, never falselyundefined).What changes do you think we should make in order to solve the problem?
Stop comparing IDs from a snapshot, and derive the relationship from live Onyx at notification time. Inside
shouldShowReportActionNotification, look up the notifying report and ask whether it is the one-transaction thread of the currently focused report — compare itsparentReportIDtoNavigation.getFocusedReportId()and confirm with the existingisOneTransactionThreadhelper. Comparing parent → child instead of child ID → possible sentinel removes both failure modes at once, because the notifying report's ownparentReportIDis always the real ID and is read after the Onyx update has landed.Two supporting changes:
CONST.FAKE_REPORT_IDflow into an ID equality check. Either returnundefinedfromgetTransactionThreadReportIDFromActionfor notification callers, or guard the comparison explicitly.reportAttributesRefdoes, not in auseEffect.Add unit tests that assert a transaction-thread comment is suppressed while the parent one-expense report is focused, for both the
childReportID-present andchildReportID-absent cases. Also worth fixing in the same pass: the push path still usesNavigation.getTopmostReportId()(shouldShowPushNotification.ts:57) rather thangetFocusedReportId(), so native foreground push still has the bug #96891 fixed for web.What alternative solutions did you explore?
One alternative explanation should be checked before any code is written. Both guards require
Visibility.hasFocus(), which on web is a baredocument.hasFocus(). If User A's browser window was visible but not the OS-focused window, a notification is correct behaviour. #95711's repro explicitly instructed the tester to click into the app to focus it; these steps drop that note. Two questions for QA would settle it:childReportIDwas present and the stale ref (or focus) is at fault; if no, the'FAKE_REPORT_ID'path is confirmed.'FAKE_REPORT_ID'cause predicts that it does.A secondary, narrower path also exists:
isClientTheLeader()picks the most recently initialised tab, not the focused one, so with two NewDot tabs in one profile the leader tab evaluates the guard against its own navigation state and focus. Unlikely in this repro if the testers used separate profiles.Confidence: medium. The code paths above are verified by reading the source at
fc3dcee; which of the two mechanisms fired in this specific recording is not, since I could not reproduce it (the repro needs two accounts) and have no client logs.shouldShowReportActionNotificationlogs a distinct reason per branch, so a session log would confirm it immediately — the absence of[LocalNotification] No notification because the report is a transaction thread associated with the current one-transaction reportalongside[LocalNotification] Creating notificationis the signature.Related issues
💡 Suggested AI code review rule
This looks like a recurring, mechanically detectable pattern, so it may be worth a coding-standards rule so the AI reviewer catches the next one. Proposed for
Expensify/App:PERF-20Assign latest-value refs during render, not in an Effectref.currentduring render. FlaguseEffect(() => { xRef.current = x; }, [x]), because the callback can fire before the passive effect flushes and will read a stale value.grep -rn -A2 'useEffect(() => {' src --include=*.tsx --include=*.ts | grep 'Ref\.current = '— 117 hits atfc3dcee, so scope review to refs read from non-React callbacks.AuthScreensInitHandler.tsx:117-121AuthScreensInitHandler.tsx:108-109No existing rule covers this:
PERF-9,PERF-10andCLEAN-REACT-PATTERNS-4cover Effect chains and side-effect structure, not latest-value refs. If it's worth adding, a maintainer can open it as a draft PR inApp/.claude/skills/app-coding-standards/.Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/101235)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
view run · no recording available
melvin-bot commentedon Sep 15, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @Pujan92 (
External)melvin-bot commentedon Sep 15, 2026
Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.
melvin-bot commentedon Sep 18, 2026
@Pujan92 Whoops! This issue is 2 days overdue. Let's get this updated quick!
melvin-bot commentedon Sep 22, 2026
@Pujan92 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
melvin-bot commentedon Sep 24, 2026
@Pujan92 Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!
ashusatyarthi-wq commentedon Sep 26, 2026
Contributor details
Your Expensify account email: ashu.satyarthi.business@gmail.com Upwork Profile Link: https://www.upwork.com/freelancers/~01b8ab177d61dc225cProposal
Please re-state the problem that we are trying to solve in this issue.
When User A has a one-single expense report open and focused, and User B sends a message on the associated transaction thread, User A receives a local/push notification instead of suppressing it while focused on the report.
What is the root cause of that problem?
In
src/libs/actions/Report/index.ts:5198-5201, suppression for transaction threads relies on:topmostOneTransactionThreadReportIDfails to match due to two issues:Stale Ref in
AuthScreensInitHandler.tsx:In
src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx:128-132:Unlike
reportAttributesRef(line 118:reportAttributesRef.current = reportAttributes;),topmostOneTransactionThreadReportIDRefis assigned inside a passiveuseEffect. When a Pusher event arrives with a new transaction thread message, the Onyx update callback executes synchronously in a microtask before React commits and runs passive effects. The ref therefore provides a stale value totriggerNotifications.CONST.FAKE_REPORT_IDsentinel and missing live parent relationship check:When the transaction thread is first created or when
childReportIDis not yet indexed on the parent action,getTransactionThreadReportIDFromActionreturnsCONST.FAKE_REPORT_ID. If this sentinel flows intoshouldShowReportActionNotification, equality checking against the real thread ID fails.Furthermore, notification suppression relies strictly on a precomputed child ID rather than checking whether the notifying report's parent is the currently focused report.
What changes do you think we should make in order to solve the problem?
Assign
topmostOneTransactionThreadReportIDRefsynchronously during render inAuthScreensInitHandler.tsx:Remove the redundant
useEffectthat delayed updating the ref.Harden
shouldShowReportActionNotificationinsrc/libs/actions/Report/index.ts:In addition to comparing
reportID === topmostOneTransactionThreadReportID, verify the relationship using the notifying report's parent data:This guarantees suppression whether the event is evaluated via the cached hook ID or directly derived from the notifying report's parent ID upon arrival.
In
shouldShowPushNotification.ts:Ensure
Navigation.getFocusedReportId()is used consistently for the focused report check.What alternative solutions did you explore? (Optional)
Relying solely on
topmostOneTransactionThreadReportIDRefleaves the system vulnerable to cases wherechildReportIDis absent from the parent report actions cache at the exact instant the message is received. Adding the live parent check ensures complete reliability across both local notifications and push notifications.melvin-bot commentedon Sep 28, 2026
@Pujan92 12 days overdue. Walking. Toward. The. Light...
melvin-bot commentedon Sep 29, 2026
@Pujan92 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
Pujan92 commentedon Oct 1, 2026
It is fixed in #96891, plz retest @nlemma and confirm
melvin-bot commentedon Oct 6, 2026
@Pujan92 Eep! 4 days overdue now. Issues have feelings too...
melvin-bot commentedon Oct 8, 2026
@Pujan92 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
melvin-bot commentedon Oct 12, 2026
@Pujan92 10 days overdue. Is anyone even seeing these? Hello?
melvin-bot commentedon Oct 13, 2026
@Pujan92 this issue is now 4 weeks old, please consider:
Thanks!
melvin-bot commentedon Oct 14, 2026
@Pujan92 12 days overdue now... This issue's end is nigh!
melvin-bot commentedon Oct 19, 2026
This issue has not been updated in over 14 days. @Pujan92 eroding to Weekly issue.
Pujan92 commentedon Oct 22, 2026
#101235 (comment)