Skip to content

Conversation

@0x5bfa
Copy link
Member

@0x5bfa 0x5bfa commented Dec 18, 2025

Resolved / Related Issues

This is part of the phase 1 mentioned in #17970 (comment)

Steps used to test these changes

Check if the click functionalities are the same as those in the main branch.

  • Right click on an item
  • Right click on empty space
  • Click on an item
@0x5bfa 0x5bfa force-pushed the 5bfa/CQ-SidebarViewRefactor1 branch from ce37c2d to 314d8a3 Compare December 18, 2025 02:29
@yaira2 yaira2 requested a review from marcelwgn December 18, 2025 20:08
@yaira2 yaira2 added the ready for review Pull requests that are ready for review label Dec 18, 2025
Comment on lines +482 to +485
private async void SidebarControl_ItemDropped(object sender, ItemDroppedEventArgs e)
{
await SidebarAdaptiveViewModel.HandleItemDroppedAsync(e);
}
Copy link

Choose a reason for hiding this comment

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

Bug: The async event handler SidebarControl_ItemDropped is missing a required deferral, which can cause the drag operation's data to become invalid before async work finishes.
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

The SidebarControl_ItemDropped event handler is an async method that performs significant asynchronous work, such as file operations and database updates, via SidebarAdaptiveViewModel.HandleItemDroppedAsync. However, it fails to acquire a deferral from the ItemDroppedEventArgs. In the WinUI drag-and-drop API, a deferral is necessary to prevent the operating system from cleaning up the drag operation's data context before the asynchronous work completes. Without it, the DataPackageView could be invalidated mid-operation, leading to failed drop actions.

💡 Suggested Fix

In the SidebarControl_ItemDropped method, acquire a deferral from the event arguments before the await call and complete it after the operation is finished. Example: var deferral = e.RawEvent.GetDeferral(); await SidebarAdaptiveViewModel.HandleItemDroppedAsync(e); deferral.Complete();

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not valid. Location: src/Files.App/Views/MainPage.xaml.cs#L482-L485 Potential issue: The `SidebarControl_ItemDropped` event handler is an `async` method that performs significant asynchronous work, such as file operations and database updates, via `SidebarAdaptiveViewModel.HandleItemDroppedAsync`. However, it fails to acquire a deferral from the `ItemDroppedEventArgs`. In the WinUI drag-and-drop API, a deferral is necessary to prevent the operating system from cleaning up the drag operation's data context before the asynchronous work completes. Without it, the `DataPackageView` could be invalidated mid-operation, leading to failed drop actions. 

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7750491

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this code from here, where there is no deferral code.

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

Labels

ready for review Pull requests that are ready for review

2 participants