-
Notifications
You must be signed in to change notification settings - Fork 75
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
Dragged element duplication #4
Comments
how to resolve this problem |
我从上往下拖不会有问题,但是从下往上拖就会有问题。而且这个问题有时候会发生有时候突然又正常了。。。。 |
@baixiyang 谢谢关注! 我观察过其他人写的基于H5的拖动库,大部分都不会出现这种问题,但是我暂时还没找到解决方法。而且最近一直在加班,没太多时间去处理这个问题,实在抱歉。 如果你有任何解决思路,请告诉我一下,谢谢! |
My boss was able to find a way to recreate the bug (Please don't mind the awful design, it's only temporary). In that GIF I am dragging an inner container and dropping it at the top of the outer container. By doing so it replaces the item that was previously placed first in the outer container. I haven't tried recreating it like this outside of our project yet though. Update: Here's another recreational version: It doesn't happen when I drag items downwards though, only when I drag them up. It also happens when I drag them into the first position I think. |
Hey again. I decided to try it out with your example code for VDDL nested lists, and I got some weird results... In this GIF I first manage to recreate the bug in my own local dev environment, running your example code (I haven't changed anything). But when I switch over to your website and do the same drag and drop actions, it works. I have tried this over and over many times now and I randomly get the bug in the dev environment, but never on your website (http://hejx.space/vddl-demo/#/nested). Update: It gets weirder. I will take a look at the code tomorrow I think, but so far I can't put my finger on what's causing it. |
I have made some progress. I believe it's this line that is removing the wrong item from the list: vddl/src/components/vddl-draggable.vue Line 87 in 5ffb105
I did some logging like this: https://imgur.com/a/2j9KW I start with a list like this (which you find in "container 1" here http://hejx.space/vddl-demo/#/nested): 0: {type: "item", id: "1"}
1: {type: "item", id: "2"}
2: {type: "item", id: "3"} And then drag item 3 up between item 1 and 2, I get this logged to the console: wrapper.splice: 2
wrapper before:
0: {type: "item", id: "1"}
1: {type: "item", id: "3"}
2: {type: "item", id: "2"}
3: {type: "item", id: "3"}
wrapper after:
0: {type: "item", id: "1"}
1: {type: "item", id: "3"}
2: {type: "item", id: "3"} This indicates that we are splicing index 2 from the list, which is The reason why it works when dragging down, but not up is because if I drag down, then an item will be added to the list below the current item's index, which means that Example: 0: {type: "item", id: "1"}
1: {type: "item", id: "2"}
2: {type: "item", id: "3"} Logged after dragging down item 1 down between item 2 and 3: wrapper.splice: 0
wrapper before:
0: {type: "item", id: "1"}
1: {type: "item", id: "2"}
2: {type: "item", id: "1"}
3: {type: "item", id: "3"}
wrapper after:
0: {type: "item", id: "1"}
1: {type: "item", id: "2"}
2: {type: "item", id: "3"} In this case the index to remove is 0, meaning However if I drag an item up, then the array will grow by 1 item (the duplicate), which pushes the start point of the drag event down one index, which causes it to delete the wrong item. For example if I change the code to: @hejianxian What do you think? Got any ideas? |
Hello, For the record, the bug occurs when you drop an item on a previous index. The item is then duplicated on both the source and target of the drag'n'drop action, instead of swapped. The target item is then lost. This doesn't solve the problem but it gives us a hint. Something has probably changed since version 2.4.2 that broke your component logic. Maybe related to reactivity or handlers execution order ? VueJS changelog Great project by the way ! |
@gjactat I tested it a bit and it appears that 2.5.0 is the breakpoint for when things started go wrong. |
Yes... Version 2.5.0 brings major changes ! |
Also, if you look at my comment I explain where the wrong element is being removed from the list. Maybe I can install Vue 2.4.4 and log the same stuff to see the difference. |
If you can downgrade to Vue 2.4.4, you can fix your issue. |
I am just running the example project that you can find in this repo when I'm testing now. |
I need to kick a new sandbox with vddl sources instead of package dependency to investigate deeper ( breakpoints and traces....). We're getting closer ! |
Ok, so I have installed the older version now and I can see that the correct index is set to Starting list: 0: {type: "item", id: "1"}
1: {type: "item", id: "2"}
2: {type: "item", id: "3"} And then drag item 3 up between item 1 and 2, I get this logged to the console: wrapper.splice: 3
wrapper before:
0: {type: "item", id: "1"}
1: {type: "item", id: "3"}
2: {type: "item", id: "2"}
3: {type: "item", id: "3"}
wrapper after:
0: {type: "item", id: "1"}
1: {type: "item", id: "3"}
2: {type: "item", id: "2"} Notice how Logging in this file: vddl/src/components/vddl-draggable.vue Line 87 in 5ffb105
I got to sleep now. It's 1:50 here... Good luck. |
I noticed that the Vuex example still suffers from this problem. Since it adds and deletes items through actions it wasn't solved by my pull request, but the solution should probably be similar now that we know the causation. |
i think the reason is vue has not update the index after drop(when drop up ,one item insert before.vue should update the index to index +1,but not) |
this way cannot suit string and number list @hejianxian ,we need stricter way to get the true index。 |
Yes, the index is passed before the list is updated for the Vuex example, we need a way to make sure that the real index is accessible. |
@awulkan I fixed it. But I think the more serious problem is: press |
@hejianxian Nice! Are you talking about the nested list when it's disabled? Well, I know that you can add |
duplication element is the biggest bug i think. it will happen certainly, when drag up ward. if the bug exit , no one will use this component at all。 |
@baixiyang The duplication bug should be solved. Where are you experiencing it? Have you updated to the latest version? |
change line 'this.splice(this.index,1)' to 'this.splice(this.wrapper.indexOf(this.draggable), 1)' is useful in my environment. this is just an adivse. |
I had a case where I had to access the final index (without the duplicated item in the list) inside the drop callback of a vddl-list and have a little workaround (although I think there might be a more elegant solution, maybe there is another callback for my problem?) handleDrop(data) {
let { index, list, item } = data
list.splice(index, 0, item)
const hasDuplicate = list.filter(el => el.id === item.id).length === 2
const oldIndex = list.findIndex(el => el.id === item.id)
if (hasDuplicate && oldIndex < index)
index -= 1
}
// do something with the final index
}, |
出现这个的问题是判断拖拽是缺少一个判断,判断当前拖拽的是向上移动还是向下移动 |
I would like to report a bug.
VDDL Version: 0.5.2
Vue Version: 2.3.3
When I drag-and-drop
<vddl-draggable>
elements within a<vddl-list>
too quickly while there is text selected on the webpage, the dragged element sometimes clones itself and replaces a different element in the list.I have created an example project here, although the bug can occur in any project.
How to reproduce:
<vddl-list>
and fill it with an arbitrary number of<vddl-draggable>
items.EDIT: I have moved the link to MediaFire so my Github projects list is not cluttered.
The text was updated successfully, but these errors were encountered: