Skip to main content
Solved

How to detect when node is deleted

  • June 26, 2023
  • 4 replies
  • 629 views

Hi, my plugin is saving a list of node ids and their corresponding aspect ratios in my root node.

I want the plugin data in my root node to be updated whenever a node is deleted. Are there any events that are triggered whenever a node is deleted? If so, what event handler should I use to handle that?

Best answer by Zack_Hong

Ok, I figured out that I have to handle the documentchange event using figma.on. Then, I need to extract out the array of documentchange objects from the event and check each object to see if they are of type “DELETE” like so:

I had a hard time understanding what you meant until I saw some code examples

This topic has been closed for replies.

4 replies

Gleb
  • Power Member
  • 4716 replies
  • June 26, 2023

  • Author
  • 30 replies
  • June 26, 2023

Where would the deleteChange event be handled? I tried to handle it using figma.on() but it doesn’t work


Gleb
  • Power Member
  • 4716 replies
  • June 26, 2023

There is no such thing as deleteChange:

All available events are listed above. I sent 3 links to the documentchange event so… that’s the one you should use. DocumentChange events have the following types (again, as shown in the links I sent):


  • Author
  • 30 replies
  • Answer
  • June 26, 2023

Ok, I figured out that I have to handle the documentchange event using figma.on. Then, I need to extract out the array of documentchange objects from the event and check each object to see if they are of type “DELETE” like so:

I had a hard time understanding what you meant until I saw some code examples