Skip to main content
Question

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!

This topic has been closed for replies.

2 replies

Gleb
  • Power Member
  • 4708 replies
  • October 2, 2023

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.


  • Author
  • 4 replies
  • October 3, 2023

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings