Skip to content

refactor: new-transaction highlight and RHP width changes - #102627

Open
TaduJR wants to merge 24 commits into
Expensify:mainfrom
TaduJR:refactor-Reports-newTransactionHighlight-and-RHPLayout-followups
Open

TaduJR wants to merge 24 commits into
Expensify:mainfrom
TaduJR:refactor-Reports-newTransactionHighlight-and-RHPLayout-followups

Conversation

@TaduJR

@TaduJR TaduJR commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

This brings back #98744, which was reverted in #100810 after eight deploy blockers. The changes are the same, and all eight blockers are fixed. Adding or duplicating an expense still highlights the new row, and the panel still widens when a report becomes a table.

Marking a new expense. When you add an expense, the app writes a note saying "highlight this row". The report's note is now written in one place instead of two that could disagree, and it's decided once per action: a report's first expenses are its contents, not additions, so opening a duplicated report no longer highlights its second expense (#100761). Each note records when it was written. Notes older than 60 seconds are ignored, clearing an old note can't remove a newer one, and a failed request removes its note.

Expenses added from elsewhere. The report table and the chat preview also compare their list before and after, to catch expenses that arrive from another device. Both wait until the whole report has loaded, so opening a report doesn't flash what was already there. Splitting an expense (#100757) and adding existing expenses to a report (#100789) now highlight the new rows.

When the flash plays. The new row appears right away; only the flash waits until you can see it. On desktop, a report dimmed under a narrower panel counts as visible and flashes straight away; on mobile it flashes when the panel closes (#94670). Each flash belongs to its expense, so it plays once, stays on the right row when the list re-sorts or scrolls, and doesn't replay when you open and close a report (#100763) or come back online (#100787). Brief highlights like the Tag row (#100771) and newly enabled workspace features (#100782) flash correctly. The table and the chat preview scroll to the new expense once you can see it.

The wide panel. Which screens are wide is now worked out from the navigation state instead of a copy kept in sync by hand. Clicking a report hands its width to the panel it opens, so the panel opens at its final width, and a closing panel keeps its width until its animation ends. #100770 is fixed by main's floating panel (#100811), so this PR doesn't touch that animation.

For reviewers. useNewTransactions now compiles with React Compiler, and both core hooks drop their lint suppressions. The stored format of pendingNewTransactionIDs changed: notes written by the current production build are ignored and cleaned up. Reassure shows no performance change, so none is claimed.

Fixed Issues

$ #96327
PROPOSAL:

Tests

  • A flash means the new row or card fades into place, then its background darkens briefly and fades back. It should happen once.
  • Prerequisite:
    • Workspace A: your default workspace, with Tags on and at least one tag.
    • Workspace B: Tags off.
    • Two expenses created in your self DM.

1. A duplicated expense flashes in the report behind (Desktop)

  1. Open workspace A's chat and click View on the newest report.
  2. Click any expense. It opens on top, with the report dimmed on the left.
  3. Click More > Duplicate expense. The menu stays open and shows Duplicated.
  4. Verify the copy appears in the dimmed report and flashes once while the expense is still open. No other row flashes.
  5. Click the dimmed report (the first click may only close the menu) and verify it comes back at full width.
  6. Duplicate another expense the same way. While the copy is still flashing, click a column header (Date, Merchant or Amount) to re-sort.
  7. Verify the flash moves with the copy to its new place, and no other row starts flashing.

2. A duplicated expense flashes when you come back (Mobile)

  1. Open workspace A's chat and tap View on the newest report.
  2. Tap an expense so it covers the report, then tap More > Duplicate expense.
  3. Verify nothing flashes while the expense covers the report.
  4. Go back to the report.
  5. Verify the copy is fully visible (not blank or squashed) and flashes once.
  6. Repeat, but wait 2 minutes on the expense before going back. Verify the same.

3. Duplicating in a one-expense report switches to the table (Desktop)

  1. In workspace A's chat, click + > Create report, then + > Create expense to add one expense to it.
  2. Click that expense's card in the chat, then More > Duplicate expense.
  3. Verify the panel widens to show the report's table and the copy flashes once.
  4. Close the panel. Verify the new card appears in the chat and flashes once after the panel has closed.

4. Bulk duplicate

  1. Open workspace A's newest report. Select 2 or 3 expenses (see Selecting expenses) and choose Duplicate expenses.
  2. Verify every copy flashes, not just the first.
  3. Add expenses to workspace A's newest report until its list scrolls (about 15 on desktop, 8 on mobile). Scroll to the top, select the first expense and duplicate it. Verify the report scrolls down to the copy and it flashes once.

5. Adding an expense from the chat

  1. In workspace A's chat, click + > Create expense > Manual and create an expense.
  2. Verify the new card flashes once, and the cards scroll to it.
  3. Within a minute, click View on the newest report. Verify the new row flashes once.
  4. Wait 5 seconds, close the report and click View again. Verify nothing flashes.
  5. Repeat steps 1–2 with Scan (Choose files and pick a receipt image, then Create expense), and with + > Track distance > Manual (enter the miles, click Next, then Create expense).

6. Nothing flashes when it shouldn't

  1. In workspace A's newest report, change an expense's amount or description and save. Verify the row doesn't flash.
  2. Delete an expense. Verify nothing flashes.
  3. Close and reopen the report a few times, and reload the page on web. Verify nothing flashes.
  4. Spend > Reports: open a report, then switch quickly between reports with the ‹ › arrows (on desktop next to "N of M" at the top right of the panel, on mobile at the right just under More). Verify nothing flashes on any report.
  5. Scroll a chat with several report previews up and down, then click through several chats. Verify no card flashes.
  6. In workspace B's chat, click + > Create report, click View on the empty report, then Add expense > Create expense and create one. Verify it doesn't flash in the report.

7. Old highlights don't come back

  1. In workspace A's chat, create an expense but don't open the report.
  2. Wait at least for some time, then click View on the newest report.
  3. Verify the new row doesn't flash.

8. Splitting an expense (#100757)

  1. In workspace A's chat, click View on the newest report, click an expense, then More > Split > Save.
  2. Verify the split rows flash in the report.
  3. Within 3 seconds, close the report (on mobile, go back to the chat).
  4. Verify the split expenses' cards flash once in the chat, after the report has closed.
  5. Open one of the split expenses and click its Amount row (it says "Amount • Cash • Split"). Change only the amounts and click Save. Verify nothing flashes.

9. The chat card doesn't flash on every open and close (#100763)

  1. In workspace A's chat, create an expense.
  2. Before its card stops flashing, click View on the newest report, then close the report.
  3. Repeat step 2 three times.
  4. Verify the card doesn't flash again after any close. The report itself may flash the new row the first time it opens.

10. Duplicate report (#100761)

  1. Open workspace A's newest report and click More > Duplicate report. The app stays on this report.
  2. Close it, and click View on the new "Copy of …" report at the bottom of the chat.
  3. Verify no expense flashes.
  4. The copy is now the newest report, so later expenses from the chat go into it.

11. Duplicating while offline (#100787)

  1. Open workspace A's newest report and turn off the internet.
  2. Select one expense and choose Duplicate expense. Do the same with a different expense.
  3. Verify each copy flashes once.
  4. Turn the internet back on and wait for it to sync.
  5. Verify nothing flashes again.

12. Adding existing expenses to a report (#100789)

  1. In workspace B's chat, click + > Create report, then click View on the empty report.
  2. Click Add expense > Add existing expense. The list shows all your draft expenses, so use Find expense to find the two self DM expenses. Tick both and click Add to report.
  3. Verify both expenses flash once.

13. Tag row on the create form (#100771)

  1. Click the grey + button > Create expense (the top item, not Quick action) > Manual, and enter an amount.
  2. At the top of the form, click the workspace row (it says "Submits to …") and pick workspace B. The Tag row disappears.
  3. Click the same row again and pick workspace A.
  4. Verify the Tag row slides in and flashes once.

14. Newly enabled workspace features (#100782)

  1. Go to Workspaces > workspace A > More features and turn on a feature that is off, such as Distance rates. If it's already on, turn it off first.
  2. Desktop: verify the new item in the workspace menu on the left flashes once, right away.
  3. Mobile: turning it on takes you back to the workspace menu. Verify the new item flashes once as the menu appears.

15. Spend lists

  1. Go to Spend > Expenses and create an expense for workspace A. On desktop use the Create button at the top right; on mobile use the grey + button.
  2. Verify the new row flashes once, and scrolling the list doesn't flash any other row.
  3. Go to Spend > Reports and create another expense the same way. Verify the app switches to Spend > Expenses and the new row flashes once there.

16. Panel width (Desktop)

  1. Spend > Reports: click a report with several expenses. Verify the panel opens at its widest right away, without opening narrow and jumping.
  2. Delete expenses until one is left. Verify the panel narrows without closing.
  3. Open a report with one expense. Verify it opens at medium width.
  4. Open a report with several expenses and close it with the back arrow, then again with Escape. Verify it slides out at full width without snapping narrow first.
  5. Reopen it, click an expense so it stacks on top, and close only that expense. Verify the report behind stays at full width without flickering.

17. Panel after navigating (Desktop)

  1. Spend > Reports: open a report with several expenses. Click Inbox in the left bar. The first click only closes the panel; that's expected.
  2. Go to Inbox, then Workspaces, then back to Spend. Verify no tab shows a leftover wide panel or dimming.
  3. Open a report, click an expense, and step through several with the next and previous arrows. Verify each opens at a steady width.
  4. In a chat, click one card inside a report preview. Verify the report opens wide and the expense stacks on top without the width jumping.

18. Panel transition stays inside the panel (#100770, Desktop)

  1. Open a report that has one expense (for example, the one from test 6 step 6).
  2. Click the report's avatar (the round picture at the top of the panel) to open its details. Click Members, then the back arrow.
  3. Verify each screen slides within the panel and nothing animates outside it.
  4. Repeat with a report that has several expenses.

Known behaviour, same as production (Please don't file)

  • Reopening a report within a few seconds of first seeing a new row can flash that row again.

  • When an empty report gets its first expense, its card in the chat flashes once when you return to the chat.

  • An expense opened more than 60 seconds after it was created doesn't flash. This is by design.

  • On mobile, if the report also has a scanned receipt and a distance expense, splitting an expense and then staying in the report for more than a few seconds means the split cards don't flash when you go back to the chat.

  • Duplicating from Spend > Expenses keeps you on the expense instead of switching to the report ([$250] Expense - Duplicated expense does not redirect to report table view #94427). This PR doesn't change that.

  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android-Native.mp4
Android: mWeb Chrome
Android-mWeb.mp4
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Mac-Chrome.mp4

…ports-newTransactionHighlight-and-RHPLayout-followups

# Conflicts:
#	src/components/WideRHPContextProvider/index.tsx
#	src/libs/Navigation/AppNavigator/Navigators/RightModalNavigator.tsx
#	src/libs/Navigation/AppNavigator/useRHPScreenOptions.ts
@TaduJR
TaduJR requested review from a team as code owners September 30, 2026 07:58
@melvin-bot
melvin-bot Bot requested review from dylanexpensify and marufsharifi and removed request for a team and dylanexpensify September 30, 2026 07:58
@melvin-bot

melvin-bot Bot commented Sep 30, 2026

Copy link
Copy Markdown

@marufsharifi 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]

@melvin-bot
melvin-bot Bot removed the request for review from a team September 30, 2026 07:59
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

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.

Files with missing lines Coverage Δ
src/CONST/index.ts 96.15% <ø> (ø)
src/components/HighlightableMenuItem.tsx 0.00% <ø> (ø)
...onents/HighlightableMenuItemWithTopDescription.tsx 100.00% <ø> (ø)
...irmationList/sections/useFieldRowHighlightStyle.ts 0.00% <ø> (ø)
...RequestReportView/ExternalScrollFlashListTable.tsx 8.06% <ø> (+8.06%) ⬆️
...equestReportView/MoneyRequestReportActionsList.tsx 97.42% <100.00%> (+0.05%) ⬆️
...stReportView/MoneyRequestReportTransactionItem.tsx 89.36% <100.00%> (+0.05%) ⬆️
...stReportView/MoneyRequestReportTransactionList.tsx 96.72% <100.00%> (-0.02%) ⬇️
...equestReportView/MoneyRequestReportUnifiedList.tsx 76.29% <100.00%> (+5.70%) ⬆️
...oneyRequestReportView/useMoneyRequestReportData.ts 100.00% <100.00%> (ø)
... and 48 more
... and 18 files with indirect coverage changes

@TaduJR

TaduJR commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Please ignore ESLint. It's failing on main.

@marufsharifi

Copy link
Copy Markdown

@TaduJR, could you please upload the records for all platforms.

@TaduJR

TaduJR commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Yes already doing it currently

Raised the new PR. Tested a lot. Recording demos now step by step

@TaduJR

TaduJR commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Added Desktop and Android demos. Having a little problem in latest Device Hub.

It's prone to conflicts and resolving might take some time if occurring so feel free to review @marufsharifi

Thanks for the patience 👍!

@TaduJR

TaduJR commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot @codex review

@MelvinBot

Copy link
Copy Markdown
Contributor

I reviewed the diff at head f4b26fa and found no correctness bugs. I didn't run tests or test the app.

What I checked
  • Choosing new rows: how useNewTransactions and useDeliveredReportTransactions decide which rows are new, and how that resets when the report changes.
  • Playing the flash: how useAnimatedHighlightStyle plays each flash once, including when a row is reused for a different item mid-animation.
  • Screen visibility: ScreenWrapper, ScreenVisibilityProvider and getIsScreenVisible, including a report dimmed under a narrower panel.
  • Stored notes: the timestamped pendingNewTransactionIDs format, the 60-second expiry, clean-up of notes in the old format, and the "report already had rows" check in MoneyRequestBuilder. That check is safe for duplicating a report and for bulk duplicate.
  • Panel width: getVisibleRHPRouteKeys, WideRHPContextProvider, the 2-second hand-off in pendingRHPWidths, and useRHPWidth with the prev/next report arrows.
  • Removed APIs: no calls to the removed APIs remain, and every caller passes the new required highlightKey and shouldFlagNewTransactionForChatPreview parameters.

These three changes in behavior look intentional. Please confirm:

  1. Delayed flash on desktop: a report or Search list in the main pane now counts as visible only when it has focus. If a panel is open on top of it, the flash waits until the panel closes. Before this PR, it played right away.
  2. Flash after scrolling: a row that scrolls out of view and back within the 4-second highlight window can flash again.
  3. Deliveries that never finish: if a report's transactionCount is higher than the number of expenses that load, the table never compares the list before and after. Expenses added from another device then don't flash. Expenses added on this device still flash.

view run

@marufsharifi

Copy link
Copy Markdown

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@marufsharifi

Copy link
Copy Markdown

BUG1:

Test steps

Prerequisite
Workspace A is your default workspace.
Workspace A has Tags enabled with at least one tag.
Create two expenses in the Workspace A chat.

Steps

  1. Go to the Workspace A chat.
  2. Create Expense 1.
  3. Create Expense 2.
  4. Verify which expense is highlighted in the workspace chat.
  5. Click View to open the report.
  6. Verify which expense is highlighted in the report.
  7. Return to the Workspace A chat.
  8. Verify that neither expense is highlighted.
  9. Click View again to reopen the report.
  10. Check whether Expense 2 is highlighted again.

Expected Result

  • After creating both expenses, only the most recently created expense (Expense 2) should be highlighted.
  • When opening the report for the first time, Expense 2 may be highlighted.
  • After returning to the Workspace A chat, neither expense should be highlighted.
  • When reopening the report again, Expense 2 should not be highlighted again.

Actual Result

  • After creating the two expenses, Expense 1 is highlighted for a few seconds first, followed by Expense 2.
  • When opening the report, Expense 2 is highlighted.
  • After returning to the Workspace A chat, neither expense is highlighted.
  • However, when opening the report again, Expense 2 is highlighted again.
RF-1.mov

@TaduJR

TaduJR commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

BUG1:

@marufsharifi

I am seeing similar behaviour on staging. Could you double check

@marufsharifi

Copy link
Copy Markdown

BUG2:

Steps

Precondition:
Log in with a new Gmail account.

Steps:

  1. Create a new Workspace.
  2. Go to More options.
  3. Enable any available feature.
  4. Tap the enabled feature multiple times consecutively.

Expected Result:
When tapping the enabled feature multiple times in a row, it should remain highlighted / selected.

Actual Result:
When tapping the enabled feature multiple times in a row, it does not remain highlighted, even though the feature is enabled.

RF-2.mov

@TaduJR

TaduJR commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

BUG2:

Just tested it. Same on staging as well.

@marufsharifi

Copy link
Copy Markdown

BUG3:

Preconditions:
It should have one report with at least two expenses.

Steps:

  1. Go to Spend → Expenses.
  2. Open any existing expense.
  3. Keep the expense RHP open, with part of the Expenses list still visible behind it.
  4. In the RHP, tap More → Duplicate expense.
  5. Wait until the Duplicated confirmation appears.
  6. Do not close the RHP.
  7. Look at the duplicated expense in the visible Expenses list.
  8. Check whether the duplicated expense highlights while the RHP is still open.
  9. Now close the RHP.
  10. Check whether the duplicate highlights only after closing the RHP.

Expected result:
If the duplicated expense is already visible in the Expenses list, its highlight animation should play immediately. Closing the RHP should not be required.

Actual behavior:

  • The duplicated expense is visible in the Expenses list, but it does not highlight while the RHP is open.
  • After closing the RHP, the duplicated expense suddenly highlights.
RF-2.mov

…ports-newTransactionHighlight-and-RHPLayout-followups

# Conflicts:
#	src/components/Search/SearchList/ListItem/ChatListItem.tsx
#	src/components/Search/SearchList/ListItem/ExpenseReportListItem.tsx
#	src/components/Search/SearchList/ListItem/GroupChildrenContainer.tsx
#	src/components/Search/SearchList/ListItem/GroupHeader.tsx
#	src/components/Search/SearchList/ListItem/TaskListItem.tsx
#	src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx
#	src/components/Search/SearchList/ListItem/TransactionListItem/TransactionListItemNarrow.tsx
#	src/components/Search/SearchList/ListItem/TransactionListItem/TransactionListItemWide.tsx
#	src/components/Search/SearchList/ListItem/hooks/useSearchTableItemHighlight.ts
#	src/components/SelectionList/ListItemComposed/hooks/useListItemHighlight.ts
#	src/libs/Navigation/helpers/navigateAfterExpenseCreate.ts
#	src/libs/actions/IOU/NavigationHelpers.ts
#	src/libs/actions/IOU/Split.ts
#	src/libs/actions/IOU/TrackExpense.ts
#	tests/actions/IOU/SplitReportTotalsTest.ts
#	tests/actions/IOUTest/DuplicateTest.ts
#	tests/unit/useListItemHighlightTest.ts
#	tests/unit/useSearchTableItemHighlightTest.ts
@marufsharifi

Copy link
Copy Markdown

@TaduJR, Gentle bump.

@marufsharifi

Copy link
Copy Markdown

@TaduJR, friendly bump. thanks.

…ports-newTransactionHighlight-and-RHPLayout-followups

# Conflicts:
#	src/components/MoneyRequestConfirmationList/sections/HighlightableExpenseFieldRow.tsx
#	src/components/MoneyRequestReportView/MoneyRequestReportTransactionItem.tsx
#	src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx
#	src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx
#	src/components/ReportActionItem/MoneyRequestReportPreview/useReportPreviewCarousel.tsx
#	src/components/ScreenWrapper/index.tsx
#	src/components/WideRHPContextProvider/index.tsx
#	src/components/WideRHPContextProvider/useRHPWidth/index.ts
#	src/hooks/useResponsiveLayoutOnWideRHP/index.ts
#	src/libs/Navigation/AppNavigator/Navigators/RightModalNavigator.tsx
#	src/pages/iou/request/step/confirmation/submission/useDistanceSubmission.ts
#	src/pages/iou/request/step/confirmation/useExpenseSubmission.ts
#	src/selectors/ReportMetaData.ts
#	tests/ui/MoneyRequestReportTransactionsNavigationTest.tsx
#	tests/unit/hooks/useExpenseSubmission.test.ts
@TaduJR

TaduJR commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@MelvinBot @codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-02T13:48:09.475305Z
We couldn’t complete this review. Comment @codex review to try again.
95381de Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Code review

I found 2 likely bugs and 3 risks worth a look. Nothing blocks merge outright, but the first two can cause a wrong highlight or a wrong panel width.

Likely bugs

  1. Highlight flags don't expire while the consumer stays mounted. src/selectors/ReportMetaData.ts:65-71 checks age with Date.now(). However, useOnyx uses useSyncExternalStoreWithSelector, which re-runs the selector only when the metadata snapshot changes. The comment says "a flag can expire while its consumer waits to show it", but that never happens unless something else writes that report's metadata.

    • Example: you flag an expense, then a super-wide RHP covers the chat for 5 minutes. When you close the RHP, the preview still scrolls to and flashes the 5-minute-old expense.
    • Fix: re-check flaggedAt against the window when the flash is about to play, or re-run the selector when visibility changes.
  2. A width hint can pin a screen wider than its data needs. In useRHPWidth/index.ts:53-59, the floor is released only when the screen's own width reaches it. If the screen settles on a narrower width, the floor stays for the screen's whole lifetime.

    • Example: Search marks a report super-wide because the row has more than one transaction. Then the report page decides on wide, for example because one transaction is pending delete or shouldDisplayReportTableView is false. The single-expense view stays super-wide until it unmounts.
    • The old Search path called unmarkReportRHPWidth for single-transaction rows, and this PR removed that safeguard.
    • Fix: release the floor once the screen's data is loaded, not only when the width reaches the floor.

Risks

  1. The table baseline depends on transactionCount. MoneyRequestReportActionsList.tsx:129 feeds report.transactionCount into useDeliveredReportTransactions. If that count is higher than what the client holds, the baseline never forms. Expenses added from another device then never highlight in the table. Please confirm the count can't include transactions the client never receives.

  2. The "once per action" rule depends on microtask timing. PendingNewTransactions.ts:13-29 caches the answer in a module-level Map and clears it on the next microtask. Any flow whose adds span an await gets a fresh answer for each add, so the second expense into an empty report would flash while the first wouldn't. Unrelated calls in the same tick also share one answer. Computing the answer once in the caller and passing it in would be sturdier.

  3. The 2-second width-hint window is tight. pendingRHPWidths.ts:26-33 drops a hint after PENDING_RHP_WIDTH_WINDOW (2000 ms). On a slow device or cold open, the target screen's effect can run later than that, and the panel opens narrow, then jumps wide. Before this PR, a hint lasted until it was used.

Findings I checked and dropped
  • Central-pane keys treated as a closing RHP (getVisibleRHPRouteKeys.ts): WideRHPReceiptPanel returns early unless the route is SEARCH_REPORT, so no central-pane screen registers a width.
  • Full-tree walk on every navigation event: this happens only while a wide RHP is registered, so the cost is small.
  • useIsDisplayedInWideRHP still calls useRoute(): that code existed before this PR and isn't a regression.

Reviewed at 95381def. Reply with @MelvinBot <your feedback> if you want me to look deeper at any item.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to sample tokens
ℹ️ 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".

…ports-newTransactionHighlight-and-RHPLayout-followups

# Conflicts:
#	src/libs/Navigation/AppNavigator/Navigators/RightModalNavigator.tsx
#	src/libs/Navigation/helpers/cleanupAndNavigateAfterExpenseCreate.ts
@TaduJR

TaduJR commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Main has the same limit so follow-up for point 2 #102627 (comment) the others are invalid.

@marufsharifi

Please continue with the review

@marufsharifi

Copy link
Copy Markdown

BUG#1:

Steps:

  1. In the workspace chat, open a draft report containing 10 expenses dated Nov 1. Return to the chat and use the preview’s left arrow to show the first expense.
  2. Click + → Create expense → Manual. Add Eleventh receipt for €11.11, dated Nov 2, to the same report.
  3. Watch the preview immediately after creation without clicking either arrow.
  4. Click View and confirm Eleventh receipt appears in the report.

Expected result: The chat preview scrolls to Eleventh receipt and highlights its card once.

Actual result: The preview automatically scrolls to Test 10 and “+1 more.” The new expense never appears or flashes in the chat preview.

Screen.Recording.2026-11-02.at.8.21.38.PM.mov

@marufsharifi

Copy link
Copy Markdown

BUG#2:

Test steps:

  1. In your Draft workspace report, create Split test — $100 and Keep report — $10.
  2. Open the $100 expense → More → Split → create two $50 parts in the same report. Save and wait for syncing.
  3. In your chat with yourself, create Add after undo — $50 and leave it unreported.
  4. Return to the report → Add expense → Add existing expense. Confirm the $50 expense appears, then go back without adding it.
  5. Test steps
  6. Go offline and remain offline throughout the test.
  7. Open a $50 split expense → Amount → open one split row → Remove split.
  8. Confirm the remaining amount becomes $100, then Save.
  9. Return to the report list and wait five seconds.
  10. Close the entire report to the workspace chat, then reopen it using View.
  11. Select Add expense → Add existing expense → Tester456— $50 → Add to report.
  12. Immediately watch the new $50 row.

Expected result: The expense is added and its row briefly highlights.

Actual result: The expense is added, but its row does not highlight.

Screen.Recording.2026-11-03.at.3.03.29.PM.mov

@marufsharifi

Copy link
Copy Markdown

@TaduJR, could you please check the last tow bugs reported. and resolve the conflicts. thanks.

…ports-newTransactionHighlight-and-RHPLayout-followups

# Conflicts:
#	src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx
#	src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx
#	src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx
#	src/components/ReportActionItem/TransactionPreview/TransactionPreviewContent.tsx
#	tests/unit/hooks/usePerDiemSubmission.test.ts
@marufsharifi

Copy link
Copy Markdown

@TaduJR, Gentle bump. thanks.

@TaduJR

TaduJR commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@marufsharifi

Already working on it!

Thanks!

@marufsharifi

Copy link
Copy Markdown

@TaduJR, Quick bump. thanks.

@TaduJR

TaduJR commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

@marufsharifi

BUG#1:

It happens on main too.

The chat preview shows up to 10 expense cards, and the 11th spot is the "+N more" link. The preview sorts oldest first, so a new expense in a report that already has 10 lands in that 11th spot. The preview scrolls to it, but there's no card there to show or flash, only "+1 more".

We need a product decision on this: skip the scroll when the new expense is behind "+N more", or always give a new expense one of the 10 cards. I'd rather handle it in a follow-up than in this PR.

BUG#2:

I reproduced it, and this one came from this PR. It's fixed in the latest push.

@marufsharifi

Copy link
Copy Markdown

@TaduJR, could you please check the failure action. thanks.

@TaduJR
TaduJR requested a review from situchan November 13, 2026 18:03
@situchan

Copy link
Copy Markdown
Contributor

Was there already a discussion to move forward with this mega PR rather than splitting or beta?

@TaduJR

TaduJR commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Yes here #96327 (comment)

Also since this is a refactoring and not a feature I think beta will not work.

@situchan

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@situchan situchan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left code quality review.
Please check and address valid ones.

Comment on lines +201 to +205
setTimeout(() => scrollToNewTransaction(index, newTransaction?.transactionID), CONST.PENDING_TRANSACTION_SCROLL_DELAY);

// We only want to scroll to a new transaction when the set of new transaction IDs changes.
// We only want to scroll to a new transaction when the set of new transaction IDs changes, or when the chat is uncovered.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [newTransactionIDs]);
}, [newTransactionIDs, isScreenVisible]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carousel scroll timer is never cleared

The effect starts a timer with no cleanup. Adding isScreenVisible to the deps means every cover and uncover of the chat queues another timer.

Fix:

const timer = setTimeout(() => scrollToNewTransaction(index, newTransaction?.transactionID), CONST.PENDING_TRANSACTION_SCROLL_DELAY);
return () => clearTimeout(timer);

import type ResponsiveLayoutOnWideRHPResult from './types';

// Tests that mock @react-navigation/native partially leave this undefined.
const FallbackRouteContext = createContext<Route<string> | undefined>(undefined);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FallbackRouteContext is duplicated

const FallbackRouteContext = createContext<Route<string> | undefined>(undefined);

It's the same context and the same useContext(NavigationRouteContext ?? FallbackRouteContext) read as in ScreenWrapper.

Fix: move it into one small hook, for example useRouteFromContext, and use it in both places.

Comment on lines +13 to +26
/** Whether each report showed rows when the current action began. From an action's second add the report includes the first, so every add uses the first answer. */
const reportsShowingRowsWhenActionBegan = new Map<string, boolean>();

/** Answers once per report per action. Cleared a microtask later, when the action's synchronous run ends. */
function wasReportShowingRowsWhenActionBegan(reportID: string, isShowingRowsNow: () => boolean): boolean {
const isShowingRowsAtActionStart = reportsShowingRowsWhenActionBegan.get(reportID);
if (isShowingRowsAtActionStart !== undefined) {
return isShowingRowsAtActionStart;
}
const isShowingRows = isShowingRowsNow();
const isFirstAnswerOfThisAction = reportsShowingRowsWhenActionBegan.size === 0;
reportsShowingRowsWhenActionBegan.set(reportID, isShowingRows);
if (isFirstAnswerOfThisAction) {
Promise.resolve().then(() => reportsShowingRowsWhenActionBegan.clear());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per-action cache depends on every add running synchronously

A module-level map remembers whether the report showed rows, and a microtask clears it. If an add flow ever awaits between adds, some rows get a highlight flag and others don't, and nothing at the call site warns about it.

Fix: work out the answer once in the caller and pass it into buildOnyxDataForMoneyRequest.

const NO_RHP_ROUTE_KEYS: RHPRouteKeys = {wide: [], superWide: []};

/** `width` includes a screen animating out; `displayed` does not. */
let rhpRouteKeys: {width: RHPRouteKeys; displayed: RHPRouteKeys} = {width: NO_RHP_ROUTE_KEYS, displayed: NO_RHP_ROUTE_KEYS};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RHP width keys are kept in two places

setRHPRouteKeysSnapshot({wide: widthWideRHPRouteKeys, superWide: widthSuperWideRHPRouteKeys}, {wide: displayedWideRHPRouteKeys, superWide: displayedSuperWideRHPRouteKeys});

wideRHPRouteKeys: widthWideRHPRouteKeys,

The same keys live in React state behind the context and in a module store filled by a layout effect. ScreenWrapper and useResponsiveLayoutOnWideRHP read the store, and about 20 other components read the context.

Fix: keep one source, or document in the provider when to use each.

*/
function getVisibleRHPKeys(allSuperWideRHPKeys: string[], allWideRHPKeys: string[]): VisibleRHPKeys {
if (!navigationRef.isReady()) {
function getVisibleRHPKeys(state: NavigationState | undefined, allWideRHPKeys: string[], allSuperWideRHPKeys: string[], seenRouteKeys: ReadonlyMap<string, string>): VisibleRHPKeys {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wide and super-wide arrays are passed in opposite orders

export default function getIsRHPDisplayedBelow(focusedRouteKey: string | undefined, visibleSuperWideRHPRouteKeys: string[], visibleWideRHPRouteKeys: string[]) {

getVisibleRHPKeys now takes (wide, superWide). It used to take (superWide, wide), and getIsRHPDisplayedBelow still does. Both are string[], so a swap type-checks.

if (transactions !== undefined && prevTransactions !== undefined && transactions.length > prevTransactions.length) {
if (skipFirstTransactionsChange.current) {
skipFirstTransactionsChange.current = false;
function useNewTransactions({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useNewTransactions is hard to follow

function useNewTransactions({
hasOnceLoadedReportActions,
transactions,
arrivedTransactionCount,
expectedTransactionCount,
transactionsReportID,
pendingNewTransactions,
railReportID,
isReportVisible,
}: UseNewTransactionsParams): Transaction[] {
const [hasSettledAfterInitialLoad, setHasSettledAfterInitialLoad] = useState(() => !!hasOnceLoadedReportActions);
const [diffState, setDiffState] = useState<DiffState>(() => ({reportID: transactionsReportID, sourceIDs: undefined, addedIDs: EMPTY_TRANSACTION_IDS}));
const deliveredTransactions = useDeliveredReportTransactions({reportID: transactionsReportID, transactions, arrivedTransactionCount, expectedTransactionCount});
const trackedTransactionIDs = hasOnceLoadedReportActions && deliveredTransactions ? deliveredTransactions.map(({transactionID}) => transactionID) : undefined;
const baselineSourceIDs = diffState.sourceIDs;
const baselineIDs = new Set(baselineSourceIDs);
const isReportSwitch = transactionsReportID !== diffState.reportID;
// A reorder is not an add.
const hasSameTransactionIDs =
trackedTransactionIDs !== undefined &&
baselineSourceIDs !== undefined &&
trackedTransactionIDs.length === baselineSourceIDs.length &&
trackedTransactionIDs.every((transactionID) => baselineIDs.has(transactionID));
if (isReportSwitch) {
// Only the new report's own list can set its baseline.
setDiffState({reportID: transactionsReportID, sourceIDs: undefined, addedIDs: EMPTY_TRANSACTION_IDS});
if (hasSettledAfterInitialLoad !== !!hasOnceLoadedReportActions) {
setHasSettledAfterInitialLoad(!!hasOnceLoadedReportActions);
}
} else if ((trackedTransactionIDs !== undefined || baselineSourceIDs !== undefined) && !hasSameTransactionIDs) {
let addedIDs = EMPTY_TRANSACTION_IDS;
if (baselineSourceIDs !== undefined && trackedTransactionIDs !== undefined && trackedTransactionIDs.length > baselineSourceIDs.length) {
if (!hasSettledAfterInitialLoad) {
setHasSettledAfterInitialLoad(true);
} else {
// Every missing row is an add, even all of them: that is what a split looks like.
addedIDs = trackedTransactionIDs.filter((transactionID) => !baselineIDs.has(transactionID));
}
} else if (diffState.addedIDs.length && trackedTransactionIDs !== undefined) {
// The same array, so a reorder or removal doesn't restart the highlight window.
addedIDs = diffState.addedIDs;
}
setDiffState({reportID: transactionsReportID, sourceIDs: trackedTransactionIDs, addedIDs});
}
// An unloaded report cannot have settled, even if the loaded flag lags a report switch.
if (!hasOnceLoadedReportActions && hasSettledAfterInitialLoad) {
setHasSettledAfterInitialLoad(false);
}
const activeFlagKeys = pendingNewTransactions?.activeFlagKeys;
const railTransactions = railReportID && activeFlagKeys && transactions.length ? transactions.filter(({transactionID}) => activeFlagKeys[transactionID]) : EMPTY_TRANSACTIONS;
let diffTransactions = EMPTY_TRANSACTIONS;
if (diffState.addedIDs.length && transactions.length) {
const addedIDs = new Set(diffState.addedIDs);
diffTransactions = transactions.filter(({transactionID}) => addedIDs.has(transactionID));
}
let newTransactions = railTransactions;
if (!railTransactions.length) {
newTransactions = diffTransactions.length ? diffTransactions : EMPTY_TRANSACTIONS;
} else {
const extraDiff = diffTransactions.filter(({transactionID}) => !activeFlagKeys?.[transactionID]);
newTransactions = extraDiff.length ? [...railTransactions, ...extraDiff] : railTransactions;
}
useEffect(() => {
if (!isReportVisible || !pendingNewTransactions) {
return;
}
const railFlagKeys = pendingNewTransactions.activeFlagKeys;
const consumedFlagKeys = newTransactions.map(({transactionID}) => railFlagKeys[transactionID]).filter(Boolean);
const claimedKeys: string[] = [];
for (const flagKey of [...consumedFlagKeys, ...pendingNewTransactions.expiredFlagKeys]) {
const sweepKey = `${railReportID}:${flagKey}`;
if (scheduledSweeps.has(sweepKey)) {
continue;
}
scheduledSweeps.add(sweepKey);
claimedKeys.push(flagKey);
}
if (!claimedKeys.length) {
return;
}
// No cleanup: a shown highlight's flag must go even if the row unmounts first.
setTimeout(() => {
// Released before deleting, so a merge that never lands stays claimable.
for (const flagKey of claimedKeys) {
scheduledSweeps.delete(`${railReportID}:${flagKey}`);
}
deletePendingNewTransactionFlags(railReportID, claimedKeys);
}, CONST.PENDING_TRANSACTION_DELETION_DELAY);
}, [isReportVisible, pendingNewTransactions, newTransactions, railReportID]);
// Compared by identity, so a later add of the same size gets its own window.
const latchedAddedIDs = diffState.addedIDs;
// Starts when the rows are first visible and never restarts, so covering them can't prolong it.
const [visibleAddedIDs, setVisibleAddedIDs] = useState<string[] | undefined>(undefined);
if (isReportVisible && latchedAddedIDs.length && visibleAddedIDs !== latchedAddedIDs) {
setVisibleAddedIDs(latchedAddedIDs);
}
useEffect(() => {
if (!visibleAddedIDs?.length) {
return;
}
const timer = setTimeout(() => {
setDiffState((previousDiffState) => (previousDiffState.addedIDs === visibleAddedIDs ? {...previousDiffState, addedIDs: EMPTY_TRANSACTION_IDS} : previousDiffState));
}, CONST.PENDING_TRANSACTION_DELETION_DELAY);
return () => clearTimeout(timer);
}, [visibleAddedIDs]);
useEffect(() => {
if (!hasOnceLoadedReportActions || hasSettledAfterInitialLoad) {
return;
}
// A report that loads without adding transactions never grows, so the diff above never settles it, and it settles here instead.
// This waits a microtask and a frame, so transactions that arrive in the same Onyx update as the loaded flag still count as the baseline, not as adds.
let frame: number | undefined;
let isStale = false;
new Promise<void>((resolve) => {
resolve();
}).then(() => {
if (isStale) {
return;
}
frame = requestAnimationFrame(() => {
setHasSettledAfterInitialLoad(true);
});
});
// Cancelled on cleanup, so a frame queued for the previous report cannot undo the reset.
return () => {
isStale = true;
if (frame === undefined) {
return;
}
cancelAnimationFrame(frame);
};
}, [hasOnceLoadedReportActions, hasSettledAfterInitialLoad]);
return newTransactions;

It takes 8 params and updates three pieces of state during render. Treating a load as settled also waits a microtask and a frame.

Fix: move the diff logic into a pure getNextDiffState(previous, input) like armedPlay.ts, and keep the hook to wiring.

Comment on lines 204 to +205
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [newTransactionIDs]);
}, [newTransactionIDs, isScreenVisible]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint suppression is no longer needed

scrollToNewTransaction is now an effect event, so the carouselTransactions lookup can move inside it.

Fix: move the lookup and drop the exhaustive-deps suppression.

Comment on lines +31 to 32
/** Highlight flags for transactions just added to this report, keyed `${transactionID}:${flaggedAt}`. */
pendingNewTransactionIDs?: Record<string, true | null>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pendingNewTransactionIDs no longer holds IDs

It now holds transactionID:flaggedAt keys, which the name hides.

Fix: rename it with a migration, or call it out as a known trade-off.

skipInitialFade?: boolean;

/** Key of the item this row shows, so a recycled row isn't mistaken for the same one. `undefined` for a row that always shows the same thing. */
highlightKey: string | undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

highlightKey is required even where it's always undefined

Four callers pass highlightKey: undefined.

Fix: make it optional, unless forcing every caller to choose is the point.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants