Skip to content

Fix/71117 - Icons disappear and reappear when navigating to the next report - #71311

Closed
dmkt9 wants to merge 28 commits into
Expensify:mainfrom
dmkt9:fix/71117
Closed

dmkt9 wants to merge 28 commits into
Expensify:mainfrom
dmkt9:fix/71117

Conversation

@dmkt9

@dmkt9 dmkt9 commented Sep 25, 2025 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$ #71117
PROPOSAL: #71117 (comment)

Tests

Same as QA Steps

  • Verify that no errors appear in the JS console

Offline tests

Same as QA Steps

QA Steps

Test 1:

  1. Launch Expensify app
  2. Create two reports in the workspace chat
  3. Go to Reports > Menu > Reports
  4. Open any report
  5. Tap arrow next button
  6. Verify that icons will not disappear when navigating to the next report

Test 2:

  1. Launch Expensify app
  2. Create two reports in the workspace chat
  3. Add at least two expenses to each report.
  4. Go to Reports > Menu > Reports
  5. Open any report
  6. Tap arrow next button
  7. Verify that transactions transition smoothly, do not briefly show a “not found” state, and do not unexpectedly highlight the transaction row when visiting a report for the second time.
  • 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
    • MacOS: Desktop
  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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 shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • 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.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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.mwb.mp4
iOS: Native
ios.native.mp4
iOS: mWeb Safari
ios.mweb.mp4
MacOS: Chrome / Safari
mac.safari.mp4
MacOS: Desktop
mac.desktop.mp4

@dmkt9
dmkt9 requested a review from a team as a code owner September 25, 2025 12:38
@melvin-bot
melvin-bot Bot requested review from ahmedGaber93 and removed request for a team September 25, 2025 12:38
@melvin-bot

melvin-bot Bot commented Sep 25, 2025

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Sep 25, 2025 •

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/hooks/usePaginatedReportActions.ts 100.00% <100.00%> (ø)
...report/ReportActionCompose/ReportActionCompose.tsx 68.80% <ø> (ø)
.../MoneyRequestReportView/MoneyRequestReportView.tsx 0.00% <0.00%> (ø)
src/hooks/useNewTransactions.ts 95.83% <88.88%> (-4.17%) ⬇️
src/pages/Search/SearchMoneyRequestReportPage.tsx 0.00% <0.00%> (ø)
... and 15 files with indirect coverage changes

@roryabraham

Copy link
Copy Markdown
Contributor

Merge main to fix claude code review (doesn't yet work for forks)

@dmkt9

dmkt9 commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Thanks. The PR is ready for review at this time.

@dmkt9 dmkt9 closed this Sep 26, 2025
@dmkt9
dmkt9 deleted the fix/71117 branch September 26, 2025 04:29
@dmkt9
dmkt9 restored the fix/71117 branch September 26, 2025 04:30
@dmkt9 dmkt9 reopened this Sep 26, 2025
@dmkt9

dmkt9 commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Apologies, I accidentally deleted my branch. It has now been restored and the pull request has been reopened

@ahmedGaber93

ahmedGaber93 commented Sep 27, 2025 •

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
    • MacOS: Desktop
  • 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 there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (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 shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • 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
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • 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 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 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 a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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
20251013131622766.mp4
Android: mWeb Chrome
aw.mp4
iOS: HybridApp
i.mp4
iOS: mWeb Safari
iw.mp4
MacOS: Chrome / Safari
w.mp4
MacOS: Desktop
d.mp4

@ahmedGaber93

Copy link
Copy Markdown
Contributor

Bug: All expenses are highlighted when navigate back from report with 1 expense to report with 2 expense

  1. Create report with 2 expense
  2. Create another report with 1 expense
  3. Go to reports tab
  4. Open the report with 2 expense
  5. Click "Next" icon to navigate to the report with 1 expense
  6. Click "Prev" icon to navigate back to the report with 2 expense

Result: All expenses are highlighted

20250927082824163.mp4

Comment thread src/hooks/usePaginatedReportActions.ts Resolved
@dmkt9

dmkt9 commented Sep 29, 2025

Copy link
Copy Markdown
Contributor Author

Bug: All expenses are highlighted when navigate back from report with 1 expense to report with 2 expense

Thanks for pointing it out. The issue happened because skipFirstTransactionsChange hadn’t been reset, so newTransactions wasn’t initialized with an empty array.

@ahmedGaber93

Copy link
Copy Markdown
Contributor

@dmkt9 It seems we still have the issue on another place.

  1. Create report with 2 transaction
  2. Open the first transaction
  3. Navigate between the 2 transaction
20250930081607914.mp4

@dmkt9

dmkt9 commented Oct 13, 2025

Copy link
Copy Markdown
Contributor Author

@dmkt9 could you please resolve the conflict?

Thanks for the reminder. I just resolved that conflict.

@roryabraham roryabraham 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.

Hmmmm I'm sorry to leave this review without suggesting a clear alternative, but I think we need to discuss this one further. It just feels like a culmination of some anti-patterns that might need to be unwinded. There's a lot of usePrevious / diff checking.

It seems to me that the root of the problem is that SearchMoneyRequestReportPage isn't re-mounting when the route changes, which results in us having to use a flag such as shouldResetSkipFirstTransactionsChange to reset a hook that itself is used to highlight changes in state between renders.

I'd love to spend some time with you to take a more holistic look at these components and see if we can improve our composition to make them more pure (just rendering based on the props they receive)

@roryabraham

Copy link
Copy Markdown
Contributor

Maybe by adding a key prop in the right place, we can force a remount and avoid having to do all the usePrevious diff checking?

@dmkt9

dmkt9 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor Author

Maybe by adding a key prop in the right place, we can force a remount and avoid having to do all the usePrevious diff checking?

Interesting. I think it’s totally doable. We can move useNewTransactions down to the MoneyRequestReportTransactionList component and add key={report.reportID} to it inside MoneyRequestReportActionsList.

@dmkt9

dmkt9 commented Oct 16, 2025

Copy link
Copy Markdown
Contributor Author

@roryabraham Besides usePrevious, do we need to eliminate any other patterns? I'm not very familiar with what counts as an anti-pattern.

After that, I can go ahead and make a full round of updates.

@dmkt9

dmkt9 commented Oct 17, 2025

Copy link
Copy Markdown
Contributor Author

@roryabraham After testing the approach of moving useNewTransactions down into the MoneyRequestReportTransactionList component, it worked very well when switching between reports. However, a bug appeared when a report already has one expense and we add another — the highlight doesn’t show up. This happens because we use two separate components to render, so MoneyRequestReportTransactionList only starts rendering after the new expense is added, which explains why the highlight doesn’t appear.

<MoneyRequestReportActionsList
report={report}
policy={policy}
transactions={visibleTransactions}
hasPendingDeletionTransaction={hasPendingDeletionTransaction}
newTransactions={newTransactions}
reportActions={reportActions}
violations={allReportViolations}
hasOlderActions={hasOlderActions}
hasNewerActions={hasNewerActions}
showReportActionsLoadingState={isLoadingInitialReportActions && !reportMetadata?.hasOnceLoadedReportActions}
/>
) : (
<ReportActionsView
report={report}
reportActions={reportActions}
isLoadingInitialReportActions={reportMetadata?.isLoadingInitialReportActions}
hasNewerActions={hasNewerActions}
hasOlderActions={hasOlderActions}
parentReportAction={parentReportAction}
transactionThreadReportID={transactionThreadReportID}
/>

To fix this bug, I think we still need to use usePrevious or a similar structure to detect the transition from ReportActionsView to MoneyRequestReportActionsList. But that would add complexity. So I’ve reverted the previous change.

@roryabraham

Copy link
Copy Markdown
Contributor

I was doing some testing, but I'm not able to reproduce the base issue on main or staging anymore

@dmkt9

dmkt9 commented Oct 23, 2025

Copy link
Copy Markdown
Contributor Author

I’ve just run some tests. It seems that the original issue on iOS is resolved. On Android, the icon still flickers slightly. Additionally, the loading indicator appears very often on Android.

2025-10-23.09-46-45.mp4

@roryabraham

Copy link
Copy Markdown
Contributor

@dmkt9 I've chatted with Cursor about this a bit, and it suggests a simpler solution:

diff --git a/src/pages/Search/SearchMoneyRequestReportPage.tsx b/src/pages/Search/SearchMoneyRequestReportPage.tsx
index c20ef96f56a..1b0920ad5c4 100644
--- a/src/pages/Search/SearchMoneyRequestReportPage.tsx
+++ b/src/pages/Search/SearchMoneyRequestReportPage.tsx
@@ -49,7 +49,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
     const {isOffline} = useNetwork();
 
     const reportIDFromRoute = getNonEmptyStringOnyxID(route.params?.reportID);
-    const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true});
+    const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {canBeMissing: true});
 
     const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {canBeMissing: true, allowStaleData: true});
     const [policies = getEmptyObject<NonNullable<OnyxCollection<Policy>>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, canBeMissing: false});
@@ -133,7 +133,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
                                     reportMetadata={reportMetadata}
                                     policy={policy}
                                     shouldDisplayReportFooter={isCurrentReportLoadedFromOnyx}
-                                    key={report?.reportID}
+                                    key={reportIDFromRoute}
                                     backToRoute={route.params.backTo}
                                 />
                             </DragAndDropProvider>
@@ -169,7 +169,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
                                         reportMetadata={reportMetadata}
                                         policy={policy}
                                         shouldDisplayReportFooter={isCurrentReportLoadedFromOnyx}
-                                        key={report?.reportID}
+                                        key={reportIDFromRoute}
                                         backToRoute={route.params.backTo}
                                     />
                                 </View>

Do you want to try that out?

@dmkt9

dmkt9 commented Oct 25, 2025

Copy link
Copy Markdown
Contributor Author

@dmkt9 I've chatted with Cursor about this a bit, and it suggests a simpler solution:

Do you want to try that out?

Hi @roryabraham, I’ve tested the proposed solution, but unfortunately I didn’t observe any improvement. That said, I believe the behavior is still understandable since we’re continuing to use the key for MoneyRequestReportView.

This solution
2025-10-25.11-34-42.mp4
Our PR
2025-10-25.11-45-59.mp4

@dmkt9
dmkt9 requested a review from a team as a code owner November 6, 2025 02:25
@melvin-bot
melvin-bot Bot requested review from heyjennahay and removed request for a team November 6, 2025 02:25
heyjennahay
heyjennahay previously approved these changes Nov 7, 2025

@heyjennahay heyjennahay 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.

No concern with product change

@ahmedGaber93

Copy link
Copy Markdown
Contributor

@roryabraham What do you think here #71311 (comment)?

@roryabraham

Copy link
Copy Markdown
Contributor

@dmkt9 I don't think I want to merge this PR given that the original issue is no longer reproducible. given that, I'm not sure what problem we're trying to solve.

@roryabraham roryabraham closed this Dec 5, 2025
@dmkt9

dmkt9 commented Dec 5, 2025

Copy link
Copy Markdown
Contributor Author

Hi @roryabraham, I understand that the issue may no longer be as clear as in the OP. If you feel that our PR does not clearly resolve a specific problem, I completely agree with not merging it. However, I would like to add a bit more context to the issue that our PR is aiming to address.

There are a few other issues that have also been submitted to fix the avatar flicker problem, for example #75195. You can see the avatar flicker when toggling the enable button.

Our case appears to be similar, as shown in the video below:

2025-12-05.14-05-31.mp4

I believe this issue is equivalent to issue #75195. If you think it makes sense, we can proceed with this PR, and if the patterns in the PR are not ideal, I can adjust them for clarity. For example, we could slightly change the use of the shouldResetSkipFirstTransactionsChange parameter.

cc @ahmedGaber93

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