Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hold for payment 2025-02-17][$250] Expense - Not here page shows up briefly when deleting the expense while it is highlighted #55251

Open
3 of 8 tasks
vincdargento opened this issue Jan 14, 2025 · 28 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@vincdargento
Copy link

vincdargento commented Jan 14, 2025

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.0.85-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Email or phone of affected tester (no customers): Mac 15.0 / Chrome
Issue reported by: Applause Internal Team
Device used: [email protected]
App Component: Chat Report View

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create three manual expenses.
  4. Go to transaction thread of any expense.
  5. Click on the header subtitle to return to expense report.
  6. Right click on the previously visited expense report which is now highlighted.
  7. Click Delete expense.
  8. Delete the expense.

Expected Result:

Not here page will not show up briefly when deleting the expense while it is highlighted.

Actual Result:

Not here page shows up briefly when deleting the expense while it is highlighted.

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

bug.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021881828763619055376
  • Upwork Job ID: 1881828763619055376
  • Last Price Increase: 2025-01-28
  • Automatic offers:
    • brunovjk | Reviewer | 105898628
Issue OwnerCurrent Issue Owner: @brunovjk
@vincdargento vincdargento added Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 labels Jan 14, 2025
Copy link

melvin-bot bot commented Jan 14, 2025

Triggered auto assignment to @JmillsExpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

Copy link

melvin-bot bot commented Jan 15, 2025

📣 @Maurishus! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

Copy link
Contributor

⚠️ @Maurishus Thanks for your proposal. Please update it to follow the proposal template, as proposals are only reviewed if they follow that format.

@M00rish
Copy link
Contributor

M00rish commented Jan 15, 2025

Proposal

Please re-state the problem that we are trying to solve in this issue.

Expense - Not here page shows up briefly when deleting the expense while it is highlighted

What is the root cause of that problem?

when the expense is highlighted it's ID is taken from the url :

const reportActionIDFromRoute = route?.params?.reportActionID ?? '';

and handed to usePaginatedReportActions to get the linkedAction:
const {reportActions, linkedAction, sortedAllReportActions, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID, reportActionIDFromRoute);

once the delete happens, and because the param is not removed immediately from the navigation, it's taken again and handed to usePaginatedReportActions,

so isLinkedActionDeleted is true and prevIsLinkedActionDeleted is true also because previous action which is same action is deleted, that makes isLinkedActionBecomesDeleted false :

const isLinkedActionBecomesDeleted = prevIsLinkedActionDeleted !== undefined && !prevIsLinkedActionDeleted && isLinkedActionDeleted;

and so shouldShowNotFoundLinkedAction is true

const shouldShowNotFoundLinkedAction =
(!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !isLinkedActionBecomesDeleted) ||

and then param is cleared with this useEffect

What changes do you think we should make in order to solve the problem?

if action has been deleted we can keep a ref of it's ID, so don't we provide it again to usePaginatedReportActions

LastDeletedActionIDRef = useReff(null);
const reportActionIDFromRoute = LastDeletedActionIDRef.current !== route?.params?.reportActionID ? route?.params?.reportActionID : '';
    useEffect(() => {
        if(!isLinkedActionDeleted){
            return;
        }
        
        LastDeletedActionIDRef.current = isLinkedActionDeleted ? linkedAction?.reportActionID ?? '' : '';
    }, [isLinkedActionDeleted]);

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

UI issue

What alternative solutions did you explore? (Optional)

if Highlighted getback to main thread before delete.

const confirmDeleteAndHideModal = useCallback(() => {


....
const confirmDeleteAndHideModal = useCallback(() => {
        const isHighlighted = navigationRef.current.getCurrentRoute().params.reportActionID === 
             reportActionRef.current?.reportActionID;
        if (isHighlighted) {
            Navigation.setParams({reportActionID: ''});
        }

        callbackWhenDeleteModalHide.current = runAndResetCallback(onConfirmDeleteModal.current);
        const reportAction = reportActionRef.current;
        if (ReportActionsUtils.isMoneyRequestAction(reportAction)) {
            const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction);
          .......

Copy link
Contributor

⚠️ @M00rish Thanks for your proposal. Please update it to follow the proposal template, as proposals are only reviewed if they follow that format.

@daledah
Copy link
Contributor

daledah commented Jan 15, 2025

Proposal

Please re-state the problem that we are trying to solve in this issue.

Not here page shows up briefly when deleting the expense while it is highlighted.

What is the root cause of that problem?

Here're the logics to show not found page

const shouldShowNotFoundPage = useMemo((): boolean => {
if (shouldShowNotFoundLinkedAction) {
return true;
}

And

const shouldShowNotFoundLinkedAction =
(!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !isLinkedActionBecomesDeleted) ||

When users delete the linked action, isLinkedActionDeleted will be true, that cause isLinkedActionBecomesDeleted is true as well (prevIsLinkedActionDeleted is false). But after the next render, prevIsLinkedActionDeleted will be true that causes isLinkedActionBecomesDeleted becomes false

So shouldShowNotFoundLinkedAction is true, that why we can see the not found page

And when isLinkedActionBecomesDeleted is true

Navigation.setParams({reportActionID: ''});

we update the linkedReportActionID to empty string, so isLinkedActionDeleted will be false (there's no linked action)

That why the not found page is shown shortly

What changes do you think we should make in order to solve the problem?

We should detect the linked action is removing, so don't open the not found page

    const isResetingLinkedAction = useRef(false);
...

const shouldShowNotFoundLinkedAction =
        (!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !isLinkedActionBecomesDeleted && !isResetingLinkedAction.current) ||
...

    useEffect(() => {
        // If the linked action is previously available but now deleted,
        // remove the reportActionID from the params to not link to the deleted action.
        if (!isLinkedActionBecomesDeleted) {
            return;
        }
        isResetingLinkedAction.current = true;
        Navigation.setParams({reportActionID: ''});
    }, [isLinkedActionBecomesDeleted]);

    useEffect(() => {
        if(linkedAction || !isResetingLinkedAction.current){
            return;
        }
        isResetingLinkedAction.current = false
    },[linkedAction])

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

This is the UI issue so no need for unit test.

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@melvin-bot melvin-bot bot added the Overdue label Jan 17, 2025
Copy link

melvin-bot bot commented Jan 20, 2025

@JmillsExpensify Huh... This is 4 days overdue. Who can take care of this?

@JmillsExpensify JmillsExpensify added the External Added to denote the issue can be worked on by a contributor label Jan 21, 2025
@melvin-bot melvin-bot bot changed the title Expense - Not here page shows up briefly when deleting the expense while it is highlighted [$250] Expense - Not here page shows up briefly when deleting the expense while it is highlighted Jan 21, 2025
Copy link

melvin-bot bot commented Jan 21, 2025

Job added to Upwork: https://www.upwork.com/jobs/~021881828763619055376

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 21, 2025
Copy link

melvin-bot bot commented Jan 21, 2025

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

@melvin-bot melvin-bot bot removed the Overdue label Jan 21, 2025
@brunovjk
Copy link
Contributor

I can reproduce, reviewing proposals

@brunovjk
Copy link
Contributor

Thank you all for the proposals. However, the root cause is still not very clear to me, I will come back here as soon as I have an update.

@melvin-bot melvin-bot bot added the Overdue label Jan 26, 2025
@M00rish
Copy link
Contributor

M00rish commented Jan 26, 2025

Proposal Updated

@brunovjk
Copy link
Contributor

Thank you @M00rish, I had to focus on other issue, I will be back here in a moment.

@melvin-bot melvin-bot bot removed the Overdue label Jan 26, 2025
@brunovjk
Copy link
Contributor

Thanks for the proposals, the fact that "isLinkedActionDeleted stays true", right after "clearing the reportActionID parameter". I need a bit more time to investigate further. I'll come back as soon as I have something.

Copy link

melvin-bot bot commented Jan 28, 2025

@JmillsExpensify @brunovjk this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

@brunovjk
Copy link
Contributor

Thank you both, @M00rish and @daledah, for your well-thought-out proposals! 🙌

After careful consideration, I’ve chosen @daledah’s proposal. It provides a clear and focused mechanism (isResettingLinkedAction) to handle the transitional state and aligns well with the current component's logic. While @M00rish’s approach was solid, @daledah’s solution is more streamlined and avoids reliance on external state tracking.

@daledah, could you create unit tests to cover this scenario? If that’s not feasible, we’ll focus on defining detailed steps for manual testing to catch any regressions. This change might impact other flows, so we’ll monitor for unintended side effects closely.

Thanks again for your contributions!

🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Jan 28, 2025

Triggered auto assignment to @roryabraham, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

Copy link

melvin-bot bot commented Jan 28, 2025

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@roryabraham
Copy link
Contributor

roryabraham commented Jan 28, 2025

Thanks for both proposals. However, these variable names have become quite confusing. I think we should take a step back and see if we can clean this up. It seems like isLinkedActionBecomesDeleted was added to solve this same problem, but it doesn't work reliably (maybe due to race conditions where additional renders happen before the reportActionIDFromRoute is cleared). So I wonder if we can solve this with a simpler solution - tracking the "clearing" state separately and only resetting it once the reportActionIDFromRoute is cleared.

diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx
index 7b29bef35a5..8a5db3d7191 100644
--- a/src/pages/home/ReportScreen.tsx
+++ b/src/pages/home/ReportScreen.tsx
@@ -386,7 +386,12 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
         () => !!linkedAction && !shouldReportActionBeVisible(linkedAction, linkedAction.reportActionID, canUserPerformWriteAction(report)),
         [linkedAction, report],
     );
-    const prevIsLinkedActionDeleted = usePrevious(linkedAction ? isLinkedActionDeleted : undefined);
+
+    // If true, this variable indicates that a linked action was previously linked correctly, but has been deleted.
+    // In this case, we clear the linked action with Navigation.setParams, and we use this flag to prevent a 404 from
+    // showing during the transition if there are any additional renders before the reportActionIDFromRoute is cleared
+    const [isClearingDeletedLinkedAction, setIsClearingDeletedLinkedAction] = useState(false);
+
     const isLinkedActionInaccessibleWhisper = useMemo(
         () => !!linkedAction && isWhisperAction(linkedAction) && !(linkedAction?.whisperedToAccountIDs ?? []).includes(currentUserAccountID),
         [currentUserAccountID, linkedAction],
@@ -416,11 +421,9 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
         (!!deleteTransactionNavigateBackUrl && getReportIDFromLink(deleteTransactionNavigateBackUrl) === report?.reportID) ||
         (!reportMetadata.isOptimisticReport && isLoading);
 
-    const isLinkedActionBecomesDeleted = prevIsLinkedActionDeleted !== undefined && !prevIsLinkedActionDeleted && isLinkedActionDeleted;
-
     // eslint-disable-next-line rulesdir/no-negated-variables
     const shouldShowNotFoundLinkedAction =
-        (!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !isLinkedActionBecomesDeleted) ||
+        (!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted && !isClearingDeletedLinkedAction) ||
         (shouldShowSkeleton &&
             !reportMetadata.isLoadingInitialReportActions &&
             !!reportActionIDFromRoute &&
@@ -737,11 +740,21 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
     useEffect(() => {
         // If the linked action is previously available but now deleted,
         // remove the reportActionID from the params to not link to the deleted action.
-        if (!isLinkedActionBecomesDeleted) {
+        if (!isLinkedActionDeleted || isClearingDeletedLinkedAction) {
             return;
         }
+        // Set isClearingLinkedAction to true to prevent a 404 showing if there are any re-renders before reportActionIDFromRoute is cleared
+        setIsClearingDeletedLinkedAction(true);
         Navigation.setParams({reportActionID: ''});
-    }, [isLinkedActionBecomesDeleted]);
+    }, [isLinkedActionDeleted, isClearingDeletedLinkedAction]);
+
+    // Reset the isClearingLinkedAction flag once the reportActionIDFromRoute is cleared
+    useEffect(() => {
+        if (!isClearingDeletedLinkedAction || reportActionIDFromRoute) {
+            return;
+        }
+        setIsClearingDeletedLinkedAction(false);
+    }, [reportActionIDFromRoute, isClearingDeletedLinkedAction]);
 
     // If user redirects to an inaccessible whisper via a deeplink, on a report they have access to,
     // then we set reportActionID as empty string, so we display them the report and not the "Not found page".

I think this is an improvement over the other proposals here. Also, it's worth noting that when I originally wrote up this suggestion, I used useRef instead of useState for isClearingDeletedLinkedAction. However, this results in a lint error when we reference isClearingDeletedLinkedAction.current in the declaration of shouldShowNotFoundLinkedAction:

Ref values (the current property) may not be accessed during render.

So we use useState instead. Some alternate solutions:

It's also worth noting that this lint error would exist in the current code, but the lint error is suppressed in usePrevious.

@roryabraham
Copy link
Contributor

Going to go ahead and assign this to @M00rish, mostly because @daledah has 7 open PRs right now, and @M00rish has none. So I'd like to try and spread the love and better parallelize our work.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 28, 2025
Copy link

melvin-bot bot commented Jan 28, 2025

📣 @brunovjk 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Jan 28, 2025

📣 @M00rish You have been assigned to this job!
Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs!
Keep in mind: Code of Conduct | Contributing 📖

@M00rish
Copy link
Contributor

M00rish commented Jan 29, 2025

Thanks! I really appreciate it, I will raise a PR tomorrow at most considering the inputs above.

@daledah
Copy link
Contributor

daledah commented Jan 30, 2025

@roryabraham

Going to go ahead and assign this to @M00rish, mostly because @daledah has 7 open PRs right now, and @M00rish has none. So I'd like to try and spread the love and better parallelize our work.

Sorry for this delay, I'm on TET holiday and there're only 2-3 PRs that delay from my side (minor updates). I'll try to update all of them in 1-2 days. I spent much time on this issue and my proposal was selected by C+ here, so I think it would be fair that I get partially compensated here. What do you think? cc @JmillsExpensify @brunovjk

@daledah
Copy link
Contributor

daledah commented Feb 3, 2025

@JmillsExpensify @mallenexpensify What do you think about the point above?

@roryabraham
Copy link
Contributor

No, I think @M00rish also found and documented the root cause and had a working solution. Even though your proposal was accepted by the C+, it ultimately wasn't the solution I wanted to see implemented

@mallenexpensify
Copy link
Contributor

my proposal was selected by C+ #55251 (comment), so I think it would be fair that I get partially compensated here.

@daledah I understand your reasoning, our process uses assignment by the Expensify engineer (or BZ) as the source of truth for consideration for payment. If you would have been hired/assigned, then the issue was reassigned to another, it's possible you would have been due partial compensation. For this instance, compensation isn't due (lil more deets in CONTRIBUTING.md here

@brunovjk
Copy link
Contributor

It seems that the automation didn't go well. PR went to production yesterday (Feb 10) on this deploy checklist.

@mallenexpensify mallenexpensify changed the title [$250] Expense - Not here page shows up briefly when deleting the expense while it is highlighted [Hold for payment 2025-02-17][$250] Expense - Not here page shows up briefly when deleting the expense while it is highlighted Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
Status: No status
Development

No branches or pull requests

7 participants