How to make a deep copy of the figma document?

I need to access the previous state of the document before a user does a change. I thought I could just do a deep copy of the document for now each time the user changes something.

But several things I tried came with issues. the clone function on the currentPage gives the nodes new ids. Lodash did not work either, I could not access “children” on a node anymore for some reason.

Do you have any idea how I could do this?

I think I could do it on each node individually but that feels like an awful solution, not sure yet.

Thanks in advance for any inputs!

The only way is to iterate through all properties manually. This approach isn’t really feasible because it’s very slow and you would run out of memory on large documents.

Ok thank you I see!

Would be so nice if the PROPERTY_CHANGE event would include how exactly something was changed. That would solve all my issues.

So I guess the only thing I can do is to identify all the nodes that I want to track specific things of and update them on each PROPERTY_CHANGE event. I guess it does the job for now.

1 Like