Live data from Hacker News

How to build undo/redo in a multiplayer environment by Liveblocks

liveblocks.io

11–20 of 49 posts

Re: How to build undo/redo in a multiplayer environment by Liveblocks

#13
post #7

Nice 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?

It's technically possible by caching only deleted shapes if any operations in the undo stack are associated with them. But is it really the UX we want every time it's happening?

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

#15
For 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.

Re: How to build undo/redo in a multiplayer environment by Liveblocks

#16
> 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

#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.

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

Re: How to build undo/redo in a multiplayer environment by Liveblocks

#18

Nice 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

Yes! We're using Durable Object under the hood :) Thanks to you for providing such a great platform!

Re: How to build undo/redo in a multiplayer environment by Liveblocks

#19

For 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.

Yes that's good way to implement it!

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
post #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.

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

For rich text editing, undo should probably reset the scroll position and the cursor close the edit you're undoing.

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.

Post reply on HN