Skip to content

Conversation

@nabi-ebrahimi
Copy link
Contributor

Explanation of Change

Fixed Issues

$ #64627
PROPOSAL: #64627 (comment)

Tests

  1. Open the Expensify app.
  2. As User A open any workspace chat.
  3. Tap on header and select "Members"
  4. Invite User B as member,
  5. Return to chat and create a manual expense.
  6. As User B open the workspace chat.
  7. Open the report of the just received expense.
  8. As User A, remove User B from workspace chat.
  9. As User B, tap on the back button on the top left corner to return to chat. (Device´s back button on Web)
  10. You should be redirected to LHP
  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."

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
    • 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
Screen.Recording.1404-04-19.at.3.03.46.PM.mov
Android: mWeb Chrome
Screen.Recording.1404-04-19.at.3.24.18.PM.mov
iOS: Native
Screen.Recording.1404-04-19.at.3.19.47.PM.mov
iOS: mWeb Safari
Screen.Recording.1404-04-19.at.3.25.27.PM.mov
MacOS: Chrome / Safari
Screen.Recording.1404-04-19.at.2.57.57.PM.mov
MacOS: Desktop

Not applicable.

@nabi-ebrahimi nabi-ebrahimi requested a review from a team as a code owner November 2, 2025 07:33
@melvin-bot melvin-bot bot requested review from allroundexperts and removed request for a team November 2, 2025 07:33
@melvin-bot
Copy link

melvin-bot bot commented Nov 2, 2025

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

}, [reportOnyx?.reportID, route.params.backTo, reportIDFromRoute]);

useFocusEffect(redirectBackOnDeletedReport);

Copy link
Contributor

Choose a reason for hiding this comment

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

❌ PERF-6 (docs)

The useCallback dependency array includes the entire reportOnyx?.reportID object property, but you're only accessing it in conditional checks. Consider specifying the individual property more explicitly if reportOnyx is an object that changes frequently.

Suggested fix: Since reportOnyx?.reportID is already a primitive value (string), this is acceptable. However, ensure that reportIDFromRoute and route.params.backTo are also primitives and not extracted from complex objects that could cause unnecessary re-renders.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2025

LGTM 👍 Thank you for your hard work!

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, friendly bump on review. thanks.

@allroundexperts
Copy link
Contributor

@nabi-ebrahimi Tests are failing.

@nabi-ebrahimi nabi-ebrahimi requested a review from a team as a code owner November 27, 2025 04:01
@melvin-bot melvin-bot bot requested review from JmillsExpensify and removed request for a team November 27, 2025 04:01
@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts Thanks for checking. Although those failures weren’t related to my changes, I’ve merged main to rerun the tests. If they fail again, I’ll investigate further.

@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/pages/home/ReportScreen.tsx 68.08% <47.36%> (+1.33%) ⬆️
... and 102 files with indirect coverage changes

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, tests are all passed, please take another look. thanks

@allroundexperts
Copy link
Contributor

Hi @nabi-ebrahimi!

Your PR still does not seem to resolve the issue.

Screen.Recording.2025-12-01.at.3.04.17.AM.mov

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, I will check it asap and update here. thanks

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, could you please re-test it? I’ve tested it again on my side, and it’s working.

Screen.Recording.1404-09-10.at.8.52.45.AM.mp4

Could you please share any specific steps in your test that caused this issue to appear? Thank you.

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, the failing test appears to be a flaky one and isn’t related to my changes. It should be resolved after re-running the tests.

Copy link
Contributor

@JmillsExpensify JmillsExpensify left a comment

Choose a reason for hiding this comment

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

Change makes sense from a product/permissions perspective.

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, can you please check this again. thanks.

@allroundexperts
Copy link
Contributor

Hi @nabi-ebrahimi!

This still does not work. Do the following to reproduce:

  1. Add a user (User B) to wokrpsace as admin.
  2. As user A, create an expense in workspace.
  3. As user B, open the expense report.
  4. As user A, remove the user B from the workspace.

You'll observe that user B is redirected to a forever loading screen.

Screen.Recording.2025-12-08.at.2.12.13.AM.mov

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts Thanks for the review. The issue reported in the OP only occurs when a user is redirected back after being removed from the chat. The issue you're referring to is related, but it wasn't part of the original scope and doesn’t require a redirect to reproduce — the user simply needs to be a workspace admin.

Would you prefer that I address this in the current PR, or should I open a separate PR since it wasn’t originally included or handled?

@allroundexperts
Copy link
Contributor

I think it is related and should be handled as part of this PR.

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, what is the expected behavior for the last issue you discovered? Should the “Not Found” page be displayed when a user is removed from the workspace? Since the member isn’t performing any action at that moment, it doesn’t seem necessary to redirect them back. What do you think?

Screenshot 1404-09-19 at 10 20 58 PM

@allroundexperts
Copy link
Contributor

@allroundexperts, what is the expected behavior for the last issue you discovered? Should the “Not Found” page be displayed when a user is removed from the workspace? Since the member isn’t performing any action at that moment, it doesn’t seem necessary to redirect them back. What do you think?

Screenshot 1404-09-19 at 10 20 58 PM

I think the behaviour should be the same as it is here.

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, my changes work as expected and redirect the user back. However, the following line navigates the user back to the unavailable report again. This issue already existed, but it became visible after we fixed the issue in OR Post

Navigation.isNavigationReady().then(() => {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(prevReport.parentReportID));
});
return;

I don’t have enough context on when this line is expected to run and trigger navigation to the previous report. Could you please provide more details on the intended behavior and how the code should be updated without breaking it?

cc @JmillsExpensify

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, @JmillsExpensify could you please check this comment when you get a chance. thanks

@nabi-ebrahimi
Copy link
Contributor Author

@allroundexperts, @JmillsExpensify kindly bump on this comment

@amyevans amyevans requested review from situchan and removed request for allroundexperts January 5, 2026 20:00
@nabi-ebrahimi
Copy link
Contributor Author

@situchan, could you please check this comment. when you get a chance. thanks

@situchan
Copy link
Contributor

situchan commented Jan 8, 2026

For me, browser back button keeps the current page (expense report) with just scrolling up.
Tested on this branch.

Screen.Recording.2026-01-08.at.1.48.03.PM.mov

@situchan
Copy link
Contributor

situchan commented Jan 8, 2026

@situchan

This comment was marked as off-topic.

@situchan
Copy link
Contributor

situchan commented Jan 8, 2026

my changes work as expected and redirect the user back. However, the following line navigates the user back to the unavailable report again. This issue already existed, but it became visible after we fixed the issue in OR Post

Navigation.isNavigationReady().then(() => {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(prevReport.parentReportID));
});
return;

I don’t have enough context on when this line is expected to run and trigger navigation to the previous report. Could you please provide more details on the intended behavior and how the code should be updated without breaking it?

@nabi-ebrahimi you can git bisect yourself.

Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(prevReport.parentReportID));

This line was added in #28702 to fix #28087

And later changed a bit (wrapped with isNavigationReady) in #63032 to fix #62568.

Navigation.isNavigationReady().then(() => {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(prevReport.parentReportID));
});

@situchan
Copy link
Contributor

situchan commented Jan 8, 2026

When tap on browser back button, reportIDFromRoute is workspace chat, while reportID in OpenReport api is concierge.
I think this is the root cause to fix.

Screen.Recording.2026-01-08.at.2.25.17.PM.mov

In this video:
6061172335000489 - workspace chat reportID
3348757821953567 - concierge reportID

@situchan
Copy link
Contributor

situchan commented Jan 8, 2026

We already have logic to redirect to Concierge chat when report doesn't exist:

Navigation.isNavigationReady().then(() => {
navigateToConciergeChat();
});

But failed because this condition is not met:

const isRemovalExpectedForReportType =
isEmpty(report) &&
(isMoneyRequest(prevReport) ||
isMoneyRequestReport(prevReport) ||
isPolicyExpenseChat(prevReport) ||
isGroupChat(prevReport) ||
isAdminRoom(prevReport) ||
isAnnounceRoom(prevReport));

Because prevReport is undefined.

This works perfectly when member is on workspace chat (not expense report) at the moment member is removed by admin.

@situchan
Copy link
Contributor

situchan commented Jan 8, 2026

@nabi-ebrahimi based on above analysis, can you please find solution to fix the real root cause?
I don't like current changes in PR.

@nabi-ebrahimi
Copy link
Contributor Author

@situchan, thanks, i will check and update today.

@nabi-ebrahimi
Copy link
Contributor Author

nabi-ebrahimi commented Jan 12, 2026

@situchan, thanks for the review, and check. I have investigated it further. And i believe this block is useles now and should be removed.

// Prevent navigation to the IOU/Expense Report if it is pending deletion.
if (isMoneyRequestReportPendingDeletion(prevReport.parentReportID)) {
return;
}
Navigation.isNavigationReady().then(() => {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(prevReport.parentReportID));
});

This block originally added in this pr to fix this issue.

But this logic handles that now. and that block never runs after Leave Room or transaction thread.

App/src/libs/actions/Report.ts

Lines 3684 to 3700 in d335917

function navigateToMostRecentReport(currentReport: OnyxEntry<Report>) {
const lastAccessedReportID = findLastAccessedReport(false, false, undefined, currentReport?.reportID)?.reportID;
if (lastAccessedReportID) {
const lastAccessedReportRoute = ROUTES.REPORT_WITH_ID.getRoute(lastAccessedReportID);
Navigation.goBack(lastAccessedReportRoute);
} else {
const isChatThread = isChatThreadReportUtils(currentReport);
// If it is not a chat thread we should call Navigation.goBack to pop the current route first before navigating to Concierge.
if (!isChatThread) {
Navigation.goBack();
}
navigateToConciergeChat(false, () => true, {forceReplace: true});
}
}

Which is called in both leaveGroupChat and leaveRoom. which will resolve the original issue from here

Since then we had two changes to that code block this pr to fix this issue, and this PR to fix this issue

I have tested my solution with that code block removed. all the issues are solved.

1. Leaving threads lands you in concierge chat issue

leave-the-thread.mov

2. Chat - LHN disappears after leaving a thread issue

Screen.Recording.1404-10-22.at.2.20.25.PM.mov

3. Chat - After deleting an expense, it navigates to different chat instead of the main chat issue

Screen.Recording.1404-10-22.at.2.26.37.PM.mov

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