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

Wrong item order during (faster) dragging inside one dropzone #29

Closed
AndreZinner opened this issue May 28, 2020 · 4 comments
Closed

Wrong item order during (faster) dragging inside one dropzone #29

AndreZinner opened this issue May 28, 2020 · 4 comments

Comments

@AndreZinner
Copy link

AndreZinner commented May 28, 2020

I recently noticed in my Serverside blazor project, that the visual order of items gets corrupted when I drag a item multiple times up and down WITHOUT releasing the mouse button.

I can reproduce the error in the sample app when i change your code in index.razor to:

 <div id="main" class="container-fluid">
    <p>Drag the list items:</p>
    <ul>
        <Dropzone>
            <Draggable>
                <li class="list-group-item" >A (order-pos: @context.OrderPosition)</li>
            </Draggable>
            <Draggable>
                <li class="list-group-item" >B (order-pos: @context.OrderPosition)</li>
            </Draggable>
            <Draggable>
                <li class="list-group-item" >C (order-pos: @context.OrderPosition)</li>
            </Draggable>
            <Draggable>
                <li class="list-group-item" >D (order-pos: @context.OrderPosition)</li>
            </Draggable>
            <Draggable>
                <li class="list-group-item" >E (order-pos: @context.OrderPosition)</li>
            </Draggable>
            <Draggable>
                <li class="list-group-item" >F (order-pos: @context.OrderPosition)</li>
            </Draggable>
            <Draggable>
                <li class="list-group-item" >G (order-pos: @context.OrderPosition)</li>
            </Draggable>
        </Dropzone>
    </ul>
</div>

If you click and hold on item "A" and move it down to the "G" and again up to "B" and repeat this several times (faster) you may notice, that the order of some items may have changed although you did not "release" your item and all other items should stay in the correct order.

Maybe its a blazor rendering / update issue ...

If I drag slowly I am not able reproduce the effect.

@Postlagerkarte
Copy link
Owner

Hi @AndreZinner , thank you for letting me know about it. I think this might be due to mouse events not raised for every pixel and the list reordering is based upon drag-enter and drag-leave events which rely upon mouse events.

@AndreZinner
Copy link
Author

AndreZinner commented May 29, 2020 via email

@bancroftway
Copy link

bancroftway commented Jun 5, 2020

I have a reproduction for this issue here. Note: branch name is 'wrongordering'.

A few points to note:

  1. My OrderDto class which is being bound to Draggable has "RowNumber" property.
  2. Inside the DropZone, I loop through a sorted list of Orders, ordered by RowNumber:
    @foreach (var order in this.Orders.OrderBy(x => x.RowNumber))
  3. After a Drop event, I remove the dragged order from the list, and insert it into the new position, so that the underlying list matches the front-end.
  4. I then re-calculate the RowNumber of every single row.
  5. When there is smaller number of items in Orders list, this issue is hard to reproduce. To reproduce this problem, either the number of items in the list should be larger, or the bound class is "heavy" ie it has many children and grandchildren. In my real work project where I am currently hitting this issue, this problem occurs with even 10 rows, because the object I am binding to Draggable tag has a few other attached properties and collections of objects.

Steps to reproduce:

  1. In the project referenced above, select a customer from Customers dropdown
  2. Go to the middle of the Orders list, like around Order# 250.
  3. Grab a row and rapidly drop it a few rows above or below.
  4. Note that the ordering of some of the rows in the vicinity gets disturbed
  5. Also note that if instead of 500 Orders, we limit the Orders per customer to something like 5 or 10, this issue becomes harder to reproduce.

Here is a screenshot of the issue, where I dragged row #250, and dropped it after row 246. But for an unknown reason, row 247 got disturbed. Also, because I recalculate the row number of every row, and I am bound to a list of Orders ordered by RowNumber, the final ordering of items is incorrect.

image

@Postlagerkarte
Copy link
Owner

Thank you @bancroftway for the detailed repro case. I already did some research after the inital report from @AndreZinner and it seems that there is nothing I can do about the problem.
The approach taken by this library is conditional rendering of captured fragments. This works fine for small sets but with larger sets it lacks perfomance and this causes troubles. When the Blazor Team implements dotnet/aspnetcore#18754 I am creating a v2.0 of the library.

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

No branches or pull requests

3 participants