Skip to content

[Payment due 1-25][$250] Scan - "Drop file here" modal does not dismiss when file is no longer dragged over the area #33820

Closed

Description

@lanitochka17

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.20-2
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

  1. Go to workspace chat > + > Request money
  2. Go to Scan
  3. Open a file explorer window next the the drag & drop area
  4. Drag a file over the area and remove it from the area repeatedly (and very quickly)

Expected Result:

"Drop file here" modal will dimiss when the file is no longer dragged over the area

Actual Result:

"Drop file here" modal does not dismiss when the file is no longer dragged over the area

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6329833_1704112789223.bandicam_2023-12-30_11-57-55-618.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01d19df269e522389b
  • Upwork Job ID: 1741888378699694080
  • Last Price Increase: 2024-01-26
  • Automatic offers:
    • s77rt | Reviewer | 28077927
    • tienifr | Contributor | 28077928

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jan 1, 2024
  2. changed the title [-]Scan - "Drop file here" modal does not dismiss when file is no longer dragged over the area[/-] [+][$500] Scan - "Drop file here" modal does not dismiss when file is no longer dragged over the area[/+] on Jan 1, 2024
  3. melvin-bot commented on Jan 1, 2024

    @melvin-bot
  4. melvin-bot commented on Jan 1, 2024

    @melvin-bot

    Triggered auto assignment to @Christinadobrzyn (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jan 1, 2024
  6. melvin-bot commented on Jan 1, 2024

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  7. melvin-bot commented on Jan 1, 2024

    @melvin-bot

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

  8. samilabud commented on Jan 1, 2024

    @samilabud
    Contributor

    Proposal

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

    "Drop file here" modal does not dismiss when file is no longer dragged over the area

    What is the root cause of that problem?

    The drag-and-drop hook is based on a reference counter to do the overlay works well, but when we use a component or window that lives outside the browser we get this bug because the counter increases more than expected.

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

    We should modify the drag-and-drop hook to take into consideration scenarios when we are dragging outside the drag-and-drop zone to decrease the reference counter.

    The code should be like:

                     case DRAG_OVER_EVENT:
                        handleDragEvent(event);
                        if (isDraggingOver && dragCounter.current > 1) {
                            dragCounter.current--;
                        }
                        break;
    

    Result - after changes:

    drag-and-drop.test.after.changes.mp4
  9. bernhardoj commented on Jan 2, 2024

    @bernhardoj
    Contributor

    Proposal

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

    The scan request drop view doesn't disappear after we stop the drag.

    What is the root cause of that problem?

    This can easily be reproduced when you start dragging your file to the instruction view (that is the Upload receipt text and image).

    Screen.Recording.2024-01-02.at.12.18.07.mov

    The drop file here view will be shown if isDraggingOver state is true.

    const {isDraggingOver, setOnDropHandler, dropZoneID} = useContext(DragAndDropContext);
    useEffect(() => {
    setOnDropHandler?.(onDrop);
    }, [onDrop, setOnDropHandler]);
    if (!isDraggingOver) {
    return null;
    }
    return <Portal hostName={dropZoneID}>{children}</Portal>;
    }

    The isDraggingOver state itself will be set based on dragCounter value.

    case DRAG_ENTER_EVENT:
    dragCounter.current++;
    handleDragEvent(event);
    if (isDraggingOver) {
    return;
    }
    setIsDraggingOver(true);
    break;
    case DRAG_LEAVE_EVENT:
    dragCounter.current--;
    if (!isDraggingOver || dragCounter.current > 0) {
    return;
    }
    setIsDraggingOver(false);
    break;

    The problem in this issue is, that the isDraggingOver value is stuck at true even though we already stopped the drag because the dragCounter is not 0.

    The reason we use drag counter is explained in the comment here.

    // This solution is borrowed from this SO: https://stackoverflow.com/questions/7110353/html5-dragleave-fired-when-hovering-a-child-element
    // This is necessary because dragging over children will cause dragleave to execute on the parent.
    // You can think of this counter as a stack. When a child is hovered over we push an element onto the stack.
    // Then we only process the dragleave event if the count is 0, because it means that the last element (the parent) has been popped off the stack.
    const dragCounter = useRef(0);

    In short, when you move from one element to another element, the ENTER (for the new element) and LEAVE (for the current element) events will be called. So, the ENTER and LEAVE events should cancel out each other. However, if the element disappears, the LEAVE event won't be called.

    In our case, if we start dragging the file to the instruction view, let's say the "Upload receipt" text,
    image

    the ENTER event will be triggered for the "Upload receipt" text. Then, the drop file here view shows AND the instruction view disappears.

    {!isDraggingOver && (Browser.isMobile() ? mobileCameraView() : desktopUploadView())}

    Thus, the LEAVE event for "Upload receipt" text is never fired leaving 1 drag counter behind.

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

    The simplest solution is to make it invisible by setting the opacity to 0 when dragging instead of unmounting it from the view.

    <View style={[styles.flex1, !Browser.isMobile() && styles.uploadReceiptView(isSmallScreenWidth), isDraggingOver && styles.opacity0]}>
        {(Browser.isMobile() ? mobileCameraView() : desktopUploadView())}
    </View>
    

    What alternative solutions did you explore? (Optional)

    The other way is:

    1. Expose the drag counter from the drag and drop context
    2. Create a separate element for the desktop scan view
    3. When the desktop scan view element unmounts, decrement the drag counter from the drag and drop context
  10. tienifr commented on Jan 2, 2024

    @tienifr
    Contributor

    Proposal

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

    "Drop file here" modal does not dismiss when the file is no longer dragged over the area

    What is the root cause of that problem?

    We're updating isDraggingOver to false if dragCounter is 0

    // You can think of this counter as a stack. When a child is hovered over we push an element onto the stack.
    // Then we only process the dragleave event if the count is 0, because it means that the last element (the parent) has been popped off the stack.

    We can think of this counter as a stack, so we will decrease dragCounter when dragLeave event is fired.
    Before users drag file, we have 3 components in IOU scan view (one of them is instruction view) -> dragEnter is triggered 3 times -> dragCounter =3
    When users start to drag file, the dragging view is present and the instruction view disappears so the dragLeave for instruction view is never triggered -> dragCounter just decease to 1 when users leave the window

    -> isDraggingOver is not set to false

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

    We should not lean on dragCounter because of the above reason. To solve the problem dragging over children will cause dragleave to execute on the parent. we need to check if the currentTarget contains relatedTarget in dragLeave then we will early return

                    case DRAG_LEAVE_EVENT:
                        if (event?.currentTarget?.contains(event.relatedTarget)) {
                            return;
                        }
    
                        setIsDraggingOver(false);
    

    Ref: https://stackoverflow.com/a/54271161

    What alternative solutions did you explore? (Optional)

    NA

    Result

    Screen.Recording.2024-01-02.at.11.45.38.mov
  11. 15 remaining items

  12. situchan commented on Jan 11, 2024

    @situchan
    Contributor

    Seems like regression came from this issue

  13. s77rt commented on Jan 22, 2024

    @s77rt
    Member
  14. s77rt commented on Jan 22, 2024

    @s77rt
    Member

    @Christinadobrzyn Can you please add the Awaiting Payment label here? Looks like Melvin is OOO

  15. Christinadobrzyn commented on Jan 23, 2024

    @Christinadobrzyn
    Contributor

    @s77rt can you confirm if we're working on this PR - #23589 or if this needs to be paid out now?

  16. s77rt commented on Jan 23, 2024

    @s77rt
    Member

    @Christinadobrzyn Ah sorry for not clarifying. This should be paid on 25th. The payment due here should be $250.

    (No work is being done on any PR. All is done already)

  17. changed the title [-][$500] Scan - "Drop file here" modal does not dismiss when file is no longer dragged over the area[/-] [+][Payment due 1-25-24][$500] Scan - "Drop file here" modal does not dismiss when file is no longer dragged over the area[/+] on Jan 26, 2024
  18. changed the title [-][Payment due 1-25-24][$500] Scan - "Drop file here" modal does not dismiss when file is no longer dragged over the area[/-] [+][Payment due 1-25-24][$250] Scan - "Drop file here" modal does not dismiss when file is no longer dragged over the area[/+] on Jan 26, 2024
  19. melvin-bot commented on Jan 26, 2024

    @melvin-bot

    Upwork job price has been updated to $250

  20. changed the title [-][Payment due 1-25-24][$250] Scan - "Drop file here" modal does not dismiss when file is no longer dragged over the area[/-] [+][Payment due 1-25][$250] Scan - "Drop file here" modal does not dismiss when file is no longer dragged over the area[/+] on Jan 26, 2024
  21. Christinadobrzyn commented on Jan 26, 2024

    @Christinadobrzyn
    Contributor

    paying this out

    Payouts due:

    Contributor: $250 @tienifr (paid in Upwork)
    Contributor+: $250 @s77rt (paid in Upwork)

    Eligible for 50% #urgency bonus? NA

    Upwork job is here.

    No regression test. Closing this out but let me know if you need anything!

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in review

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions