Skip to content

Notification appears when user A is focused on the report #101235

Closed

Description

@nlemma

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: 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

  1. Open the one-single expense report as User A
  2. As User B, open the transaction thread (you can invite the user by mentioning them on the report)
  3. 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

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Bug7237214_1787142100468.670283.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @Pujan92

Activity

  1. added
    Daily
    Bug
    on Sep 15, 2026
  2. MelvinBot commented on Sep 15, 2026

    @MelvinBot
    Contributor

    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-5170 suppresses a transaction-thread comment only when reportID === topmostOneTransactionThreadReportID. That right-hand side is wrong in two ways:

    1. 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.
    2. 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.

    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 → getFocusedReportId and never touched the one-transaction branch.

    Evidence chain and history

    Execution order in the repro:

    1. User A focuses the one-expense report → getFocusedReportId() = expense report ID ✅
    2. useOneTransactionThreadReportID returns childReportID ?? 'FAKE_REPORT_ID'
    3. That value is snapshotted into topmostOneTransactionThreadReportIDRef in a passive effect
    4. User B comments → Pusher ONYX_API_UPDATE → Onyx.update(pushJSON) writes report_{threadID} and reportActions_{threadID}
    5. .then() → triggerNotifications(..., ref.current) — ref holds the pre-update value
    6. Guard at Report/index.ts:5167 does not match → notification shown

    History:

    PR What it did
    Notification: Handle one transaction report Added the one-transaction guard, computing the thread ID live from Onyx.
    Pass reportActions as param to shouldShowReportActionNotification Replaced the live computation with the useRef snapshot + useOneTransactionThreadReportID. This is the regression surface.
    fix: Notification appears when user is focused on the report 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:

    1. 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.
    2. 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.

    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:

    • 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.
    • Offending code (❌): AuthScreensInitHandler.tsx:117-121
    • Correct pattern (✅), in the same file: AuthScreensInitHandler.tsx:108-109

    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.


    view run · no recording available

  3. added
    External
    on Sep 15, 2026
  4. melvin-bot commented on Sep 15, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @Pujan92 (External)

  5. melvin-bot commented on Sep 15, 2026

    @melvin-bot

    Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

  6. melvin-bot commented on Sep 18, 2026

    @melvin-bot

    @Pujan92 Whoops! This issue is 2 days overdue. Let's get this updated quick!

  7. melvin-bot commented on Sep 22, 2026

    @melvin-bot

    @Pujan92 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  8. melvin-bot commented on Sep 24, 2026

    @melvin-bot

    @Pujan92 Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!

  9. ashusatyarthi-wq commented on Sep 26, 2026

    @ashusatyarthi-wq
    Contributor details Your Expensify account email: ashu.satyarthi.business@gmail.com Upwork Profile Link: https://www.upwork.com/freelancers/~01b8ab177d61dc225c

    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`);
        return false;
    }

    topmostOneTransactionThreadReportID fails to match due to two issues:

    1. Stale Ref in AuthScreensInitHandler.tsx:
      In src/libs/Navigation/AppNavigator/AuthScreensInitHandler.tsx:128-132:

      const topmostOneTransactionThreadReportID = useOneTransactionThreadReportID(topmostReportID);
      const topmostOneTransactionThreadReportIDRef = useRef(topmostOneTransactionThreadReportID);
      
      useEffect(() => {
          topmostOneTransactionThreadReportIDRef.current = topmostOneTransactionThreadReportID;
      }, [topmostOneTransactionThreadReportID]);

      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.

    2. 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?

    1. Assign topmostOneTransactionThreadReportIDRef synchronously during render in AuthScreensInitHandler.tsx:

      const topmostOneTransactionThreadReportID = useOneTransactionThreadReportID(topmostReportID);
      const topmostOneTransactionThreadReportIDRef = useRef(topmostOneTransactionThreadReportID);
      topmostOneTransactionThreadReportIDRef.current = topmostOneTransactionThreadReportID;

      Remove the redundant useEffect that delayed updating the ref.

    2. 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:

      const isViewingParentOneTransactionReport = () => {
          if (reportID === topmostOneTransactionThreadReportID && topmostOneTransactionThreadReportID !== CONST.FAKE_REPORT_ID) {
              return true;
          }
          const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
          if (report?.parentReportID && report.parentReportID === topmostReportID) {
              const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`];
              return isOneTransactionThread(report, parentReport);
          }
          return false;
      };
      
      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`);
          return false;
      }

      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.

    3. 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.

  10. melvin-bot commented on Sep 28, 2026

    @melvin-bot

    @Pujan92 12 days overdue. Walking. Toward. The. Light...

  11. melvin-bot commented on Sep 29, 2026

    @melvin-bot

    @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!

  12. Pujan92 commented on Oct 1, 2026

    @Pujan92
    Contributor

    It is fixed in #96891, plz retest @nlemma and confirm

  13. melvin-bot commented on Oct 6, 2026

    @melvin-bot

    @Pujan92 Eep! 4 days overdue now. Issues have feelings too...

  14. melvin-bot commented on Oct 8, 2026

    @melvin-bot

    @Pujan92 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  15. melvin-bot commented on Oct 12, 2026

    @melvin-bot

    @Pujan92 10 days overdue. Is anyone even seeing these? Hello?

  16. melvin-bot commented on Oct 13, 2026

    @melvin-bot

    @Pujan92 this issue is now 4 weeks old, please consider:

    • Finding a contributor to fix the bug
    • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
    • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

    Thanks!

  17. melvin-bot commented on Oct 14, 2026

    @melvin-bot

    @Pujan92 12 days overdue now... This issue's end is nigh!

  18. added
    Weekly
    and removed
    Daily
    on Oct 19, 2026
  19. melvin-bot commented on Oct 19, 2026

    @melvin-bot

    This issue has not been updated in over 14 days. @Pujan92 eroding to Weekly issue.

  20. Pujan92 commented on Oct 22, 2026

    @Pujan92
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugExternalWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions