Deleted components don't flag properly

I have a plugin that deals with saving node ids into my Figma file. I have some functions that update my save data when :

i) a node is deleted when my plugin is running
ii) the node is already removed when the plugin is launched

I’m having some issues with components and their child nodes at the moment. When I delete a component while my plugin is running, the component and its children don’t seem to trigger any documentChange delete events.

Also, if I delete my component then launch my plugin, Figma doesn’t seem to flag its child nodes as deleted ie node.removed is still false, getNodeById(node.id) is not null even though the child node is already gone from the Figma file.

This happens whether I soft-delete ie delete the component but keep any instances to it, or hard-delete aka delete component and all its instances.

Stranger still, Figma does kinda register that I deleted my component i.e. component node and its children don’t show up when I call figma.root.findAll()

Is this behaviour a bug, or is this intended for components?

This might be a bug. Deleting a component should trigger the node deleted event.

This is how components work currently. You can check if main component is removed by using !component.parent && !component.remote condition — if component doesn’t have a parent and it’s not remote, it is “soft-deleted” as you called it. Also if the component doesn’t have any instances attached to it, it should be gone after you reload the file.

thanks, I’ll try your suggestion for now.

i’ll also inform Figma support of a potential bug

It does trigger, but only for components which are direct children of the current page. So say you have a component set on the page, and delete it then delete event will trigger. If you delete a component from a component set it doesn’t because it does not directly have any effect on the page as the count of its children does not change.

1 Like