Skip to content

[Due for payment 2026-04-01] [$250] Scan request page active drop zone UI keeps showing #85135

Closed

Description

@m-natarajan

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: 9.3.36-9
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from BrowserStack:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @bernhardoj
Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Open Create expense page > Scan tab
  2. Drag a file into and out of the drop area of the scan page repeatedly and quickly

Expected Result:

When we are not hovering over the drop area, the active drop zone UI should not be shown

Actual Result:

When we are not hovering over the drop area, the active drop zone UI keeps showing

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

web.mp4
Recording.2523.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @mallenexpensify
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022032190966570411183
  • Upwork Job ID: 2032190966570411183
  • Last Price Increase: 2026-03-12
  • Automatic offers:
    • FitseTLT | Contributor | 110804922

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 12, 2026
  2. MelvinBot commented on Mar 12, 2026

    @MelvinBot
    Contributor

    Proposal

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

    When on the Create expense page > Scan tab, rapidly dragging a file into and out of the drop area causes the active drop zone UI to remain visible even after the cursor (with the file) has left the drop area. The normal camera/upload view stays hidden and the drop zone overlay persists indefinitely.

    What is the root cause of that problem?

    The root cause is in the useDragAndDrop hook (src/hooks/useDragAndDrop/index.ts), which tracks drag state using a dragCounter ref and a 50ms debounced setTimeout on dragleave. There are two interacting bugs:

    1. Event listener re-registration during active drag (primary cause): The dropZoneDragHandler callback includes isDraggingOver in its useCallback dependency array (line 127). When isDraggingOver transitions from false to true on the first dragenter, React creates a new callback, which triggers the useEffect (line 130) to remove old event listeners and attach new ones. During rapid drag in/out, the browser may have queued dragenter/dragleave events targeting the old listener. These events are silently lost because the old listener was removed, but the browser considers them dispatched. This causes the dragCounter to accumulate extra enters without matching leaves, so it never reaches 0 and isDraggingOver stays true.

    2. Debounce timeout cleared by subsequent events: Every invocation of the event handler clears any pending debounce timeout (lines 91-95) before processing the event type. This means even DRAG_OVER_EVENT events (which fire at ~60Hz while hovering) cancel the pending setIsDraggingOver(false) timeout. If the user drags out (starting the 50ms timeout) but a trailing dragover event fires within that window, the timeout is cancelled and isDraggingOver remains true.

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

    1. Remove isDraggingOver from the useCallback dependency array of dropZoneDragHandler in src/hooks/useDragAndDrop/index.ts. The isDraggingOver check on line 104 (if (dragCounter.current === 1 && !isDraggingOver)) should instead read from a ref that mirrors the state value. This prevents the callback from being recreated on every state change, which prevents event listener re-registration during active drag sequences.

    2. Only clear the debounce timeout on DRAG_ENTER_EVENT, not on every event type. The timeout clearing at lines 91-95 should be moved inside the DRAG_ENTER_EVENT case, since that's the only event that legitimately needs to cancel a pending leave. DRAG_OVER_EVENT and DROP_EVENT should not cancel it.

    What alternative solutions did you explore? (Optional)

    • Using drop event on document as a fallback reset: Adding a document-level drop/dragleave listener that resets isDraggingOver when the drag leaves the browser window entirely. This would help as a safety net but doesn't address the core counter desync issue.
    • Replacing the counter approach with event.relatedTarget checking: Instead of counting enter/leave pairs, checking event.relatedTarget on dragleave to determine if the drag is truly leaving the drop zone vs moving to a child element. This is more robust but has inconsistent browser support.
    • Adding a dragend listener as a reset mechanism: The dragend event fires when the drag operation completes (including if the user drops outside the browser), which could be used to force-reset isDraggingOver. This is a good supplementary fix but doesn't solve the flickering during active drag.

    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Mar 12, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Mar 12, 2026
  5. melvin-bot commented on Mar 12, 2026

    @melvin-bot

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

  6. changed the title [-]Scan request page active drop zone UI keeps showing[/-] [+][$250] Scan request page active drop zone UI keeps showing[/+] on Mar 12, 2026
  7. melvin-bot commented on Mar 12, 2026

    @melvin-bot
  8. FitseTLT commented on Mar 12, 2026

    @FitseTLT
    Contributor

    Proposal

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

    Scan request page active drop zone UI keeps showing

    What is the root cause of that problem?

    The logic we have here is correct

    if (debounceTimeoutRef.current) {
    clearTimeout(debounceTimeoutRef.current);
    debounceTimeoutRef.current = null;
    }
    switch (event.type) {
    case DRAG_OVER_EVENT:
    handleDragEvent(event);
    break;
    case DRAG_ENTER_EVENT:
    handleDragEvent(event);
    dragCounter.current += 1;
    if (dragCounter.current === 1 && !isDraggingOver) {
    setIsDraggingOver(true);
    }
    break;
    case DRAG_LEAVE_EVENT:
    dragCounter.current -= 1;
    if (dragCounter.current <= 0) {
    dragCounter.current = 0;
    // Add small debounce to prevent rapid flickering
    debounceTimeoutRef.current = setTimeout(() => {
    setIsDraggingOver(false);
    }, 50);

    It is setup to only reset isDraggingOver state to false 50ms after drag leaves to avoid multiple update of the state and rapid flickering. But the problem is, from my debugging, the drag enter event is sometimes (on rapid drag in and out) called multiple times before drag leave is called making dragCounter > 1 so when the drag leave is called the decrement will not make it <=0 so this code is never called
    if (dragCounter.current <= 0) {
    dragCounter.current = 0;
    // Add small debounce to prevent rapid flickering
    debounceTimeoutRef.current = setTimeout(() => {
    setIsDraggingOver(false);

    making the state stuck on true.

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

    We should not use incrementing instead we should set the value to 1 and 0

                        dragCounter.current = 1;
    
    

    on drag enter and

                        dragCounter.current = 0;
    
    

    on drag leave. Or we can use a boolean value instead.

    What alternative solutions did you explore? (Optional)

  9. dassoft-official commented on Mar 13, 2026

    @dassoft-official

    Proposal: Stabilizing Drop Zone UI in Scan Request Flow

    While testing the Scan tab, I noticed that rapidly dragging a file into and out of the drop zone can cause the drop zone UI to remain visible indefinitely, blocking the normal view.

    After investigating, this appears to be caused by event listener desynchronization combined with debounce behavior.


    Root Causes

    1. Event Listener Desync

    dropZoneDragHandler currently depends on isDraggingOver.
    This causes the effect to re-register drag listeners whenever the state toggles.

    During rapid drag movements:

    • dragleave can fire while listeners are temporarily detached
    • dragCounter becomes out of sync
    • isDraggingOver may remain true

    2. Debounce Interference

    The dragover event fires continuously while hovering.

    Currently it clears the dragleave debounce timer, which prevents the UI from hiding if a dragover occurs shortly after a dragleave.


    Proposed Fix

    1. Stabilize Handler Using ref

    Track drag state using a ref instead of state inside the handler.
    This prevents the effect from re-running and ensures listeners remain stable.

    const isDraggingOverRef = useRef(false);
    
    const setIsDraggingOverWithRef = useCallback((value: boolean) => {
        isDraggingOverRef.current = value;
        setIsDraggingOver(value);
    }, []);
    
    // remove isDraggingOver from dependency list
    const dropZoneDragHandler = useCallback((event: DragEvent) => {
        if (dragCounter.current === 1 && !isDraggingOverRef.current) {
            setIsDraggingOverWithRef(true);
        }
    }, [..., setIsDraggingOverWithRef]);

    This keeps listener registration stable while still syncing UI state.


    2. Restrict Debounce Clearing

    Only clear the dragleave debounce timer when we know a real re-entry occurs.

    Instead of clearing it on every dragover, only clear on:

    • dragenter
    • drop
    switch (event.type) {
        case DRAG_ENTER_EVENT:
            if (debounceTimeoutRef.current) {
                clearTimeout(debounceTimeoutRef.current);
                debounceTimeoutRef.current = null;
            }
            // increment counter
            break;
    }

    This prevents hover noise from blocking the UI reset.


    3. Stronger State Reset

    When the component becomes unfocused or disabled, we should force reset all drag state.

    useEffect(() => {
        if (isFocused && !isDisabled) return;
    
        dragCounter.current = 0;
        setIsDraggingOverWithRef(false);
    }, [isFocused, isDisabled, setIsDraggingOverWithRef]);

    This ensures the UI cannot remain stuck when navigating away.


    Alternative Safeguards (Optional)

    1. dragend Global Reset

    Attach a document listener for dragend to force-reset the drop zone when the drag operation ends outside the browser.

    2. relatedTarget Leave Detection

    Instead of relying on enter/leave counters, check event.relatedTarget to determine whether the pointer actually left the drop zone.

    3. Window-level drop Reset

    Add a window drop listener that resets drag state if a file is dropped anywhere on the page.


    ✅ Result

    These changes stabilize drag listeners, prevent debounce conflicts, and ensure the drop zone UI reliably resets even during rapid drag interactions.

  10. yuvrajangadsingh commented on Mar 13, 2026

    @yuvrajangadsingh
    Contributor

    Proposal

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

    On the Scan request page, rapidly dragging a file into and out of the drop area causes the active drop zone UI to stay visible permanently, even after the cursor has left.

    What is the root cause of that problem?

    The root cause is the invisible overlay rendered in DragAndDropProvider (src/components/DragAndDrop/Provider/index.tsx, lines 59-63) when isDraggingOver becomes true:

    {isDraggingOver && (
        <View style={[styles.fullScreen, styles.invisibleOverlay]}>
            <PortalHost name={dropZoneID.current} />
        </View>
    )}

    This overlay has zIndex: 1000 (src/styles/index.ts:3594) and covers the entire drop zone, but it has no pointerEvents: 'none'. The DropZoneUI content (icon, text, dashed border) gets portaled into it via DragAndDropConsumer (src/components/DragAndDrop/Consumer/index.tsx:21).

    Because the overlay and its children are interactive, the browser generates synthetic dragenter/dragleave events every time the overlay DOM appears under the cursor. When React renders the overlay (which is batched and slightly delayed from the state change), the browser fires a dragenter for the new overlay element, inflating dragCounter in useDragAndDrop (src/hooks/useDragAndDrop/index.ts:29). During rapid in/out movements, this inflation happens repeatedly. The user leaves the drop zone, a dragleave fires and decrements the counter, but the counter is still > 0 (inflated by the overlay's synthetic enters), so the condition at line 110 (dragCounter.current <= 0) is never satisfied and the debounce to reset isDraggingOver never starts.

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

    Add pointerEvents: 'none' to the overlay View in src/components/DragAndDrop/Provider/index.tsx (line 60):

    <View style={[styles.fullScreen, styles.invisibleOverlay]} pointerEvents="none">

    On web, this maps to CSS pointer-events: none, which prevents the overlay and all its portal children from being drag event targets. Drag events pass through to the drop zone underneath, keeping dragCounter accurate (1 on enter, 0 on leave). The overlay is purely visual, it should never intercept pointer or drag events.

    This is the only change needed. The dragCounter logic, debounce timing, and listener registration all work correctly when the counter isn't being inflated by overlay children.

    What alternative solutions did you explore? (Optional)

    Replacing the counter with a boolean (as another proposal suggests) would mask the inflation rather than fix it. The counter exists for a good reason: tracking nested child element boundaries. Making it a flat boolean would break the standard dragenter/dragleave child-nesting pattern and could cause flickering when moving between child elements. Fixing the overlay to not generate events in the first place is the correct fix since the overlay has no reason to be interactive.

  11. Abubakar-01 commented on Mar 13, 2026

    @Abubakar-01

    Proposal

    Please re-state the problem that we are trying to solve in this issue.
    When a user navigates to reports > expense page > create expense > scan, and drags a file back and forth over the drop area rapidly, the drop zone remains highlighted even if the file is outside the drop area.

    What is the root cause of that problem?
    In the file src/hooks/useDragAndDrop/index.ts, there is a function defined called useDragAndDrop (lines 16-150)

    The primary problem in the function is that dropZoneDragHandler callback (lines 108-117) is recreated every time isDraggingOver changes (it's in the dependency array), which causes the event listeners to be re-registered mid-drag, dropping events and corrupting the counter.

    const dropZoneDragHandler = useCallback(
           (event: DragEvent) => {
    

    DRAG_ENTER_EVENT increments the counter from 0 to 1. When its active, we can see the highlighted screen. (lines 101-107)

    case DRAG_ENTER_EVENT:
                       handleDragEvent(event);
                       dragCounter.current += 1;
                       if (dragCounter.current === 1 && !isDraggingOver) {
                           setIsDraggingOver(true);
                       }
                       break;
    
    

    DRAG_LEAVE_EVENT decrements the counter and sets isDraggingOver to false (lines 108-117)

      case DRAG_LEAVE_EVENT:
                         dragCounter.current -= 1;
                         if (dragCounter.current <= 0) {
                             dragCounter.current = 0;
                             // Add small debounce to prevent rapid flickering
                             debounceTimeoutRef.current = setTimeout(() => {
                                 setIsDraggingOver(false);
                             }, 50);
                         }
                         break;
    

    Since draggingOver is in the dependency array, it resets the function.

    What changes do you think we should make in order to solve the problem?
    To solve it, we can remove the debouncing and counter logic in DRAG_LEAVE_EVENT and instead, rely on mousePointer event which would be a more reliable dependency in this particular case because if we can track the mouse’s position, it wont matter how rapidly the cursor moves back and forth, it will set values as required. Remove the following block of code (lines: 109-117) in file (src/hooks/useDragAndDrop)

    case DRAG_LEAVE_EVENT:
                       dragCounter.current -= 1;
                       if (dragCounter.current <= 0) {
                           dragCounter.current = 0;
                           // Add small debounce to prevent rapid flickering
                           debounceTimeoutRef.current = setTimeout(() => {
                               setIsDraggingOver(false);
                           }, 50);
                       }
                       break;
    

    REPLACE it with the following.

    case DRAG_LEAVE_EVENT:
                       const related = event.relatedTarget as Node | null;
                       const isLeavingDropZone = !related || !dropZone.current?.contains(related);
                       if (isLeavingDropZone) {
                           dragCounter.current = 0;
                           setIsDraggingOver(false);
                       }
                       break;
    

    This way, we only rely on the cursor's position and setIsDraggingOver false based on it.

    What alternative solutions did you explore? (Optional)
    You could also remove isDraggingOver from the dependency array. It would resolve the highlighted issue. However, its still not as reliable as depending on mouse cursor position so its not guaranteed to work in cases where the state changes too rapidly to not break. If you want to keep isDraggingOver then you can put all event listeners in a dependency array of useEffect. That would work fine too

  12. added a commit that references this issue on Mar 15, 2026
    294ebfe
  13. 16 remaining items

  14. melvin-bot commented on Mar 25, 2026

    @melvin-bot

    @FitseTLT / @brunovjk The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  15. melvin-bot commented on Mar 25, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  16. FitseTLT commented on Mar 27, 2026

    @FitseTLT
    Contributor

    @francoisl Can u create a new issue for this bug and assign me and @brunovjk ? Thx
    Steps:

    1. Open App > Inbox
    2. Open Finder and drag file from left side of the screen to the attachment drop zone
      Actual Result
      Attachment zone is not highlighted with broken line
      Expected Result
      Attachment zone is highlighted with broken line as it is the active drop zone
    2026-03-18.20-04-32.mp4
  17. francoisl commented on Mar 28, 2026

    @francoisl
    Contributor

    Thanks for the reminder @FitseTLT. This is a minor UI fix so I'll handle it internally.

  18. brunovjk commented on Mar 30, 2026

    @brunovjk
    Contributor

    BugZero Checklist:

    • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

      Link to comment: No PR introduced this bug directly.

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

      Link to discussion:

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Regression Test Proposal

    Precondition:

    Test:

    1. Open Create expense page > Scan tab
    2. Drag a file into and out of the drop area of the scan page repeatedly and quickly
    3. Verify that when we are not hovering over the drop area, the active drop zone UI is not shown

    Do we agree 👍 or 👎

    Zapier Logs Run ID: 00040eee-a661-a9c8-fa82-192685d48954
    Zapier Logs Run ID: 00040eee-f202-a98a-6d8b-de731051a354
  19. mallenexpensify commented on Apr 2, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor: @FitseTLT paid $250 via Upwork
    Contributor+: @brunovjk due $250 via NewDot

    ^ Test case created

    Thx

  20. twisterdotcom commented on Apr 3, 2026

    @twisterdotcom
    Contributor

    @brunovjk has submitted payment for this report on ND here.

    SO: https://stackoverflowteams.com/c/expensify/questions/7582

    Zapier Logs Run ID: 00040eee-5e01-ad11-bab5-3001d1ff3eb4
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 contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions