Love this style of interactive posts. I recently had to solve the same problem for my own app and did it pretty similarly.
How to build undo/redo in a multiplayer environment by Liveblocks
11–20 of 49 posts
Re: How to build undo/redo in a multiplayer environment by Liveblocks
#12Re: How to build undo/redo in a multiplayer environment by Liveblocks
#13Nice work! Regarding your question on how to handle undoing a command on a shape that doesn't exist anymore, is there a way we could automatically recreate the shape?
Let's imagine that we work together on a design file that contains hundreds of icons. I'm responsible for adjusting the color palette while you're removing the old icons that are not used anymore. If I undo my last color update on all icons, I probably don't want to recreate the icon inadvertently and override the triage you're doing! So IMO, it's more of UX question than a technical question. Is there a better default solution that we can find to improve these edge cases? My initial thought is to have a small "toast" letting the user know that the undo operation couldn't be applied because X does not exist anymore, with a link to the version history panel to allow him to reinsert X if it wants to.
Re: How to build undo/redo in a multiplayer environment by Liveblocks
#14Also, excellent explanation and visualizations :)
Good luck with all of it
Re: How to build undo/redo in a multiplayer environment by Liveblocks
#15So if you undo a change to an object that was delete by a different user, you can restore that object first to the last known state, then apply the undo?
I'm not sure this makes sense for other cases besides object deletion.
Re: How to build undo/redo in a multiplayer environment by Liveblocks
#16Does anyone have an idea what these use cases could be? My mental model for undo/redo is based on productivity applications and I’m at a loss; I’m genuinely curious though since this is something I’ve been implementing.
Re: How to build undo/redo in a multiplayer environment by Liveblocks
#17> Depending on the use case, the state of features like user selection, user page selection, user zoom setting, etc. could be included in the undo/redo stack to provide a great experience. Does anyone have an idea what these use cases could be? My mental model for undo/redo is based on productivity applications and I’m at a loss; I’m genuinely curious though since this is something I’ve been implementing.
Re: How to build undo/redo in a multiplayer environment by Liveblocks
#18Nice to see someone make a product out of Cloudflare Workers (and Durable Objects for sync?). Also, excellent explanation and visualizations :) Good luck with all of it
Re: How to build undo/redo in a multiplayer environment by Liveblocks
#19For deleted items, could you not store a memo of the object in addition to the user-local changes they did? So if you undo a change to an object that was delete by a different user, you can restore that object first to the last known state, then apply the undo? I'm not sure this makes sense for other cases besides object deletion.
But I'm still not sure this is the default behavior that we want, even it's only for deletion. I think it's more of a UX problem than an engineering problem as explained here: https://news.ycombinator.com/item?id=31682073
To take another example, for rich text editing, I don't think undoing a formatting operation on text that has been deleted at the same time should reinsert the text.
Re: How to build undo/redo in a multiplayer environment by Liveblocks
#20> Depending on the use case, the state of features like user selection, user page selection, user zoom setting, etc. could be included in the undo/redo stack to provide a great experience. Does anyone have an idea what these use cases could be? My mental model for undo/redo is based on productivity applications and I’m at a loss; I’m genuinely curious though since this is something I’ve been implementing.
In design tools, like Figma, undo sometimes just walks backwards through your selection (even if you didn't change anything). It'll even switch between pages. I'm interesting in seeing if there are other ones people can bring up
I think reseting the time position would also make sense for video editing.
So basically, it's a way to get back as much as possible in the context you were at the time of the operation that is undone.