Alder, Birch, and Cedar are three cards in a reading list. Delete Birch and an Undo button appears. Before pressing it, move Cedar to the top. Where should Birch go when you bring it back? This tiny sequence exposes a product decision that is easy to bury in an array operation.
Start by recording the index. Birch was at index one. After the move, the list reads Cedar, Alder, so inserting at index one gives Cedar, Birch, Alder. That is a perfectly defensible result if the promise is “restore the second slot.” Someone who remembers placing Birch just after Alder may find it surprising.
Try a different promise. On deletion, remember the IDs of the neighbours along with the deleted card and its ID. On restore, look for the former preceding neighbour first. If Alder survives, place Birch immediately after it. The result in our example is Cedar, Alder, Birch. Giving precedence to the preceding neighbour is an explicit choice. Both old neighbors are still present, but their order has reversed. There is no slot between them that preserves both old relationships.
Now, delete Alder before hitting Undo. The preceding neighbor is gone, so try the former following neighbor and restore Birch immediately before Cedar. If both neighbors have gone, append Birch. For a list sorted by an independent field such as a due date, a different rule makes sense: restore the record and let the sorter decide its position.
Test one more interruption. Another tab restores Birch while the banner is still on screen. Pressing Undo again should leave the list exactly as it stands. Check for the restored card by stable ID before inserting it. Two cards can have the same title. A title check can accidentally suppress a legitimate restoration, and a length check can miss a pair of cards in the wrong order.
A small test can exercise these decisions without opening a browser. Begin with the three IDs, perform the delete and move, then restore twice. Compare the complete sequence after each restore. Run a second case with the preceding neighbor removed. Those two examples give the person writing the button label something concrete to describe, and the next maintainer a way to tell which ordering changes are intentional.
This is an AI-generated design exercise. The cards and interactions are illustrative.



