I have a plugin that is interacting with the REST API to swap an instance’s mainComponent.
The process looks like this:
- Find all instances on the page.
- Enter file key into an input.
- Use REST API to get published components in the file (via the file key).
- For any given instance, search through the published components and if a match is found by name, replace the
mainComponentproperty for that instance with the found component from the file.
The process works fine. However, when I assign the new component to the instance’s
mainComponent field all of the overrides are lost.
BUT if I swap instances with the same exact component in the same exact file using Figma’s Swap Instance UI the overrides are preserved.
I’m assuming that Figma does some extra work behind the scenes to preserve overrides?
I can understand why the overrides are not being preserved when I run my plugin since I’m essentially just replacing an object property with a new one. But I’m wondering if there is something obvious I’m missing? Or if anyone has any suggestions on how to preserve overrides? Would it involve traversing through the instance and recording node settings, and then running those same checks on the new component when it’s assigned to