Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #596, where the wrong element in the list is decorated as a shadow element.
What happens is that the shadow element is not yet present when a decoration is triggered due to, for some still unknown reason, the splice at line 159
items.splice(shadowElIdx, 0, shadowElData);
not running.That splice is responsible for adding to the list of items a copy with the following properties:
Specifically, the ID is modified to that value and the
isDndShadowItem
property is added.When that shadow copy is missing, we have one less item in the list and when the
decorateShadowEl(draggableEl)
function runs, it hits the correct index position but in that index position the wrong HTML element will be.Immediately after, this internal routine runs again, properly adds the shadow copy, then hits the correct element.
The thing is, in a healthy drag, the internal routine runs just once, in the problematic version it runs twice, first without adding the shadow copy and automatically it triggers again and properly adds the shadow copy.
Here is this quick video I first show a healthy drag, then a problematic drag:
Screencast.from.12-09-2024.21.04.17.webm
This fix is inelegant because it doesn't get to the root cause of the issue, but apparently it works, it uses a side effect that I noticed, in the first, problematic internal routine run, one of the items object will have the ID as
"id": "id:dnd-shadow-placeholder-0000"
, and in a healthy internal routine run, the ID of the item will be the correct ID as defined by the app, so the logic here is to check if one of the items has the shadow ID, which is indicative of a problematic run, and then not to decorate the element.Ideally, we should figure out why the problematic run happens, so any suggestion on this is appreciated.
I had a couple ideas for fixes:
1 - Undecorate the element after a problematic run.
2 - The one suggested in this PR, which is to not decorate if the side effect is noticed.
But of course I would prefer to do 3:
3 - Eventually reach the source of this problem and not even have the problematic run.
I have tons of logs I can share that allowed me to arrive at this conclusion and solution.
Example of my logs about the items, using console log stringify items, right before the decoration, showing a problematic run where this runs twice:
Also, this bug was introduced in the version 42. Before that however, the last working version for my setup was 28.
From 29 to 41, all of them freeze when I try to drop with a
"getBoudingEtc..."
error.In my setup this change doesn't seem to interfere with anything else, but I'm not sure about the wide range of use cases out there.
If it is better to discuss or further work on this before merging I'm open to it!