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
Adding and then sorting an array breaks repeat binding #233
Comments
i am facing the same issue |
Ye, this is a huge problem for me as well :/ I can't to this.somearray[0] = something, since it is not reflected in the views. On the other hand, pushing works just fine. this.somearray.push(something) works... I hope this will be fixed quickly |
@BruceL33t your issue is different than what @simonfox reported. Aurelia cannot observe indexed assignment of an array- at least not without Object.observe, which is no longer being championed in TC39. As long as you use methods on the array instance to mutate the array it will work as you expect. In your case, change |
This is what I'm experiencing when doing The repeat gets two change records. One for adding 1 view (with index inside the bounds of the array). Another for removing 1 view, on max index +2.
Second splice index off by +1? @jdanyow / @EisenbergEffect Any ideas? Potentially looks like the splices are calculated wrong somewhere in calcSplices. |
Failing test for bug aurelia/binding#233
@jdanyow @martingust I wanted to push out a release today or tomorrow since we've built up a number of fixes. Any idea if this could be fixed by tomorrow? I just want to know if I should wait or not. |
@EisenbergEffect I will continue look into this tomorrow, but I have no idea right now what the issue would be so I can't say if it will be fixed or not by then. |
No problem. The master is safe to release as is though, correct? |
yep- all tests passing (other than this one) |
Ok, great. I'll get a release out and then we can get this one in as soon as it's done in a later patch. |
@EisenbergEffect @jdanyow I continued trying to trace this down. This is what I have found so far. The bug happens when doing Here is without concatenating records: // initial array
var foo = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
// doing push and sort
foo.push('10');
foo.sort((a, b) => {});
console.log(foo); // ["0", "10", "2", "3", "4", "1", "6", "7", "8", "9", "5"] (issue does not happen when the array is shorter) The If doing an ugly hack, to skip deleting if index is outside of array, the In other words; the problem (as I see it) is with the third splice, which should not contain any deletes, just 1 add. I have looked through |
Failing test for bug aurelia/binding#233
@martingust I merged in the integration test you put together and added logic to the array observation to force a flush of the change records prior to doing an array operation that requires a "reset" (sort or reverse). Downside is this will cause DOM changes outside of the task queue but I couldn't think of a way to get around it. |
@jdanyow Awesome. I think we can live with that, |
@EisenbergEffect any chance of getting a patch release for this fix this week? |
Yes, I'm waiting to hear about a couple of other issues. |
Awesome thanks @EisenbergEffect |
I'm coming across a similar issue and can't get it to work. In an array ( Here are the relevant parts of the code I've tried: steps.js (VM)
steps.html
Both options have problems when the view gets updated. Sometime the moved item gets duplicated, sometimes the array gets an empty new item, sometimes an item gets missing, ... Is this stil a bug in the binding system or am I doing something wrong when updating the array ? |
@jdanyow @martingust Can you guys look into this? |
Experiencing the exact issue @martingust described in detail here earlier, using the latest version. |
I'm seeing this also. More generally I'm seeing Aurelian fail to maintain the array order with the order on screen if I do many splices and pushes in a row. :( |
Oh and latest version here too. |
My perspective on the importance of this bug is that Aurelia has never been able to maintain order of my lists in the view due to various bugs, two of which have been fixed but this one remains. My website is all about sorting things by score. In the year I've been using Aurelia it's never been fit for this simplest of purposes. That coupled with dealing with so many bugs and a lack of documentation has left me feeling extremely regretful about my choice. |
When adding (
push
ing) to an array and then sorting the result, a repeat binding doesn't update correctly.I have created a repro here. I have added a
repeat
binding over a collection to theWelcome
view model. There are a couple buttons below, one to add then sort and one to add without sort. If you use add with sort, you will see the unexpected behavior.The text was updated successfully, but these errors were encountered: