You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: When using IonReorder and trying to save the order in state, the list snaps to a different order #28496
I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
v7.x
Current Behavior
I've got an array of arrays stored in state called items, I want to reorder the array of arrays and save it within state with the new order. Instead I seem to get a random order.
Expected Behavior
I expect it to work so that when I reorder the array of arrays, the order stays in that new order and I'm able to save it in state. The order stays how I expect it to only if I get rid of the line where I try to use setItems to save the new order.
Thanks for the issue. I am going to close this as this is not a bug in Ionic Framework. As per the Reorder Updating Data documentation, Ionic will try to reorder the DOM nodes when calling event.detail.complete. This clashes with React's render lifecycle which is why the position appears to be reset. In this case, you should pass false to event.detail.complete to prevent Ionic from reordering the DOM nodes.
Alternatively, you could simplify this code even more by calling setItems(event.detail.complete(items)); which will have Ionic handle reordering the array for you. Passing in the items array will also disable Ionic's automatic DOM reorder behavior.
One other option I forgot to mention is you can use key to assign a stable identity to each element in your loop. Something like this should work too (and let you keep your existing doReorder implementation):
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Activity
liamdebeasi commentedon Nov 9, 2023
Thanks for the issue. I am going to close this as this is not a bug in Ionic Framework. As per the Reorder Updating Data documentation, Ionic will try to reorder the DOM nodes when calling
event.detail.complete. This clashes with React's render lifecycle which is why the position appears to be reset. In this case, you should passfalsetoevent.detail.completeto prevent Ionic from reordering the DOM nodes.Alternatively, you could simplify this code even more by calling
setItems(event.detail.complete(items));which will have Ionic handle reordering the array for you. Passing in theitemsarray will also disable Ionic's automatic DOM reorder behavior.liamdebeasi commentedon Nov 9, 2023
One other option I forgot to mention is you can use
keyto assign a stable identity to each element in your loop. Something like this should work too (and let you keep your existingdoReorderimplementation):edit: I updated the docs to make this clearer: ionic-team/ionic-docs#3239
ionitron-bot commentedon Dec 9, 2023
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.